Browse Source

Use a PreferenceManager to handle SharedPreferences among classes

master
Anthony Restaino 10 years ago
parent
commit
2d347074a6
  1. 7
      src/acr/browser/lightning/AdBlock.java
  2. 38
      src/acr/browser/lightning/AdvancedSettingsActivity.java
  3. 7
      src/acr/browser/lightning/BookmarkActivity.java
  4. 3
      src/acr/browser/lightning/BookmarkManager.java
  5. 89
      src/acr/browser/lightning/BrowserActivity.java
  6. 39
      src/acr/browser/lightning/DisplaySettingsActivity.java
  7. 5
      src/acr/browser/lightning/DownloadHandler.java
  8. 78
      src/acr/browser/lightning/GeneralSettingsActivity.java
  9. 11
      src/acr/browser/lightning/IncognitoActivity.java
  10. 49
      src/acr/browser/lightning/LightningView.java
  11. 8
      src/acr/browser/lightning/MainActivity.java
  12. 56
      src/acr/browser/lightning/PreferenceConstants.java
  13. 399
      src/acr/browser/lightning/PreferenceManager.java
  14. 49
      src/acr/browser/lightning/PrivacySettingsActivity.java
  15. 16
      src/acr/browser/lightning/ReadingActivity.java
  16. 7
      src/acr/browser/lightning/SearchAdapter.java
  17. 117
      src/acr/browser/lightning/SettingsActivity.java
  18. 9
      src/acr/browser/lightning/ThemableActivity.java
  19. 9
      src/acr/browser/lightning/ThemableSettingsActivity.java

7
src/acr/browser/lightning/AdBlock.java

