Browse Source

Moved history page creation to separate class

master
Anthony Restaino 10 years ago
parent
commit
aa49c7b848
  1. 47
      src/acr/browser/lightning/BrowserActivity.java
  2. 59
      src/acr/browser/lightning/HistoryPage.java
  3. 21
      src/acr/browser/lightning/HistoryPageVariables.java

47
src/acr/browser/lightning/BrowserActivity.java

@ -1834,45 +1834,16 @@ public class BrowserActivity extends Activity implements BrowserController {
return bookmarks; return bookmarks;
} }
/**
* returns a list of HistoryItems
*/
private List<HistoryItem> getLatestHistory() {
HistoryDatabaseHandler historyHandler = new HistoryDatabaseHandler(mContext);
return historyHandler.getLastHundredItems();
}
/** /**
* function that opens the HTML history page in the browser * function that opens the HTML history page in the browser
*/ */
private void openHistory() { private void openHistory() {
// use a thread so that history retrieval doesn't block the UI
Thread history = new Thread(new Runnable() { Thread history = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
String historyHtml = HistoryPageVariables.Heading; mCurrentView.loadUrl(HistoryPage.getHistoryPage(mContext));
List<HistoryItem> historyList = getLatestHistory();
Iterator<HistoryItem> it = historyList.iterator();
HistoryItem helper;
while (it.hasNext()) {
helper = it.next();
historyHtml += HistoryPageVariables.Part1 + helper.getUrl()
+ HistoryPageVariables.Part2 + helper.getTitle()
+ HistoryPageVariables.Part3 + helper.getUrl()
+ HistoryPageVariables.Part4;
}
historyHtml += HistoryPageVariables.End;
File historyWebPage = new File(getFilesDir(), "history.html");
try {
FileWriter hWriter = new FileWriter(historyWebPage, false);
hWriter.write(historyHtml);
hWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
mCurrentView.loadUrl(Constants.FILE + historyWebPage);
mSearch.setText(""); mSearch.setText("");
} }
@ -1900,17 +1871,17 @@ public class BrowserActivity extends Activity implements BrowserController {
* open the HTML bookmarks page, parameter view is the WebView that should show the page * open the HTML bookmarks page, parameter view is the WebView that should show the page
*/ */
public void openBookmarkPage(WebView view) { public void openBookmarkPage(WebView view) {
String bookmarkHtml = BookmarkPageVariables.Heading; String bookmarkHtml = BookmarkPage.HEADING;
Iterator<HistoryItem> iter = mBookmarkList.iterator(); Iterator<HistoryItem> iter = mBookmarkList.iterator();
HistoryItem helper; HistoryItem helper;
while (iter.hasNext()) { while (iter.hasNext()) {
helper = iter.next(); helper = iter.next();
bookmarkHtml += (BookmarkPageVariables.Part1 + helper.getUrl() bookmarkHtml += (BookmarkPage.PART1 + helper.getUrl()
+ BookmarkPageVariables.Part2 + helper.getUrl() + BookmarkPageVariables.Part3 + BookmarkPage.PART2 + helper.getUrl() + BookmarkPage.PART3
+ helper.getTitle() + BookmarkPageVariables.Part4); + helper.getTitle() + BookmarkPage.PART4);
} }
bookmarkHtml += BookmarkPageVariables.End; bookmarkHtml += BookmarkPage.END;
File bookmarkWebPage = new File(mContext.getFilesDir(), "bookmarks.html"); File bookmarkWebPage = new File(mContext.getFilesDir(), BookmarkPage.FILENAME);
try { try {
FileWriter bookWriter = new FileWriter(bookmarkWebPage, false); FileWriter bookWriter = new FileWriter(bookmarkWebPage, false);
bookWriter.write(bookmarkHtml); bookWriter.write(bookmarkHtml);
@ -1980,7 +1951,7 @@ public class BrowserActivity extends Activity implements BrowserController {
Intent i = new Intent(Intent.ACTION_GET_CONTENT); Intent i = new Intent(Intent.ACTION_GET_CONTENT);
i.addCategory(Intent.CATEGORY_OPENABLE); i.addCategory(Intent.CATEGORY_OPENABLE);
i.setType("*/*"); i.setType("*/*");
startActivityForResult(Intent.createChooser(i, "File Chooser"), 1); startActivityForResult(Intent.createChooser(i, getString(R.string.title_file_chooser)), 1);
} }
@Override @Override

59
src/acr/browser/lightning/HistoryPage.java

@ -0,0 +1,59 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import android.content.Context;
public class HistoryPage {
private static final String FILENAME = "history.html";
private static final String HEADING = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>"
+ BrowserApp.getAppContext().getString(R.string.action_history)
+ "</title></head><style>body { background: #e1e1e1;}.box { vertical-align:middle;position:relative; display: block; margin: 10px;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:5px; background-color:#fff;box-shadow: 0px 3px rgba( 0, 0, 0, 0.1 );font-family: Arial;color: #444;font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;border-radius: 2px;}.box a { width: 100%; height: 100%; position: absolute; left: 0; top: 0;}.black {color: black;font-size: 15px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}.font {color: gray;font-size: 10px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}</style><body><div id=\"content\">";
private static final String PART1 = "<div class=\"box\"><a href=\"";
private static final String PART2 = "\"></a><p class=\"black\">";
private static final String PART3 = "</p><p class=\"font\">";
private static final String PART4 = "</p></div></div>";
private static final String END = "</div></body></html>";
public static String getHistoryPage(Context context) {
String historyHtml = HistoryPage.HEADING;
List<HistoryItem> historyList = getWebHistory(context);
Iterator<HistoryItem> it = historyList.iterator();
HistoryItem helper;
while (it.hasNext()) {
helper = it.next();
historyHtml += HistoryPage.PART1 + helper.getUrl() + HistoryPage.PART2
+ helper.getTitle() + HistoryPage.PART3 + helper.getUrl() + HistoryPage.PART4;
}
historyHtml += HistoryPage.END;
File historyWebPage = new File(context.getFilesDir(), FILENAME);
try {
FileWriter historyWriter = new FileWriter(historyWebPage, false);
historyWriter.write(historyHtml);
historyWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
return Constants.FILE + historyWebPage;
}
private static List<HistoryItem> getWebHistory(Context context) {
HistoryDatabaseHandler databaseHandler = new HistoryDatabaseHandler(context);
return databaseHandler.getLastHundredItems();
}
}

21
src/acr/browser/lightning/HistoryPageVariables.java

@ -1,21 +0,0 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning;
public class HistoryPageVariables {
public static final String Heading = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta content=\"en-us\" http-equiv=\"Content-Language\" /><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" /><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>"
+ BrowserApp.getAppContext().getString(R.string.action_history)
+ "</title></head><style>body { background: #e1e1e1;}.box { vertical-align:middle;position:relative; display: block; margin: 10px;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:5px; background-color:#fff;box-shadow: 0px 3px rgba( 0, 0, 0, 0.1 );font-family: Arial;color: #444;font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;border-radius: 2px;}.box a { width: 100%; height: 100%; position: absolute; left: 0; top: 0;}.black {color: black;font-size: 15px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}.font {color: gray;font-size: 10px;font-family: Arial; white-space: nowrap; overflow: hidden;margin:auto; text-overflow: ellipsis; -o-text-overflow: ellipsis; -ms-text-overflow: ellipsis;}</style><body><div id=\"content\">";
public static final String Part1 = "<div class=\"box\"><a href=\"";
public static final String Part2 = "\"></a><p class=\"black\">";
public static final String Part3 = "</p><p class=\"font\">";
public static final String Part4 = "</p></div></div>";
public static final String End = "</div></body></html>";
}
Loading…
Cancel
Save