diff options
author | John Reck <jreck@google.com> | 2011-08-08 15:07:49 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-08-08 15:07:49 -0700 |
commit | 2db901c0c9788d6317faa9149d272478a9979d99 (patch) | |
tree | 4f6608a89689cadc1593c18e2afb62f34f52907c | |
parent | 2e7e55c5e7ec4903fa1e0aaf6dabf205859fe786 (diff) | |
parent | eabe5dabe4e56a78c5d6cf99e6f171452bad2f23 (diff) | |
download | packages_apps_Browser-2db901c0c9788d6317faa9149d272478a9979d99.zip packages_apps_Browser-2db901c0c9788d6317faa9149d272478a9979d99.tar.gz packages_apps_Browser-2db901c0c9788d6317faa9149d272478a9979d99.tar.bz2 |
Merge "Add preview for contrast"
-rw-r--r-- | res/xml/accessibility_preferences.xml | 11 | ||||
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 8 | ||||
-rw-r--r-- | src/com/android/browser/WebViewProperties.java | 21 | ||||
-rw-r--r-- | src/com/android/browser/preferences/FontSizePreview.java | 74 | ||||
-rw-r--r-- | src/com/android/browser/preferences/InvertedContrastPreview.java | 88 | ||||
-rw-r--r-- | src/com/android/browser/preferences/SeekBarSummaryPreference.java (renamed from src/com/android/browser/preferences/FontSizePreference.java) | 8 | ||||
-rw-r--r-- | src/com/android/browser/preferences/WebViewPreview.java | 32 |
7 files changed, 204 insertions, 38 deletions
diff --git a/res/xml/accessibility_preferences.xml b/res/xml/accessibility_preferences.xml index db5a539..ac96e6e 100644 --- a/res/xml/accessibility_preferences.xml +++ b/res/xml/accessibility_preferences.xml @@ -23,16 +23,16 @@ android:defaultValue="false" /> <PreferenceCategory android:title="@string/pref_font_size_category"> - <com.android.browser.preferences.WebViewPreview + <com.android.browser.preferences.FontSizePreview android:title="@string/preview" /> - <com.android.browser.preferences.FontSizePreference + <com.android.browser.preferences.SeekBarSummaryPreference android:key="text_zoom" android:title="@string/pref_text_zoom" android:defaultValue="10" android:max="30" /> - <com.android.browser.preferences.FontSizePreference + <com.android.browser.preferences.SeekBarSummaryPreference android:key="min_font_size" android:title="@string/pref_min_font_size" android:defaultValue="0" @@ -41,6 +41,8 @@ </PreferenceCategory> <PreferenceCategory android:title="@string/pref_inverted_category"> + <com.android.browser.preferences.InvertedContrastPreview + android:title="@string/preview" /> <CheckBoxPreference android:key="inverted" @@ -48,9 +50,10 @@ android:title="@string/pref_inverted" android:summary="@string/pref_inverted_summary" /> - <com.android.browser.preferences.FontSizePreference + <com.android.browser.preferences.SeekBarSummaryPreference android:key="inverted_contrast" android:title="@string/pref_inverted_contrast" + android:dependency="inverted" android:defaultValue="0" android:max="20" /> diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index b3f7689..ad42146 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -250,10 +250,10 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, settings.setUserAgentString(USER_AGENTS[getUserAgent()]); } - settings.setProperty(PREF_INVERTED, + settings.setProperty(WebViewProperties.gfxInvertedScreen, useInvertedRendering() ? "true" : "false"); - settings.setProperty(PREF_INVERTED_CONTRAST, + settings.setProperty(WebViewProperties.gfxInvertedScreenContrast, Float.toString(getInvertedContrast())); } @@ -742,10 +742,6 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, return 1 + (mPrefs.getInt(PREF_INVERTED_CONTRAST, 0) / 10f); } - public void setInvertedContrast(int contrast) { - mPrefs.edit().putInt(PREF_INVERTED_CONTRAST, contrast).apply(); - } - // ----------------------------- // getter/setters for privacy_security_preferences.xml // ----------------------------- diff --git a/src/com/android/browser/WebViewProperties.java b/src/com/android/browser/WebViewProperties.java new file mode 100644 index 0000000..9a656d7 --- /dev/null +++ b/src/com/android/browser/WebViewProperties.java @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.browser; + +public interface WebViewProperties { + static final String gfxInvertedScreen = "inverted"; + static final String gfxInvertedScreenContrast = "inverted_contrast"; +} diff --git a/src/com/android/browser/preferences/FontSizePreview.java b/src/com/android/browser/preferences/FontSizePreview.java new file mode 100644 index 0000000..7311e80 --- /dev/null +++ b/src/com/android/browser/preferences/FontSizePreview.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser.preferences; + +import android.content.Context; +import android.content.res.Resources; +import android.util.AttributeSet; +import android.view.View; +import android.webkit.WebSettings; +import android.webkit.WebView; + +import com.android.browser.BrowserSettings; +import com.android.browser.R; +import com.android.browser.WebViewProperties; + +public class FontSizePreview extends WebViewPreview { + + static final String HTML_FORMAT = "<html><head><style type=\"text/css\">p { margin: 2px auto;}</style><body><p style=\"font-size: 4pt\">%s</p><p style=\"font-size: 8pt\">%s</p><p style=\"font-size: 10pt\">%s</p><p style=\"font-size: 14pt\">%s</p><p style=\"font-size: 18pt\">%s</p></body></html>"; + + String mHtml; + + public FontSizePreview( + Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public FontSizePreview(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FontSizePreview(Context context) { + super(context); + } + + @Override + protected void init(Context context) { + super.init(context); + Resources res = context.getResources(); + Object[] visualNames = res.getStringArray(R.array.pref_text_size_choices); + mHtml = String.format(HTML_FORMAT, visualNames); + } + + @Override + protected void updatePreview() { + if (mWebView == null) return; + + WebSettings ws = mWebView.getSettings(); + BrowserSettings bs = BrowserSettings.getInstance(); + ws.setMinimumFontSize(bs.getMinimumFontSize()); + ws.setTextZoom(bs.getTextZoom()); + mWebView.loadData(mHtml, "text/html", "utf-8"); + } + + @Override + protected void setupWebView(WebView view) { + super.setupWebView(view); + view.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + } + +} diff --git a/src/com/android/browser/preferences/InvertedContrastPreview.java b/src/com/android/browser/preferences/InvertedContrastPreview.java new file mode 100644 index 0000000..a2d2910 --- /dev/null +++ b/src/com/android/browser/preferences/InvertedContrastPreview.java @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2011 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.browser.preferences; + +import android.content.Context; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.webkit.WebSettings; + +import com.android.browser.BrowserSettings; +import com.android.browser.WebViewProperties; + +public class InvertedContrastPreview extends WebViewPreview { + + static final String IMG_ROOT = "content://com.android.browser.home/res/raw/"; + static final String[] THUMBS = new String[] { + "thumb_google", + "thumb_amazon", + "thumb_cnn", + "thumb_espn", + "", // break + "thumb_bbc", + "thumb_nytimes", + "thumb_weatherchannel", + "thumb_picasa", + }; + + String mHtml; + + public InvertedContrastPreview( + Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public InvertedContrastPreview(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public InvertedContrastPreview(Context context) { + super(context); + } + + @Override + protected void init(Context context) { + super.init(context); + StringBuilder builder = new StringBuilder("<html><body style=\"width: 1000px\">"); + for (String thumb : THUMBS) { + if (TextUtils.isEmpty(thumb)) { + builder.append("<br />"); + continue; + } + builder.append("<img src=\""); + builder.append(IMG_ROOT); + builder.append(thumb); + builder.append("\" /> "); + } + builder.append("</body></html>"); + mHtml = builder.toString(); + } + + @Override + protected void updatePreview() { + if (mWebView == null) return; + + WebSettings ws = mWebView.getSettings(); + BrowserSettings bs = BrowserSettings.getInstance(); + ws.setProperty(WebViewProperties.gfxInvertedScreen, + bs.useInvertedRendering() ? "true" : "false"); + ws.setProperty(WebViewProperties.gfxInvertedScreenContrast, + Float.toString(bs.getInvertedContrast())); + mWebView.loadData(mHtml, "text/html", "utf-8"); + } + +} diff --git a/src/com/android/browser/preferences/FontSizePreference.java b/src/com/android/browser/preferences/SeekBarSummaryPreference.java index 0ff1e6d..481fbc7 100644 --- a/src/com/android/browser/preferences/FontSizePreference.java +++ b/src/com/android/browser/preferences/SeekBarSummaryPreference.java @@ -26,23 +26,23 @@ import android.widget.TextView; import com.android.browser.R; -public class FontSizePreference extends SeekBarPreference { +public class SeekBarSummaryPreference extends SeekBarPreference { CharSequence mSummary; TextView mSummaryView; - public FontSizePreference( + public SeekBarSummaryPreference( Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); init(); } - public FontSizePreference(Context context, AttributeSet attrs) { + public SeekBarSummaryPreference(Context context, AttributeSet attrs) { super(context, attrs); init(); } - public FontSizePreference(Context context) { + public SeekBarSummaryPreference(Context context) { super(context); init(); } diff --git a/src/com/android/browser/preferences/WebViewPreview.java b/src/com/android/browser/preferences/WebViewPreview.java index 27c4f00..4117388 100644 --- a/src/com/android/browser/preferences/WebViewPreview.java +++ b/src/com/android/browser/preferences/WebViewPreview.java @@ -16,28 +16,22 @@ package com.android.browser.preferences; -import com.android.browser.BrowserSettings; -import com.android.browser.PreferenceKeys; -import com.android.browser.R; - import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.content.res.Resources; import android.preference.Preference; import android.preference.PreferenceManager; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; -import android.webkit.WebSettings; import android.webkit.WebView; -public class WebViewPreview extends Preference implements OnSharedPreferenceChangeListener { +import com.android.browser.R; - static final String HTML_FORMAT = "<html><head><style type=\"text/css\">p { margin: 2px auto;}</style><body><p style=\"font-size: 4pt\">%s</p><p style=\"font-size: 8pt\">%s</p><p style=\"font-size: 10pt\">%s</p><p style=\"font-size: 14pt\">%s</p><p style=\"font-size: 18pt\">%s</p></body></html>"; +public abstract class WebViewPreview extends Preference + implements OnSharedPreferenceChangeListener { - String mHtml; - private WebView mWebView; + protected WebView mWebView; public WebViewPreview( Context context, AttributeSet attrs, int defStyle) { @@ -55,30 +49,20 @@ public class WebViewPreview extends Preference implements OnSharedPreferenceChan init(context); } - void init(Context context) { - Resources res = context.getResources(); - Object[] visualNames = res.getStringArray(R.array.pref_text_size_choices); - mHtml = String.format(HTML_FORMAT, visualNames); + protected void init(Context context) { setLayoutResource(R.layout.webview_preview); } - void updatePreview() { - if (mWebView == null) return; + protected abstract void updatePreview(); - WebSettings ws = mWebView.getSettings(); - BrowserSettings bs = BrowserSettings.getInstance(); - ws.setMinimumFontSize(bs.getMinimumFontSize()); - ws.setTextZoom(bs.getTextZoom()); - ws.setProperty(PreferenceKeys.PREF_INVERTED_CONTRAST, Float.toString(bs.getInvertedContrast())); - mWebView.loadData(mHtml, "text/html", "utf-8"); - } + protected void setupWebView(WebView view) {} @Override protected View onCreateView(ViewGroup parent) { View root = super.onCreateView(parent); WebView webView = (WebView) root.findViewById(R.id.webview); webView.setFocusable(false); - webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); + setupWebView(webView); return root; } |