Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsView.java |
| 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 5e5e53796fad62881c82b6ab928d266c7e57a764..e8712396e11fd01a87366daf0576f22c13956fea 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 mFontFamilyView; |
|
newt (away)
2014/08/20 20:54:51
s/View/Spinner
Yaron
2014/08/20 21:01:21
Done.
|
| + |
| + private final NumberFormat mPercentageFormatter; |
| /** |
| * Creates a DistilledPagePrefsView. |
| @@ -96,18 +104,72 @@ public class DistilledPagePrefsView extends LinearLayout |
| mFontScaleSeekBar = (SeekBar) findViewById(R.id.font_size); |
| mFontScaleTextView = (TextView) findViewById(R.id.font_size_percentage); |
| + mFontFamilyView = (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, getContext().getResources().getStringArray( |
|
newt (away)
2014/08/20 20:54:51
s/getContext().getResources()/getResources()
Yaron
2014/08/20 21:01:21
Done.
|
| + 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 maybeOverrideTypeFace(view, position); |
| + } |
| + |
| + @Override |
| + public View getDropDownView(int position, View convertView, ViewGroup parent) { |
| + View view = super.getDropDownView(position, convertView, parent); |
| + return maybeOverrideTypeFace(view, position); |
| + } |
| + |
| + private View maybeOverrideTypeFace(View view, int position) { |
|
newt (away)
2014/08/20 20:54:51
What does the "maybe" refer to? Is view sometimes
Yaron
2014/08/20 21:01:21
I assumed that OEM could make it non-TextView. How
|
| + 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); |
| + mFontFamilyView.setAdapter(adapter); |
| + mFontFamilyView.setSelection(mDistilledPagePrefs.getFontFamily().ordinal()); |
| + mFontFamilyView.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 = |
|
newt (away)
2014/08/20 20:54:51
does this fit on one line?
Yaron
2014/08/20 21:01:21
This was eclipse auto-fixing but ya, I can make it
|
| - (ViewGroup.LayoutParams) button.getLayoutParams(); |
| + button.getLayoutParams(); |
| layoutParams.width = 0; |
| } |
| @@ -120,7 +182,7 @@ public class DistilledPagePrefsView extends LinearLayout |
| mRadioGroup.setOrientation(VERTICAL); |
| for (RadioButton innerLoopButton : mColorModeButtons.values()) { |
| ViewGroup.LayoutParams layoutParams = |
| - (ViewGroup.LayoutParams) innerLoopButton.getLayoutParams(); |
| + innerLoopButton.getLayoutParams(); |
| layoutParams.width = LayoutParams.MATCH_PARENT; |
| } |
| break; |
| @@ -146,7 +208,7 @@ public class DistilledPagePrefsView extends LinearLayout |
| @Override |
| public void onChangeFontFamily(FontFamily fontFamily) { |
| - // TODO(smaslo): add GUI and front end implementation for FontFamily. |
| + mFontFamilyView.setSelection(fontFamily.ordinal()); |
| } |
| /** |
| @@ -165,7 +227,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 |