@ -1,7 +1,6 @@
package acr.browser.lightning; package acr.browser.lightning;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.util.Log; import android.util.Log;
@ -19,7 +18,6 @@ public class AdBlock {
private static final String TAG = "AdBlock"; private static final String TAG = "AdBlock";
private static final String BLOCKED_DOMAINS_LIST_FILE_NAME = "hosts.txt"; private static final String BLOCKED_DOMAINS_LIST_FILE_NAME = "hosts.txt";
private static final Set<String> mBlockedDomainsList = new HashSet<String>(); private static final Set<String> mBlockedDomainsList = new HashSet<String>();
private SharedPreferences mPreferences;
private boolean mBlockAds; private boolean mBlockAds;
private static final Locale mLocale = Locale.getDefault(); private static final Locale mLocale = Locale.getDefault();
private static AdBlock mInstance; private static AdBlock mInstance;
@ -35,12 +33,11 @@ public class AdBlock {
if (mBlockedDomainsList.isEmpty()) { if (mBlockedDomainsList.isEmpty()) {
loadBlockedDomainsList(context); loadBlockedDomainsList(context);
} }
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mBlockAds = PreferenceManager.getInstance().getAdBlockEnabled();
mBlockAds = mPreferences.getBoolean(PreferenceConstants.BLOCK_ADS, false);
} }
public void updatePreference() { public void updatePreference() {
mBlockAds = mPreferences.getBoolean(PreferenceConstants.BLOCK_ADS, false); mBlockAds = PreferenceManager.getInstance().getAdBlockEnabled();
} }
private void loadBlockedDomainsList(final Context context) { private void loadBlockedDomainsList(final Context context) {

38
src/acr/browser/lightning/AdvancedSettingsActivity.java

@ -7,7 +7,6 @@ import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
@ -22,13 +21,13 @@ import android.widget.TextView;
public class AdvancedSettingsActivity extends ThemableSettingsActivity { public class AdvancedSettingsActivity extends ThemableSettingsActivity {
private SharedPreferences mPreferences;
private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs; private CheckBox cbAllowPopups, cbAllowCookies, cbAllowIncognitoCookies, cbRestoreTabs;
private Context mContext; private Context mContext;
private TextView mRenderText; private TextView mRenderText;
private TextView mUrlText; private TextView mUrlText;
private Activity mActivity; private Activity mActivity;
private CharSequence[] mUrlOptions; private CharSequence[] mUrlOptions;
private PreferenceManager mPreferences;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -53,7 +52,8 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
} }
private void initialize() { private void initialize() {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
mPreferences = PreferenceManager.getInstance();
RelativeLayout rAllowPopups, rAllowCookies, rAllowIncognitoCookies, rRestoreTabs; RelativeLayout rAllowPopups, rAllowCookies, rAllowIncognitoCookies, rRestoreTabs;
LinearLayout lRenderPicker, lUrlContent; LinearLayout lRenderPicker, lUrlContent;
@ -70,17 +70,15 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
cbAllowIncognitoCookies = (CheckBox) findViewById(R.id.cbAllowIncognitoCookies); cbAllowIncognitoCookies = (CheckBox) findViewById(R.id.cbAllowIncognitoCookies);
cbRestoreTabs = (CheckBox) findViewById(R.id.cbRestoreTabs); cbRestoreTabs = (CheckBox) findViewById(R.id.cbRestoreTabs);
cbAllowPopups.setChecked(mPreferences.getBoolean(PreferenceConstants.POPUPS, true)); cbAllowPopups.setChecked(mPreferences.getPopupsEnabled());
cbAllowCookies.setChecked(mPreferences.getBoolean(PreferenceConstants.COOKIES, true)); cbAllowCookies.setChecked(mPreferences.getCookiesEnabled());
cbAllowIncognitoCookies.setChecked(mPreferences.getBoolean( cbAllowIncognitoCookies.setChecked(mPreferences.getIncognitoCookiesEnabled());
PreferenceConstants.INCOGNITO_COOKIES, false)); cbRestoreTabs.setChecked(mPreferences.getRestoreLostTabsEnabled());
cbRestoreTabs.setChecked(mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS,
true));
mRenderText = (TextView) findViewById(R.id.renderText); mRenderText = (TextView) findViewById(R.id.renderText);
mUrlText = (TextView) findViewById(R.id.urlText); mUrlText = (TextView) findViewById(R.id.urlText);
switch (mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0)) { switch (mPreferences.getRenderingMode()) {
case 0: case 0:
mRenderText.setText(mContext.getString(R.string.name_normal)); mRenderText.setText(mContext.getString(R.string.name_normal));
break; break;
@ -96,7 +94,7 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
} }
mUrlOptions = this.getResources().getStringArray(R.array.url_content_array); mUrlOptions = this.getResources().getStringArray(R.array.url_content_array);
int option = mPreferences.getInt(PreferenceConstants.URL_BOX_CONTENTS, 0); int option = mPreferences.getUrlBoxContentChoice();
mUrlText.setText(mUrlOptions[option]); mUrlText.setText(mUrlOptions[option]);
LayoutClickListener listener = new LayoutClickListener(); LayoutClickListener listener = new LayoutClickListener();
@ -150,18 +148,16 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch (buttonView.getId()) { switch (buttonView.getId()) {
case R.id.cbAllowPopups: case R.id.cbAllowPopups:
mPreferences.edit().putBoolean(PreferenceConstants.POPUPS, isChecked).apply(); mPreferences.setPopupsEnabled(isChecked);
break; break;
case R.id.cbAllowCookies: case R.id.cbAllowCookies:
mPreferences.edit().putBoolean(PreferenceConstants.COOKIES, isChecked).apply(); mPreferences.setCookiesEnabled(isChecked);
break; break;
case R.id.cbAllowIncognitoCookies: case R.id.cbAllowIncognitoCookies:
mPreferences.edit() mPreferences.setIncognitoCookiesEnabled(isChecked);
.putBoolean(PreferenceConstants.INCOGNITO_COOKIES, isChecked).apply();
break; break;
case R.id.cbRestoreTabs: case R.id.cbRestoreTabs:
mPreferences.edit() mPreferences.setRestoreLostTabsEnabled(isChecked);
.putBoolean(PreferenceConstants.RESTORE_LOST_TABS, isChecked).apply();
break; break;
} }
} }
@ -177,13 +173,13 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
mContext.getString(R.string.name_grayscale), mContext.getString(R.string.name_grayscale),
mContext.getString(R.string.name_inverted_grayscale) }; mContext.getString(R.string.name_inverted_grayscale) };
int n = mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0); int n = mPreferences.getRenderingMode();
picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.edit().putInt(PreferenceConstants.RENDERING_MODE, which).apply(); mPreferences.setRenderingMode(which);
switch (which) { switch (which) {
case 0: case 0:
mRenderText.setText(mContext.getString(R.string.name_normal)); mRenderText.setText(mContext.getString(R.string.name_normal));
@ -216,13 +212,13 @@ public class AdvancedSettingsActivity extends ThemableSettingsActivity {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.url_contents)); picker.setTitle(getResources().getString(R.string.url_contents));
int n = mPreferences.getInt(PreferenceConstants.URL_BOX_CONTENTS, 0); int n = mPreferences.getUrlBoxContentChoice();
picker.setSingleChoiceItems(mUrlOptions, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(mUrlOptions, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.edit().putInt(PreferenceConstants.URL_BOX_CONTENTS, which).apply(); mPreferences.setUrlBoxContentChoice(which);
if (which < mUrlOptions.length) { if (which < mUrlOptions.length) {
mUrlText.setText(mUrlOptions[which]); mUrlText.setText(mUrlOptions[which]);
} }

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

@ -8,7 +8,6 @@ import android.app.AlertDialog;
import android.app.AlertDialog.Builder; import android.app.AlertDialog.Builder;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -21,8 +20,8 @@ import android.widget.TextView;
public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener { public class BookmarkActivity extends ThemableSettingsActivity implements OnClickListener {
private BookmarkManager mBookmarkManager; private BookmarkManager mBookmarkManager;
private PreferenceManager mPreferences;
private boolean mSystemBrowser; private boolean mSystemBrowser;
private SharedPreferences mPreferences;
private File[] mFileList; private File[] mFileList;
private String[] mFileNameList; private String[] mFileNameList;
private File mPath = new File(Environment.getExternalStorageDirectory().toString()); private File mPath = new File(Environment.getExternalStorageDirectory().toString());
@ -47,9 +46,7 @@ public class BookmarkActivity extends ThemableSettingsActivity implements OnClic
mBookmarkManager = BookmarkManager.getInstance(getApplicationContext()); mBookmarkManager = BookmarkManager.getInstance(getApplicationContext());
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mSystemBrowser = mPreferences.getSystemBrowserPresent();
mSystemBrowser = mPreferences.getBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, false);
exportBackup.setOnClickListener(this); exportBackup.setOnClickListener(this);
importBackup.setOnClickListener(this); importBackup.setOnClickListener(this);

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

@ -321,8 +321,7 @@ public class BookmarkManager {
* permanent bookmark storage * permanent bookmark storage
*/ */
public synchronized void importBookmarksFromBrowser() { public synchronized void importBookmarksFromBrowser() {
if (mContext.getSharedPreferences(PreferenceConstants.PREFERENCES, 0).getBoolean( if (PreferenceManager.getInstance().getSystemBrowserPresent()) {
PreferenceConstants.SYSTEM_BROWSER_PRESENT, false)) {
List<HistoryItem> bookmarkList = new ArrayList<HistoryItem>(); List<HistoryItem> bookmarkList = new ArrayList<HistoryItem>();
String[] columns = new String[] { Browser.BookmarkColumns.TITLE, String[] columns = new String[] { Browser.BookmarkColumns.TITLE,

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

@ -117,7 +117,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
// Storage // Storage
private HistoryDatabase mHistoryDatabase; private HistoryDatabase mHistoryDatabase;
private BookmarkManager mBookmarkManager; private BookmarkManager mBookmarkManager;
private SharedPreferences mPreferences; private PreferenceManager mPreferences;
// Image // Image
private Bitmap mDefaultVideoPoster, mWebpageBitmap; private Bitmap mDefaultVideoPoster, mWebpageBitmap;
@ -145,9 +145,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = PreferenceManager.getInstance();
mDarkTheme = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false) mDarkTheme = mPreferences.getUseDarkTheme() || isIncognito();
|| isIncognito();
mActivity = this; mActivity = this;
mWebViews.clear(); mWebViews.clear();
@ -182,7 +181,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} }
mActionBar = getSupportActionBar(); mActionBar = getSupportActionBar();
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE); mHomepage = mPreferences.getHomepage();
mTitleAdapter = new LightningViewAdapter(this, R.layout.tab_list_item, mWebViews); mTitleAdapter = new LightningViewAdapter(this, R.layout.tab_list_item, mWebViews);
mDrawerListLeft.setAdapter(mTitleAdapter); mDrawerListLeft.setAdapter(mTitleAdapter);
@ -272,12 +271,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
String url = mPreferences.getString(PreferenceConstants.SAVE_URL, null); String url = mPreferences.getSavedUrl();
if (url != null) { if (url != null) {
newTab(url, true); newTab(url, true);
Toast.makeText(mActivity, R.string.deleted_tab, Toast.LENGTH_SHORT).show(); Toast.makeText(mActivity, R.string.deleted_tab, Toast.LENGTH_SHORT).show();
} }
mPreferences.edit().putString(PreferenceConstants.SAVE_URL, null).apply(); mPreferences.setSavedUrl(null);
return true; return true;
} }
@ -487,25 +486,21 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* proxying for this session * proxying for this session
*/ */
public boolean checkForTor() { public boolean checkForTor() {
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false); boolean useProxy = mPreferences.getUseProxy();
OrbotHelper oh = new OrbotHelper(this); OrbotHelper oh = new OrbotHelper(this);
if (oh.isOrbotInstalled() if (oh.isOrbotInstalled() && !mPreferences.getCheckedForTor()) {
&& !mPreferences.getBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, false)) { mPreferences.setCheckedForTor(true);
mPreferences.edit().putBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR, true).apply();
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { switch (which) {
case DialogInterface.BUTTON_POSITIVE: case DialogInterface.BUTTON_POSITIVE:
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, true) mPreferences.setUseProxy(true);
.apply();
initializeTor(); initializeTor();
break; break;
case DialogInterface.BUTTON_NEGATIVE: case DialogInterface.BUTTON_NEGATIVE:
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, false) mPreferences.setUseProxy(false);
.apply();
break; break;
} }
} }
@ -520,7 +515,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} else if (oh.isOrbotInstalled() & useProxy) { } else if (oh.isOrbotInstalled() & useProxy) {
return true; return true;
} else { } else {
mPreferences.edit().putBoolean(PreferenceConstants.USE_PROXY, false).apply(); mPreferences.setUseProxy(false);
return false; return false;
} }
} }
@ -535,8 +530,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
oh.requestOrbotStart(this); oh.requestOrbotStart(this);
} }
try { try {
String host = mPreferences.getString(PreferenceConstants.USE_PROXY_HOST, "localhost"); String host = mPreferences.getProxyHost();
int port = mPreferences.getInt(PreferenceConstants.USE_PROXY_PORT, 8118); int port = mPreferences.getProxyPort();
WebkitProxy.setProxy(this.getPackageName() + ".BrowserApp", getApplicationContext(), WebkitProxy.setProxy(this.getPackageName() + ".BrowserApp", getApplicationContext(),
host, port); host, port);
} catch (Exception e) { } catch (Exception e) {
@ -602,9 +597,9 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} }
} }
} }
if (mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) { if (mPreferences.getRestoreLostTabsEnabled()) {
String mem = mPreferences.getString(PreferenceConstants.URL_MEMORY, ""); String mem = mPreferences.getMemoryUrl();
mPreferences.edit().putString(PreferenceConstants.URL_MEMORY, "").apply(); mPreferences.setMemoryUrl("");
String[] array = Utils.getArray(mem); String[] array = Utils.getArray(mem);
int count = 0; int count = 0;
for (int n = 0; n < array.length; n++) { for (int n = 0; n < array.length; n++) {
@ -627,11 +622,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} }
public void initializePreferences() { public void initializePreferences() {
if (mPreferences == null) { mFullScreen = mPreferences.getFullScreenEnabled();
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mColorMode = mPreferences.getColorModeEnabled();
}
mFullScreen = mPreferences.getBoolean(PreferenceConstants.FULL_SCREEN, false);
mColorMode = mPreferences.getBoolean(PreferenceConstants.ENABLE_COLOR_MODE, true);
mColorMode &= !mDarkTheme; mColorMode &= !mDarkTheme;
if (!isIncognito() && !mColorMode && !mDarkTheme && mWebpageBitmap != null) { if (!isIncognito() && !mColorMode && !mDarkTheme && mWebpageBitmap != null) {
@ -649,17 +641,16 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mBrowserFrame.removeView(mToolbarLayout); mBrowserFrame.removeView(mToolbarLayout);
mUiLayout.addView(mToolbarLayout, 0); mUiLayout.addView(mToolbarLayout, 0);
} }
if (mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)) { if (mPreferences.getHideStatusBarEnabled()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams.FLAG_FULLSCREEN);
} else { } else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
} }
switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) { switch (mPreferences.getSearchChoice()) {
case 0: case 0:
mSearchText = mPreferences.getString(PreferenceConstants.SEARCH_URL, mSearchText = mPreferences.getSearchUrl();
Constants.GOOGLE_SEARCH);
if (!mSearchText.startsWith(Constants.HTTP) if (!mSearchText.startsWith(Constants.HTTP)
&& !mSearchText.startsWith(Constants.HTTPS)) { && !mSearchText.startsWith(Constants.HTTPS)) {
mSearchText = Constants.GOOGLE_SEARCH; mSearchText = Constants.GOOGLE_SEARCH;
@ -698,7 +689,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} }
updateCookiePreference(); updateCookiePreference();
if (mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false)) { if (mPreferences.getUseProxy()) {
initializeTor(); initializeTor();
} else { } else {
try { try {
@ -1155,7 +1146,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
return; return;
} }
if (reference.getUrl() != null && !reference.getUrl().startsWith(Constants.FILE)) { if (reference.getUrl() != null && !reference.getUrl().startsWith(Constants.FILE)) {
mPreferences.edit().putString(PreferenceConstants.SAVE_URL, reference.getUrl()).apply(); mPreferences.setSavedUrl(reference.getUrl());
} }
boolean isShown = reference.isShown(); boolean isShown = reference.isShown();
if (isShown) { if (isShown) {
@ -1191,20 +1182,17 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
closeActivity(); closeActivity();
} else { } else {
mWebViews.remove(position); mWebViews.remove(position);
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false) if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
&& mCurrentView != null && !isIncognito()) {
mCurrentView.clearCache(true); mCurrentView.clearCache(true);
Log.d(Constants.TAG, "Cache Cleared"); Log.d(Constants.TAG, "Cache Cleared");
} }
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT, false) if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
&& !isIncognito()) {
clearHistory(); clearHistory();
Log.d(Constants.TAG, "History Cleared"); Log.d(Constants.TAG, "History Cleared");
} }
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT, false) if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
&& !isIncognito()) {
clearCookies(); clearCookies();
Log.d(Constants.TAG, "Cookies Cleared"); Log.d(Constants.TAG, "Cookies Cleared");
@ -1237,20 +1225,17 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
private void closeBrowser() { private void closeBrowser() {
mBrowserFrame.setBackgroundColor(mBackgroundColor); mBrowserFrame.setBackgroundColor(mBackgroundColor);
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, false) if (mPreferences.getClearCacheExit() && mCurrentView != null && !isIncognito()) {
&& mCurrentView != null && !isIncognito()) {
mCurrentView.clearCache(true); mCurrentView.clearCache(true);
Log.d(Constants.TAG, "Cache Cleared"); Log.d(Constants.TAG, "Cache Cleared");
} }
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT, false) if (mPreferences.getClearHistoryExitEnabled() && !isIncognito()) {
&& !isIncognito()) {
clearHistory(); clearHistory();
Log.d(Constants.TAG, "History Cleared"); Log.d(Constants.TAG, "History Cleared");
} }
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT, false) if (mPreferences.getClearCookiesExitEnabled() && !isIncognito()) {
&& !isIncognito()) {
clearCookies(); clearCookies();
Log.d(Constants.TAG, "Cookies Cleared"); Log.d(Constants.TAG, "Cookies Cleared");
@ -1335,14 +1320,14 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} }
public void saveOpenTabs() { public void saveOpenTabs() {
if (mPreferences.getBoolean(PreferenceConstants.RESTORE_LOST_TABS, true)) { if (mPreferences.getRestoreLostTabsEnabled()) {
String s = ""; String s = "";
for (int n = 0; n < mWebViews.size(); n++) { for (int n = 0; n < mWebViews.size(); n++) {
if (mWebViews.get(n).getUrl() != null) { if (mWebViews.get(n).getUrl() != null) {
s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|"; s = s + mWebViews.get(n).getUrl() + "|$|SEPARATOR|$|";
} }
} }
mPreferences.edit().putString(PreferenceConstants.URL_MEMORY, s).apply(); mPreferences.setMemoryUrl(s);
} }
} }
@ -1749,7 +1734,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
return; return;
} }
if (shortUrl && !url.startsWith(Constants.FILE)) { if (shortUrl && !url.startsWith(Constants.FILE)) {
switch (mPreferences.getInt(PreferenceConstants.URL_BOX_CONTENTS, 0)) { switch (mPreferences.getUrlBoxContentChoice()) {
case 0: // Default, show only the domain case 0: // Default, show only the domain
url = url.replaceFirst(Constants.HTTP, ""); url = url.replaceFirst(Constants.HTTP, "");
url = Utils.getDomainName(url); url = Utils.getDomainName(url);
@ -1794,8 +1779,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
Runnable update = new Runnable() { Runnable update = new Runnable() {
@Override @Override
public void run() { public void run() {
if (isSystemBrowserAvailable() if (isSystemBrowserAvailable() && mPreferences.getSyncHistoryEnabled()) {
&& mPreferences.getBoolean(PreferenceConstants.SYNC_HISTORY, true)) {
try { try {
Browser.updateVisitedHistory(getContentResolver(), url, true); Browser.updateVisitedHistory(getContentResolver(), url, true);
} catch (NullPointerException ignored) { } catch (NullPointerException ignored) {
@ -1848,8 +1832,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
c.close(); c.close();
c = null; c = null;
} }
mPreferences.edit().putBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, browserFlag) mPreferences.setSystemBrowserPresent(browserFlag);
.apply();
return browserFlag; return browserFlag;
} }
@ -2051,7 +2034,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} catch (SecurityException e) { } catch (SecurityException e) {
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on"); Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
} }
setFullscreen(mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, false)); setFullscreen(mPreferences.getHideStatusBarEnabled());
FrameLayout decor = (FrameLayout) getWindow().getDecorView(); FrameLayout decor = (FrameLayout) getWindow().getDecorView();
if (decor != null) { if (decor != null) {
decor.removeView(mFullscreenContainer); decor.removeView(mFullscreenContainer);

39
src/acr/browser/lightning/DisplaySettingsActivity.java

@ -5,7 +5,6 @@ package acr.browser.lightning;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.view.MenuItem; import android.view.MenuItem;
@ -19,7 +18,7 @@ import android.widget.RelativeLayout;
public class DisplaySettingsActivity extends ThemableSettingsActivity { public class DisplaySettingsActivity extends ThemableSettingsActivity {
// mPreferences variables // mPreferences variables
private SharedPreferences mPreferences; private PreferenceManager mPreferences;
private CheckBox cbHideStatusBar, cbFullScreen, cbWideViewPort, cbOverView, cbTextReflow, private CheckBox cbHideStatusBar, cbFullScreen, cbWideViewPort, cbOverView, cbTextReflow,
cbDarkTheme; cbDarkTheme;
@ -28,7 +27,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.display_settings); setContentView(R.layout.display_settings);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = PreferenceManager.getInstance();
// set up ActionBar // set up ActionBar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
@ -64,14 +63,12 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
cbTextReflow = (CheckBox) findViewById(R.id.cbTextReflow); cbTextReflow = (CheckBox) findViewById(R.id.cbTextReflow);
cbDarkTheme = (CheckBox) findViewById(R.id.cbDarkTheme); cbDarkTheme = (CheckBox) findViewById(R.id.cbDarkTheme);
cbHideStatusBar.setChecked(mPreferences.getBoolean(PreferenceConstants.HIDE_STATUS_BAR, cbHideStatusBar.setChecked(mPreferences.getHideStatusBarEnabled());
false)); cbFullScreen.setChecked(mPreferences.getFullScreenEnabled());
cbFullScreen.setChecked(mPreferences.getBoolean(PreferenceConstants.FULL_SCREEN, false)); cbWideViewPort.setChecked(mPreferences.getUseWideViewportEnabled());
cbWideViewPort.setChecked(mPreferences.getBoolean(PreferenceConstants.USE_WIDE_VIEWPORT, cbOverView.setChecked(mPreferences.getOverviewModeEnabled());
true)); cbTextReflow.setChecked(mPreferences.getTextReflowEnabled());
cbOverView.setChecked(mPreferences.getBoolean(PreferenceConstants.OVERVIEW_MODE, true)); cbDarkTheme.setChecked(mPreferences.getUseDarkTheme());
cbTextReflow.setChecked(mPreferences.getBoolean(PreferenceConstants.TEXT_REFLOW, false));
cbDarkTheme.setChecked(mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false));
rHideStatusBar(rHideStatusBar); rHideStatusBar(rHideStatusBar);
rFullScreen(rFullScreen); rFullScreen(rFullScreen);
@ -93,8 +90,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(PreferenceConstants.HIDE_STATUS_BAR, isChecked) mPreferences.setHideStatusBarEnabled(isChecked);
.apply();
} }
}); });
@ -105,7 +101,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(PreferenceConstants.FULL_SCREEN, isChecked).apply(); mPreferences.setFullScreenEnabled(isChecked);
} }
}); });
@ -116,7 +112,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(PreferenceConstants.DARK_THEME, isChecked).apply(); mPreferences.setUseDarkTheme(isChecked);
restart(); restart();
} }
@ -128,8 +124,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(PreferenceConstants.USE_WIDE_VIEWPORT, isChecked) mPreferences.setUseWideViewportEnabled(isChecked);
.apply();
} }
}); });
@ -140,8 +135,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(PreferenceConstants.OVERVIEW_MODE, isChecked) mPreferences.setOverviewModeEnabled(isChecked);
.apply();
} }
}); });
@ -152,7 +146,7 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.edit().putBoolean(PreferenceConstants.TEXT_REFLOW, isChecked).apply(); mPreferences.setTextReflowEnabled(isChecked);
} }
}); });
} }
@ -234,15 +228,14 @@ public class DisplaySettingsActivity extends ThemableSettingsActivity {
AlertDialog.Builder picker = new AlertDialog.Builder(DisplaySettingsActivity.this); AlertDialog.Builder picker = new AlertDialog.Builder(DisplaySettingsActivity.this);
picker.setTitle(getResources().getString(R.string.title_text_size)); picker.setTitle(getResources().getString(R.string.title_text_size));
int n = mPreferences.getInt(PreferenceConstants.TEXT_SIZE, 3); int n = mPreferences.getTextSize();
picker.setSingleChoiceItems(R.array.text_size, n - 1, picker.setSingleChoiceItems(R.array.text_size, n - 1,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mPreferences.edit() mPreferences.setTextSize(which + 1);
.putInt(PreferenceConstants.TEXT_SIZE, which + 1).apply();
} }
}); });

