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 fc20132be0fd00abde1a8d2b602ee2f1df10a7df..4260ad12bce119067a992cc943e2baed8e51bbc3 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 |
@@ -9,30 +9,49 @@ import android.util.AttributeSet; |
import android.view.LayoutInflater; |
import android.view.View; |
import android.view.ViewGroup; |
+import android.widget.LinearLayout; |
import android.widget.RadioButton; |
import android.widget.RadioGroup; |
+import android.widget.SeekBar; |
+import android.widget.TextView; |
import org.chromium.chrome.R; |
+import org.chromium.chrome.browser.accessibility.FontSizePrefs; |
import org.chromium.chrome.browser.profiles.Profile; |
import org.chromium.components.dom_distiller.core.DistilledPagePrefs; |
import org.chromium.components.dom_distiller.core.Theme; |
+import java.text.NumberFormat; |
import java.util.EnumMap; |
+import java.util.Locale; |
import java.util.Map; |
/** |
* A view which displays preferences for distilled pages. This allows users |
* to change the theme, font size, etc. of distilled pages. |
*/ |
-public class DistilledPagePrefsView extends RadioGroup |
- implements DistilledPagePrefs.Observer { |
+public class DistilledPagePrefsView extends LinearLayout |
+ implements DistilledPagePrefs.Observer, SeekBar.OnSeekBarChangeListener, |
+ FontSizePrefs.Observer { |
// XML layout for View. |
private static final int VIEW_LAYOUT = R.layout.distilled_page_prefs_view; |
+ // RadioGroup for color mode buttons. |
+ private RadioGroup mRadioGroup; |
+ |
// Buttons for color mode. |
private final Map<Theme, RadioButton> mColorModeButtons; |
private final DistilledPagePrefs mDistilledPagePrefs; |
+ private final FontSizePrefs mFontSizePrefs; |
+ |
+ // Text field showing font scale percentage. |
+ private TextView mFontScaleTextView; |
+ |
+ // SeekBar for font scale. Has range of [0, 30]. |
+ private SeekBar mFontScaleSeekBar; |
+ |
+ private NumberFormat mPercentageFormatter; |
/** |
* Creates a DistilledPagePrefsView. |
@@ -44,7 +63,9 @@ public class DistilledPagePrefsView extends RadioGroup |
super(context, attrs); |
mDistilledPagePrefs = DomDistillerServiceFactory.getForProfile( |
Profile.getLastUsedProfile()).getDistilledPagePrefs(); |
+ mFontSizePrefs = FontSizePrefs.getInstance(getContext()); |
mColorModeButtons = new EnumMap<Theme, RadioButton>(Theme.class); |
+ mPercentageFormatter = NumberFormat.getPercentInstance(Locale.getDefault()); |
} |
public static DistilledPagePrefsView create(Context context) { |
@@ -55,6 +76,7 @@ public class DistilledPagePrefsView extends RadioGroup |
@Override |
public void onFinishInflate() { |
super.onFinishInflate(); |
+ mRadioGroup = (RadioGroup) findViewById(R.id.radio_button_group); |
mColorModeButtons.put(Theme.LIGHT, |
initializeAndGetButton(R.id.light_mode, Theme.LIGHT)); |
mColorModeButtons.put(Theme.DARK, |
@@ -62,11 +84,18 @@ public class DistilledPagePrefsView extends RadioGroup |
mColorModeButtons.put(Theme.SEPIA, |
initializeAndGetButton(R.id.sepia_mode, Theme.SEPIA)); |
mColorModeButtons.get(mDistilledPagePrefs.getTheme()).setChecked(true); |
+ |
+ mFontScaleSeekBar = (SeekBar) findViewById(R.id.font_size); |
+ mFontScaleTextView = (TextView) findViewById(R.id.font_size_percentage); |
+ |
+ // Setting initial progress on font scale seekbar. |
+ onChangeFontSize(mFontSizePrefs.getFontScaleFactor()); |
+ mFontScaleSeekBar.setOnSeekBarChangeListener(this); |
} |
@Override |
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
- setOrientation(HORIZONTAL); |
+ mRadioGroup.setOrientation(HORIZONTAL); |
for (RadioButton button : mColorModeButtons.values()) { |
ViewGroup.LayoutParams layoutParams = |
@@ -80,7 +109,7 @@ public class DistilledPagePrefsView extends RadioGroup |
// top of each other. |
for (RadioButton button : mColorModeButtons.values()) { |
if (button.getLineCount() > 1) { |
- setOrientation(VERTICAL); |
+ mRadioGroup.setOrientation(VERTICAL); |
for (RadioButton innerLoopButton : mColorModeButtons.values()) { |
ViewGroup.LayoutParams layoutParams = |
(ViewGroup.LayoutParams) innerLoopButton.getLayoutParams(); |
@@ -115,6 +144,37 @@ public class DistilledPagePrefsView extends RadioGroup |
mColorModeButtons.get(theme).setChecked(true); |
} |
+ // SeekBar.OnSeekBarChangeListener |
+ |
+ @Override |
+ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
+ // progress = [0, 30] |
+ // newValue = .50, .55, .60, ..., 1.95, 2.00 (supported font scales) |
+ float newValue = (progress / 20f + .5f); |
+ setFontScaleTextView(newValue); |
+ mFontSizePrefs.setFontScaleFactor((float) newValue); |
+ } |
+ |
+ @Override |
+ public void onStartTrackingTouch(SeekBar seekBar) {} |
+ |
+ @Override |
+ public void onStopTrackingTouch(SeekBar seekBar) {} |
+ |
+ // FontSizePrefs.Observer |
+ |
+ @Override |
+ public void onChangeFontSize(float newFontSize) { |
+ setFontScaleTextView(newFontSize); |
+ setFontScaleProgress(newFontSize); |
+ } |
+ |
+ @Override |
+ public void onChangeForceEnableZoom(boolean enabled) {} |
+ |
+ @Override |
+ public void onChangeUserSetForceEnableZoom(boolean enabled) {} |
+ |
/** |
* Initiatializes a Button and selects it if it corresponds to the current |
* theme. |
@@ -129,4 +189,21 @@ public class DistilledPagePrefsView extends RadioGroup |
}); |
return button; |
} |
+ |
+ /** |
+ * Sets the progress of mFontScaleSeekBar. |
+ */ |
+ private void setFontScaleProgress(float newValue) { |
+ // newValue = .50, .55, .60, ..., 1.95, 2.00 (supported font scales) |
+ // progress = [0, 30] |
+ int progress = (int) ((newValue - .5) * 20); |
+ mFontScaleSeekBar.setProgress(progress); |
+ } |
+ |
+ /** |
+ * Sets the text for the font scale text view. |
+ */ |
+ private void setFontScaleTextView(float newValue) { |
+ mFontScaleTextView.setText(mPercentageFormatter.format(newValue)); |
+ } |
} |