FileDocCategorySizeDatePackage
BrowserSettings.javaAPI DocAndroid 1.5 API16466Wed May 06 22:42:42 BST 2009com.android.browser

BrowserSettings

public class BrowserSettings extends Observable

Fields Summary
private boolean
loadsImagesAutomatically
private boolean
javaScriptEnabled
private boolean
pluginsEnabled
private String
pluginsPath
private boolean
javaScriptCanOpenWindowsAutomatically
private boolean
showSecurityWarnings
private boolean
rememberPasswords
private boolean
saveFormData
private boolean
openInBackground
private String
defaultTextEncodingName
private String
homeUrl
private boolean
loginInitialized
private boolean
autoFitPage
private boolean
showDebugSettings
public WebSettings.LayoutAlgorithm
layoutAlgorithm
private boolean
useWideViewPort
private int
userAgent
private boolean
tracing
private boolean
lightTouch
private boolean
navDump
private boolean
doFlick
private static int
minimumFontSize
private static int
minimumLogicalFontSize
private static int
defaultFontSize
private static int
defaultFixedFontSize
private static WebSettings.TextSize
textSize
public static final String
PREF_CLEAR_CACHE
public static final String
PREF_CLEAR_COOKIES
public static final String
PREF_CLEAR_HISTORY
public static final String
PREF_HOMEPAGE
public static final String
PREF_CLEAR_FORM_DATA
public static final String
PREF_CLEAR_PASSWORDS
public static final String
PREF_EXTRAS_RESET_DEFAULTS
public static final String
PREF_DEBUG_SETTINGS
public static final String
PREF_GEARS_SETTINGS
public static final String
PREF_TEXT_SIZE
public static final String
PREF_DEFAULT_TEXT_ENCODING
private static final String
DESKTOP_USERAGENT
private static final String
IPHONE_USERAGENT
public static final int
MAX_TEXTVIEW_LEN
private TabControl
mTabControl
private static BrowserSettings
sSingleton
private HashMap
mWebSettingsToObservers
Constructors Summary
private BrowserSettings()

    
Methods Summary
public com.android.browser.BrowserSettings$ObserveraddObserver(android.webkit.WebSettings s)
Add a WebSettings object to the list of observers that will be updated when update() is called.

param
s A WebSettings object that is strictly tied to the life of a WebView.

        Observer old = mWebSettingsToObservers.get(s);
        if (old != null) {
            super.deleteObserver(old);
        }
        Observer o = new Observer(s);
        mWebSettingsToObservers.put(s, o);
        super.addObserver(o);
        return o;
    
voidclearCache(android.content.Context context)

        WebIconDatabase.getInstance().removeAllIcons();
        if (mTabControl != null) {
            WebView current = mTabControl.getCurrentWebView();
            if (current != null) {
                current.clearCache(true);
            }
        }
    
voidclearCookies(android.content.Context context)

        CookieManager.getInstance().removeAllCookie();
    
voidclearFormData(android.content.Context context)

        WebViewDatabase.getInstance(context).clearFormData();
        if (mTabControl != null) {
            mTabControl.getCurrentTopWebView().clearFormData();
        }
    
voidclearHistory(android.content.Context context)

        ContentResolver resolver = context.getContentResolver();
        Browser.clearHistory(resolver);
        Browser.clearSearches(resolver);
    
voidclearPasswords(android.content.Context context)

        WebViewDatabase db = WebViewDatabase.getInstance(context);
        db.clearUsernamePassword();
        db.clearHttpAuthUsernamePassword();
    
public voiddeleteObserver(android.webkit.WebSettings s)
Delete the given WebSettings observer from the list of observers.

param
s The WebSettings object to be deleted.

        Observer o = mWebSettingsToObservers.get(s);
        if (o != null) {
            mWebSettingsToObservers.remove(s);
            super.deleteObserver(o);
        }
    
public booleandoFlick()

        return doFlick;
    
public java.lang.StringgetHomePage()

        return homeUrl;
    
static com.android.browser.BrowserSettingsgetInstance()

        if (sSingleton == null ) {
            sSingleton = new BrowserSettings();
        }
        return sSingleton;
    
public java.lang.StringgetPluginsPath()

        return pluginsPath;
    
public WebSettings.TextSizegetTextSize()

        return textSize;
    
public booleanisLightTouch()

        return lightTouch;
    
public booleanisLoginInitialized()

        return loginInitialized;
    
public booleanisNavDump()

        return navDump;
    
public booleanisTracing()

        return tracing;
    
public voidloadFromDb(android.content.Context ctx)
Load settings from the browser app's database. NOTE: Strings used for the preferences must match those specified in the browser_preferences.xml

