Browse Source

Optimize webpage builders, fixed bug in bookmark activity

master
Anthony Restaino 10 years ago
parent
commit
be3a59c74c
  1. 3
      src/acr/browser/lightning/BookmarkActivity.java
  2. 18
      src/acr/browser/lightning/BrowserActivity.java
  3. 19
      src/acr/browser/lightning/HistoryPage.java
  4. 2
      src/acr/browser/lightning/HomepageVariables.java
  5. 86
      src/acr/browser/lightning/LightningView.java
  6. 2
      src/acr/browser/lightning/PreferenceManager.java

3
src/acr/browser/lightning/BookmarkActivity.java

@ -45,7 +45,8 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable); TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable);
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext()); mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
mPreferences = PreferenceManager.getInstance();
mSystemBrowser = mPreferences.getSystemBrowserPresent(); mSystemBrowser = mPreferences.getSystemBrowserPresent();
exportBackup.setOnClickListener(this); exportBackup.setOnClickListener(this);

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

@ -1917,19 +1917,25 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* 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 = BookmarkPage.HEADING; StringBuilder bookmarkBuilder = new StringBuilder();
bookmarkBuilder.append(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 += (BookmarkPage.PART1 + helper.getUrl() + BookmarkPage.PART2 bookmarkBuilder.append(BookmarkPage.PART1);
+ helper.getUrl() + BookmarkPage.PART3 + helper.getTitle() + BookmarkPage.PART4); bookmarkBuilder.append(helper.getUrl());
} bookmarkBuilder.append(BookmarkPage.PART2);
bookmarkHtml += BookmarkPage.END; bookmarkBuilder.append(helper.getUrl());
bookmarkBuilder.append(BookmarkPage.PART3);
bookmarkBuilder.append(helper.getTitle());
bookmarkBuilder.append(BookmarkPage.PART4);
}
bookmarkBuilder.append(BookmarkPage.END);
File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME); File bookmarkWebPage = new File(mActivity.getFilesDir(), BookmarkPage.FILENAME);
try { try {
FileWriter bookWriter = new FileWriter(bookmarkWebPage, false); FileWriter bookWriter = new FileWriter(bookmarkWebPage, false);
bookWriter.write(bookmarkHtml); bookWriter.write(bookmarkBuilder.toString());
bookWriter.close(); bookWriter.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

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

@ -30,21 +30,27 @@ public class HistoryPage {
private static final String END = "</div></body></html>"; private static final String END = "</div></body></html>";
public static String getHistoryPage(Context context) { public static String getHistoryPage(Context context) {
String historyHtml = HistoryPage.HEADING; StringBuilder historyBuilder = new StringBuilder();
historyBuilder.append(HistoryPage.HEADING);
List<HistoryItem> historyList = getWebHistory(context); List<HistoryItem> historyList = getWebHistory(context);
Iterator<HistoryItem> it = historyList.iterator(); Iterator<HistoryItem> it = historyList.iterator();
HistoryItem helper; HistoryItem helper;
while (it.hasNext()) { while (it.hasNext()) {
helper = it.next(); helper = it.next();
historyHtml += HistoryPage.PART1 + helper.getUrl() + HistoryPage.PART2 historyBuilder.append(HistoryPage.PART1);
+ helper.getTitle() + HistoryPage.PART3 + helper.getUrl() + HistoryPage.PART4; historyBuilder.append(helper.getUrl());
historyBuilder.append(HistoryPage.PART2);
historyBuilder.append(helper.getTitle());
historyBuilder.append(HistoryPage.PART3);
historyBuilder.append(helper.getUrl());
historyBuilder.append(HistoryPage.PART4);
} }
historyHtml += HistoryPage.END; historyBuilder.append(HistoryPage.END);
File historyWebPage = new File(context.getFilesDir(), FILENAME); File historyWebPage = new File(context.getFilesDir(), FILENAME);
try { try {
FileWriter historyWriter = new FileWriter(historyWebPage, false); FileWriter historyWriter = new FileWriter(historyWebPage, false);
historyWriter.write(historyHtml); historyWriter.write(historyBuilder.toString());
historyWriter.close(); historyWriter.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -53,7 +59,8 @@ public class HistoryPage {
} }
private static List<HistoryItem> getWebHistory(Context context) { private static List<HistoryItem> getWebHistory(Context context) {
HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context.getApplicationContext()); HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context
.getApplicationContext());
return databaseHandler.getLastHundredItems(); return databaseHandler.getLastHundredItems();
} }
} }

2
src/acr/browser/lightning/HomepageVariables.java

@ -22,7 +22,7 @@ public class HomepageVariables {
+ "#search_submit{outline:none;height:37px;float:right;color:#404040;font-size:16px;font-weight:bold;border:none;" + "#search_submit{outline:none;height:37px;float:right;color:#404040;font-size:16px;font-weight:bold;border:none;"
+ "background-color:transparent;}.outer { display: table; position: absolute; height: 100%; width: 100%;}" + "background-color:transparent;}.outer { display: table; position: absolute; height: 100%; width: 100%;}"
+ ".middle { display: table-cell; vertical-align: middle;}.inner { margin-left: auto; margin-right: auto; " + ".middle { display: table-cell; vertical-align: middle;}.inner { margin-left: auto; margin-right: auto; "
+ "margin-bottom:10%; <!-->maybe bad for small screens</!--> width: 100%;}img.smaller{width:50%;max-width:300px;}" + "margin-bottom:10%; width: 100%;}img.smaller{width:50%;max-width:300px;}"
+ ".box { vertical-align:middle;position:relative; display: block; margin: 10px;padding-left:10px;padding-right:10px;padding-top:5px;padding-bottom:5px;" + ".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;" + " 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;" + "font-size: 12px;-moz-border-radius: 2px;-webkit-border-radius: 2px;"

86
src/acr/browser/lightning/LightningView.java

@ -146,97 +146,91 @@ public class LightningView {
} }
public String getHomepage() { public String getHomepage() {
String home; StringBuilder homepageBuilder = new StringBuilder();
home = HomepageVariables.HEAD; homepageBuilder.append(HomepageVariables.HEAD);
String icon;
String searchUrl;
switch (mPreferences.getSearchChoice()) { switch (mPreferences.getSearchChoice()) {
case 0: case 0:
// CUSTOM SEARCH // CUSTOM SEARCH
home = home + "file:///android_asset/lightning.png"; icon = "file:///android_asset/lightning.png";
home = home + HomepageVariables.MIDDLE; searchUrl = mPreferences.getSearchUrl();
home = home + mPreferences.getSearchUrl();
break; break;
case 1: case 1:
// GOOGLE_SEARCH; // GOOGLE_SEARCH;
home = home + "file:///android_asset/google.png"; icon = "file:///android_asset/google.png";
// + "https://www.google.com/images/srpr/logo11w.png"; // "https://www.google.com/images/srpr/logo11w.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.GOOGLE_SEARCH;
home = home + Constants.GOOGLE_SEARCH;
break; break;
case 2: case 2:
// ANDROID SEARCH; // ANDROID SEARCH;
home = home + "file:///android_asset/ask.png"; icon = "file:///android_asset/ask.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.ASK_SEARCH;
home = home + Constants.ASK_SEARCH;
break; break;
case 3: case 3:
// BING_SEARCH; // BING_SEARCH;
home = home + "file:///android_asset/bing.png"; icon = "file:///android_asset/bing.png";
// +
// "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png"; // "http://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Bing_logo_%282013%29.svg/500px-Bing_logo_%282013%29.svg.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.BING_SEARCH;
home = home + Constants.BING_SEARCH;
break; break;
case 4: case 4:
// YAHOO_SEARCH; // YAHOO_SEARCH;
home = home + "file:///android_asset/yahoo.png"; icon = "file:///android_asset/yahoo.png";
// +
// "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png"; // "http://upload.wikimedia.org/wikipedia/commons/thumb/2/24/Yahoo%21_logo.svg/799px-Yahoo%21_logo.svg.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.YAHOO_SEARCH;
home = home + Constants.YAHOO_SEARCH;
break; break;
case 5: case 5:
// STARTPAGE_SEARCH; // STARTPAGE_SEARCH;
home = home + "file:///android_asset/startpage.png"; icon = "file:///android_asset/startpage.png";
// + "https://startpage.com/graphics/startp_logo.gif"; // "https://startpage.com/graphics/startp_logo.gif";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.STARTPAGE_SEARCH;
home = home + Constants.STARTPAGE_SEARCH;
break; break;
case 6: case 6:
// STARTPAGE_MOBILE // STARTPAGE_MOBILE
home = home + "file:///android_asset/startpage.png"; icon = "file:///android_asset/startpage.png";
// + "https://startpage.com/graphics/startp_logo.gif"; // "https://startpage.com/graphics/startp_logo.gif";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.STARTPAGE_MOBILE_SEARCH;
home = home + Constants.STARTPAGE_MOBILE_SEARCH;
case 7: case 7:
// DUCK_SEARCH; // DUCK_SEARCH;
home = home + "file:///android_asset/duckduckgo.png"; icon = "file:///android_asset/duckduckgo.png";
// +
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.DUCK_SEARCH;
home = home + Constants.DUCK_SEARCH;
break; break;
case 8: case 8:
// DUCK_LITE_SEARCH; // DUCK_LITE_SEARCH;
home = home + "file:///android_asset/duckduckgo.png"; icon = "file:///android_asset/duckduckgo.png";
// +
// "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.DUCK_LITE_SEARCH;
home = home + Constants.DUCK_LITE_SEARCH;
break; break;
case 9: case 9:
// BAIDU_SEARCH; // BAIDU_SEARCH;
home = home + "file:///android_asset/baidu.png"; icon = "file:///android_asset/baidu.png";
// + "http://www.baidu.com/img/bdlogo.gif"; // "http://www.baidu.com/img/bdlogo.gif";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.BAIDU_SEARCH;
home = home + Constants.BAIDU_SEARCH;
break; break;
case 10: case 10:
// YANDEX_SEARCH; // YANDEX_SEARCH;
home = home + "file:///android_asset/yandex.png"; icon = "file:///android_asset/yandex.png";
// +
// "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png"; // "http://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Yandex.svg/600px-Yandex.svg.png";
home = home + HomepageVariables.MIDDLE; searchUrl = Constants.YANDEX_SEARCH;
home = home + Constants.YANDEX_SEARCH; break;
default:
// DEFAULT GOOGLE_SEARCH;
icon = "file:///android_asset/google.png";
searchUrl = Constants.GOOGLE_SEARCH;
break; break;
} }
home = home + HomepageVariables.END; homepageBuilder.append(icon);
homepageBuilder.append(HomepageVariables.MIDDLE);
homepageBuilder.append(searchUrl);
homepageBuilder.append(HomepageVariables.END);
File homepage = new File(mActivity.getFilesDir(), "homepage.html"); File homepage = new File(mActivity.getFilesDir(), "homepage.html");
try { try {
FileWriter hWriter = new FileWriter(homepage, false); FileWriter hWriter = new FileWriter(homepage, false);
hWriter.write(home); hWriter.write(homepageBuilder.toString());
hWriter.close(); hWriter.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

2
src/acr/browser/lightning/PreferenceManager.java

@ -5,7 +5,7 @@ import android.os.Environment;
public class PreferenceManager { public class PreferenceManager {
private class Name { private static class Name {
public static final String ADOBE_FLASH_SUPPORT = "enableflash"; public static final String ADOBE_FLASH_SUPPORT = "enableflash";
public static final String BLOCK_ADS = "AdBlock"; public static final String BLOCK_ADS = "AdBlock";
public static final String BLOCK_IMAGES = "blockimages"; public static final String BLOCK_IMAGES = "blockimages";

Loading…
Cancel
Save