5
src/acr/browser/lightning/DownloadHandler.java

@ -27,7 +27,6 @@ public class DownloadHandler {
private static final String LOGTAG = "DLHandler"; private static final String LOGTAG = "DLHandler";
private static Activity mActivity;
/** /**
* Notify the host application a download should be done, or that the data * Notify the host application a download should be done, or that the data
@ -48,7 +47,6 @@ public class DownloadHandler {
*/ */
public static void onDownloadStart(Activity activity, String url, String userAgent, public static void onDownloadStart(Activity activity, String url, String userAgent,
String contentDisposition, String mimetype, boolean privateBrowsing) { String contentDisposition, String mimetype, boolean privateBrowsing) {
mActivity = activity;
// if we're dealing wih A/V content that's not explicitly marked // if we're dealing wih A/V content that's not explicitly marked
// for download, check if it's streamable. // for download, check if it's streamable.
if (contentDisposition == null if (contentDisposition == null
@ -183,8 +181,7 @@ public class DownloadHandler {
// or, should it be set to one of several Environment.DIRECTORY* dirs // or, should it be set to one of several Environment.DIRECTORY* dirs
// depending on mimetype? // depending on mimetype?
String location = mActivity.getSharedPreferences(PreferenceConstants.PREFERENCES, 0) String location = PreferenceManager.getInstance().getDownloadDirectory();
.getString(PreferenceConstants.DOWNLOAD_DIRECTORY, Environment.DIRECTORY_DOWNLOADS);
request.setDestinationInExternalPublicDir(location, filename); request.setDestinationInExternalPublicDir(location, filename);
// let this downloaded file be scanned by MediaScanner - so that it can // let this downloaded file be scanned by MediaScanner - so that it can
// show up in Gallery app, for example. // show up in Gallery app, for example.

78
src/acr/browser/lightning/GeneralSettingsActivity.java

@ -6,7 +6,6 @@ package acr.browser.lightning;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
@ -28,8 +27,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
// mPreferences variables // mPreferences variables
private static final int API = android.os.Build.VERSION.SDK_INT; private static final int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences mPreferences; private PreferenceManager mPreferences;
private SharedPreferences.Editor mEditPrefs;
private int mAgentChoice; private int mAgentChoice;
private String mHomepage; private String mHomepage;
private TextView mAgentTextView; private TextView mAgentTextView;
@ -51,10 +49,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// TODO WARNING: SharedPreferences.edit() without a corresponding mPreferences = PreferenceManager.getInstance();
// commit() or apply() call
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
mEditPrefs = mPreferences.edit();
mActivity = this; mActivity = this;
initialize(); initialize();
@ -70,7 +65,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
mSearchText = (TextView) findViewById(R.id.searchText); mSearchText = (TextView) findViewById(R.id.searchText);
switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) { switch (mPreferences.getSearchChoice()) {
case 0: case 0:
mSearchText.setText(getResources().getString(R.string.custom_url)); mSearchText.setText(getResources().getString(R.string.custom_url));
break; break;
@ -108,10 +103,9 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
mAgentTextView = (TextView) findViewById(R.id.agentText); mAgentTextView = (TextView) findViewById(R.id.agentText);
mHomepageText = (TextView) findViewById(R.id.homepageText); mHomepageText = (TextView) findViewById(R.id.homepageText);
mDownloadTextView = (TextView) findViewById(R.id.downloadText); mDownloadTextView = (TextView) findViewById(R.id.downloadText);
mAgentChoice = mPreferences.getInt(PreferenceConstants.USER_AGENT, 1); mAgentChoice = mPreferences.getUserAgentChoice();
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE); mHomepage = mPreferences.getHomepage();
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY, mDownloadLocation = mPreferences.getDownloadDirectory();
Environment.DIRECTORY_DOWNLOADS);
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/' + mDownloadLocation); mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/' + mDownloadLocation);
@ -144,8 +138,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
cbSearchSuggestions = (CheckBox) findViewById(R.id.cbGoogleSuggestions); cbSearchSuggestions = (CheckBox) findViewById(R.id.cbGoogleSuggestions);
cbSearchSuggestions.setChecked(mPreferences.getBoolean( cbSearchSuggestions.setChecked(mPreferences.getGoogleSearchSuggestionsEnabled());
PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, true));
RelativeLayout agent = (RelativeLayout) findViewById(R.id.layoutUserAgent); RelativeLayout agent = (RelativeLayout) findViewById(R.id.layoutUserAgent);
RelativeLayout download = (RelativeLayout) findViewById(R.id.layoutDownload); RelativeLayout download = (RelativeLayout) findViewById(R.id.layoutDownload);
@ -173,14 +166,13 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
"DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)", "DuckDuckGo (Privacy)", "DuckDuckGo Lite (Privacy)", "Baidu (Chinese)",
"Yandex (Russian)" }; "Yandex (Russian)" };
int n = mPreferences.getInt(PreferenceConstants.SEARCH, 1); int n = mPreferences.getSearchChoice();
picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() { picker.setSingleChoiceItems(chars, n, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.SEARCH, which); mPreferences.setSearchChoice(which);
mEditPrefs.apply();
switch (which) { switch (which) {
case 0: case 0:
searchUrlPicker(); searchUrlPicker();
@ -237,8 +229,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
urlPicker.setTitle(getResources().getString(R.string.custom_url)); urlPicker.setTitle(getResources().getString(R.string.custom_url));
final EditText getSearchUrl = new EditText(this); final EditText getSearchUrl = new EditText(this);
String mSearchUrl = mPreferences.getString(PreferenceConstants.SEARCH_URL, String mSearchUrl = mPreferences.getSearchUrl();
Constants.GOOGLE_SEARCH);
getSearchUrl.setText(mSearchUrl); getSearchUrl.setText(mSearchUrl);
urlPicker.setView(getSearchUrl); urlPicker.setView(getSearchUrl);
urlPicker.setPositiveButton(getResources().getString(R.string.action_ok), urlPicker.setPositiveButton(getResources().getString(R.string.action_ok),
@ -247,8 +238,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getSearchUrl.getText().toString(); String text = getSearchUrl.getText().toString();
mEditPrefs.putString(PreferenceConstants.SEARCH_URL, text); mPreferences.setSearchUrl(text);
mEditPrefs.apply();
mSearchText.setText(getResources().getString(R.string.custom_url) + ": " mSearchText.setText(getResources().getString(R.string.custom_url) + ": "
+ text); + text);
} }
@ -263,14 +253,13 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
public void onClick(View v) { public void onClick(View v) {
AlertDialog.Builder agentPicker = new AlertDialog.Builder(mActivity); AlertDialog.Builder agentPicker = new AlertDialog.Builder(mActivity);
agentPicker.setTitle(getResources().getString(R.string.title_user_agent)); agentPicker.setTitle(getResources().getString(R.string.title_user_agent));
mAgentChoice = mPreferences.getInt(PreferenceConstants.USER_AGENT, 1); mAgentChoice = mPreferences.getUserAgentChoice();
agentPicker.setSingleChoiceItems(R.array.user_agent, mAgentChoice - 1, agentPicker.setSingleChoiceItems(R.array.user_agent, mAgentChoice - 1,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.USER_AGENT, which + 1); mPreferences.setUserAgentChoice(which + 1);
mEditPrefs.apply();
switch (which + 1) { switch (which + 1) {
case 1: case 1:
mAgentTextView.setText(getResources().getString( mAgentTextView.setText(getResources().getString(
@ -329,8 +318,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getAgent.getText().toString(); String text = getAgent.getText().toString();
mEditPrefs.putString(PreferenceConstants.USER_AGENT_STRING, text); mPreferences.setUserAgentString(text);
mEditPrefs.apply();
mAgentTextView.setText(getResources().getString(R.string.agent_custom)); mAgentTextView.setText(getResources().getString(R.string.agent_custom));
} }
}); });
@ -345,8 +333,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.title_download_location)); picker.setTitle(getResources().getString(R.string.title_download_location));
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY, mDownloadLocation = mPreferences.getDownloadDirectory();
Environment.DIRECTORY_DOWNLOADS);
int n; int n;
if (mDownloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) { if (mDownloadLocation.contains(Environment.DIRECTORY_DOWNLOADS)) {
n = 1; n = 1;
@ -362,10 +349,8 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
switch (which + 1) { switch (which + 1) {
case 1: case 1:
mEditPrefs.putString( mPreferences
PreferenceConstants.DOWNLOAD_DIRECTORY, .setDownloadDirectory(Environment.DIRECTORY_DOWNLOADS);
Environment.DIRECTORY_DOWNLOADS);
mEditPrefs.apply();
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/' mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/'
+ Environment.DIRECTORY_DOWNLOADS); + Environment.DIRECTORY_DOWNLOADS);
break; break;
@ -394,7 +379,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
final AlertDialog.Builder homePicker = new AlertDialog.Builder(mActivity); final AlertDialog.Builder homePicker = new AlertDialog.Builder(mActivity);
homePicker.setTitle(getResources().getString(R.string.title_custom_homepage)); homePicker.setTitle(getResources().getString(R.string.title_custom_homepage));
final EditText getHome = new EditText(this); final EditText getHome = new EditText(this);
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE); mHomepage = mPreferences.getHomepage();
if (!mHomepage.startsWith("about:")) { if (!mHomepage.startsWith("about:")) {
getHome.setText(mHomepage); getHome.setText(mHomepage);
} else { } else {
@ -407,8 +392,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getHome.getText().toString(); String text = getHome.getText().toString();
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, text); mPreferences.setHomepage(text);
mEditPrefs.apply();
mHomepageText.setText(text); mHomepageText.setText(text);
} }
}); });
@ -422,8 +406,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
downLocationPicker.setTitle(getResources().getString(R.string.title_download_location)); downLocationPicker.setTitle(getResources().getString(R.string.title_download_location));
final EditText getDownload = new EditText(this); final EditText getDownload = new EditText(this);
getDownload.setBackgroundResource(0); getDownload.setBackgroundResource(0);
mDownloadLocation = mPreferences.getString(PreferenceConstants.DOWNLOAD_DIRECTORY, mDownloadLocation = mPreferences.getDownloadDirectory();
Environment.DIRECTORY_DOWNLOADS);
int padding = Utils.convertDpToPixels(10); int padding = Utils.convertDpToPixels(10);
LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams(
@ -453,8 +436,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getDownload.getText().toString(); String text = getDownload.getText().toString();
mEditPrefs.putString(PreferenceConstants.DOWNLOAD_DIRECTORY, text); mPreferences.setDownloadDirectory(text);
mEditPrefs.apply();
mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/' + text); mDownloadTextView.setText(Constants.EXTERNAL_STORAGE + '/' + text);
} }
}); });
@ -468,8 +450,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
public void onClick(View v) { public void onClick(View v) {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.home)); picker.setTitle(getResources().getString(R.string.home));
mHomepage = mPreferences mHomepage = mPreferences.getHomepage();
.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE);
int n; int n;
if (mHomepage.contains("about:home")) { if (mHomepage.contains("about:home")) {
n = 1; n = 1;
@ -489,23 +470,17 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
switch (which + 1) { switch (which + 1) {
case 1: case 1:
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, mPreferences.setHomepage("about:home");
"about:home");
mEditPrefs.apply();
mHomepageText.setText(getResources().getString( mHomepageText.setText(getResources().getString(
R.string.action_homepage)); R.string.action_homepage));
break; break;
case 2: case 2:
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, mPreferences.setHomepage("about:blank");
"about:blank");
mEditPrefs.apply();
mHomepageText.setText(getResources().getString( mHomepageText.setText(getResources().getString(
R.string.action_blank)); R.string.action_blank));
break; break;
case 3: case 3:
mEditPrefs.putString(PreferenceConstants.HOMEPAGE, mPreferences.setHomepage("about:bookmarks");
"about:bookmarks");
mEditPrefs.apply();
mHomepageText.setText(getResources().getString( mHomepageText.setText(getResources().getString(
R.string.action_bookmarks)); R.string.action_bookmarks));
@ -536,8 +511,7 @@ public class GeneralSettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, isChecked); mPreferences.setGoogleSearchSuggestionsEnabled(isChecked);
mEditPrefs.apply();
} }
}); });

