tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 7a0403fd087740a1e2c537788806c72935357edd
parent 0be5ba54d30a9da6db2039a9ba76529ffff7071a
Author: RebecaTudor <rebecatudor273@gmail.com>
Date:   Mon, 29 Dec 2025 22:14:20 +0000

Bug 1975017 - Part 2 - Apply compose slider. r=android-reviewers,android-l10n-reviewers,flod,gmalekpour

Differential Revision: https://phabricator.services.mozilla.com/D268841

Diffstat:
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt | 27++++++++++-----------------
Amobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ComposeTextSizePreference.kt | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/TextPercentageSeekBarPreference.kt | 494-------------------------------------------------------------------------------
Mmobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexer.kt | 3---
Dmobile/android/fenix/app/src/main/res/layout/layout_percentage_seek_bar.xml | 90-------------------------------------------------------------------------------
Amobile/android/fenix/app/src/main/res/layout/preference_compose_font_size_slider.xml | 13+++++++++++++
Mmobile/android/fenix/app/src/main/res/values/colors.xml | 1-
Mmobile/android/fenix/app/src/main/res/values/dimens.xml | 1-
Mmobile/android/fenix/app/src/main/res/values/strings.xml | 2+-
Mmobile/android/fenix/app/src/main/res/xml/accessibility_preferences.xml | 16++--------------
10 files changed, 103 insertions(+), 621 deletions(-)

diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/AccessibilityFragment.kt @@ -6,12 +6,14 @@ package org.mozilla.fenix.settings import android.os.Bundle import androidx.navigation.fragment.navArgs +import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference import org.mozilla.fenix.R import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar +import org.mozilla.fenix.utils.Settings /** * Displays font size controls for accessibility. @@ -41,26 +43,21 @@ class AccessibilityFragment : PreferenceFragmentCompat() { true } - val textSizePreference = requirePreference<TextPercentageSeekBarPreference>( + val textSizePreference = requirePreference<ComposeTextSizePreference>( R.string.pref_key_accessibility_font_scale, ) - textSizePreference.setOnPreferenceChangeListener<Int> { preference, newTextSize -> - val settings = preference.context.settings() - val components = preference.context.components - // Value is mapped from 0->30 in steps of 1 so let's convert to float in range 0.5->2.0 - val newTextScale = - ((newTextSize * STEP_SIZE) + MIN_SCALE_VALUE).toFloat() / PERCENT_TO_DECIMAL + textSizePreference.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue -> + val newTextScale = newValue as Float + val components = preference.context.components // Save new text scale value. We assume auto sizing is off if this change listener was called. - settings.fontSizeFactor = newTextScale components.core.engine.settings.fontSizeFactor = newTextScale // Reload the current session to reflect the new text scale components.useCases.sessionUseCases.reload() true } - textSizePreference.isEnabled = !requireContext().settings().shouldUseAutoSize val useAutoSizePreference = requirePreference<SwitchPreference>(R.string.pref_key_accessibility_auto_size) @@ -78,26 +75,22 @@ class AccessibilityFragment : PreferenceFragmentCompat() { components.core.engine.settings.fontSizeFactor = settings.fontSizeFactor } - // Enable the manual sizing controls if automatic sizing is turned off. - textSizePreference.isEnabled = !useAutoSize + textSizePreference.setIsSliderEnabled(!useAutoSize) // Reload the current session to reflect the new text scale components.useCases.sessionUseCases.reload() true } + textSizePreference.setIsSliderEnabled(!requireContext().settings().shouldUseAutoSize) + args.preferenceToScrollTo?.let { scrollToPreference(it) } } override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + preferenceManager.sharedPreferencesName = Settings.FENIX_PREFERENCES setPreferencesFromResource(R.xml.accessibility_preferences, rootKey) } - - companion object { - const val MIN_SCALE_VALUE = 50 - const val STEP_SIZE = 5 - const val PERCENT_TO_DECIMAL = 100f - } } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ComposeTextSizePreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ComposeTextSizePreference.kt @@ -0,0 +1,77 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix.settings + +import android.content.Context +import android.util.AttributeSet +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableFloatStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.platform.ComposeView +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import org.mozilla.fenix.R +import org.mozilla.fenix.theme.FirefoxTheme + +/** + * A custom Preference hosting a Compose slider for font size control. + * + * @param context The context used to initialize the preference . + * @param attrs Optional attribute set applied from XML. + */ +class ComposeTextSizePreference( + context: Context, + attrs: AttributeSet? = null, +) : Preference(context, attrs) { + + private var isSliderEnabled: Boolean = true + + init { + layoutResource = R.layout.preference_compose_font_size_slider + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + val composeView = + holder.itemView.findViewById<ComposeView>(R.id.compose_view_font_size_slider) + + composeView.setContent { + // Converts the stored factor (1.0) into a UI-friendly percentage (100.0). + val initialPercentage = getPersistedFloat(1.0f) * 100f + + var sliderValue by remember(initialPercentage) { mutableFloatStateOf(initialPercentage) } + var isSliderEnabled by remember(isSliderEnabled) { mutableStateOf(isSliderEnabled) } + + FirefoxTheme { + FontSizePreference( + isEnabled = isSliderEnabled, + value = sliderValue, + onValueChange = { newValue -> + sliderValue = newValue + }, + onValueChangeFinished = { + // Converts back to the stored factor (1.0). + val newFactor = sliderValue / 100f + if (callChangeListener(newFactor)) { + persistFloat(newFactor) + } + }, + ) + } + } + } + + /** + * Updates whether or not the slider is enabled. + * + * @param isEnabled New enabled state. + */ + fun setIsSliderEnabled(isEnabled: Boolean) { + this.isSliderEnabled = isEnabled + notifyChanged() + } +} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/TextPercentageSeekBarPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/TextPercentageSeekBarPreference.kt @@ -1,494 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package org.mozilla.fenix.settings - -/* - * Copyright 2018 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import android.content.Context -import android.content.res.TypedArray -import android.os.Build -import android.os.Parcel -import android.os.Parcelable -import android.util.AttributeSet -import android.util.Log -import android.util.TypedValue -import android.view.KeyEvent -import android.view.View -import android.view.accessibility.AccessibilityNodeInfo -import android.view.accessibility.AccessibilityNodeInfo.RangeInfo -import android.widget.SeekBar -import android.widget.SeekBar.OnSeekBarChangeListener -import android.widget.TextView -import androidx.core.content.withStyledAttributes -import androidx.preference.Preference -import androidx.preference.PreferenceViewHolder -import org.mozilla.fenix.R -import java.text.NumberFormat -import kotlin.math.PI -import kotlin.math.abs -import kotlin.math.min -import kotlin.math.roundToInt -import androidx.preference.R as preferenceR - -/** - * Preference based on android.preference.SeekBarPreference but uses support preference as a base. - * It contains a title and a [SeekBar] and a SeekBar value [TextView] and an Example [TextView]. - * The actual preference layout is customizable by setting `android:layout` on the - * preference widget layout or `seekBarPreferenceStyle` attribute. - * - * The [SeekBar] within the preference can be defined adjustable or not by setting `adjustable` attribute. - * If adjustable, the preference will be responsive to DPAD left/right keys. - * Otherwise, it skips those keys. - * - * The [SeekBar] value view can be shown or disabled by setting `showSeekBarValue` - * attribute to true or false, respectively. - * - * Other [SeekBar] specific attributes (e.g. `title, summary, defaultValue, min, max`) - * can be set directly on the preference widget layout. - */ -@SuppressWarnings("LargeClass") -class TextPercentageSeekBarPreference @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyleAttr: Int = preferenceR.attr.seekBarPreferenceStyle, - defStyleRes: Int = 0, -) : Preference(context, attrs, defStyleAttr, defStyleRes) { - // synthetic access - internal var mSeekBarValue: Int = 0 - - // synthetic access - internal var mMin: Int = 0 - private var mMax: Int = 0 - private var mSeekBarIncrement: Int = 0 - - // synthetic access - internal var mTrackingTouch: Boolean = false - - // synthetic access - internal var mSeekBar: SeekBar? = null - private var mSeekBarValueTextView: TextView? = null - private var mExampleTextTextView: TextView? = null - - /** - * Whether the SeekBar should respond to the left/right keys - */ - // synthetic access - var isAdjustable: Boolean = false - - /** - * Whether to show the SeekBar value TextView next to the bar - */ - private var mShowSeekBarValue: Boolean = false - - /** - * Whether the SeekBarPreference should continuously save the Seekbar value while it is being dragged. - */ - // synthetic access - var updatesContinuously: Boolean = false - - /** - * Listener reacting to the [SeekBar] changing value by the user - */ - private val mSeekBarChangeListener = object : OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { - if (fromUser && (updatesContinuously || !mTrackingTouch)) { - syncValueInternal(seekBar) - } else { - // We always want to update the text while the seekbar is being dragged - updateLabelValue(progress + mMin) - updateExampleTextValue(progress + mMin) - } - } - - override fun onStartTrackingTouch(seekBar: SeekBar) { - mTrackingTouch = true - } - - override fun onStopTrackingTouch(seekBar: SeekBar) { - mTrackingTouch = false - if (seekBar.progress + mMin != mSeekBarValue) { - syncValueInternal(seekBar) - } - } - } - - /** - * Listener reacting to the user pressing DPAD left/right keys if `adjustable` attribute is - * set to true; it transfers the key presses to the [SeekBar] - * to be handled accordingly. - */ - private val mSeekBarKeyListener = View.OnKeyListener { _, keyCode, event -> - return@OnKeyListener if (event.action != KeyEvent.ACTION_DOWN) { - false - } else if (!isAdjustable && (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)) { - // Right or left keys are pressed when in non-adjustable mode; Skip the keys. - false - } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) { - // We don't want to propagate the click keys down to the SeekBar view since it will - // create the ripple effect for the thumb. - false - } else if (mSeekBar == null) { - Log.e(TAG, "SeekBar view is null and hence cannot be adjusted.") - false - } else { - mSeekBar!!.onKeyDown(keyCode, event) - } - } - - /** - * Gets the lower bound set on the [SeekBar]. - * @return The lower bound set - * Sets the lower bound on the [SeekBar]. - * @param min The lower bound to set - */ - var min: Int - get() = mMin - set(min) { - var minimum = min - if (minimum > mMax) { - minimum = mMax - } - if (minimum != mMin) { - mMin = minimum - notifyChanged() - } - } - - /** - * The amount of increment change applied to the [SeekBar] for each arrow key press. - * - * If the user-specified increment is non-zero, that value is used. Otherwise, the default - * increment comes from [android.widget.AbsSeekBar]'s `mKeyProgressIncrement`. - * - * When set, the value is clamped to the range `0..(mMax - mMin)` and its absolute value is used. - */ - var seekBarIncrement: Int - get() = mSeekBarIncrement - set(value) { - if (value != mSeekBarIncrement) { - mSeekBarIncrement = min(mMax - mMin, abs(value)) - notifyChanged() - } - } - - /** - * Gets/Sets the upper bound set on the [SeekBar]. - */ - var max: Int - get() = mMax - set(max) { - var maximum = max - if (maximum < mMin) { - maximum = mMin - } - if (maximum != mMax) { - mMax = maximum - notifyChanged() - } - } - - /** - * Whether the current [SeekBar] value is displayed to the user. - */ - var showSeekBarValue: Boolean - get() = mShowSeekBarValue - set(value) { - mShowSeekBarValue = value - notifyChanged() - } - - /** - * Gets/Sets the current progress of the [SeekBar]. - */ - var value: Int - get() = mSeekBarValue - set(seekBarValue) = setValueInternal(seekBarValue, true) - - init { - context.withStyledAttributes( - attrs, - R.styleable.TextPercentageSeekBarPreference, - defStyleAttr, - defStyleRes, - ) { - // The ordering of these two statements are important. If we want to set max first, we need - // to perform the same steps by changing min/max to max/min as following: - // mMax = a.getInt(...) and setMin(...). - mMin = getInt(R.styleable.TextPercentageSeekBarPreference_min, 0) - max = getInt(R.styleable.TextPercentageSeekBarPreference_android_max, SEEK_BAR_MAX) - seekBarIncrement = getInt(R.styleable.TextPercentageSeekBarPreference_seekBarIncrement, 0) - isAdjustable = getBoolean(R.styleable.TextPercentageSeekBarPreference_adjustable, true) - mShowSeekBarValue = getBoolean(R.styleable.TextPercentageSeekBarPreference_showSeekBarValue, false) - updatesContinuously = getBoolean(R.styleable.TextPercentageSeekBarPreference_updatesContinuously, false) - } - } - - override fun onBindViewHolder(view: PreferenceViewHolder) { - super.onBindViewHolder(view) - view.itemView.setOnKeyListener(mSeekBarKeyListener) - mSeekBar = view.findViewById(R.id.seekbar) as SeekBar - mExampleTextTextView = view.findViewById(R.id.sampleText) as TextView - mSeekBarValueTextView = view.findViewById(R.id.seekbar_value) as TextView - if (mShowSeekBarValue) { - mSeekBarValueTextView?.visibility = View.VISIBLE - } else { - mSeekBarValueTextView?.visibility = View.GONE - mSeekBarValueTextView = null - } - - if (mSeekBar == null) { - Log.e(TAG, "SeekBar view is null in onBindViewHolder.") - return - } - mSeekBar?.setOnSeekBarChangeListener(mSeekBarChangeListener) - mSeekBar?.max = mMax - mMin - // If the increment is not zero, use that. Otherwise, use the default mKeyProgressIncrement - // in AbsSeekBar when it's zero. This default increment value is set by AbsSeekBar - // after calling setMax. That's why it's important to call setKeyProgressIncrement after - // calling setMax() since setMax() can change the increment value. - if (mSeekBarIncrement != 0) { - mSeekBar?.keyProgressIncrement = mSeekBarIncrement - } else { - mSeekBarIncrement = mSeekBar!!.keyProgressIncrement - } - - mSeekBar?.progress = mSeekBarValue - mMin - updateExampleTextValue(mSeekBarValue) - updateLabelValue(mSeekBarValue) - mSeekBar?.isEnabled = isEnabled - mSeekBarValueTextView?.alpha = if (isEnabled) 1F else HALF_ALPHA - mExampleTextTextView?.alpha = if (isEnabled) 1F else HALF_ALPHA - mSeekBar?.let { - it.thumbOffset = it.thumb.intrinsicWidth.div(2 * PI).roundToInt() - } - } - - override fun onSetInitialValue(initialValue: Any?) { - var defaultValue = initialValue - if (defaultValue == null) { - defaultValue = 0 - } - value = getPersistedInt((defaultValue as Int?)!!) - } - - override fun onGetDefaultValue(a: TypedArray, index: Int): Any { - return a.getInt(index, 0) - } - - private fun setValueInternal(value: Int, notifyChanged: Boolean) { - var seekBarValue = value - if (seekBarValue < mMin) { - seekBarValue = mMin - } - if (seekBarValue > mMax) { - seekBarValue = mMax - } - - if (seekBarValue != mSeekBarValue) { - mSeekBarValue = seekBarValue - updateLabelValue(mSeekBarValue) - updateExampleTextValue(mSeekBarValue) - persistInt(seekBarValue) - if (notifyChanged) { - notifyChanged() - } - } - } - - /** - * Persist the [SeekBar]'s SeekBar value if callChangeListener returns true, otherwise - * set the [SeekBar]'s value to the stored value. - */ - // synthetic access - internal fun syncValueInternal(seekBar: SeekBar) { - val seekBarValue = mMin + seekBar.progress - if (seekBarValue != mSeekBarValue) { - if (callChangeListener(seekBarValue)) { - setValueInternal(seekBarValue, false) - } else { - seekBar.progress = mSeekBarValue - mMin - updateLabelValue(mSeekBarValue) - updateExampleTextValue(mSeekBarValue) - } - } - } - - /** - * Attempts to update the TextView label that displays the current value. - * - * @param labelValue the value to display next to the [SeekBar] - */ - // synthetic access - internal fun updateLabelValue(labelValue: Int) { - var value = labelValue - if (mSeekBarValueTextView != null) { - value = value * STEP_SIZE + MIN_VALUE - val decimalValue = (value / DECIMAL_CONVERSION).toDouble() - val percentage = NumberFormat.getPercentInstance().format(decimalValue) - mSeekBarValueTextView?.text = percentage - } - - mSeekBar?.setAccessibilityDelegate( - object : - View.AccessibilityDelegate() { - override fun onInitializeAccessibilityNodeInfo( - host: View, - info: AccessibilityNodeInfo, - ) { - super.onInitializeAccessibilityNodeInfo(host, info) - val initialInfo = info.rangeInfo - val percentageValueDescription = String.format( - context.getString(R.string.a11y_preference_accessibility_font_size_percentage), - value, - ) - - info.rangeInfo = initialInfo?.let { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { - host.stateDescription = percentageValueDescription - RangeInfo( - RangeInfo.RANGE_TYPE_PERCENT, - MIN_VALUE.toFloat(), - SEEK_BAR_MAX.toFloat(), - convertCurrentValue(it.current), - ) - } else { - @Suppress("DEPRECATION") - RangeInfo.obtain( - RangeInfo.RANGE_TYPE_PERCENT, - MIN_VALUE.toFloat(), - SEEK_BAR_MAX.toFloat(), - convertCurrentValue(it.current), - ) - } - } - } - }, - ) - } - - /** - * Attempts to update the example TextView text with text scale size. - * - * @param textValue the value of text size - */ - internal fun updateExampleTextValue(textValue: Int) { - var value = textValue - if (mExampleTextTextView != null) { - value = value * STEP_SIZE + MIN_VALUE - val decimal = value / DECIMAL_CONVERSION - val textSize = TEXT_SIZE * decimal - mExampleTextTextView?.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize) - } - } - - override fun onSaveInstanceState(): Parcelable? { - val superState = super.onSaveInstanceState() - if (isPersistent) { - // No need to save instance state since it's persistent - return superState - } - - // Save the instance state - - return if (superState != null) { - val myState = SavedState(superState) - myState.mSeekBarValue = mSeekBarValue - myState.mMin = mMin - myState.mMax = mMax - myState - } else { - null - } - } - - override fun onRestoreInstanceState(state: Parcelable?) { - if (state?.javaClass != SavedState::class.java) { - // Didn't save state for us in onSaveInstanceState - super.onRestoreInstanceState(state) - return - } - - // Restore the instance state - val myState = state as SavedState? - super.onRestoreInstanceState(myState!!.superState) - mSeekBarValue = myState.mSeekBarValue - mMin = myState.mMin - mMax = myState.mMax - notifyChanged() - } - - /** - * SavedState, a subclass of [BaseSavedState], will store the state of this preference. - * - * - * It is important to always call through to super methods. - */ - private class SavedState : BaseSavedState { - - internal var mSeekBarValue: Int = 0 - internal var mMin: Int = 0 - internal var mMax: Int = 0 - - internal constructor(source: Parcel) : super(source) { - - // Restore the click counter - mSeekBarValue = source.readInt() - mMin = source.readInt() - mMax = source.readInt() - } - - internal constructor(superState: Parcelable) : super(superState) - - override fun writeToParcel(dest: Parcel, flags: Int) { - super.writeToParcel(dest, flags) - - // Save the click counter - dest.writeInt(mSeekBarValue) - dest.writeInt(mMin) - dest.writeInt(mMax) - } - - companion object { - @JvmField - val CREATOR: Parcelable.Creator<SavedState> = object : Parcelable.Creator<SavedState> { - override fun createFromParcel(`in`: Parcel): SavedState { - return SavedState(`in`) - } - - override fun newArray(size: Int): Array<SavedState?> { - return arrayOfNulls(size) - } - } - } - } - - private fun convertCurrentValue(current: Float): Float { - return current * STEP_SIZE + MIN_VALUE.toFloat() - } - - companion object { - private const val TAG = "SeekBarPreference" - private const val STEP_SIZE = 5 - private const val HALF_ALPHA = 0.5F - private const val MIN_VALUE = 50 - private const val DECIMAL_CONVERSION = 100f - private const val TEXT_SIZE = 16f - private const val SEEK_BAR_MAX = 200 - } -} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexer.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/DefaultFenixSettingsIndexer.kt @@ -91,7 +91,6 @@ class DefaultFenixSettingsIndexer(private val context: Context) : SettingsIndexe PREFERENCE_TAG, SWITCH_PREFERENCE_TAG, SWITCH_PREFERENCE_PLAIN_TAG, - TEXT_PERCENTAGE_SEEK_BAR_PREFERENCE_TAG, TOGGLE_RADIO_BUTTON_PREFERENCE_TAG, -> { val item = createSettingsSearchItemFromAttributes( @@ -290,8 +289,6 @@ class DefaultFenixSettingsIndexer(private val context: Context) : SettingsIndexe private const val CUSTOM_CBH_SWITCH_PREFERENCE_TAG = "org.mozilla.fenix.settings.cookiebannerhandling.CustomCBHSwitchPreference" private const val DEFAULT_BROWSER_PREFERENCE_TAG = "org.mozilla.fenix.settings.DefaultBrowserPreference" - private const val TEXT_PERCENTAGE_SEEK_BAR_PREFERENCE_TAG = - "org.mozilla.fenix.settings.TextPercentageSeekBarPreference" private const val RADIO_BUTTON_PREFERENCE_TAG = "org.mozilla.fenix.settings.RadioButtonPreference" private const val TOGGLE_RADIO_BUTTON_PREFERENCE_TAG = "org.mozilla.fenix.settings.ToggleRadioButtonPreference" private const val KEY_ATTRIBUTE_NAME = "key" diff --git a/mobile/android/fenix/app/src/main/res/layout/layout_percentage_seek_bar.xml b/mobile/android/fenix/app/src/main/res/layout/layout_percentage_seek_bar.xml @@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- This Source Code Form is subject to the terms of the Mozilla Public - - License, v. 2.0. If a copy of the MPL was not distributed with this - - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:baselineAligned="false" - android:clipChildren="false" - android:clipToPadding="false" - android:paddingTop="@dimen/preference_seek_bar_padding" - android:paddingBottom="@dimen/preference_seek_bar_padding"> - - <TextView - android:id="@android:id/title" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingStart="@dimen/top_bar_alignment_margin_start" - android:paddingEnd="@dimen/radio_button_preference_horizontal" - android:textAppearance="?android:attr/textAppearanceListItem" - android:textAlignment="viewStart" - app:layout_constraintTop_toTopOf="parent" - tools:text="Font size" /> - - <TextView - android:id="@android:id/summary" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:paddingStart="@dimen/top_bar_alignment_margin_start" - android:paddingEnd="@dimen/radio_button_preference_horizontal" - android:textAppearance="?android:attr/textAppearanceSmall" - android:textAlignment="viewStart" - android:textColor="?android:attr/textColorSecondary" - app:layout_constraintTop_toBottomOf="@android:id/title" - tools:text="Make text on websites larger or smaller" /> - - <SeekBar - android:id="@+id/seekbar" - android:layout_width="0dp" - android:layout_height="@dimen/accessibility_min_height" - android:paddingStart="@dimen/top_bar_alignment_margin_start" - android:paddingEnd="80dp" - app:layout_constraintBottom_toBottomOf="@+id/seekbar_value" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="@+id/seekbar_value" /> - - <TextView - android:id="@+id/seekbar_value" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="30dp" - android:layout_marginBottom="30dp" - android:gravity="end|center_vertical" - android:paddingStart="16dp" - android:paddingEnd="@dimen/radio_button_preference_horizontal" - android:textColor="?attr/textPrimary" - android:textSize="16sp" - app:layout_constraintBottom_toTopOf="@+id/sampleText" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintTop_toBottomOf="@android:id/summary" - tools:text="200%" /> - - <View - android:layout_width="0dp" - android:layout_height="0dp" - android:background="@color/photonViolet05" - app:layout_constraintBottom_toBottomOf="@+id/sampleText" - app:layout_constraintEnd_toEndOf="@+id/sampleText" - app:layout_constraintStart_toStartOf="@+id/sampleText" - app:layout_constraintTop_toTopOf="@+id/sampleText" /> - - <TextView - android:id="@+id/sampleText" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="33dp" - android:layout_marginStart="@dimen/top_bar_alignment_margin_start" - android:layout_marginEnd="@dimen/radio_button_preference_horizontal" - android:padding="16dp" - android:textAlignment="viewStart" - android:text="@string/accessibility_text_size_sample_text_1" - android:textColor="@color/text_scale_example_text_color" - android:textSize="16sp" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" /> -</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/mobile/android/fenix/app/src/main/res/layout/preference_compose_font_size_slider.xml b/mobile/android/fenix/app/src/main/res/layout/preference_compose_font_size_slider.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- This Source Code Form is subject to the terms of the Mozilla Public + - License, v. 2.0. If a copy of the MPL was not distributed with this + - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content"> + + <androidx.compose.ui.platform.ComposeView + android:id = "@+id/compose_view_font_size_slider" + android:layout_width="match_parent" + android:layout_height="wrap_content"/> +</FrameLayout> diff --git a/mobile/android/fenix/app/src/main/res/values/colors.xml b/mobile/android/fenix/app/src/main/res/values/colors.xml @@ -252,7 +252,6 @@ <!-- Misc colors applied universally--> <color name="suggestion_highlight_color">#5C592ACB</color> - <color name="text_scale_example_text_color">#232749</color> <color name="sync_error_background_color">#FFF36E</color> <color name="sync_error_text_color">@color/photonYellow90</color> <color name="bottom_bar_shadow">#1A000000</color> diff --git a/mobile/android/fenix/app/src/main/res/values/dimens.xml b/mobile/android/fenix/app/src/main/res/values/dimens.xml @@ -37,7 +37,6 @@ <dimen name="exceptions_description_margin">12dp</dimen> <dimen name="component_exceptions_learn_more_height">48dp</dimen> <dimen name="component_tp_exceptions_icon_size">48dp</dimen> - <dimen name="preference_seek_bar_padding">16dp</dimen> <dimen name="custom_checkbox_alignment_margin">68dp</dimen> <dimen name="context_menu_height">48dp</dimen> diff --git a/mobile/android/fenix/app/src/main/res/values/strings.xml b/mobile/android/fenix/app/src/main/res/values/strings.xml @@ -2129,7 +2129,7 @@ <!-- Title for Accessibility Text Size Scaling Preference --> <string name="preference_accessibility_font_size_title">Font Size</string> <!-- %d is the percentage of the slide bar for setting the text font size and %% will be announced as "percent". --> - <string name="a11y_preference_accessibility_font_size_percentage">%d %%.</string> + <string name="a11y_preference_accessibility_font_size_percentage" tools:ignore="UnusedResources" moz:removedIn="148">%d %%.</string> <!-- Title for Accessibility Text Automatic Size Scaling Preference --> <string name="preference_accessibility_auto_size_2">Automatic font sizing</string> diff --git a/mobile/android/fenix/app/src/main/res/xml/accessibility_preferences.xml b/mobile/android/fenix/app/src/main/res/xml/accessibility_preferences.xml @@ -9,20 +9,8 @@ android:key="@string/pref_key_accessibility_auto_size" android:summary="@string/preference_accessibility_auto_size_summary" android:title="@string/preference_accessibility_auto_size_2" /> - <!-- 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: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:enabled="false" - app:iconSpaceReserved="false" - app:min="0" - app:seekBarIncrement="1" - app:showSeekBarValue="true" /> + <org.mozilla.fenix.settings.ComposeTextSizePreference + android:key="@string/pref_key_accessibility_font_scale"/> <SwitchPreference android:defaultValue="false" android:key="@string/pref_key_accessibility_force_enable_zoom"