From be3a59c74c28642fcaf16da2d58f0d599f21f020 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Sat, 18 Apr 2015 15:34:40 -0400 Subject: [PATCH] Optimize webpage builders, fixed bug in bookmark activity --- .../browser/lightning/BookmarkActivity.java | 3 +- .../browser/lightning/BrowserActivity.java | 18 ++-- src/acr/browser/lightning/HistoryPage.java | 19 ++-- .../browser/lightning/HomepageVariables.java | 2 +- src/acr/browser/lightning/LightningView.java | 86 +++++++++---------- .../browser/lightning/PreferenceManager.java | 2 +- 6 files changed, 69 insertions(+), 61 deletions(-) diff --git a/src/acr/browser/lightning/BookmarkActivity.java b/src/acr/browser/lightning/BookmarkActivity.java index f549b3b..592dbfc 100644 --- a/src/acr/browser/lightning/BookmarkActivity.java +++ b/src/acr/browser/lightning/BookmarkActivity.java @@ -45,7 +45,8 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic TextView importBookmarks = (TextView) findViewById(R.id.isImportBrowserAvailable); mBookmarkManager = BookmarkManager.getInstance(getApplicationContext()); - + mPreferences = PreferenceManager.getInstance(); + mSystemBrowser = mPreferences.getSystemBrowserPresent(); exportBackup.setOnClickListener(this); diff --git a/src/acr/browser/lightning/BrowserActivity.java b/src/acr/browser/lightning/BrowserActivity.java index 3ee9b00..e59fd41 100644 --- a/src/acr/browser/lightning/BrowserActivity.java +++ b/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 */ public void openBookmarkPage(WebView view) { - String bookmarkHtml = BookmarkPage.HEADING; + StringBuilder bookmarkBuilder = new StringBuilder(); + bookmarkBuilder.append(BookmarkPage.HEADING); Iterator iter = mBookmarkList.iterator(); HistoryItem helper; while (iter.hasNext()) { helper = iter.next(); - bookmarkHtml += (BookmarkPage.PART1 + helper.getUrl() + BookmarkPage.PART2 - + helper.getUrl() + BookmarkPage.PART3 + helper.getTitle() + BookmarkPage.PART4); - } - bookmarkHtml += BookmarkPage.END; + bookmarkBuilder.append(BookmarkPage.PART1); + bookmarkBuilder.append(helper.getUrl()); + bookmarkBuilder.append(BookmarkPage.PART2); + 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); try { FileWriter bookWriter = new FileWriter(bookmarkWebPage, false); - bookWriter.write(bookmarkHtml); + bookWriter.write(bookmarkBuilder.toString()); bookWriter.close(); } catch (IOException e) { e.printStackTrace(); diff --git a/src/acr/browser/lightning/HistoryPage.java b/src/acr/browser/lightning/HistoryPage.java index a087e52..2ec79d8 100644 --- a/src/acr/browser/lightning/HistoryPage.java +++ b/src/acr/browser/lightning/HistoryPage.java @@ -30,21 +30,27 @@ public class HistoryPage { private static final String END = ""; public static String getHistoryPage(Context context) { - String historyHtml = HistoryPage.HEADING; + StringBuilder historyBuilder = new StringBuilder(); + historyBuilder.append(HistoryPage.HEADING); List historyList = getWebHistory(context); Iterator 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; + historyBuilder.append(HistoryPage.PART1); + 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); try { FileWriter historyWriter = new FileWriter(historyWebPage, false); - historyWriter.write(historyHtml); + historyWriter.write(historyBuilder.toString()); historyWriter.close(); } catch (IOException e) { e.printStackTrace(); @@ -53,7 +59,8 @@ public class HistoryPage { } private static List getWebHistory(Context context) { - HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context.getApplicationContext()); + HistoryDatabase databaseHandler = HistoryDatabase.getInstance(context + .getApplicationContext()); return databaseHandler.getLastHundredItems(); } } diff --git a/src/acr/browser/lightning/HomepageVariables.java b/src/acr/browser/lightning/HomepageVariables.java index 185b8be..de59fa1 100644 --- a/src/acr/browser/lightning/HomepageVariables.java +++ b/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;" + "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; " - + "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;" + " 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;" diff --git a/src/acr/browser/lightning/LightningView.java b/src/acr/browser/lightning/LightningView.java index 901a39f..51fba7e 100644 --- a/src/acr/browser/lightning/LightningView.java +++ b/src/acr/browser/lightning/LightningView.java @@ -146,97 +146,91 @@ public class LightningView { } public String getHomepage() { - String home; - home = HomepageVariables.HEAD; + StringBuilder homepageBuilder = new StringBuilder(); + homepageBuilder.append(HomepageVariables.HEAD); + String icon; + String searchUrl; switch (mPreferences.getSearchChoice()) { case 0: // CUSTOM SEARCH - home = home + "file:///android_asset/lightning.png"; - home = home + HomepageVariables.MIDDLE; - home = home + mPreferences.getSearchUrl(); + icon = "file:///android_asset/lightning.png"; + searchUrl = mPreferences.getSearchUrl(); break; case 1: // GOOGLE_SEARCH; - home = home + "file:///android_asset/google.png"; - // + "https://www.google.com/images/srpr/logo11w.png"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.GOOGLE_SEARCH; + icon = "file:///android_asset/google.png"; + // "https://www.google.com/images/srpr/logo11w.png"; + searchUrl = Constants.GOOGLE_SEARCH; break; case 2: // ANDROID SEARCH; - home = home + "file:///android_asset/ask.png"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.ASK_SEARCH; + icon = "file:///android_asset/ask.png"; + searchUrl = Constants.ASK_SEARCH; break; case 3: // 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"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.BING_SEARCH; + searchUrl = Constants.BING_SEARCH; break; case 4: // 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"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.YAHOO_SEARCH; + searchUrl = Constants.YAHOO_SEARCH; break; case 5: // STARTPAGE_SEARCH; - home = home + "file:///android_asset/startpage.png"; - // + "https://startpage.com/graphics/startp_logo.gif"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.STARTPAGE_SEARCH; + icon = "file:///android_asset/startpage.png"; + // "https://startpage.com/graphics/startp_logo.gif"; + searchUrl = Constants.STARTPAGE_SEARCH; break; case 6: // STARTPAGE_MOBILE - home = home + "file:///android_asset/startpage.png"; - // + "https://startpage.com/graphics/startp_logo.gif"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.STARTPAGE_MOBILE_SEARCH; + icon = "file:///android_asset/startpage.png"; + // "https://startpage.com/graphics/startp_logo.gif"; + searchUrl = Constants.STARTPAGE_MOBILE_SEARCH; case 7: // DUCK_SEARCH; - home = home + "file:///android_asset/duckduckgo.png"; - // + + icon = "file:///android_asset/duckduckgo.png"; // "https://duckduckgo.com/assets/logo_homepage.normal.v101.png"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.DUCK_SEARCH; + searchUrl = Constants.DUCK_SEARCH; break; case 8: // 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"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.DUCK_LITE_SEARCH; + searchUrl = Constants.DUCK_LITE_SEARCH; break; case 9: // BAIDU_SEARCH; - home = home + "file:///android_asset/baidu.png"; - // + "http://www.baidu.com/img/bdlogo.gif"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.BAIDU_SEARCH; + icon = "file:///android_asset/baidu.png"; + // "http://www.baidu.com/img/bdlogo.gif"; + searchUrl = Constants.BAIDU_SEARCH; break; case 10: // 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"; - home = home + HomepageVariables.MIDDLE; - home = home + Constants.YANDEX_SEARCH; + searchUrl = Constants.YANDEX_SEARCH; + break; + default: + // DEFAULT GOOGLE_SEARCH; + icon = "file:///android_asset/google.png"; + searchUrl = Constants.GOOGLE_SEARCH; 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"); try { FileWriter hWriter = new FileWriter(homepage, false); - hWriter.write(home); + hWriter.write(homepageBuilder.toString()); hWriter.close(); } catch (IOException e) { e.printStackTrace(); diff --git a/src/acr/browser/lightning/PreferenceManager.java b/src/acr/browser/lightning/PreferenceManager.java index fd98465..e4a9f15 100644 --- a/src/acr/browser/lightning/PreferenceManager.java +++ b/src/acr/browser/lightning/PreferenceManager.java @@ -5,7 +5,7 @@ import android.os.Environment; public class PreferenceManager { - private class Name { + private static class Name { public static final String ADOBE_FLASH_SUPPORT = "enableflash"; public static final String BLOCK_ADS = "AdBlock"; public static final String BLOCK_IMAGES = "blockimages";