Browse Source

Organize PreferenceManager

master
Anthony Restaino 10 years ago
parent
commit
6f30103cd9
  1. 401
      src/acr/browser/lightning/PreferenceManager.java

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

@ -5,13 +5,55 @@ import android.os.Environment;
public class PreferenceManager { public class PreferenceManager {
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";
}
private static PreferenceManager mInstance; private static PreferenceManager mInstance;
private static SharedPreferences mPrefs; private static SharedPreferences mPrefs;
private static final String PREFERENCES = "settings";
private PreferenceManager() { private static final String PREFERENCES = "settings";
mPrefs = BrowserApp.getAppContext().getSharedPreferences(PREFERENCES, 0);
}
public static PreferenceManager getInstance() { public static PreferenceManager getInstance() {
if (mInstance == null) { if (mInstance == null) {
@ -20,380 +62,339 @@ public class PreferenceManager {
return mInstance; return mInstance;
} }
public int getFlashSupport() { private PreferenceManager() {
return mPrefs.getInt(Name.ADOBE_FLASH_SUPPORT, 0); mPrefs = BrowserApp.getAppContext().getSharedPreferences(PREFERENCES, 0);
}
public void setFlashSupport(int n) {
putInt(Name.ADOBE_FLASH_SUPPORT, n);
} }
public boolean getAdBlockEnabled() { public boolean getAdBlockEnabled() {
return mPrefs.getBoolean(Name.BLOCK_ADS, false); 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() { public boolean getBlockImagesEnabled() {
return mPrefs.getBoolean(Name.BLOCK_IMAGES, false); return mPrefs.getBoolean(Name.BLOCK_IMAGES, false);
} }
public void setBlockImagesEnabled(boolean enable) { public boolean getBlockThirdPartyCookiesEnabled() {
putBoolean(Name.BLOCK_IMAGES, enable); return mPrefs.getBoolean(Name.BLOCK_THIRD_PARTY, false);
}
public boolean getInvertColors() {
return mPrefs.getBoolean(Name.INVERT_COLORS, false);
} }
public void setInvertColors(boolean enable) { public boolean getCheckedForTor() {
putBoolean(Name.INVERT_COLORS, enable); return mPrefs.getBoolean(Name.INITIAL_CHECK_FOR_TOR, false);
} }
public boolean getClearCacheExit() { public boolean getClearCacheExit() {
return mPrefs.getBoolean(Name.CLEAR_CACHE_EXIT, false); return mPrefs.getBoolean(Name.CLEAR_CACHE_EXIT, false);
} }
public void setClearCacheExit(boolean enable) { public boolean getClearCookiesExitEnabled() {
putBoolean(Name.CLEAR_CACHE_EXIT, enable); return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false);
} }
public boolean getCookiesEnabled() { public boolean getClearHistoryExitEnabled() {
return mPrefs.getBoolean(Name.COOKIES, true); return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false);
} }
public void setCookiesEnabled(boolean enable) { public boolean getColorModeEnabled() {
putBoolean(Name.COOKIES, enable); return mPrefs.getBoolean(Name.ENABLE_COLOR_MODE, true);
}
public boolean getCookiesEnabled() {
return mPrefs.getBoolean(Name.COOKIES, true);
} }
public String getDownloadDirectory() { public String getDownloadDirectory() {
return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, Environment.DIRECTORY_DOWNLOADS); return mPrefs.getString(Name.DOWNLOAD_DIRECTORY, Environment.DIRECTORY_DOWNLOADS);
} }
public void setDownloadDirectory(String directory) { public int getFlashSupport() {
putString(Name.DOWNLOAD_DIRECTORY, directory); return mPrefs.getInt(Name.ADOBE_FLASH_SUPPORT, 0);
} }
public boolean getFullScreenEnabled() { public boolean getFullScreenEnabled() {
return mPrefs.getBoolean(Name.FULL_SCREEN, false); return mPrefs.getBoolean(Name.FULL_SCREEN, false);
} }
public void setFullScreenEnabled(boolean enable) { public boolean getGoogleSearchSuggestionsEnabled() {
putBoolean(Name.FULL_SCREEN, enable); return mPrefs.getBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, true);
} }
public boolean getHideStatusBarEnabled() { public boolean getHideStatusBarEnabled() {
return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false); return mPrefs.getBoolean(Name.HIDE_STATUS_BAR, false);
} }
public void setHideStatusBarEnabled(boolean enable) {
putBoolean(Name.HIDE_STATUS_BAR, enable);
}
public String getHomepage() { public String getHomepage() {
return mPrefs.getString(Name.HOMEPAGE, Constants.HOMEPAGE); 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() { public boolean getIncognitoCookiesEnabled() {
return mPrefs.getBoolean(Name.INCOGNITO_COOKIES, false); return mPrefs.getBoolean(Name.INCOGNITO_COOKIES, false);
} }
public void setIncognitoCookiesEnabled(boolean enable) { public boolean getInvertColors() {
putBoolean(Name.INCOGNITO_COOKIES, enable); return mPrefs.getBoolean(Name.INVERT_COLORS, false);
} }
public boolean getJavaScriptEnabled() { public boolean getJavaScriptEnabled() {
return mPrefs.getBoolean(Name.JAVASCRIPT, true); return mPrefs.getBoolean(Name.JAVASCRIPT, true);
} }
public void setJavaScriptEnabled(boolean enable) {
putBoolean(Name.JAVASCRIPT, enable);
}
public boolean getLocationEnabled() { public boolean getLocationEnabled() {
return mPrefs.getBoolean(Name.LOCATION, false); return mPrefs.getBoolean(Name.LOCATION, false);
} }
public void setLocationEnabled(boolean enable) { public String getMemoryUrl() {
putBoolean(Name.LOCATION, enable); return mPrefs.getString(Name.URL_MEMORY, "");
} }
public boolean getOverviewModeEnabled() { public boolean getOverviewModeEnabled() {
return mPrefs.getBoolean(Name.OVERVIEW_MODE, true); return mPrefs.getBoolean(Name.OVERVIEW_MODE, true);
} }
public void setOverviewModeEnabled(boolean enable) {
putBoolean(Name.OVERVIEW_MODE, enable);
}
public boolean getPopupsEnabled() { public boolean getPopupsEnabled() {
return mPrefs.getBoolean(Name.POPUPS, true); return mPrefs.getBoolean(Name.POPUPS, true);
} }
public void setPopupsEnabled(boolean enable) { public String getProxyHost() {
putBoolean(Name.POPUPS, enable); return mPrefs.getString(Name.USE_PROXY_HOST, "localhost");
}
public int getProxyPort() {
return mPrefs.getInt(Name.USE_PROXY_PORT, 8118);
}
public int getReadingTextSize() {
return mPrefs.getInt(Name.READING_TEXT_SIZE, 2);
}
public int getRenderingMode() {
return mPrefs.getInt(Name.RENDERING_MODE, 0);
} }
public boolean getRestoreLostTabsEnabled() { public boolean getRestoreLostTabsEnabled() {
return mPrefs.getBoolean(Name.RESTORE_LOST_TABS, true); return mPrefs.getBoolean(Name.RESTORE_LOST_TABS, true);
} }
public void setRestoreLostTabsEnabled(boolean enable) { public String getSavedUrl() {
putBoolean(Name.RESTORE_LOST_TABS, enable); return mPrefs.getString(Name.SAVE_URL, null);
} }
public boolean getSavePasswordsEnabled() { public boolean getSavePasswordsEnabled() {
return mPrefs.getBoolean(Name.SAVE_PASSWORDS, true); return mPrefs.getBoolean(Name.SAVE_PASSWORDS, true);
} }
public void setSavePasswordsEnabled(boolean enable) {
putBoolean(Name.SAVE_PASSWORDS, enable);
}
public int getSearchChoice() { public int getSearchChoice() {
return mPrefs.getInt(Name.SEARCH, 1); return mPrefs.getInt(Name.SEARCH, 1);
} }
public void setSearchChoice(int choice) {
putInt(Name.SEARCH, choice);
}
public String getSearchUrl() { public String getSearchUrl() {
return mPrefs.getString(Name.SEARCH_URL, Constants.GOOGLE_SEARCH); return mPrefs.getString(Name.SEARCH_URL, Constants.GOOGLE_SEARCH);
} }
public void setSearchUrl(String url) { public boolean getSyncHistoryEnabled() {
putString(Name.SEARCH_URL, url); return mPrefs.getBoolean(Name.SYNC_HISTORY, true);
} }
public boolean getSystemBrowserPresent() { public boolean getSystemBrowserPresent() {
return mPrefs.getBoolean(Name.SYSTEM_BROWSER_PRESENT, false); return mPrefs.getBoolean(Name.SYSTEM_BROWSER_PRESENT, false);
} }
public void setSystemBrowserPresent(boolean available) {
putBoolean(Name.SYSTEM_BROWSER_PRESENT, available);
}
public boolean getTextReflowEnabled() { public boolean getTextReflowEnabled() {
return mPrefs.getBoolean(Name.TEXT_REFLOW, false); return mPrefs.getBoolean(Name.TEXT_REFLOW, false);
} }
public void setTextReflowEnabled(boolean enable) {
putBoolean(Name.TEXT_REFLOW, enable);
}
public int getTextSize() { public int getTextSize() {
return mPrefs.getInt(Name.TEXT_SIZE, 3); return mPrefs.getInt(Name.TEXT_SIZE, 3);
} }
public void setTextSize(int size) { public int getUrlBoxContentChoice() {
putInt(Name.TEXT_SIZE, size); return mPrefs.getInt(Name.URL_BOX_CONTENTS, 0);
} }
public String getMemoryUrl() { public boolean getUseDarkTheme() {
return mPrefs.getString(Name.URL_MEMORY, ""); return mPrefs.getBoolean(Name.DARK_THEME, false);
} }
public void setMemoryUrl(String url) { public boolean getUseProxy() {
putString(Name.URL_MEMORY, url); return mPrefs.getBoolean(Name.USE_PROXY, false);
}
public int getUserAgentChoice() {
return mPrefs.getInt(Name.USER_AGENT, 1);
}
public String getUserAgentString(String def) {
return mPrefs.getString(Name.USER_AGENT_STRING, def);
} }
public boolean getUseWideViewportEnabled() { public boolean getUseWideViewportEnabled() {
return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true); return mPrefs.getBoolean(Name.USE_WIDE_VIEWPORT, true);
} }
public void setUseWideViewportEnabled(boolean enable) { private void putBoolean(String name, boolean value) {
putBoolean(Name.USE_WIDE_VIEWPORT, enable); mPrefs.edit().putBoolean(name, value).apply();
} }
public int getUserAgentChoice() { private void putInt(String name, int value) {
return mPrefs.getInt(Name.USER_AGENT, 1); mPrefs.edit().putInt(name, value).apply();
} }
public void setUserAgentChoice(int choice) { private void putString(String name, String value) {
putInt(Name.USER_AGENT, choice); mPrefs.edit().putString(name, value).apply();
} }
public String getUserAgentString(String def) { public void setAdBlockEnabled(boolean enable) {
return mPrefs.getString(Name.USER_AGENT_STRING, def); putBoolean(Name.BLOCK_ADS, enable);
} }
public void setUserAgentString(String agent) { public void setBlockImagesEnabled(boolean enable) {
putString(Name.USER_AGENT_STRING, agent); putBoolean(Name.BLOCK_IMAGES, enable);
} }
public boolean getGoogleSearchSuggestionsEnabled() { public void setBlockThirdPartyCookiesEnabled(boolean enable) {
return mPrefs.getBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, true); putBoolean(Name.BLOCK_THIRD_PARTY, enable);
} }
public void setGoogleSearchSuggestionsEnabled(boolean enabled) { public void setCheckedForTor(boolean check) {
putBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, enabled); putBoolean(Name.INITIAL_CHECK_FOR_TOR, check);
} }
public boolean getClearHistoryExitEnabled() { public void setClearCacheExit(boolean enable) {
return mPrefs.getBoolean(Name.CLEAR_HISTORY_EXIT, false); putBoolean(Name.CLEAR_CACHE_EXIT, enable);
}
public void setClearCookiesExitEnabled(boolean enable) {
putBoolean(Name.CLEAR_COOKIES_EXIT, enable);
} }
public void setClearHistoryExitEnabled(boolean enable) { public void setClearHistoryExitEnabled(boolean enable) {
putBoolean(Name.CLEAR_HISTORY_EXIT, enable); putBoolean(Name.CLEAR_HISTORY_EXIT, enable);
} }
public boolean getClearCookiesExitEnabled() { public void setColorModeEnabled(boolean enable) {
return mPrefs.getBoolean(Name.CLEAR_COOKIES_EXIT, false); putBoolean(Name.ENABLE_COLOR_MODE, enable);
} }
public void setClearCookiesExitEnabled(boolean enable) { public void setCookiesEnabled(boolean enable) {
putBoolean(Name.CLEAR_COOKIES_EXIT, enable); putBoolean(Name.COOKIES, enable);
} }
public String getSavedUrl() { public void setDownloadDirectory(String directory) {
return mPrefs.getString(Name.SAVE_URL, null); putString(Name.DOWNLOAD_DIRECTORY, directory);
} }
public void setSavedUrl(String url) { public void setFlashSupport(int n) {
putString(Name.SAVE_URL, url); putInt(Name.ADOBE_FLASH_SUPPORT, n);
} }
public int getRenderingMode() { public void setFullScreenEnabled(boolean enable) {
return mPrefs.getInt(Name.RENDERING_MODE, 0); putBoolean(Name.FULL_SCREEN, enable);
} }
public void setRenderingMode(int mode) { public void setGoogleSearchSuggestionsEnabled(boolean enabled) {
putInt(Name.RENDERING_MODE, mode); putBoolean(Name.GOOGLE_SEARCH_SUGGESTIONS, enabled);
} }
public boolean getSyncHistoryEnabled() { public void setHideStatusBarEnabled(boolean enable) {
return mPrefs.getBoolean(Name.SYNC_HISTORY, true); putBoolean(Name.HIDE_STATUS_BAR, enable);
} }
public void setSyncHistoryEnabled(boolean enable) { public void setHomepage(String homepage) {
putBoolean(Name.SYNC_HISTORY, enable); putString(Name.HOMEPAGE, homepage);
} }
public boolean getBlockThirdPartyCookiesEnabled() { public void setIncognitoCookiesEnabled(boolean enable) {
return mPrefs.getBoolean(Name.BLOCK_THIRD_PARTY, false); putBoolean(Name.INCOGNITO_COOKIES, enable);
} }
public void setBlockThirdPartyCookiesEnabled(boolean enable) { public void setInvertColors(boolean enable) {
putBoolean(Name.BLOCK_THIRD_PARTY, enable); putBoolean(Name.INVERT_COLORS, enable);
} }
public boolean getColorModeEnabled() { public void setJavaScriptEnabled(boolean enable) {
return mPrefs.getBoolean(Name.ENABLE_COLOR_MODE, true); putBoolean(Name.JAVASCRIPT, enable);
} }
public void setColorModeEnabled(boolean enable) { public void setLocationEnabled(boolean enable) {
mPrefs.edit().putBoolean(Name.ENABLE_COLOR_MODE, enable).apply(); putBoolean(Name.LOCATION, enable);
} }
public int getUrlBoxContentChoice() { public void setMemoryUrl(String url) {
return mPrefs.getInt(Name.URL_BOX_CONTENTS, 0); putString(Name.URL_MEMORY, url);
} }
public void setUrlBoxContentChoice(int choice) { public void setOverviewModeEnabled(boolean enable) {
mPrefs.edit().putInt(Name.URL_BOX_CONTENTS, choice).apply(); putBoolean(Name.OVERVIEW_MODE, enable);
} }
public boolean getUseProxy() { public void setPopupsEnabled(boolean enable) {
return mPrefs.getBoolean(Name.USE_PROXY, false); putBoolean(Name.POPUPS, enable);
} }
public void setUseProxy(boolean enable) { public void setReadingTextSize(int size) {
mPrefs.edit().putBoolean(Name.USE_PROXY, enable).apply(); putInt(Name.READING_TEXT_SIZE, 2);
} }
public String getProxyHost() { public void setRenderingMode(int mode) {
return mPrefs.getString(Name.USE_PROXY_HOST, "localhost"); putInt(Name.RENDERING_MODE, mode);
} }
public int getProxyPort() { public void setRestoreLostTabsEnabled(boolean enable) {
return mPrefs.getInt(Name.USE_PROXY_PORT, 8118); putBoolean(Name.RESTORE_LOST_TABS, enable);
} }
public boolean getCheckedForTor() { public void setSavedUrl(String url) {
return mPrefs.getBoolean(Name.INITIAL_CHECK_FOR_TOR, false); putString(Name.SAVE_URL, url);
} }
public void setCheckedForTor(boolean check) { public void setSavePasswordsEnabled(boolean enable) {
putBoolean(Name.INITIAL_CHECK_FOR_TOR, check); putBoolean(Name.SAVE_PASSWORDS, enable);
} }
private void putInt(String name, int value) { public void setSearchChoice(int choice) {
mPrefs.edit().putInt(name, value).apply(); putInt(Name.SEARCH, choice);
} }
private void putBoolean(String name, boolean value) { public void setSearchUrl(String url) {
mPrefs.edit().putBoolean(name, value).apply(); putString(Name.SEARCH_URL, url);
} }
private void putString(String name, String value) { public void setSyncHistoryEnabled(boolean enable) {
mPrefs.edit().putString(name, value).apply(); putBoolean(Name.SYNC_HISTORY, enable);
} }
private class Name { public void setSystemBrowserPresent(boolean available) {
public static final String ADOBE_FLASH_SUPPORT = "enableflash"; putBoolean(Name.SYSTEM_BROWSER_PRESENT, available);
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 void setTextReflowEnabled(boolean enable) {
public static final String USE_PROXY_HOST = "useProxyHost"; putBoolean(Name.TEXT_REFLOW, enable);
public static final String USE_PROXY_PORT = "useProxyPort"; }
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
public void setTextSize(int size) {
putInt(Name.TEXT_SIZE, size);
}
public void setUrlBoxContentChoice(int choice) {
putInt(Name.URL_BOX_CONTENTS, choice);
}
public void setUseDarkTheme(boolean use) {
putBoolean(Name.DARK_THEME, use);
}
public void setUseProxy(boolean enable) {
putBoolean(Name.USE_PROXY, enable);
}
public void setUserAgentChoice(int choice) {
putInt(Name.USER_AGENT, choice);
}
public void setUserAgentString(String agent) {
putString(Name.USER_AGENT_STRING, agent);
}
public void setUseWideViewportEnabled(boolean enable) {
putBoolean(Name.USE_WIDE_VIEWPORT, enable);
} }
} }

Loading…
Cancel
Save