11
src/acr/browser/lightning/IncognitoActivity.java

@ -1,7 +1,6 @@
package acr.browser.lightning; package acr.browser.lightning;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
@ -11,27 +10,21 @@ import android.webkit.CookieSyncManager;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class IncognitoActivity extends BrowserActivity { public class IncognitoActivity extends BrowserActivity {
SharedPreferences mPreferences;
CookieManager mCookieManager; CookieManager mCookieManager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
} }
@Override @Override
public void updateCookiePreference() { public void updateCookiePreference() {
if (mPreferences == null) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
}
mCookieManager = CookieManager.getInstance(); mCookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
} }
mCookieManager.setAcceptCookie(mPreferences.getBoolean( mCookieManager
PreferenceConstants.INCOGNITO_COOKIES, false)); .setAcceptCookie(PreferenceManager.getInstance().getIncognitoCookiesEnabled());
super.updateCookiePreference(); super.updateCookiePreference();
} }

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

@ -19,7 +19,6 @@ import android.content.ActivityNotFoundException;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.ColorMatrix; import android.graphics.ColorMatrix;
@ -66,7 +65,7 @@ public class LightningView {
private static String mHomepage; private static String mHomepage;
private static String mDefaultUserAgent; private static String mDefaultUserAgent;
private static Bitmap mWebpageBitmap; private static Bitmap mWebpageBitmap;
private static SharedPreferences mPreferences; private static PreferenceManager mPreferences;
private AdBlock mAdBlock; private AdBlock mAdBlock;
private boolean isForegroundTab; private boolean isForegroundTab;
private IntentUtils mIntentUtils; private IntentUtils mIntentUtils;
@ -149,14 +148,12 @@ public class LightningView {
public String getHomepage() { public String getHomepage() {
String home; String home;
home = HomepageVariables.HEAD; home = HomepageVariables.HEAD;
switch (mPreferences.getInt(PreferenceConstants.SEARCH, 1)) { switch (mPreferences.getSearchChoice()) {
case 0: case 0:
// CUSTOM SEARCH // CUSTOM SEARCH
home = home + "file:///android_asset/lightning.png"; home = home + "file:///android_asset/lightning.png";
home = home + HomepageVariables.MIDDLE; home = home + HomepageVariables.MIDDLE;
home = home home = home + mPreferences.getSearchUrl();
+ mPreferences.getString(PreferenceConstants.SEARCH_URL,
Constants.GOOGLE_SEARCH);
break; break;
case 1: case 1:
// GOOGLE_SEARCH; // GOOGLE_SEARCH;
@ -251,8 +248,8 @@ public class LightningView {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@SuppressLint({ "NewApi", "SetJavaScriptEnabled" }) @SuppressLint({ "NewApi", "SetJavaScriptEnabled" })
public synchronized void initializePreferences(Context context) { public synchronized void initializePreferences(Context context) {
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = PreferenceManager.getInstance();
mHomepage = mPreferences.getString(PreferenceConstants.HOMEPAGE, Constants.HOMEPAGE); mHomepage = mPreferences.getHomepage();
mAdBlock.updatePreference(); mAdBlock.updatePreference();
if (mSettings == null && mWebView != null) { if (mSettings == null && mWebView != null) {
mSettings = mWebView.getSettings(); mSettings = mWebView.getSettings();
@ -260,16 +257,15 @@ public class LightningView {
return; return;
} }
setColorMode(mPreferences.getInt(PreferenceConstants.RENDERING_MODE, 0)); setColorMode(mPreferences.getRenderingMode());
if (!mBrowserController.isIncognito()) { if (!mBrowserController.isIncognito()) {
mSettings.setGeolocationEnabled(mPreferences.getBoolean(PreferenceConstants.LOCATION, mSettings.setGeolocationEnabled(mPreferences.getLocationEnabled());
false));
} else { } else {
mSettings.setGeolocationEnabled(false); mSettings.setGeolocationEnabled(false);
} }
if (API < 19) { if (API < 19) {
switch (mPreferences.getInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0)) { switch (mPreferences.getFlashSupport()) {
case 0: case 0:
mSettings.setPluginState(PluginState.OFF); mSettings.setPluginState(PluginState.OFF);
break; break;
@ -284,7 +280,7 @@ public class LightningView {
} }
} }
switch (mPreferences.getInt(PreferenceConstants.USER_AGENT, 1)) { switch (mPreferences.getUserAgentChoice()) {
case 1: case 1:
if (API > 16) { if (API > 16) {
mSettings.setUserAgentString(WebSettings.getDefaultUserAgent(context)); mSettings.setUserAgentString(WebSettings.getDefaultUserAgent(context));
@ -299,13 +295,11 @@ public class LightningView {
mSettings.setUserAgentString(Constants.MOBILE_USER_AGENT); mSettings.setUserAgentString(Constants.MOBILE_USER_AGENT);
break; break;
case 4: case 4:
mSettings.setUserAgentString(mPreferences.getString( mSettings.setUserAgentString(mPreferences.getUserAgentString(mDefaultUserAgent));
PreferenceConstants.USER_AGENT_STRING, mDefaultUserAgent));
break; break;
} }
if (mPreferences.getBoolean(PreferenceConstants.SAVE_PASSWORDS, false) if (mPreferences.getSavePasswordsEnabled() && !mBrowserController.isIncognito()) {
&& !mBrowserController.isIncognito()) {
if (API < 18) { if (API < 18) {
mSettings.setSavePassword(true); mSettings.setSavePassword(true);
} }
@ -317,12 +311,12 @@ public class LightningView {
mSettings.setSaveFormData(false); mSettings.setSaveFormData(false);
} }
if (mPreferences.getBoolean(PreferenceConstants.JAVASCRIPT, true)) { if (mPreferences.getJavaScriptEnabled()) {
mSettings.setJavaScriptEnabled(true); mSettings.setJavaScriptEnabled(true);
mSettings.setJavaScriptCanOpenWindowsAutomatically(true); mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
} }
if (mPreferences.getBoolean(PreferenceConstants.TEXT_REFLOW, false)) { if (mPreferences.getTextReflowEnabled()) {
mTextReflow = true; mTextReflow = true;
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS); mSettings.setLayoutAlgorithm(LayoutAlgorithm.NARROW_COLUMNS);
if (API >= android.os.Build.VERSION_CODES.KITKAT) { if (API >= android.os.Build.VERSION_CODES.KITKAT) {
@ -339,15 +333,11 @@ public class LightningView {
mSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL); mSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
} }
mSettings.setBlockNetworkImage(mPreferences.getBoolean(PreferenceConstants.BLOCK_IMAGES, mSettings.setBlockNetworkImage(mPreferences.getBlockImagesEnabled());
false)); mSettings.setSupportMultipleWindows(mPreferences.getPopupsEnabled());
mSettings.setSupportMultipleWindows(mPreferences.getBoolean(PreferenceConstants.POPUPS, mSettings.setUseWideViewPort(mPreferences.getUseWideViewportEnabled());
true)); mSettings.setLoadWithOverviewMode(mPreferences.getOverviewModeEnabled());
mSettings.setUseWideViewPort(mPreferences.getBoolean(PreferenceConstants.USE_WIDE_VIEWPORT, switch (mPreferences.getTextSize()) {
true));
mSettings.setLoadWithOverviewMode(mPreferences.getBoolean(
PreferenceConstants.OVERVIEW_MODE, true));
switch (mPreferences.getInt(PreferenceConstants.TEXT_SIZE, 3)) {
case 1: case 1:
mSettings.setTextZoom(200); mSettings.setTextZoom(200);
break; break;
@ -366,7 +356,7 @@ public class LightningView {
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView, CookieManager.getInstance().setAcceptThirdPartyCookies(mWebView,
!mPreferences.getBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, false)); !mPreferences.getBlockThirdPartyCookiesEnabled());
} }
} }
@ -759,7 +749,6 @@ public class LightningView {
public void run() { public void run() {
mZoomScale = newScale; mZoomScale = newScale;
view.evaluateJavascript(Constants.JAVASCRIPT_TEXT_REFLOW, null); view.evaluateJavascript(Constants.JAVASCRIPT_TEXT_REFLOW, null);
Log.d("YOLO", "SCALE CHANGING " + newScale);
mIsRunning = false; mIsRunning = false;
} }

8
src/acr/browser/lightning/MainActivity.java

@ -1,7 +1,6 @@
package acr.browser.lightning; package acr.browser.lightning;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
@ -11,25 +10,20 @@ import android.webkit.CookieSyncManager;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public class MainActivity extends BrowserActivity { public class MainActivity extends BrowserActivity {
SharedPreferences mPreferences;
CookieManager mCookieManager; CookieManager mCookieManager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
} }
@Override @Override
public void updateCookiePreference() { public void updateCookiePreference() {
if (mPreferences == null) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
}
mCookieManager = CookieManager.getInstance(); mCookieManager = CookieManager.getInstance();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
CookieSyncManager.createInstance(this); CookieSyncManager.createInstance(this);
} }
mCookieManager.setAcceptCookie(mPreferences.getBoolean(PreferenceConstants.COOKIES, true)); mCookieManager.setAcceptCookie(PreferenceManager.getInstance().getCookiesEnabled());
super.updateCookiePreference(); super.updateCookiePreference();
} }

56
src/acr/browser/lightning/PreferenceConstants.java

@ -1,56 +0,0 @@
/*
* Copyright 2014 A.C.R. Development
*/
package acr.browser.lightning;
public final class PreferenceConstants {
private PreferenceConstants() {
}
public static final String ADOBE_FLASH_SUPPORT = "enableflash";
public static final String BLOCK_ADS = "AdBlock";
public static final String BLOCK_IMAGES = "blockimages";
public static final String CLEAR_CACHE_EXIT = "cache";
public static final String COOKIES = "cookies";
public static final String DOWNLOAD_DIRECTORY = "download";
public static final String FULL_SCREEN = "fullscreen";
public static final String HIDE_STATUS_BAR = "hidestatus";
public static final String HOMEPAGE = "home";
public static final String INCOGNITO_COOKIES = "incognitocookies";
public static final String JAVASCRIPT = "java";
public static final String LOCATION = "location";
public static final String OVERVIEW_MODE = "overviewmode";
public static final String POPUPS = "newwindows";
public static final String PREFERENCES = "settings";
public static final String RESTORE_LOST_TABS = "restoreclosed";
public static final String SAVE_PASSWORDS = "passwords";
public static final String SEARCH = "search";
public static final String SEARCH_URL = "searchurl";
public static final String SYSTEM_BROWSER_PRESENT = "SystemBrowser";
public static final String TEXT_REFLOW = "textreflow";
public static final String TEXT_SIZE = "textsize";
public static final String URL_MEMORY = "memory";
public static final String USE_WIDE_VIEWPORT = "wideviewport";
public static final String USER_AGENT = "agentchoose";
public static final String USER_AGENT_STRING = "userAgentString";
public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions";
public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit";
public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit";
public static final String SAVE_URL = "saveUrl";
public static final String RENDERING_MODE = "renderMode";
public static final String SYNC_HISTORY = "syncHistory";
public static final String BLOCK_THIRD_PARTY = "thirdParty";
public static final String ENABLE_COLOR_MODE = "colorMode";
public static final String URL_BOX_CONTENTS = "urlContent";
public static final String INVERT_COLORS = "invertColors";
public static final String READING_TEXT_SIZE = "readingTextSize";
public static final String DARK_THEME = "darkTheme";
public static final String USE_PROXY = "useProxy";
public static final String USE_PROXY_HOST = "useProxyHost";
public static final String USE_PROXY_PORT = "useProxyPort";
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
public static final String OLD_BOOKMARKS_IMPORTED = "oldBookmarksImported";
}

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

@ -0,0 +1,399 @@
package acr.browser.lightning;
import android.content.SharedPreferences;
import android.os.Environment;
public class PreferenceManager {
private static PreferenceManager mInstance;
private static SharedPreferences mPrefs;
private static final String PREFERENCES = "settings";
private PreferenceManager() {
mPrefs = BrowserApp.getAppContext().getSharedPreferences(PREFERENCES, 0);
}
public static PreferenceManager getInstance() {
if (mInstance == null) {
mInstance = new PreferenceManager();
}
return mInstance;
}
public int getFlashSupport() {
return mPrefs.getInt(Name.ADOBE_FLASH_SUPPORT, 0);
}
public void setFlashSupport(int n) {
putInt(Name.ADOBE_FLASH_SUPPORT, n);
}
public boolean getAdBlockEnabled() {
return mPrefs.getBoolean(Name.BLOCK_ADS, false);
}
public void setAdBlockEnabled(boolean enable) {
putBoolean(Name.BLOCK_ADS, enable);
}
public int getReadingTextSize() {
return mPrefs.getInt(Name.READING_TEXT_SIZE, 2);
}
public void setReadingTextSize(int size) {
putInt(Name.READING_TEXT_SIZE, 2);
}
public boolean getBlockImagesEnabled() {
return mPrefs.getBoolean(Name.BLOCK_IMAGES, false);
}
public void setBlockImagesEnabled(boolean enable) {
putBoolean(Name.BLOCK_IMAGES, enable);
}
public boolean getInvertColors() {
return mPrefs.getBoolean(Name.INVERT_COLORS, false);
}
public void setInvertColors(boolean enable) {
putBoolean(Name.INVERT_COLORS, enable);
}
public boolean getClearCacheExit() {
return mPrefs.getBoolean(Name.CLEAR_CACHE_EXIT, false);
}
public void setClearCacheExit(boolean enable) {
putBoolean(Name.CLEAR_CACHE_EXIT, enable);
}
public boolean getCookiesEnabled() {
return mPrefs.getBoolean(Name.COOKIES, true);
}
public void setCookiesEnabled(boolean enable) {
putBoolean(Name.COOKIES, enable);
}
public String getDownloadDirectory() {
return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, Environment.DIRECTORY_DOWNLOADS);
}
public void setDownloadDirectory(String directory) {
putString(Name.DOWNLOAD_DIRECTORY, directory);
}
public boolean getFullScreenEnabled() {
return mPrefs.getBoolean(Name.FULL_SCREEN, false);
}
public void setFullScreenEnabled(boolean enable) {
putBoolean(Name.FULL_SCREEN, enable);
}
public boolean getHideStatusBarEnabled() {
return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false);
}
public void setHideStatusBarEnabled(boolean enable) {
putBoolean(Name.HIDE_STATUS_BAR, enable);
}
public String getHomepage() {
return mPrefs.getString(Name.HOMEPAGE, Constants.HOMEPAGE);
}
public void setHomepage(String homepage) {
putString(Name.HOMEPAGE, homepage);
}
public boolean getUseDarkTheme() {
return mPrefs.getBoolean(Name.DARK_THEME, false);
}
public void setUseDarkTheme(boolean use) {
putBoolean(Name.DARK_THEME, use);
}
public boolean getIncognitoCookiesEnabled() {
return mPrefs.getBoolean(Name.INCOGNITO_COOKIES, false);
}
public void setIncognitoCookiesEnabled(boolean enable) {
putBoolean(Name.INCOGNITO_COOKIES, enable);
}
public boolean getJavaScriptEnabled() {
return mPrefs.getBoolean(Name.JAVASCRIPT, true);
}
public void setJavaScriptEnabled(boolean enable) {
putBoolean(Name.JAVASCRIPT, enable);
}
public boolean getLocationEnabled() {
return mPrefs.getBoolean(Name.LOCATION, false);
}
public void setLocationEnabled(boolean enable) {
putBoolean(Name.LOCATION, enable);
}
public boolean getOverviewModeEnabled() {
return mPrefs.getBoolean(Name.OVERVIEW_MODE, true);
}
public void setOverviewModeEnabled(boolean enable) {
putBoolean(Name.OVERVIEW_MODE, enable);
}
public boolean getPopupsEnabled() {
return mPrefs.getBoolean(Name.POPUPS, true);
}
public void setPopupsEnabled(boolean enable) {
putBoolean(Name.POPUPS, enable);
}
public boolean getRestoreLostTabsEnabled() {
return mPrefs.getBoolean(Name.RESTORE_LOST_TABS, true);
}
public void setRestoreLostTabsEnabled(boolean enable) {
putBoolean(Name.RESTORE_LOST_TABS, enable);
}
public boolean getSavePasswordsEnabled() {
return mPrefs.getBoolean(Name.SAVE_PASSWORDS, true);
}
public void setSavePasswordsEnabled(boolean enable) {
putBoolean(Name.SAVE_PASSWORDS, enable);
}
public int getSearchChoice() {
return mPrefs.getInt(Name.SEARCH, 1);
}
public void setSearchChoice(int choice) {
putInt(Name.SEARCH, choice);
}
public String getSearchUrl() {
return mPrefs.getString(Name.SEARCH_URL, Constants.GOOGLE_SEARCH);
}
public void setSearchUrl(String url) {
putString(Name.SEARCH_URL, url);
}
public boolean getSystemBrowserPresent() {
return mPrefs.getBoolean(Name.SYSTEM_BROWSER_PRESENT, false);
}
public void setSystemBrowserPresent(boolean available) {
putBoolean(Name.SYSTEM_BROWSER_PRESENT, available);
}
public boolean getTextReflowEnabled() {
return mPrefs.getBoolean(Name.TEXT_REFLOW, false);
}
public void setTextReflowEnabled(boolean enable) {
putBoolean(Name.TEXT_REFLOW, enable);
}
public int getTextSize() {
return mPrefs.getInt(Name.TEXT_SIZE, 3);
}
public void setTextSize(int size) {
putInt(Name.TEXT_SIZE, size);
}
public String getMemoryUrl() {
return mPrefs.getString(Name.URL_MEMORY, "");
}
public void setMemoryUrl(String url) {
putString(Name.URL_MEMORY, url);
}
public boolean getUseWideViewportEnabled() {
return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true);
}
public void setUseWideViewportEnabled(boolean enable) {
putBoolean(Name.USE_WIDE_VIEWPORT, enable);
}
public int getUserAgentChoice() {
return mPrefs.getInt(Name.USER_AGENT, 1);
}
public void setUserAgentChoice(int choice) {
putInt(Name.USER_AGENT, choice);
}
public String getUserAgentString(String def) {
return mPrefs.getString(Name.USER_AGENT_STRING, def);
}
public void setUserAgentString(String agent) {
putString(Name.USER_AGENT_STRING, agent);
}
public boolean getGoogleSearchSuggestionsEnabled() {
return mPrefs.getBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, true);
}
public void setGoogleSearchSuggestionsEnabled(boolean enabled) {
putBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, enabled);
}
public boolean getClearHistoryExitEnabled() {
return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false);
}
public void setClearHistoryExitEnabled(boolean enable) {
putBoolean(Name.CLEAR_HISTORY_EXIT, enable);
}
public boolean getClearCookiesExitEnabled() {
return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false);
}
public void setClearCookiesExitEnabled(boolean enable) {
putBoolean(Name.CLEAR_COOKIES_EXIT, enable);
}
public String getSavedUrl() {
return mPrefs.getString(Name.SAVE_URL, null);
}
public void setSavedUrl(String url) {
putString(Name.SAVE_URL, url);
}
public int getRenderingMode() {
return mPrefs.getInt(Name.RENDERING_MODE, 0);
}
public void setRenderingMode(int mode) {
putInt(Name.RENDERING_MODE, mode);
}
public boolean getSyncHistoryEnabled() {
return mPrefs.getBoolean(Name.SYNC_HISTORY, true);
}
public void setSyncHistoryEnabled(boolean enable) {
putBoolean(Name.SYNC_HISTORY, enable);
}
public boolean getBlockThirdPartyCookiesEnabled() {
return mPrefs.getBoolean(Name.BLOCK_THIRD_PARTY, false);
}
public void setBlockThirdPartyCookiesEnabled(boolean enable) {
putBoolean(Name.BLOCK_THIRD_PARTY, enable);
}
public boolean getColorModeEnabled() {
return mPrefs.getBoolean(Name.ENABLE_COLOR_MODE, true);
}
public void setColorModeEnabled(boolean enable) {
mPrefs.edit().putBoolean(Name.ENABLE_COLOR_MODE, enable).apply();
}
public int getUrlBoxContentChoice() {
return mPrefs.getInt(Name.URL_BOX_CONTENTS, 0);
}
public void setUrlBoxContentChoice(int choice) {
mPrefs.edit().putInt(Name.URL_BOX_CONTENTS, choice).apply();
}
public boolean getUseProxy() {
return mPrefs.getBoolean(Name.USE_PROXY, false);
}
public void setUseProxy(boolean enable) {
mPrefs.edit().putBoolean(Name.USE_PROXY, enable).apply();
}
public String getProxyHost() {
return mPrefs.getString(Name.USE_PROXY_HOST, "localhost");
}
public int getProxyPort() {
return mPrefs.getInt(Name.USE_PROXY_PORT, 8118);
}
public boolean getCheckedForTor() {
return mPrefs.getBoolean(Name.INITIAL_CHECK_FOR_TOR, false);
}
public void setCheckedForTor(boolean check) {
putBoolean(Name.INITIAL_CHECK_FOR_TOR, check);
}
private void putInt(String name, int value) {
mPrefs.edit().putInt(name, value).apply();
}
private void putBoolean(String name, boolean value) {
mPrefs.edit().putBoolean(name, value).apply();
}
private void putString(String name, String value) {
mPrefs.edit().putString(name, value).apply();
}
private class Name {
public static final String ADOBE_FLASH_SUPPORT = "enableflash";
public static final String BLOCK_ADS = "AdBlock";
public static final String BLOCK_IMAGES = "blockimages";
public static final String CLEAR_CACHE_EXIT = "cache";
public static final String COOKIES = "cookies";
public static final String DOWNLOAD_DIRECTORY = "download";
public static final String FULL_SCREEN = "fullscreen";
public static final String HIDE_STATUS_BAR = "hidestatus";
public static final String HOMEPAGE = "home";
public static final String INCOGNITO_COOKIES = "incognitocookies";
public static final String JAVASCRIPT = "java";
public static final String LOCATION = "location";
public static final String OVERVIEW_MODE = "overviewmode";
public static final String POPUPS = "newwindows";
public static final String RESTORE_LOST_TABS = "restoreclosed";
public static final String SAVE_PASSWORDS = "passwords";
public static final String SEARCH = "search";
public static final String SEARCH_URL = "searchurl";
public static final String SYSTEM_BROWSER_PRESENT = "SystemBrowser";
public static final String TEXT_REFLOW = "textreflow";
public static final String TEXT_SIZE = "textsize";
public static final String URL_MEMORY = "memory";
public static final String USE_WIDE_VIEWPORT = "wideviewport";
public static final String USER_AGENT = "agentchoose";
public static final String USER_AGENT_STRING = "userAgentString";
public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions";
public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit";
public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit";
public static final String SAVE_URL = "saveUrl";
public static final String RENDERING_MODE = "renderMode";
public static final String SYNC_HISTORY = "syncHistory";
public static final String BLOCK_THIRD_PARTY = "thirdParty";
public static final String ENABLE_COLOR_MODE = "colorMode";
public static final String URL_BOX_CONTENTS = "urlContent";
public static final String INVERT_COLORS = "invertColors";
public static final String READING_TEXT_SIZE = "readingTextSize";
public static final String DARK_THEME = "darkTheme";
public static final String USE_PROXY = "useProxy";
public static final String USE_PROXY_HOST = "useProxyHost";
public static final String USE_PROXY_PORT = "useProxyPort";
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
}
}

49
src/acr/browser/lightning/PrivacySettingsActivity.java

@ -6,7 +6,6 @@ package acr.browser.lightning;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -27,8 +26,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
// mPreferences variables // mPreferences variables
private static final int API = android.os.Build.VERSION.SDK_INT; private static final int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences mPreferences; private PreferenceManager mPreferences;
private SharedPreferences.Editor mEditPrefs;
private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit, private CheckBox cbLocation, cbSavePasswords, cbClearCacheExit, cbClearHistoryExit,
cbClearCookiesExit, cbThirdParty; cbClearCookiesExit, cbThirdParty;
private Context mContext; private Context mContext;
@ -48,10 +46,9 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
// TODO WARNING: SharedPreferences.edit() without a corresponding // TODO WARNING: SharedPreferences.edit() without a corresponding
// commit() or apply() call // commit() or apply() call
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = PreferenceManager.getInstance();
mEditPrefs = mPreferences.edit();
mSystemBrowser = mPreferences.getBoolean(PreferenceConstants.SYSTEM_BROWSER_PRESENT, false); mSystemBrowser = mPreferences.getSystemBrowserPresent();
mContext = this; mContext = this;
initialize(); initialize();
} }
@ -83,17 +80,12 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit); cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit);
cbThirdParty = (CheckBox) findViewById(R.id.cbThirdParty); cbThirdParty = (CheckBox) findViewById(R.id.cbThirdParty);
cbLocation.setChecked(mPreferences.getBoolean(PreferenceConstants.LOCATION, false)); cbLocation.setChecked(mPreferences.getLocationEnabled());
cbSavePasswords.setChecked(mPreferences cbSavePasswords.setChecked(mPreferences.getSavePasswordsEnabled());
.getBoolean(PreferenceConstants.SAVE_PASSWORDS, true)); cbClearCacheExit.setChecked(mPreferences.getClearCacheExit());
cbClearCacheExit.setChecked(mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, cbClearHistoryExit.setChecked(mPreferences.getClearHistoryExitEnabled());
false)); cbClearCookiesExit.setChecked(mPreferences.getClearCookiesExitEnabled());
cbClearHistoryExit.setChecked(mPreferences.getBoolean( cbThirdParty.setChecked(mPreferences.getBlockThirdPartyCookiesEnabled());
PreferenceConstants.CLEAR_HISTORY_EXIT, false));
cbClearCookiesExit.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_COOKIES_EXIT, false));
cbThirdParty.setChecked(mPreferences.getBoolean(PreferenceConstants.BLOCK_THIRD_PARTY,
false));
cbThirdParty.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); cbThirdParty.setEnabled(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP);
@ -129,7 +121,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.SYNC_HISTORY, isChecked).apply(); mPreferences.setSyncHistoryEnabled(isChecked);
} }
}); });
@ -140,8 +132,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
syncHistory.setText(getResources().getString(R.string.stock_browser_unavailable)); syncHistory.setText(getResources().getString(R.string.stock_browser_unavailable));
} else { } else {
cbSyncHistory.setEnabled(true); cbSyncHistory.setEnabled(true);
cbSyncHistory.setChecked(mPreferences cbSyncHistory.setChecked(mPreferences.getSyncHistoryEnabled());
.getBoolean(PreferenceConstants.SYNC_HISTORY, true));
syncHistory.setText(getResources().getString(R.string.stock_browser_available)); syncHistory.setText(getResources().getString(R.string.stock_browser_available));
} }
@ -180,8 +171,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.LOCATION, isChecked); mPreferences.setLocationEnabled(isChecked);
mEditPrefs.apply();
} }
}); });
@ -192,8 +182,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.SAVE_PASSWORDS, isChecked); mPreferences.setSavePasswordsEnabled(isChecked);
mEditPrefs.apply();
} }
}); });
@ -204,8 +193,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, isChecked); mPreferences.setClearCacheExit(isChecked);
mEditPrefs.apply();
} }
}); });
@ -216,8 +204,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT, isChecked); mPreferences.setClearHistoryExitEnabled(isChecked);
mEditPrefs.apply();
} }
}); });
@ -228,8 +215,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_THIRD_PARTY, isChecked); mPreferences.setBlockThirdPartyCookiesEnabled(isChecked);
mEditPrefs.apply();
} }
}); });
@ -240,8 +226,7 @@ public class PrivacySettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT, isChecked); mPreferences.setClearCookiesExitEnabled(isChecked);
mEditPrefs.apply();
} }
}); });

