diff options
author | John Reck <jreck@google.com> | 2011-06-16 15:22:06 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-06-16 15:22:06 -0700 |
commit | f43990eed0a2b97f181c44fd03271f1844a8d133 (patch) | |
tree | 273fec62964b234f8a9a04abd179bfabd65d53e7 | |
parent | a56822d654cc5776f810af3d9da23166dcacb8a1 (diff) | |
parent | 8fc22a1c7846b4c7c7b74d1ec59ffc59c2695c15 (diff) | |
download | packages_apps_browser-f43990eed0a2b97f181c44fd03271f1844a8d133.zip packages_apps_browser-f43990eed0a2b97f181c44fd03271f1844a8d133.tar.gz packages_apps_browser-f43990eed0a2b97f181c44fd03271f1844a8d133.tar.bz2 |
Merge "Clean up accessibility settings"
-rw-r--r-- | res/layout/webview_preview.xml | 74 | ||||
-rw-r--r-- | res/values/strings.xml | 6 | ||||
-rw-r--r-- | res/xml/accessibility_preferences.xml | 35 | ||||
-rw-r--r-- | src/com/android/browser/BrowserSettings.java | 12 | ||||
-rw-r--r-- | src/com/android/browser/preferences/AccessibilityPreferencesFragment.java | 1 | ||||
-rw-r--r-- | src/com/android/browser/preferences/FontSizePreference.java | 49 | ||||
-rw-r--r-- | src/com/android/browser/preferences/MinFontSizePreference.java | 170 | ||||
-rw-r--r-- | src/com/android/browser/preferences/WebViewPreview.java | 30 |
8 files changed, 161 insertions, 216 deletions
diff --git a/res/layout/webview_preview.xml b/res/layout/webview_preview.xml index 6edbcce..8f8d810 100644 --- a/res/layout/webview_preview.xml +++ b/res/layout/webview_preview.xml @@ -17,22 +17,70 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="vertical" - android:paddingRight="6dip" - android:paddingTop="6dip" - android:paddingBottom="6dip" - android:paddingLeft="8dip"> - - <TextView - android:text="@string/preview" + android:minHeight="?android:attr/listPreferredItemHeight" + android:gravity="center_vertical" + android:paddingRight="?android:attr/scrollbarSize"> + + <LinearLayout + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:gravity="center" + android:minWidth="@*android:dimen/preference_icon_minWidth" + android:orientation="horizontal"> + <ImageView + android:id="@android:id/icon" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:minWidth="48dp" + /> + </LinearLayout> + + <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textAppearance="?android:attr/textAppearanceMedium" /> + android:layout_marginLeft="16dip" + android:layout_marginRight="8dip" + android:layout_marginTop="6dip" + android:layout_marginBottom="6dip" + android:layout_weight="1"> + + <TextView android:id="@android:id/title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:singleLine="true" + android:textAppearance="?android:attr/textAppearanceMedium" + android:ellipsize="marquee" + android:fadingEdge="horizontal" /> + + <TextView android:id="@android:id/summary" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_below="@android:id/title" + android:layout_alignLeft="@android:id/title" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textColor="?android:attr/textColorSecondary" + android:maxLines="4" /> + + <!-- Preference should place its actual preference widget here. --> + <LinearLayout android:id="@android:id/widget_frame" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:layout_below="@android:id/summary" + android:layout_alignLeft="@android:id/title" + android:minWidth="@dimen/preference_widget_width" + android:gravity="center" + android:orientation="vertical" /> + + <WebView + android:id="@+id/webview" + android:layout_width="match_parent" + android:layout_height="180dp" + android:layout_below="@android:id/summary" + android:layout_toRightOf="@android:id/widget_frame" + android:layout_alignParentRight="true" /> - <WebView - android:id="@+id/webview" - android:layout_width="match_parent" - android:layout_height="180dp" /> + </RelativeLayout> </LinearLayout> diff --git a/res/values/strings.xml b/res/values/strings.xml index 1e92fb5..d2515d9 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -642,6 +642,8 @@ <string name="pref_default_text_encoding_default" translatable="false">Latin-1</string> <!-- Title for accessibility settings [CHAR LIMIT=25] --> <string name="pref_accessibility_title">Accessibility</string> + <!-- Font size settings category under accessibility settings [CHAR LIMIT=50] --> + <string name="pref_font_size_category">Font size</string> <!-- Title for lab settings [CHAR LIMIT=25] --> <string name="pref_lab_title">Labs</string> <!-- Title for lab quick controls feature [CHAR LIMIT=40] --> @@ -1005,8 +1007,8 @@ <string name="recover_yes">Restore</string> <!-- No, don't recover windows from last time [CHAR LIMIT=10] --> <string name="recover_no">No</string> - <!-- Font size preview label [CHAR LIMIT=30] --> - <string name="preview">Preview:</string> + <!-- Font size preview label in settings [CHAR LIMIT=30] --> + <string name="preview">Preview</string> <!-- Name for the user's unsynced, local bookmarks [CHAR LIMIT=50] --> <string name="local_bookmarks">Local</string> <!-- Popup menu option that allows the user to select the mobile version of a webpage [CHAR LIMIT=50] --> diff --git a/res/xml/accessibility_preferences.xml b/res/xml/accessibility_preferences.xml index 799d0e2..6109a64 100644 --- a/res/xml/accessibility_preferences.xml +++ b/res/xml/accessibility_preferences.xml @@ -17,24 +17,29 @@ <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> - <com.android.browser.preferences.WebViewPreview /> - - <ListPreference - android:key="text_size" - android:title="@string/pref_text_size" - android:defaultValue="NORMAL" - android:entries="@array/pref_text_size_choices" - android:entryValues="@array/pref_text_size_values" - android:dialogTitle="@string/pref_text_size_dialogtitle" /> - - <com.android.browser.preferences.MinFontSizePreference - android:key="min_font_size" - android:title="@string/pref_min_font_size" - android:defaultValue="1" /> - <CheckBoxPreference android:key="force_userscalable" android:title="@string/pref_force_userscalable" android:summary="@string/pref_force_userscalable_summary" android:defaultValue="false" /> + <PreferenceCategory android:title="@string/pref_font_size_category"> + <com.android.browser.preferences.WebViewPreview + android:title="@string/preview" /> + + <ListPreference + android:key="text_size" + android:title="@string/pref_text_size" + android:defaultValue="NORMAL" + android:entries="@array/pref_text_size_choices" + android:entryValues="@array/pref_text_size_values" + android:dialogTitle="@string/pref_text_size_dialogtitle" /> + + <com.android.browser.preferences.FontSizePreference + android:key="min_font_size" + android:title="@string/pref_min_font_size" + android:defaultValue="0" + android:max="18" /> + + </PreferenceCategory> + </PreferenceScreen> diff --git a/src/com/android/browser/BrowserSettings.java b/src/com/android/browser/BrowserSettings.java index 101effa..3aef08f 100644 --- a/src/com/android/browser/BrowserSettings.java +++ b/src/com/android/browser/BrowserSettings.java @@ -83,6 +83,11 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, HONEYCOMB_USERAGENT, }; + // The minimum min font size + // Aka, the lower bounds for the min font size range + // which is 1:5..24 + private static final int MIN_FONT_SIZE_OFFSET = 5; + private static BrowserSettings sInstance; private Context mContext; @@ -423,7 +428,12 @@ public class BrowserSettings implements OnSharedPreferenceChangeListener, } public int getMinimumFontSize() { - return mPrefs.getInt(PREF_MIN_FONT_SIZE, 1); + int minFont = mPrefs.getInt(PREF_MIN_FONT_SIZE, 0); + minFont++; // Preference starts at 0, min font at 1 + if (minFont > 1) { + minFont += MIN_FONT_SIZE_OFFSET; + } + return minFont; } public boolean forceEnableUserScalable() { diff --git a/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java b/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java index 99bd687..d083f43 100644 --- a/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java +++ b/src/com/android/browser/preferences/AccessibilityPreferencesFragment.java @@ -43,7 +43,6 @@ public class AccessibilityPreferencesFragment extends PreferenceFragment @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - getListView().setItemsCanFocus(true); } @Override diff --git a/src/com/android/browser/preferences/FontSizePreference.java b/src/com/android/browser/preferences/FontSizePreference.java new file mode 100644 index 0000000..266a584 --- /dev/null +++ b/src/com/android/browser/preferences/FontSizePreference.java @@ -0,0 +1,49 @@ +/* + * 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.util.AttributeSet; +import android.widget.SeekBar; + +public class FontSizePreference extends SeekBarPreference { + + public FontSizePreference( + Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public FontSizePreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FontSizePreference(Context context) { + super(context); + } + + @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/MinFontSizePreference.java b/src/com/android/browser/preferences/MinFontSizePreference.java deleted file mode 100644 index 22092b0..0000000 --- a/src/com/android/browser/preferences/MinFontSizePreference.java +++ /dev/null @@ -1,170 +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 com.android.browser.R; - -import android.content.Context; -import android.os.Parcel; -import android.os.Parcelable; -import android.preference.Preference; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.SeekBar; -import android.widget.SeekBar.OnSeekBarChangeListener; - -public class MinFontSizePreference extends Preference implements OnSeekBarChangeListener { - - // range from 1:6..24 - static final int MIN = 5; - static final int MAX = 23; - private int mProgress; - View mRoot; - - public MinFontSizePreference( - Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - - public MinFontSizePreference(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public MinFontSizePreference(Context context) { - super(context); - } - - @Override - public View getView(View convertView, ViewGroup parent) { - if (mRoot == null) { - LayoutInflater inflater = LayoutInflater.from(getContext()); - mRoot = inflater.inflate(R.layout.min_font_size, parent, false); - SeekBar seek = (SeekBar) mRoot.findViewById(R.id.seekbar); - seek.setMax((MAX - MIN)); - seek.setProgress(mProgress); - seek.setOnSeekBarChangeListener(this); - } - return mRoot; - } - - @Override - protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { - mProgress = restoreValue ? getPersistedInt(mProgress) - : (Integer) defaultValue; - mProgress -= 1; - } - - @Override - public void onProgressChanged( - SeekBar seekBar, int progress, boolean fromUser) { - if (fromUser) { - if (progress == 0) { - persistInt(1); - } else { - persistInt(progress + MIN + 1); - } - } - mRoot.invalidate(); - } - - @Override - public void onStartTrackingTouch(SeekBar seekBar) { - } - - @Override - public void onStopTrackingTouch(SeekBar seekBar) { - } - - - @Override - protected Parcelable onSaveInstanceState() { - /* - * Suppose a client uses this preference type without persisting. We - * must save the instance state so it is able to, for example, survive - * orientation changes. - */ - - final Parcelable superState = super.onSaveInstanceState(); - if (isPersistent()) { - // No need to save instance state since it's persistent - return superState; - } - - // Save the instance state - final SavedState myState = new SavedState(superState); - myState.progress = mProgress; - return myState; - } - - @Override - protected void onRestoreInstanceState(Parcelable state) { - if (!state.getClass().equals(SavedState.class)) { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state); - return; - } - - // Restore the instance state - SavedState myState = (SavedState) state; - super.onRestoreInstanceState(myState.getSuperState()); - mProgress = myState.progress; - notifyChanged(); - } - - /** - * SavedState, a subclass of {@link BaseSavedState}, will store the state - * of MyPreference, a subclass of Preference. - * <p> - * It is important to always call through to super methods. - */ - private static class SavedState extends BaseSavedState { - int progress; - - public SavedState(Parcel source) { - super(source); - - // Restore the click counter - progress = source.readInt(); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - - // Save the click counter - dest.writeInt(progress); - } - - public SavedState(Parcelable superState) { - super(superState); - } - - public static final Parcelable.Creator<SavedState> CREATOR = - new Parcelable.Creator<SavedState>() { - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - } - -} diff --git a/src/com/android/browser/preferences/WebViewPreview.java b/src/com/android/browser/preferences/WebViewPreview.java index a269dbd..dca4d19 100644 --- a/src/com/android/browser/preferences/WebViewPreview.java +++ b/src/com/android/browser/preferences/WebViewPreview.java @@ -26,7 +26,6 @@ import android.content.res.Resources; import android.preference.Preference; import android.preference.PreferenceManager; import android.util.AttributeSet; -import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.webkit.WebSettings; @@ -34,11 +33,9 @@ import android.webkit.WebView; public class WebViewPreview extends Preference implements OnSharedPreferenceChangeListener { - // 80 char line width limit? Rules are made to be broken. static final String HTML_FORMAT = "<html><head><style type=\"text/css\">p { margin: 2px auto;}</style><body><p style=\"font-size: .4em\">%s</p><p style=\"font-size: .7em\">%s</p><p style=\"font-size: 1em\">%s</p><p style=\"font-size: 1.3em\">%s</p><p style=\"font-size: 1.6em\">%s</p></body></html>"; - String HTML; - private View mRoot; + String mHtml; private WebView mWebView; public WebViewPreview( @@ -60,7 +57,8 @@ public class WebViewPreview extends Preference implements OnSharedPreferenceChan void init(Context context) { Resources res = context.getResources(); Object[] visualNames = res.getStringArray(R.array.pref_text_size_choices); - HTML = String.format(HTML_FORMAT, visualNames); + mHtml = String.format(HTML_FORMAT, visualNames); + setLayoutResource(R.layout.webview_preview); } void updatePreview() { @@ -70,19 +68,23 @@ public class WebViewPreview extends Preference implements OnSharedPreferenceChan BrowserSettings bs = BrowserSettings.getInstance(); ws.setMinimumFontSize(bs.getMinimumFontSize()); ws.setTextSize(bs.getTextSize()); - mWebView.loadData(HTML, "text/html", "utf-8"); + mWebView.loadData(mHtml, "text/html", "utf-8"); } @Override - public View getView(View convertView, ViewGroup parent) { - if (mWebView == null) { - LayoutInflater inflater = LayoutInflater.from(getContext()); - mRoot = inflater.inflate(R.layout.webview_preview, parent, false); - mWebView = (WebView) mRoot.findViewById(R.id.webview); - mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); - } + 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); + return root; + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + mWebView = (WebView) view.findViewById(R.id.webview); updatePreview(); - return mRoot; } @Override |