mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-11 13:11:01 +00:00
Update mapping to represent steps of 5 from 50-200
This commit is contained in:
parent
2956ca0c82
commit
a44322b120
@ -17,11 +17,12 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
|
|||||||
(activity as AppCompatActivity).title = getString(R.string.preferences_accessibility)
|
(activity as AppCompatActivity).title = getString(R.string.preferences_accessibility)
|
||||||
(activity as AppCompatActivity).supportActionBar?.show()
|
(activity as AppCompatActivity).supportActionBar?.show()
|
||||||
val textSizePreference =
|
val textSizePreference =
|
||||||
findPreference<PercentageSeekBarPreference>(getString(R.string.pref_key_accessibility_font_scale))
|
findPreference<TextPercentageSeekBarPreference>(getString(R.string.pref_key_accessibility_font_scale))
|
||||||
textSizePreference?.onPreferenceChangeListener =
|
textSizePreference?.onPreferenceChangeListener =
|
||||||
Preference.OnPreferenceChangeListener { _, newValue ->
|
Preference.OnPreferenceChangeListener { _, newValue ->
|
||||||
(newValue as? Int).let {
|
(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)
|
Settings.getInstance(context!!).setFontSizeFactor(newTextScale)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
@ -33,6 +34,8 @@ class AccessibilityFragment : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val MIN_SCALE_VALUE = 50
|
||||||
|
const val STEP_SIZE = 5
|
||||||
const val PERCENT_TO_DECIMAL = 100f
|
const val PERCENT_TO_DECIMAL = 100f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,11 @@ import java.text.NumberFormat;
|
|||||||
* max})
|
* max})
|
||||||
* can be set directly on the preference widget layout.
|
* 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 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 */
|
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
||||||
int mSeekBarValue;
|
int mSeekBarValue;
|
||||||
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
@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) {
|
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
|
||||||
@ -154,15 +157,15 @@ public class PercentageSeekBarPreference extends Preference {
|
|||||||
a.recycle();
|
a.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentageSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
public TextPercentageSeekBarPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
this(context, attrs, defStyleAttr, 0);
|
this(context, attrs, defStyleAttr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentageSeekBarPreference(Context context, AttributeSet attrs) {
|
public TextPercentageSeekBarPreference(Context context, AttributeSet attrs) {
|
||||||
this(context, attrs, R.attr.seekBarPreferenceStyle);
|
this(context, attrs, R.attr.seekBarPreferenceStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PercentageSeekBarPreference(Context context) {
|
public TextPercentageSeekBarPreference(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,23 +418,25 @@ public class PercentageSeekBarPreference extends Preference {
|
|||||||
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
||||||
void updateLabelValue(int value) {
|
void updateLabelValue(int value) {
|
||||||
if (mSeekBarValueTextView != null) {
|
if (mSeekBarValueTextView != null) {
|
||||||
double m = value / 100d;
|
value = (value * STEP_SIZE) + MIN_VALUE;
|
||||||
final String percentage = NumberFormat.getPercentInstance().format(m);
|
final double decimalValue = value / DECIMAL_CONVERSION;
|
||||||
|
final String percentage = NumberFormat.getPercentInstance().format(decimalValue);
|
||||||
mSeekBarValueTextView.setText(percentage);
|
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
|
* @param value the value of text size
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
@SuppressWarnings("WeakerAccess") /* synthetic access */
|
||||||
void updateExampleTextValue(int value) {
|
void updateExampleTextValue(int value) {
|
||||||
if (mExampleTextTextView != null) {
|
if (mExampleTextTextView != null) {
|
||||||
float decimal = value / 100f;
|
value = (value * STEP_SIZE) + MIN_VALUE;
|
||||||
final float textsize = 16f * decimal;
|
final float decimal = value / DECIMAL_CONVERSION;
|
||||||
mExampleTextTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textsize);
|
final float textSize = 16f * decimal;
|
||||||
|
mExampleTextTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -35,8 +35,8 @@
|
|||||||
<SeekBar
|
<SeekBar
|
||||||
android:id="@+id/seekbar"
|
android:id="@+id/seekbar"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="0dp"
|
||||||
android:paddingEnd="75dp"
|
android:paddingEnd="60dp"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/seekbar_value"
|
app:layout_constraintBottom_toBottomOf="@+id/seekbar_value"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
@ -51,6 +51,7 @@
|
|||||||
android:gravity="end|center_vertical"
|
android:gravity="end|center_vertical"
|
||||||
android:paddingStart="16dp"
|
android:paddingStart="16dp"
|
||||||
android:text="200%"
|
android:text="200%"
|
||||||
|
android:textColor="?attr/primaryText"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/sampleText"
|
app:layout_constraintBottom_toTopOf="@+id/sampleText"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
@ -59,8 +60,7 @@
|
|||||||
<View
|
<View
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:alpha="0.2"
|
android:background="@color/violet_05"
|
||||||
android:background="?accentBright"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/sampleText"
|
app:layout_constraintBottom_toBottomOf="@+id/sampleText"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/sampleText"
|
app:layout_constraintEnd_toEndOf="@+id/sampleText"
|
||||||
app:layout_constraintStart_toStartOf="@+id/sampleText"
|
app:layout_constraintStart_toStartOf="@+id/sampleText"
|
||||||
@ -73,6 +73,7 @@
|
|||||||
android:layout_marginTop="33dp"
|
android:layout_marginTop="33dp"
|
||||||
android:padding="16dp"
|
android:padding="16dp"
|
||||||
android:text="@string/accessibility_text_size_sample_text"
|
android:text="@string/accessibility_text_size_sample_text"
|
||||||
|
android:textColor="@color/text_scale_example_text_color"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
@ -131,6 +131,8 @@
|
|||||||
<color name="dark_grey_90">#15141A</color>
|
<color name="dark_grey_90">#15141A</color>
|
||||||
<color name="neutral_text">@color/white_color</color>
|
<color name="neutral_text">@color/white_color</color>
|
||||||
<color name="disabled_text">#cccccc</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 -->
|
<!-- Reader View colors -->
|
||||||
<color name="mozac_feature_readerview_text_color">@color/primary_text_light_theme</color>
|
<color name="mozac_feature_readerview_text_color">@color/primary_text_light_theme</color>
|
||||||
|
@ -5,16 +5,17 @@
|
|||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<org.mozilla.fenix.settings.PercentageSeekBarPreference
|
<!-- Custom Preference that scales from 50-200% by steps of 5 represented by 0-30 in steps of 1-->
|
||||||
android:layout="@layout/layout_percentage_seek_bar"
|
<org.mozilla.fenix.settings.TextPercentageSeekBarPreference
|
||||||
android:defaultValue="100"
|
android:defaultValue="10"
|
||||||
android:key="@string/pref_key_accessibility_font_scale"
|
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:summary="@string/preference_accessibility_text_size_summary"
|
||||||
android:title="@string/preference_accessibility_font_size_title"
|
android:title="@string/preference_accessibility_font_size_title"
|
||||||
app:adjustable="true"
|
app:adjustable="true"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:min="50"
|
app:min="0"
|
||||||
app:seekBarIncrement="5"
|
app:seekBarIncrement="1"
|
||||||
app:showSeekBarValue="true" />
|
app:showSeekBarValue="true" />
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
Loading…
Reference in New Issue
Block a user