param
ctx A Context object used to query the browser's settings database. If the database exists, the saved settings will be stored in this BrowserSettings object. This will update all observers of this object.

        SharedPreferences p =
                PreferenceManager.getDefaultSharedPreferences(ctx);

        // Set the default value for the plugins path to the application's
        // local directory.
        pluginsPath = ctx.getDir("plugins", 0).getPath();

        homeUrl += Partner.getString(ctx.getContentResolver(), Partner.CLIENT_ID);

        // Load the defaults from the xml
        // This call is TOO SLOW, need to manually keep the defaults
        // in sync
        //PreferenceManager.setDefaultValues(ctx, R.xml.browser_preferences);
        syncSharedPreferences(p);
    
public booleanopenInBackground()

        return openInBackground;
    
voidresetDefaultPreferences(android.content.Context context)

        SharedPreferences p =
            PreferenceManager.getDefaultSharedPreferences(context);
        p.edit().clear().commit();
        PreferenceManager.setDefaultValues(context, R.xml.browser_preferences,
                true);
    
public voidsetHomePage(android.content.Context context, java.lang.String url)

        Editor ed = PreferenceManager.
                getDefaultSharedPreferences(context).edit();
        ed.putString(PREF_HOMEPAGE, url);
        ed.commit();
        homeUrl = url;
    
public voidsetLoginInitialized(android.content.Context context)

        loginInitialized = true;
        Editor ed = PreferenceManager.
                getDefaultSharedPreferences(context).edit();
        ed.putBoolean("login_initialized", loginInitialized);
        ed.commit();
    
voidsetTabControl(TabControl tabControl)

        mTabControl = tabControl;
    
public booleanshowDebugSettings()

        return showDebugSettings;
    
public booleanshowSecurityWarnings()

        return showSecurityWarnings;
    
voidsyncSharedPreferences(android.content.SharedPreferences p)


        homeUrl =
            p.getString(PREF_HOMEPAGE, homeUrl);

        loadsImagesAutomatically = p.getBoolean("load_images",
                loadsImagesAutomatically);
        javaScriptEnabled = p.getBoolean("enable_javascript",
                javaScriptEnabled);
        pluginsEnabled = p.getBoolean("enable_plugins",
                pluginsEnabled);
        pluginsPath = p.getString("plugins_path", pluginsPath);
        javaScriptCanOpenWindowsAutomatically = !p.getBoolean(
            "block_popup_windows",
            !javaScriptCanOpenWindowsAutomatically);
        showSecurityWarnings = p.getBoolean("show_security_warnings",
                showSecurityWarnings);
        rememberPasswords = p.getBoolean("remember_passwords",
                rememberPasswords);
        saveFormData = p.getBoolean("save_formdata",
                saveFormData);
        boolean accept_cookies = p.getBoolean("accept_cookies",
                CookieManager.getInstance().acceptCookie());
        CookieManager.getInstance().setAcceptCookie(accept_cookies);
        openInBackground = p.getBoolean("open_in_background", openInBackground);
        loginInitialized = p.getBoolean("login_initialized", loginInitialized);
        textSize = WebSettings.TextSize.valueOf(
                p.getString(PREF_TEXT_SIZE, textSize.name()));
        autoFitPage = p.getBoolean("autofit_pages", autoFitPage);
        useWideViewPort = true; // use wide view port for either setting
        if (autoFitPage) {
            layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
        } else {
            layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
        }
        defaultTextEncodingName =
                p.getString(PREF_DEFAULT_TEXT_ENCODING,
                        defaultTextEncodingName);

        showDebugSettings =
                p.getBoolean(PREF_DEBUG_SETTINGS, showDebugSettings);
        // Debug menu items have precidence if the menu is visible
        if (showDebugSettings) {
            boolean small_screen = p.getBoolean("small_screen",
                    layoutAlgorithm ==
                    WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
            if (small_screen) {
                layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN;
            } else {
                boolean normal_layout = p.getBoolean("normal_layout",
                        layoutAlgorithm == WebSettings.LayoutAlgorithm.NORMAL);
                if (normal_layout) {
                    layoutAlgorithm = WebSettings.LayoutAlgorithm.NORMAL;
                } else {
                    layoutAlgorithm =
                            WebSettings.LayoutAlgorithm.NARROW_COLUMNS;
                }
            }
            useWideViewPort = p.getBoolean("wide_viewport", useWideViewPort);
            tracing = p.getBoolean("enable_tracing", tracing);
            lightTouch = p.getBoolean("enable_light_touch", lightTouch);
            navDump = p.getBoolean("enable_nav_dump", navDump);
            doFlick = p.getBoolean("enable_flick", doFlick);
            userAgent = Integer.parseInt(p.getString("user_agent", "0"));
            mTabControl.getBrowserActivity().setBaseSearchUrl(
                    p.getString("search_url", ""));
        }
        update();
    
public voidtoggleDebugSettings()

        showDebugSettings = !showDebugSettings;
        navDump = showDebugSettings;
        update();
    
voidupdate()

        setChanged();
        notifyObservers();