16
src/acr/browser/lightning/ReadingActivity.java

@ -12,7 +12,6 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
@ -31,7 +30,7 @@ public class ReadingActivity extends ActionBarActivity {
private TextView mBody; private TextView mBody;
private boolean mInvert; private boolean mInvert;
private String mUrl = null; private String mUrl = null;
private SharedPreferences mPreferences; private PreferenceManager mPreferences;
private int mTextSize; private int mTextSize;
private static final float XXLARGE = 30.0f; private static final float XXLARGE = 30.0f;
private static final float XLARGE = 26.0f; private static final float XLARGE = 26.0f;
@ -42,9 +41,8 @@ public class ReadingActivity extends ActionBarActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = PreferenceManager.getInstance();
boolean initInvert = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false); mInvert = mPreferences.getInvertColors();
mInvert = mPreferences.getBoolean(PreferenceConstants.INVERT_COLORS, initInvert);
if (mInvert) { if (mInvert) {
this.setTheme(R.style.Theme_SettingsTheme_Dark); this.setTheme(R.style.Theme_SettingsTheme_Dark);
} }
@ -58,7 +56,7 @@ public class ReadingActivity extends ActionBarActivity {
mTitle = (TextView) findViewById(R.id.textViewTitle); mTitle = (TextView) findViewById(R.id.textViewTitle);
mBody = (TextView) findViewById(R.id.textViewBody); mBody = (TextView) findViewById(R.id.textViewBody);
mTextSize = mPreferences.getInt(PreferenceConstants.READING_TEXT_SIZE, 2); mTextSize = mPreferences.getReadingTextSize();
mBody.setTextSize(getTextSize(mTextSize)); mBody.setTextSize(getTextSize(mTextSize));
mTitle.setText(getString(R.string.untitled)); mTitle.setText(getString(R.string.untitled));
mBody.setText(getString(R.string.loading)); mBody.setText(getString(R.string.loading));
@ -198,7 +196,7 @@ public class ReadingActivity extends ActionBarActivity {
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.invert_item: case R.id.invert_item:
mPreferences.edit().putBoolean(PreferenceConstants.INVERT_COLORS, !mInvert).apply(); mPreferences.setInvertColors(!mInvert);
Intent read = new Intent(this, ReadingActivity.class); Intent read = new Intent(this, ReadingActivity.class);
read.putExtra(Constants.LOAD_READING_URL, mUrl); read.putExtra(Constants.LOAD_READING_URL, mUrl);
startActivity(read); startActivity(read);
@ -235,9 +233,7 @@ public class ReadingActivity extends ActionBarActivity {
public void onClick(DialogInterface arg0, int arg1) { public void onClick(DialogInterface arg0, int arg1) {
mTextSize = bar.getProgress(); mTextSize = bar.getProgress();
mBody.setTextSize(getTextSize(mTextSize)); mBody.setTextSize(getTextSize(mTextSize));
mPreferences.edit() mPreferences.setReadingTextSize(bar.getProgress());
.putInt(PreferenceConstants.READING_TEXT_SIZE, bar.getProgress())
.apply();
} }
}); });

