diff options
author | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-21 01:05:30 +0000 |
---|---|---|
committer | yfriedman@chromium.org <yfriedman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-21 01:06:30 +0000 |
commit | 406017a0f700a29becbef462922fe13a13dd397e (patch) | |
tree | 8a32aefd488a70b4c8c0a03671e7d3a88720bee4 | |
parent | 2d548617ea93eb1eba966321e7316f112072bf75 (diff) | |
download | chromium_src-406017a0f700a29becbef462922fe13a13dd397e.zip chromium_src-406017a0f700a29becbef462922fe13a13dd397e.tar.gz chromium_src-406017a0f700a29becbef462922fe13a13dd397e.tar.bz2 |
Add font family selector ui for distilled page viewer.
Builds on https://codereview.chromium.org/430473007 and adds the UI
for setting font family.
BUG=383630
NOTRY=true
Review URL: https://codereview.chromium.org/483183002
Cr-Commit-Position: refs/heads/master@{#290968}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290968 0039d316-1c4b-4281-b951-d872f2087c98
7 files changed, 119 insertions, 9 deletions
diff --git a/chrome/android/java/res/layout/distilled_page_font_family_spinner.xml b/chrome/android/java/res/layout/distilled_page_font_family_spinner.xml new file mode 100644 index 0000000..431fad7 --- /dev/null +++ b/chrome/android/java/res/layout/distilled_page_font_family_spinner.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- Copyright 2014 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> + +<TextView xmlns:android="http://schemas.android.com/apk/res/android" + style="?android:attr/spinnerDropDownItemStyle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginTop="10dp" + android:layout_marginBottom="10dp" + android:padding="10dp" + android:ellipsize="end" + android:singleLine="true" /> + diff --git a/chrome/android/java/res/layout/distilled_page_prefs_view.xml b/chrome/android/java/res/layout/distilled_page_prefs_view.xml index 2b13404..f0a73c3 100644 --- a/chrome/android/java/res/layout/distilled_page_prefs_view.xml +++ b/chrome/android/java/res/layout/distilled_page_prefs_view.xml @@ -34,6 +34,15 @@ style="@style/DistilledPagePrefThemeButton" /> </RadioGroup> + + <Spinner + android:id="@+id/font_family" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="1" + android:orientation="horizontal" + android:padding="10dp"/> + <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" diff --git a/chrome/android/java/res/values/arrays.xml b/chrome/android/java/res/values/arrays.xml new file mode 100644 index 0000000..d8266f3 --- /dev/null +++ b/chrome/android/java/res/values/arrays.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright 2014 The Chromium Authors. All rights reserved. + Use of this source code is governed by a BSD-style license that can be + found in the LICENSE file. +--> +<resources> + <!-- These must be kept in sync (and in-order) with components/dom_distiller/core/font_family_list.h --> + <string-array name="distiller_mode_font_family_values"> + <item>@string/sans_serif</item> + <item>@string/serif</item> + <item>@string/monospace</item> + </string-array> +</resources> diff --git a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsView.java b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsView.java index 5e5e537..5e8305e 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsView.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsView.java @@ -6,14 +6,19 @@ package org.chromium.chrome.browser.dom_distiller; import android.app.AlertDialog; import android.content.Context; +import android.graphics.Typeface; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; +import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.SeekBar; +import android.widget.Spinner; import android.widget.TextView; import org.chromium.chrome.R; @@ -53,7 +58,10 @@ public class DistilledPagePrefsView extends LinearLayout // SeekBar for font scale. Has range of [0, 30]. private SeekBar mFontScaleSeekBar; - private NumberFormat mPercentageFormatter; + // Spinner for choosing a font family. + private Spinner mFontFamilySpinner; + + private final NumberFormat mPercentageFormatter; /** * Creates a DistilledPagePrefsView. @@ -96,18 +104,71 @@ public class DistilledPagePrefsView extends LinearLayout mFontScaleSeekBar = (SeekBar) findViewById(R.id.font_size); mFontScaleTextView = (TextView) findViewById(R.id.font_size_percentage); + mFontFamilySpinner = (Spinner) findViewById(R.id.font_family); + initFontFamilySpinner(); + // Setting initial progress on font scale seekbar. onChangeFontSize(mFontSizePrefs.getFontScaleFactor()); mFontScaleSeekBar.setOnSeekBarChangeListener(this); } + private void initFontFamilySpinner() { + ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(), + android.R.layout.simple_spinner_item, getResources().getStringArray( + R.array.distiller_mode_font_family_values)) { + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View view = super.getView(position, convertView, parent); + return overrideTypeFace(view, position); + } + + @Override + public View getDropDownView(int position, View convertView, ViewGroup parent) { + View view = super.getDropDownView(position, convertView, parent); + return overrideTypeFace(view, position); + } + + private View overrideTypeFace(View view, int position) { + if (view instanceof TextView) { + TextView textView = (TextView) view; + FontFamily family = FontFamily.values()[position]; + if (family == FontFamily.MONOSPACE) { + textView.setTypeface(Typeface.MONOSPACE); + } else if (family == FontFamily.SANS_SERIF) { + textView.setTypeface(Typeface.SANS_SERIF); + } else if (family == FontFamily.SERIF) { + textView.setTypeface(Typeface.SERIF); + } + } + return view; + } + }; + + adapter.setDropDownViewResource(R.layout.distilled_page_font_family_spinner); + mFontFamilySpinner.setAdapter(adapter); + mFontFamilySpinner.setSelection(mDistilledPagePrefs.getFontFamily().ordinal()); + mFontFamilySpinner.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + FontFamily family = FontFamily.getFontFamilyForValue(position); + if (family != null) { + mDistilledPagePrefs.setFontFamily(family); + } + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + // Nothing to do. + } + }); + } + @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mRadioGroup.setOrientation(HORIZONTAL); for (RadioButton button : mColorModeButtons.values()) { - ViewGroup.LayoutParams layoutParams = - (ViewGroup.LayoutParams) button.getLayoutParams(); + ViewGroup.LayoutParams layoutParams = button.getLayoutParams(); layoutParams.width = 0; } @@ -119,8 +180,7 @@ public class DistilledPagePrefsView extends LinearLayout if (button.getLineCount() > 1) { mRadioGroup.setOrientation(VERTICAL); for (RadioButton innerLoopButton : mColorModeButtons.values()) { - ViewGroup.LayoutParams layoutParams = - (ViewGroup.LayoutParams) innerLoopButton.getLayoutParams(); + ViewGroup.LayoutParams layoutParams = innerLoopButton.getLayoutParams(); layoutParams.width = LayoutParams.MATCH_PARENT; } break; @@ -146,7 +206,7 @@ public class DistilledPagePrefsView extends LinearLayout @Override public void onChangeFontFamily(FontFamily fontFamily) { - // TODO(smaslo): add GUI and front end implementation for FontFamily. + mFontFamilySpinner.setSelection(fontFamily.ordinal()); } /** @@ -165,7 +225,7 @@ public class DistilledPagePrefsView extends LinearLayout // newValue = .50, .55, .60, ..., 1.95, 2.00 (supported font scales) float newValue = (progress / 20f + .5f); setFontScaleTextView(newValue); - mFontSizePrefs.setFontScaleFactor((float) newValue); + mFontSizePrefs.setFontScaleFactor(newValue); } @Override diff --git a/chrome/android/java/strings/android_chrome_strings.grd b/chrome/android/java/strings/android_chrome_strings.grd index 5eaaace..1f7d771 100644 --- a/chrome/android/java/strings/android_chrome_strings.grd +++ b/chrome/android/java/strings/android_chrome_strings.grd @@ -363,6 +363,15 @@ You are signing in with a managed account and giving its administrator control o <message name="IDS_SEPIA_MODE" desc="Title of button that will change theme of distilled pages to sepia mode."> Sepia </message> + <message name="IDS_SANS_SERIF" desc="Title of the selector button that will change the typeface of distilled pages to use a SansSerif font."> + Sans Serif + </message> + <message name="IDS_SERIF" desc="Title of the selector button that will change the typeface of distilled pages to use a Serif font."> + Serif + </message> + <message name="IDS_MONOSPACE" desc="Title of the selector button that will change the typeface of distilled pages to use a Monospace font."> + Monospace + </message> <message name="IDS_TEXT_SIZE_SIGNIFIER" desc="A typical letter of the alphabet. This is drawn on either end of a slider bar that allows the user to change the font size. On one end, it is drawn smaller and on the other end larger."> A </message> diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/FontFamily.template b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/FontFamily.template index 2511549..bc0ff25 100644 --- a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/FontFamily.template +++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/FontFamily.template @@ -25,7 +25,7 @@ int asNativeEnum() { return mFontFamily; } -static FontFamily getFontFamilyForValue(int value) { +public static FontFamily getFontFamilyForValue(int value) { for (FontFamily fontFamily: FontFamily.values()) { if (fontFamily.mFontFamily == value) { return fontFamily; diff --git a/components/dom_distiller/core/font_family_list.h b/components/dom_distiller/core/font_family_list.h index 9800741..806133f 100644 --- a/components/dom_distiller/core/font_family_list.h +++ b/components/dom_distiller/core/font_family_list.h @@ -10,7 +10,9 @@ #endif // First argument represents the enum name, second argument represents enum -// value. FONT_FAMILY_COUNT used only by native enum. +// value. +// These must be kept in sync with the resource strings in +// chrome/android/java/res/values/arrays.xml DEFINE_FONT_FAMILY(SANS_SERIF, 0) DEFINE_FONT_FAMILY(SERIF, 1) DEFINE_FONT_FAMILY(MONOSPACE, 2) |