From 3b13999b03f9002e0b3c89d253e4f07b61e8fd63 Mon Sep 17 00:00:00 2001 From: Anthony Restaino Date: Mon, 3 Aug 2015 22:33:11 -0400 Subject: [PATCH] Added text encoding setting, updated support libraries --- app/app.iml | 18 ++++----- app/build.gradle | 16 +++----- .../browser/lightning/constant/Constants.java | 6 ++- .../fragment/AdvancedSettingsFragment.java | 38 ++++++++++++++++++- .../preference/PreferenceManager.java | 15 ++++++-- .../browser/lightning/view/LightningView.java | 7 +--- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/preference_advanced.xml | 11 ++++-- 8 files changed, 78 insertions(+), 34 deletions(-) diff --git a/app/app.iml b/app/app.iml index 2bb4528..aa58656 100644 --- a/app/app.iml +++ b/app/app.iml @@ -92,10 +92,10 @@ - - - - + + + + @@ -114,13 +114,13 @@ + - - - - - + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 6afc2c7..ba998b2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,13 +3,11 @@ apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" - defaultConfig { minSdkVersion 14 targetSdkVersion 22 - versionName "4.0.10a" + versionName "4.1.0a" } - buildTypes { debug { minifyEnabled false @@ -23,32 +21,28 @@ android { proguardFiles 'proguard-project.txt' } } - productFlavors { lightningPlus { buildConfigField "boolean", "FULL_VERSION", "true" applicationId "acr.browser.lightning" - versionCode 78 + versionCode 79 } - lightningLite { buildConfigField "boolean", "FULL_VERSION", "false" applicationId "acr.browser.barebones" versionCode 81 } } - lintOptions { abortOnError false } } dependencies { - compile 'com.android.support:palette-v7:22.2.0' - compile 'com.android.support:appcompat-v7:22.2.0' - compile 'com.android.support:design:22.2.0' + compile 'com.android.support:palette-v7:22.2.1' + compile 'com.android.support:appcompat-v7:22.2.1' + compile 'com.android.support:design:22.2.1' compile 'org.jsoup:jsoup:1.8.1' - // Only Lightning Plus needs the proxy libraries lightningPlusCompile 'net.i2p.android:client:0.7' lightningPlusCompile(project(':libnetcipher')) diff --git a/app/src/main/java/acr/browser/lightning/constant/Constants.java b/app/src/main/java/acr/browser/lightning/constant/Constants.java index 7c635ae..11d9457 100644 --- a/app/src/main/java/acr/browser/lightning/constant/Constants.java +++ b/app/src/main/java/acr/browser/lightning/constant/Constants.java @@ -13,7 +13,7 @@ public final class Constants { } public static final boolean FULL_VERSION = BuildConfig.FULL_VERSION; - + public static final String DESKTOP_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36"; public static final String MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; U; Android 4.4; en-us; Nexus 4 Build/JOP24G) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"; public static final String YAHOO_SEARCH = "https://search.yahoo.com/search?p="; @@ -46,4 +46,8 @@ public final class Constants { public static final int PROXY_ORBOT = 1; public static final int PROXY_I2P = 2; public static final int PROXY_MANUAL = 3; + + public static final String DEFAULT_ENCODING = "UTF-8"; + + public static final String[] TEXT_ENCODINGS = {"ISO-8859-1", "UTF-8", "GBK", "Big5", "ISO-2022-JP", "SHIFT_JS", "EUC-JP", "EUC-KR"}; } diff --git a/app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java b/app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java index 7d0df2c..b361506 100644 --- a/app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java +++ b/app/src/main/java/acr/browser/lightning/fragment/AdvancedSettingsFragment.java @@ -11,7 +11,12 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.support.v7.app.AlertDialog; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import acr.browser.lightning.R; +import acr.browser.lightning.constant.Constants; import acr.browser.lightning.preference.PreferenceManager; public class AdvancedSettingsFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { @@ -22,11 +27,12 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref private static final String SETTINGS_RESTORETABS = "restore_tabs"; private static final String SETTINGS_RENDERINGMODE = "rendering_mode"; private static final String SETTINGS_URLCONTENT = "url_contents"; + private static final String SETTINGS_TEXTENCODING = "text_encoding"; private Activity mActivity; private PreferenceManager mPreferences; private CheckBoxPreference cbAllowPopups, cbenablecookies, cbcookiesInkognito, cbrestoreTabs; - private Preference renderingmode, urlcontent; + private Preference renderingmode, urlcontent, textEncoding; private CharSequence[] mUrlOptions; @Override @@ -45,6 +51,7 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref mPreferences = PreferenceManager.getInstance(); renderingmode = findPreference(SETTINGS_RENDERINGMODE); + textEncoding = findPreference(SETTINGS_TEXTENCODING); urlcontent = findPreference(SETTINGS_URLCONTENT); cbAllowPopups = (CheckBoxPreference) findPreference(SETTINGS_NEWWINDOW); cbenablecookies = (CheckBoxPreference) findPreference(SETTINGS_ENABLECOOKIES); @@ -52,6 +59,7 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref cbrestoreTabs = (CheckBoxPreference) findPreference(SETTINGS_RESTORETABS); renderingmode.setOnPreferenceClickListener(this); + textEncoding.setOnPreferenceClickListener(this); urlcontent.setOnPreferenceClickListener(this); cbAllowPopups.setOnPreferenceChangeListener(this); cbenablecookies.setOnPreferenceChangeListener(this); @@ -73,6 +81,8 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref break; } + textEncoding.setSummary(mPreferences.getTextEncoding()); + mUrlOptions = getResources().getStringArray(R.array.url_content_array); int option = mPreferences.getUrlBoxContentChoice(); urlcontent.setSummary(mUrlOptions[option]); @@ -92,6 +102,9 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref case SETTINGS_URLCONTENT: urlBoxPicker(); return true; + case SETTINGS_TEXTENCODING: + textEncodingPicker(); + return true; default: return false; } @@ -162,6 +175,29 @@ public class AdvancedSettingsFragment extends PreferenceFragment implements Pref picker.show(); } + private void textEncodingPicker() { + AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); + picker.setTitle(getResources().getString(R.string.text_encoding)); + final List textEncodingList = Arrays.asList(Constants.TEXT_ENCODINGS); + int n = textEncodingList.indexOf(mPreferences.getTextEncoding()); + + picker.setSingleChoiceItems(Constants.TEXT_ENCODINGS, n, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mPreferences.setTextEncoding(Constants.TEXT_ENCODINGS[which]); + textEncoding.setSummary(Constants.TEXT_ENCODINGS[which]); + } + }); + picker.setNeutralButton(getResources().getString(R.string.action_ok), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }); + picker.show(); + } + private void urlBoxPicker() { AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); picker.setTitle(getResources().getString(R.string.url_contents)); diff --git a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java index 0a863e2..2e01414 100644 --- a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java +++ b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java @@ -47,6 +47,7 @@ public class PreferenceManager { public static final String READING_TEXT_SIZE = "readingTextSize"; public static final String THEME = "Theme"; public static final String DEFAULT_BOOKMARKS = "defaultBookmarks"; + public static final String TEXT_ENCODING = "textEncoding"; public static final String USE_PROXY = "useProxy"; public static final String PROXY_CHOICE = "proxyChoice"; @@ -248,6 +249,10 @@ public class PreferenceManager { return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true); } + public String getTextEncoding() { + return mPrefs.getString(Name.TEXT_ENCODING, Constants.DEFAULT_ENCODING); + } + private void putBoolean(String name, boolean value) { mPrefs.edit().putBoolean(name, value).apply(); } @@ -260,6 +265,10 @@ public class PreferenceManager { mPrefs.edit().putString(name, value).apply(); } + public void setTextEncoding(String encoding) { + putString(Name.TEXT_ENCODING, encoding); + } + public void setAdBlockEnabled(boolean enable) { putBoolean(Name.BLOCK_ADS, enable); } @@ -411,9 +420,9 @@ public class PreferenceManager { /** * Valid choices: *
    - *
  • {@link Constants#NO_PROXY}
  • - *
  • {@link Constants#PROXY_ORBOT}
  • - *
  • {@link Constants#PROXY_I2P}
  • + *
  • {@link Constants#NO_PROXY}
  • + *
  • {@link Constants#PROXY_ORBOT}
  • + *
  • {@link Constants#PROXY_I2P}
  • *
* * @param choice the proxy to use. diff --git a/app/src/main/java/acr/browser/lightning/view/LightningView.java b/app/src/main/java/acr/browser/lightning/view/LightningView.java index c4a9165..bb06c15 100644 --- a/app/src/main/java/acr/browser/lightning/view/LightningView.java +++ b/app/src/main/java/acr/browser/lightning/view/LightningView.java @@ -252,10 +252,10 @@ public class LightningView { return Constants.FILE + homepage; } - @SuppressWarnings("deprecation") - @SuppressLint({"NewApi", "SetJavaScriptEnabled"}) public synchronized void initializePreferences(Context context) { mPreferences = PreferenceManager.getInstance(); + + mSettings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); mHomepage = mPreferences.getHomepage(); mAdBlock.updatePreference(); if (mSettings == null && mWebView != null) { @@ -353,8 +353,6 @@ public class LightningView { } } - @SuppressWarnings("deprecation") - @SuppressLint({"SetJavaScriptEnabled", "NewApi"}) private void initializeSettings(WebSettings settings, Context context) { if (API < Build.VERSION_CODES.JELLY_BEAN_MR2) { settings.setAppCacheMaxSize(Long.MAX_VALUE); @@ -380,7 +378,6 @@ public class LightningView { settings.setDisplayZoomControls(false); settings.setAllowContentAccess(true); settings.setAllowFileAccess(true); - settings.setDefaultTextEncodingName("utf-8"); if (API >= Build.VERSION_CODES.JELLY_BEAN) { settings.setAllowFileAccessFromFileURLs(false); settings.setAllowUniversalAccessFromFileURLs(false); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c0f723d..3271a9c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -193,6 +193,7 @@ jsoup: Java HTML Parser MIT License URL Box Contents + Text Encoding Domain (default) URL diff --git a/app/src/main/res/xml/preference_advanced.xml b/app/src/main/res/xml/preference_advanced.xml index 6a91499..3064bed 100644 --- a/app/src/main/res/xml/preference_advanced.xml +++ b/app/src/main/res/xml/preference_advanced.xml @@ -5,13 +5,13 @@ + android:summary="@string/recommended" + android:title="@string/window" /> + android:summary="@string/recommended" + android:title="@string/cookies" /> +