7
src/acr/browser/lightning/SearchAdapter.java

@ -21,7 +21,6 @@ import org.xmlpull.v1.XmlPullParserFactory;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources.Theme; import android.content.res.Resources.Theme;
import android.graphics.Color; import android.graphics.Color;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
@ -45,7 +44,6 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private List<HistoryItem> mFilteredList; private List<HistoryItem> mFilteredList;
private List<HistoryItem> mAllBookmarks; private List<HistoryItem> mAllBookmarks;
private HistoryDatabase mDatabaseHandler; private HistoryDatabase mDatabaseHandler;
private SharedPreferences mPreferences;
private Context mContext; private Context mContext;
private boolean mUseGoogle = true; private boolean mUseGoogle = true;
private boolean mIsExecuting = false; private boolean mIsExecuting = false;
@ -68,8 +66,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
mSuggestions = new ArrayList<HistoryItem>(); mSuggestions = new ArrayList<HistoryItem>();
mBookmarkManager = BookmarkManager.getInstance(context.getApplicationContext()); mBookmarkManager = BookmarkManager.getInstance(context.getApplicationContext());
mAllBookmarks = mBookmarkManager.getBookmarks(true); mAllBookmarks = mBookmarkManager.getBookmarks(true);
mPreferences = context.getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
mUseGoogle = mPreferences.getBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, true);
mContext = context; mContext = context;
mSearchSubtitle = mContext.getString(R.string.suggestion); mSearchSubtitle = mContext.getString(R.string.suggestion);
mDarkTheme = dark || incognito; mDarkTheme = dark || incognito;
@ -109,7 +106,7 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} }
public void refreshPreferences() { public void refreshPreferences() {
mUseGoogle = mPreferences.getBoolean(PreferenceConstants.GOOGLE_SEARCH_SUGGESTIONS, true); mUseGoogle = PreferenceManager.getInstance().getGoogleSearchSuggestionsEnabled();
if (!mUseGoogle && mSuggestions != null) { if (!mUseGoogle && mSuggestions != null) {
mSuggestions.clear(); mSuggestions.clear();
} }

117
src/acr/browser/lightning/SettingsActivity.java

@ -10,7 +10,6 @@ import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnCancelListener;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
@ -29,8 +28,7 @@ import info.guardianproject.onionkit.ui.OrbotHelper;
public class SettingsActivity extends ThemableSettingsActivity { public class SettingsActivity extends ThemableSettingsActivity {
private static int API = android.os.Build.VERSION.SDK_INT; private static int API = android.os.Build.VERSION.SDK_INT;
private SharedPreferences.Editor mEditPrefs; private PreferenceManager mPreferences;
private SharedPreferences mPreferences;
private Context mContext; private Context mContext;
private Activity mActivity; private Activity mActivity;
@ -58,8 +56,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// mPreferences storage // mPreferences storage
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = PreferenceManager.getInstance();
mEditPrefs = mPreferences.edit();
// initialize UI // initialize UI
RelativeLayout layoutFlash = (RelativeLayout) findViewById(R.id.layoutFlash); RelativeLayout layoutFlash = (RelativeLayout) findViewById(R.id.layoutFlash);
@ -80,12 +77,11 @@ public class SettingsActivity extends ThemableSettingsActivity {
}); });
if (API >= 19) { if (API >= 19) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0); mPreferences.setFlashSupport(0);
mEditPrefs.apply();
} }
int flashNum = mPreferences.getInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0); int flashNum = mPreferences.getFlashSupport();
boolean imagesBool = mPreferences.getBoolean(PreferenceConstants.BLOCK_IMAGES, false); boolean imagesBool = mPreferences.getBlockImagesEnabled();
boolean enableJSBool = mPreferences.getBoolean(PreferenceConstants.JAVASCRIPT, true); boolean enableJSBool = mPreferences.getJavaScriptEnabled();
CheckBox flash = (CheckBox) findViewById(R.id.cbFlash); CheckBox flash = (CheckBox) findViewById(R.id.cbFlash);
CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock); CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock);
@ -101,9 +97,9 @@ public class SettingsActivity extends ThemableSettingsActivity {
} else { } else {
flash.setChecked(false); flash.setChecked(false);
} }
adblock.setChecked(mPreferences.getBoolean(PreferenceConstants.BLOCK_ADS, false)); adblock.setChecked(mPreferences.getAdBlockEnabled());
orbot.setChecked(mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false)); orbot.setChecked(mPreferences.getUseProxy());
color.setChecked(mPreferences.getBoolean(PreferenceConstants.ENABLE_COLOR_MODE, true)); color.setChecked(mPreferences.getColorModeEnabled());
initCheckBox(flash, adblock, images, enablejs, orbot, color); initCheckBox(flash, adblock, images, enablejs, orbot, color);
clickListenerForCheckBoxes(layoutFlash, layoutBlockAds, layoutImages, layoutEnableJS, clickListenerForCheckBoxes(layoutFlash, layoutBlockAds, layoutImages, layoutEnableJS,
@ -197,8 +193,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
if (isChecked) { if (isChecked) {
getFlashChoice(); getFlashChoice();
} else { } else {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0); mPreferences.setFlashSupport(0);
mEditPrefs.apply();
} }
boolean flashInstalled = false; boolean flashInstalled = false;
@ -216,8 +211,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
getResources().getString(R.string.title_warning), getResources() getResources().getString(R.string.title_warning), getResources()
.getString(R.string.dialog_adobe_not_installed)); .getString(R.string.dialog_adobe_not_installed));
buttonView.setChecked(false); buttonView.setChecked(false);
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0); mPreferences.setFlashSupport(0);
mEditPrefs.apply();
} else if ((API >= 17) && isChecked) { } else if ((API >= 17) && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this, Utils.createInformativeDialog(SettingsActivity.this,
@ -231,8 +225,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_ADS, isChecked); mPreferences.setAdBlockEnabled(isChecked);
mEditPrefs.apply();
} }
}); });
@ -240,8 +233,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_IMAGES, isChecked); mPreferences.setBlockImagesEnabled(isChecked);
mEditPrefs.apply();
} }
@ -250,9 +242,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.JAVASCRIPT, isChecked); mPreferences.setJavaScriptEnabled(isChecked);
mEditPrefs.apply();
} }
}); });
@ -265,8 +255,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, isChecked); mPreferences.setUseProxy(isChecked);
mEditPrefs.apply();
} }
@ -275,8 +264,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.ENABLE_COLOR_MODE, isChecked); mPreferences.setColorModeEnabled(isChecked);
mEditPrefs.apply();
} }
@ -292,8 +280,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 1); mPreferences.setFlashSupport(1);
mEditPrefs.apply();
} }
}) })
.setNegativeButton(getResources().getString(R.string.action_auto), .setNegativeButton(getResources().getString(R.string.action_auto),
@ -301,15 +288,13 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 2); mPreferences.setFlashSupport(2);
mEditPrefs.apply();
} }
}).setOnCancelListener(new OnCancelListener() { }).setOnCancelListener(new OnCancelListener() {
@Override @Override
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0); mPreferences.setFlashSupport(0);
mEditPrefs.apply();
} }
}); });
@ -317,71 +302,12 @@ public class SettingsActivity extends ThemableSettingsActivity {
alert.show(); alert.show();
} }
public void initCheckBox(CheckBox flash, CheckBox images, CheckBox enablejs) {
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int n = 0;
if (isChecked) {
n = 1;
}
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, n);
mEditPrefs.apply();
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
if (ai != null) {
flashInstalled = true;
}
} catch (NameNotFoundException e) {
flashInstalled = false;
}
if (!flashInstalled && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this,
getResources().getString(R.string.title_warning), getResources()
.getString(R.string.dialog_adobe_not_installed));
buttonView.setChecked(false);
mEditPrefs.putInt(PreferenceConstants.ADOBE_FLASH_SUPPORT, 0);
mEditPrefs.apply();
} else if ((API > 17) && isChecked) {
Utils.createInformativeDialog(SettingsActivity.this,
getResources().getString(R.string.title_warning), getResources()
.getString(R.string.dialog_adobe_unsupported));
}
}
});
images.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.BLOCK_IMAGES, isChecked);
mEditPrefs.apply();
}
});
enablejs.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.JAVASCRIPT, isChecked);
mEditPrefs.apply();
}
});
}
public void agentPicker() { public void agentPicker() {
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity); final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);
agentStringPicker.setTitle(getResources().getString(R.string.title_user_agent)); agentStringPicker.setTitle(getResources().getString(R.string.title_user_agent));
final EditText getAgent = new EditText(this); final EditText getAgent = new EditText(this);
getAgent.append(mPreferences.getString(PreferenceConstants.USER_AGENT_STRING, "")); getAgent.append(mPreferences.getUserAgentString(""));
agentStringPicker.setView(getAgent); agentStringPicker.setView(getAgent);
agentStringPicker.setPositiveButton(getResources().getString(R.string.action_ok), agentStringPicker.setPositiveButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@ -389,8 +315,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
String text = getAgent.getText().toString(); String text = getAgent.getText().toString();
mEditPrefs.putString(PreferenceConstants.USER_AGENT_STRING, text); mPreferences.setUserAgentString(text);
mEditPrefs.apply();
getAgent.setText(getResources().getString(R.string.agent_custom)); getAgent.setText(getResources().getString(R.string.agent_custom));
} }
}); });

