From eabe5dabe4e56a78c5d6cf99e6f171452bad2f23 Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 8 Aug 2011 13:24:13 -0700 Subject: Add preview for contrast Bug: 5135321 Bug: 5118011 Add a preview for the contrast accisibility settings. Rename FontSizePreference to the more generic SeekBarSummaryPreference as it has nothing to do with font size specifically. Change-Id: Id516d63d62822cf026af3ce531ec33eb48ae667a --- res/xml/accessibility_preferences.xml | 11 ++- src/com/android/browser/BrowserSettings.java | 8 +- src/com/android/browser/WebViewProperties.java | 21 +++++ .../browser/preferences/FontSizePreference.java | 89 ---------------------- .../browser/preferences/FontSizePreview.java | 74 ++++++++++++++++++ .../preferences/InvertedContrastPreview.java | 88 +++++++++++++++++++++ .../preferences/SeekBarSummaryPreference.java | 89 ++++++++++++++++++++++ .../browser/preferences/WebViewPreview.java | 32 ++------ 8 files changed, 289 insertions(+), 123 deletions(-) create mode 100644 src/com/android/browser/WebViewProperties.java delete mode 100644 src/com/android/browser/preferences/FontSizePreference.java create mode 100644 src/com/android/browser/preferences/FontSizePreview.java create mode 100644 src/com/android/browser/preferences/InvertedContrastPreview.java create mode 100644 src/com/android/browser/preferences/SeekBarSummaryPreference.java 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" /> - - - + - 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/FontSizePreference.java b/src/com/android/browser/preferences/FontSizePreference.java deleted file mode 100644 index 0ff1e6d..0000000 --- a/src/com/android/browser/preferences/FontSizePreference.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.preference.SeekBarPreference; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.View; -import android.widget.SeekBar; -import android.widget.TextView; - -import com.android.browser.R; - -public class FontSizePreference extends SeekBarPreference { - - CharSequence mSummary; - TextView mSummaryView; - - public FontSizePreference( - Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(); - } - - public FontSizePreference(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - public FontSizePreference(Context context) { - super(context); - init(); - } - - void init() { - setWidgetLayoutResource(R.layout.font_size_widget); - } - - @Override - public void setSummary(CharSequence summary) { - mSummary = summary; - if (mSummaryView != null) { - mSummaryView.setText(mSummary); - } - } - - @Override - public CharSequence getSummary() { - return null; - } - - @Override - protected void onBindView(View view) { - super.onBindView(view); - mSummaryView = (TextView) view.findViewById(R.id.text); - if (TextUtils.isEmpty(mSummary)) { - mSummaryView.setVisibility(View.GONE); - } else { - mSummaryView.setVisibility(View.VISIBLE); - mSummaryView.setText(mSummary); - } - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - // Intentionally blank - prevent super.onStartTrackingTouch from running - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - // Intentionally blank - prevent onStopTrackingTouch from running - } - -} 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 = "

%s

%s

%s

%s

%s

"; + + 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(""); + for (String thumb : THUMBS) { + if (TextUtils.isEmpty(thumb)) { + builder.append("
"); + continue; + } + builder.append(" "); + } + builder.append(""); + 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/SeekBarSummaryPreference.java b/src/com/android/browser/preferences/SeekBarSummaryPreference.java new file mode 100644 index 0000000..481fbc7 --- /dev/null +++ b/src/com/android/browser/preferences/SeekBarSummaryPreference.java @@ -0,0 +1,89 @@ +/* + * 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.preference.SeekBarPreference; +import android.text.TextUtils; +import android.util.AttributeSet; +import android.view.View; +import android.widget.SeekBar; +import android.widget.TextView; + +import com.android.browser.R; + +public class SeekBarSummaryPreference extends SeekBarPreference { + + CharSequence mSummary; + TextView mSummaryView; + + public SeekBarSummaryPreference( + Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(); + } + + public SeekBarSummaryPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public SeekBarSummaryPreference(Context context) { + super(context); + init(); + } + + void init() { + setWidgetLayoutResource(R.layout.font_size_widget); + } + + @Override + public void setSummary(CharSequence summary) { + mSummary = summary; + if (mSummaryView != null) { + mSummaryView.setText(mSummary); + } + } + + @Override + public CharSequence getSummary() { + return null; + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + mSummaryView = (TextView) view.findViewById(R.id.text); + if (TextUtils.isEmpty(mSummary)) { + mSummaryView.setVisibility(View.GONE); + } else { + mSummaryView.setVisibility(View.VISIBLE); + mSummaryView.setText(mSummary); + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + // Intentionally blank - prevent super.onStartTrackingTouch from running + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + // Intentionally blank - prevent onStopTrackingTouch from running + } + +} 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 = "

%s

%s

%s

%s

%s

"; +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; } -- cgit v1.1