1
0
Fork 0

Update mapping to represent steps of 5 from 50-200

master
Emily Kager 2019-05-16 13:30:09 -07:00 committed by Jeff Boek
parent 2956ca0c82
commit a44322b120
5 changed files with 35 additions and 23 deletions

View File

@ -17,11 +17,12 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
(activity as AppCompatActivity).title = getString(R.string.preferences_accessibility)
(activity as AppCompatActivity).supportActionBar?.show()
val textSizePreference =
findPreference<PercentageSeekBarPreference>(getString(R.string.pref_key_accessibility_font_scale))
findPreference<TextPercentageSeekBarPreference>(getString(R.string.pref_key_accessibility_font_scale))
textSizePreference?.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
(newValue as? Int).let {
val newTextScale = (newValue as Int).toFloat() / PERCENT_TO_DECIMAL
// Value is mapped from 0->30 in steps of 1 so let's convert to float in range 0.5->2.0
val newTextScale = ((newValue as Int * STEP_SIZE) + MIN_SCALE_VALUE).toFloat() / PERCENT_TO_DECIMAL
Settings.getInstance(context!!).setFontSizeFactor(newTextScale)
}
true
@ -33,6 +34,8 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
}
companion object {
const val MIN_SCALE_VALUE = 50
const val STEP_SIZE = 5
const val PERCENT_TO_DECIMAL = 100f
}
}

View File

@ -50,8 +50,11 @@ import java.text.NumberFormat;
* max})
* can be set directly on the preference widget layout.
*/
public class PercentageSeekBarPreference extends Preference {
public class TextPercentageSeekBarPreference extends Preference {
private static final String TAG = "SeekBarPreference";
private static final int STEP_SIZE = 5;
private static final int MIN_VALUE = 50;
private static final float DECIMAL_CONVERSION = 100f;
@SuppressWarnings("WeakerAccess") /* synthetic access */
int mSeekBarValue;
@SuppressWarnings("WeakerAccess") /* synthetic access */
@ -134,7 +137,7 @@ public class PercentageSeekBarPreference extends Preference {
}
};
public PercentageSeekBarPreference(
public TextPercentageSeekBarPreference(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
@ -154,15 +157,15 @@ public class PercentageSeekBarPreference extends Preference {
a.recycle();
}
public PercentageSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
public TextPercentageSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
}
public PercentageSeekBarPreference(Context context, AttributeSet attrs) {
public TextPercentageSeekBarPreference(Context context, AttributeSet attrs) {
this(context, attrs, R.attr.seekBarPreferenceStyle);
}
public PercentageSeekBarPreference(Context context) {
public TextPercentageSeekBarPreference(Context context) {
this(context, null);
}
@ -415,23 +418,25 @@ public class PercentageSeekBarPreference extends Preference {
@SuppressWarnings("WeakerAccess") /* synthetic access */
void updateLabelValue(int value) {
if (mSeekBarValueTextView != null) {
double m = value / 100d;
final String percentage = NumberFormat.getPercentInstance().format(m);
value = (value * STEP_SIZE) + MIN_VALUE;
final double decimalValue = value / DECIMAL_CONVERSION;
final String percentage = NumberFormat.getPercentInstance().format(decimalValue);
mSeekBarValueTextView.setText(percentage);
}
}
/**
* Attempts to update the example TextView text to given text scale size.
* Attempts to update the example TextView text with text scale size.
*
* @param value the value of text size
*/
@SuppressWarnings("WeakerAccess") /* synthetic access */
void updateExampleTextValue(int value) {
if (mExampleTextTextView != null) {
float decimal = value / 100f;
final float textsize = 16f * decimal;
mExampleTextTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textsize);
value = (value * STEP_SIZE) + MIN_VALUE;
final float decimal = value / DECIMAL_CONVERSION;
final float textSize = 16f * decimal;
mExampleTextTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
}
}

View File

@ -35,8 +35,8 @@
<SeekBar
android:id="@+id/seekbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingEnd="75dp"
android:layout_height="0dp"
android:paddingEnd="60dp"
app:layout_constraintBottom_toBottomOf="@+id/seekbar_value"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -51,6 +51,7 @@
android:gravity="end|center_vertical"
android:paddingStart="16dp"
android:text="200%"
android:textColor="?attr/primaryText"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/sampleText"
app:layout_constraintEnd_toEndOf="parent"
@ -59,8 +60,7 @@
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:alpha="0.2"
android:background="?accentBright"
android:background="@color/violet_05"
app:layout_constraintBottom_toBottomOf="@+id/sampleText"
app:layout_constraintEnd_toEndOf="@+id/sampleText"
app:layout_constraintStart_toStartOf="@+id/sampleText"
@ -73,6 +73,7 @@
android:layout_marginTop="33dp"
android:padding="16dp"
android:text="@string/accessibility_text_size_sample_text"
android:textColor="@color/text_scale_example_text_color"
android:textSize="16sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"

View File

@ -131,6 +131,8 @@
<color name="dark_grey_90">#15141A</color>
<color name="neutral_text">@color/white_color</color>
<color name="disabled_text">#cccccc</color>
<color name="violet_05">#E7DFFF</color>
<color name="text_scale_example_text_color">#232749</color>
<!-- Reader View colors -->
<color name="mozac_feature_readerview_text_color">@color/primary_text_light_theme</color>

View File

@ -5,16 +5,17 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.mozilla.fenix.settings.PercentageSeekBarPreference
android:layout="@layout/layout_percentage_seek_bar"
android:defaultValue="100"
<!-- Custom Preference that scales from 50-200% by steps of 5 represented by 0-30 in steps of 1-->
<org.mozilla.fenix.settings.TextPercentageSeekBarPreference
android:defaultValue="10"
android:key="@string/pref_key_accessibility_font_scale"
android:max="200"
android:layout="@layout/layout_percentage_seek_bar"
android:max="30"
android:summary="@string/preference_accessibility_text_size_summary"
android:title="@string/preference_accessibility_font_size_title"
app:adjustable="true"
app:iconSpaceReserved="false"
app:min="50"
app:seekBarIncrement="5"
app:min="0"
app:seekBarIncrement="1"
app:showSeekBarValue="true" />
</PreferenceScreen>