9
src/acr/browser/lightning/ThemableActivity.java

@ -1,19 +1,16 @@
package acr.browser.lightning; package acr.browser.lightning;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
public abstract class ThemableActivity extends ActionBarActivity { public abstract class ThemableActivity extends ActionBarActivity {
private SharedPreferences mPreferences;
private boolean mDark; private boolean mDark;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mDark = PreferenceManager.getInstance().getUseDarkTheme();
mDark = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false);
// set the theme // set the theme
if (mDark) { if (mDark) {
@ -25,9 +22,7 @@ public abstract class ThemableActivity extends ActionBarActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (mPreferences != null if (PreferenceManager.getInstance().getUseDarkTheme() != mDark) {
&& mPreferences.getBoolean(PreferenceConstants.DARK_THEME,
false) != mDark) {
restart(); restart();
} }
} }

9
src/acr/browser/lightning/ThemableSettingsActivity.java

@ -1,19 +1,16 @@
package acr.browser.lightning; package acr.browser.lightning;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
public abstract class ThemableSettingsActivity extends ActionBarActivity { public abstract class ThemableSettingsActivity extends ActionBarActivity {
private SharedPreferences mPreferences;
private boolean mDark; private boolean mDark;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mDark = PreferenceManager.getInstance().getUseDarkTheme();
mDark = mPreferences.getBoolean(PreferenceConstants.DARK_THEME, false);
// set the theme // set the theme
if (mDark) { if (mDark) {
@ -25,9 +22,7 @@ public abstract class ThemableSettingsActivity extends ActionBarActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (mPreferences != null if (PreferenceManager.getInstance().getUseDarkTheme() != mDark) {
&& mPreferences.getBoolean(PreferenceConstants.DARK_THEME,
false) != mDark) {
restart(); restart();
} }
} }

Loading…
Cancel
Save