commit 36927b24f4e6a26cb1e0a66521449d1c78aeca89 parent 6cf8a9bed89f08bdc3adeec3ff64f0f22709bcff Author: iorgamgabriel <iorgamgabriel@yahoo.com> Date: Mon, 10 Nov 2025 14:41:28 +0000 Bug 1994126 - Fix colour issues in private mode for setting options. r=android-reviewers,tthibaud Differential Revision: https://phabricator.services.mozilla.com/D269958 Diffstat:
16 files changed, 74 insertions(+), 49 deletions(-)
diff --git a/mobile/android/android-components/components/feature/addons/src/main/res/layout/mozac_feature_addons_item.xml b/mobile/android/android-components/components/feature/addons/src/main/res/layout/mozac_feature_addons_item.xml @@ -113,6 +113,7 @@ android:layout_gravity="center_vertical" android:layout_marginStart="6dp" android:textSize="12sp" + android:textColor="?attr/colorOnSurface" tools:text="Reviews: 591,642" /> </LinearLayout> </LinearLayout> diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/collections/CollectionsListAdapter.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/collections/CollectionsListAdapter.kt @@ -9,12 +9,13 @@ import android.view.ViewGroup import android.widget.CheckedTextView import androidx.annotation.VisibleForTesting import androidx.appcompat.content.res.AppCompatResources -import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.DrawableCompat import androidx.core.view.updatePaddingRelative import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.color.MaterialColors import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelativeWithIntrinsicBounds import org.mozilla.fenix.R +import com.google.android.material.R as materialR import mozilla.components.ui.icons.R as iconsR /** @@ -56,9 +57,10 @@ class CollectionsListAdapter( drawable?.let { DrawableCompat.setTint( it, - ContextCompat.getColor( + MaterialColors.getColor( holder.textView.context, - R.color.fx_mobile_icon_color_primary, + materialR.attr.colorOnSurface, + "Could not resolve themed color", ), ) } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarShortcutPreference.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/ToolbarShortcutPreference.kt @@ -6,7 +6,6 @@ package org.mozilla.fenix.settings import android.content.Context import android.content.res.ColorStateList -import android.content.res.Configuration import android.util.AttributeSet import android.view.LayoutInflater import android.view.View @@ -15,17 +14,17 @@ import android.widget.ImageView import android.widget.LinearLayout import android.widget.RadioButton import android.widget.TextView +import androidx.annotation.AttrRes +import androidx.annotation.ColorInt import androidx.annotation.DrawableRes import androidx.annotation.StringRes -import androidx.compose.ui.graphics.toArgb import androidx.core.widget.ImageViewCompat import androidx.preference.Preference import androidx.preference.PreferenceViewHolder -import mozilla.components.compose.base.theme.AcornColors -import mozilla.components.compose.base.theme.darkColorPalette -import mozilla.components.compose.base.theme.lightColorPalette +import com.google.android.material.color.MaterialColors import org.mozilla.fenix.R import org.mozilla.fenix.ext.settings +import com.google.android.material.R as materialR import mozilla.components.ui.icons.R as iconsR /** @@ -72,6 +71,15 @@ class ToolbarShortcutPreference @JvmOverloads constructor( ) } + @ColorInt + private var colorTertiary: Int = 0 + + @ColorInt + private var colorOnSurface: Int = 0 + + @ColorInt + private var colorOnSurfaceVariant: Int = 0 + init { layoutResource = R.layout.preference_toolbar_shortcut isSelectable = false @@ -87,6 +95,10 @@ class ToolbarShortcutPreference @JvmOverloads constructor( val optionsContainer = holder.findViewById(R.id.options_container) as LinearLayout val separator = holder.findViewById(R.id.separator) as View + colorTertiary = holder.itemView.getMaterialColor(materialR.attr.colorTertiary) + colorOnSurface = holder.itemView.getMaterialColor(materialR.attr.colorOnSurface) + colorOnSurfaceVariant = holder.itemView.getMaterialColor(materialR.attr.colorOnSurfaceVariant) + val selected = options.firstOrNull { it.key == selectedKey } ?: options.first() selectedContainer.removeAllViews() @@ -140,16 +152,14 @@ class ToolbarShortcutPreference @JvmOverloads constructor( radio.isChecked = isChecked radio.isEnabled = true - val colors = getPalette(context) - label.setTextColor( - (if (isChecked) colors.textAccentDisabled else colors.textPrimary).toArgb(), + if (isChecked) colorTertiary else colorOnSurface, ) ImageViewCompat.setImageTintList( icon, ColorStateList.valueOf( - (if (isChecked) colors.iconAccentViolet else colors.iconPrimary).toArgb(), + if (isChecked) colorTertiary else colorOnSurface, ), ) @@ -158,7 +168,7 @@ class ToolbarShortcutPreference @JvmOverloads constructor( intArrayOf(android.R.attr.state_checked), intArrayOf(-android.R.attr.state_checked), ), - intArrayOf(colors.formSelected.toArgb(), colors.formDefault.toArgb()), + intArrayOf(colorTertiary, colorOnSurfaceVariant), ) if (isEnabled) { @@ -173,17 +183,8 @@ class ToolbarShortcutPreference @JvmOverloads constructor( return row } - /** - * Get the color palette based on the current browsing mode. - * - * N.B: This logic was taken from [Theme.getTheme] in FirefoxTheme, however we cannot use it - * directly because those functions are annotated to be Composable and refactoring that can be - * done in a follow-up when needed. This needs to be done less hacky. - * https://bugzilla.mozilla.org/show_bug.cgi?id=1993265 - */ - private fun getPalette(context: Context): AcornColors { - val uiMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - return if (uiMode == Configuration.UI_MODE_NIGHT_YES) darkColorPalette else lightColorPalette + private fun View.getMaterialColor(@AttrRes attr: Int): Int { + return MaterialColors.getColor(this, attr) } private data class Option( diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/autofill/AutofillSettingFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/autofill/AutofillSettingFragment.kt @@ -14,12 +14,12 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.annotation.VisibleForTesting -import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope import androidx.navigation.NavController import androidx.navigation.fragment.findNavController import androidx.preference.Preference import androidx.preference.SwitchPreference +import com.google.android.material.color.MaterialColors import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay @@ -41,6 +41,7 @@ import org.mozilla.fenix.settings.SharedPreferenceUpdater import org.mozilla.fenix.settings.SyncPreferenceView import org.mozilla.fenix.settings.biometric.BiometricPromptPreferenceFragment import org.mozilla.fenix.settings.requirePreference +import com.google.android.material.R as materialR import mozilla.components.ui.icons.R as iconsR /** @@ -234,9 +235,10 @@ class AutofillSettingFragment : BiometricPromptPreferenceFragment() { } else { manageAddressesPreference.setIcon(iconsR.drawable.mozac_ic_plus_24) manageAddressesPreference.icon?.setTint( - ContextCompat.getColor( - requireContext(), - R.color.fx_mobile_icon_color_primary, + MaterialColors.getColor( + requireActivity(), + materialR.attr.colorOnSurface, + "Could not resolve themed color", ), ) manageAddressesPreference.title = @@ -276,9 +278,10 @@ class AutofillSettingFragment : BiometricPromptPreferenceFragment() { } else { manageSavedCardsPreference.setIcon(iconsR.drawable.mozac_ic_plus_24) manageSavedCardsPreference.icon?.setTint( - ContextCompat.getColor( + MaterialColors.getColor( requireContext(), - R.color.fx_mobile_icon_color_primary, + materialR.attr.colorOnSurface, + "Could not resolve themed color", ), ) manageSavedCardsPreference.title = diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SitePermissionsDetailsExceptionsFragment.kt @@ -8,11 +8,11 @@ import android.content.Context import android.content.DialogInterface import android.os.Bundle import androidx.annotation.VisibleForTesting -import androidx.core.content.ContextCompat import androidx.lifecycle.lifecycleScope import androidx.navigation.findNavController import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat +import com.google.android.material.color.MaterialColors import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -40,6 +40,7 @@ import org.mozilla.fenix.settings.PhoneFeature.PERSISTENT_STORAGE import org.mozilla.fenix.settings.quicksettings.AutoplayValue import org.mozilla.fenix.settings.requirePreference import org.mozilla.fenix.utils.Settings +import com.google.android.material.R as materialR @SuppressWarnings("TooManyFunctions") class SitePermissionsDetailsExceptionsFragment : PreferenceFragmentCompat() { @@ -101,9 +102,10 @@ class SitePermissionsDetailsExceptionsFragment : PreferenceFragmentCompat() { true } preference.icon?.setTint( - ContextCompat.getColor( + MaterialColors.getColor( provideContext(), - R.color.fx_mobile_icon_color_primary, + materialR.attr.colorOnSurface, + "Could not resolve themed color", ), ) } diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SiteSettingsFragment.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/sitepermissions/SiteSettingsFragment.kt @@ -5,13 +5,13 @@ package org.mozilla.fenix.settings.sitepermissions import android.os.Bundle -import androidx.core.content.ContextCompat import androidx.navigation.findNavController import androidx.navigation.fragment.navArgs import androidx.preference.Preference import androidx.preference.Preference.OnPreferenceClickListener import androidx.preference.PreferenceFragmentCompat import androidx.preference.SwitchPreference +import com.google.android.material.color.MaterialColors import mozilla.components.browser.state.action.DefaultDesktopModeAction import mozilla.telemetry.glean.private.NoExtras import org.mozilla.fenix.GleanMetrics.Autoplay @@ -24,6 +24,7 @@ import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.settings.PhoneFeature import org.mozilla.fenix.settings.requirePreference +import com.google.android.material.R as materialR /** * Screen for managing settings related to site permissions and content defaults. @@ -56,7 +57,13 @@ class SiteSettingsFragment : PreferenceFragmentCompat() { private fun bindDesktopMode() { requirePreference<SwitchPreference>(R.string.pref_key_desktop_browsing).apply { - icon?.setTint(ContextCompat.getColor(context, R.color.fx_mobile_icon_color_primary)) + icon?.setTint( + MaterialColors.getColor( + requireContext(), + materialR.attr.colorOnSurface, + "Could not resolve themed color", + ), + ) isChecked = requireComponents.core.store.state.desktopMode isPersistent = false onPreferenceChangeListener = @@ -99,12 +106,6 @@ class SiteSettingsFragment : PreferenceFragmentCompat() { val preference = requirePreference<Preference>(phoneFeature.getPreferenceId()) preference.summary = phoneFeature.getActionLabel(context, settings = settings) - preference.icon?.setTint( - ContextCompat.getColor( - context, - R.color.fx_mobile_icon_color_primary, - ), - ) preference.isVisible = true preference.onPreferenceClickListener = OnPreferenceClickListener { navigateToPhoneFeature(phoneFeature) diff --git a/mobile/android/fenix/app/src/main/res/drawable/ic_new_pin.xml b/mobile/android/fenix/app/src/main/res/drawable/ic_new_pin.xml @@ -8,6 +8,6 @@ android:viewportWidth="12" android:viewportHeight="12"> <path - android:fillColor="@color/fx_mobile_icon_color_primary" + android:fillColor="?attr/colorOnSurface" android:pathData="M9.05,4.055H7.6L7.156,3.89C7.156,3.89 6.19,2.926 5.612,2.349L6.106,1.855C6.302,1.659 6.302,1.342 6.106,1.147C5.91,0.951 5.593,0.951 5.398,1.147L4.689,1.855L1.147,5.398C0.951,5.594 0.951,5.911 1.147,6.106C1.343,6.302 1.66,6.302 1.855,6.106L2.349,5.612C2.93,6.194 3.904,7.17 3.904,7.17L4.054,7.597L4.055,9.049C4.055,9.425 4.279,9.76 4.626,9.904C4.742,9.952 4.862,9.975 4.981,9.975C5.221,9.975 5.457,9.881 5.634,9.703L7.314,8.023L10.144,10.853C10.34,11.049 10.657,11.049 10.852,10.853C11.048,10.657 11.048,10.34 10.852,10.145L8.022,7.315L9.702,5.635C9.968,5.369 10.046,4.974 9.903,4.627C9.761,4.279 9.425,4.055 9.05,4.055Z" /> </vector> diff --git a/mobile/android/fenix/app/src/main/res/layout/amo_collection_override_dialog.xml b/mobile/android/fenix/app/src/main/res/layout/amo_collection_override_dialog.xml @@ -19,6 +19,7 @@ android:hint="@string/customize_addon_collection_user_hint" android:inputType="number" android:singleLine="true" + android:textColorHint="?attr/colorOnSurfaceVariant" android:textColor="?attr/textPrimary" /> <EditText @@ -31,6 +32,7 @@ android:hint="@string/customize_addon_collection_hint" android:inputType="text" android:singleLine="true" + android:textColorHint="?attr/colorOnSurfaceVariant" android:textColor="?attr/textPrimary" /> </LinearLayout> diff --git a/mobile/android/fenix/app/src/main/res/layout/etp_dropdown_item.xml b/mobile/android/fenix/app/src/main/res/layout/etp_dropdown_item.xml @@ -9,6 +9,7 @@ android:layout_height="wrap_content" android:minHeight="48dp" android:paddingEnd="15dp" + android:textColor="?attr/colorOnSurface" android:paddingStart="15dp" android:gravity="center_vertical" android:background="@drawable/etp_spinner_item_background" diff --git a/mobile/android/fenix/app/src/main/res/layout/fragment_manage_site_permissions_feature_phone.xml b/mobile/android/fenix/app/src/main/res/layout/fragment_manage_site_permissions_feature_phone.xml @@ -22,6 +22,7 @@ android:id="@+id/ask_to_allow_radio" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textColor="?attr/colorOnSurface" android:background="?android:attr/selectableItemBackground" android:button="@null" android:drawablePadding="@dimen/radio_button_preference_drawable_padding" @@ -37,6 +38,7 @@ android:id="@+id/block_radio" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textColor="?attr/colorOnSurface" android:background="?android:attr/selectableItemBackground" android:button="@null" android:drawablePadding="@dimen/radio_button_preference_drawable_padding" @@ -52,6 +54,7 @@ android:id="@+id/third_radio" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textColor="?attr/colorOnSurface" android:background="?android:attr/selectableItemBackground" android:button="@null" android:drawablePadding="@dimen/radio_button_preference_drawable_padding" @@ -66,6 +69,7 @@ android:id="@+id/fourth_radio" android:layout_width="match_parent" android:layout_height="wrap_content" + android:textColor="?attr/colorOnSurface" android:background="?android:attr/selectableItemBackground" android:button="@null" android:drawablePadding="@dimen/radio_button_preference_drawable_padding" diff --git a/mobile/android/fenix/app/src/main/res/layout/fragment_save_search_engine.xml b/mobile/android/fenix/app/src/main/res/layout/fragment_save_search_engine.xml @@ -43,7 +43,8 @@ android:layout_height="wrap_content" android:minHeight="@dimen/accessibility_min_height" android:hint="@string/search_add_custom_engine_name_hint_2" - android:inputType="text" /> + android:inputType="text" + android:textColorHint="?attr/colorOnSurfaceVariant"/> </com.google.android.material.textfield.TextInputLayout> <TextView @@ -71,7 +72,8 @@ android:layout_height="wrap_content" android:minHeight="@dimen/accessibility_min_height" android:hint="@string/search_add_custom_engine_search_string_hint_2" - android:inputType="text"/> + android:inputType="text" + android:textColorHint="?attr/colorOnSurfaceVariant" /> </com.google.android.material.textfield.TextInputLayout> <LinearLayout @@ -123,7 +125,8 @@ android:layout_height="wrap_content" android:minHeight="@dimen/accessibility_min_height" android:hint="@string/search_add_custom_engine_suggest_string_hint" - android:inputType="text"/> + android:inputType="text" + android:textColorHint="?attr/colorOnSurfaceVariant"/> </com.google.android.material.textfield.TextInputLayout> <LinearLayout diff --git a/mobile/android/fenix/app/src/main/res/layout/preference_search_add_engine.xml b/mobile/android/fenix/app/src/main/res/layout/preference_search_add_engine.xml @@ -23,7 +23,7 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:srcCompat="@drawable/mozac_ic_plus_24" - app:tint="@color/fx_mobile_icon_color_primary" /> + app:tint="?attr/colorOnSurface" /> <TextView android:id="@+id/add_engine_text" diff --git a/mobile/android/fenix/app/src/main/res/layout/search_widget_large.xml b/mobile/android/fenix/app/src/main/res/layout/search_widget_large.xml @@ -6,6 +6,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="50dp" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_gravity="center" android:background="@drawable/rounded_search_widget_background"> @@ -42,6 +43,6 @@ android:contentDescription="@string/search_widget_voice" android:scaleType="centerInside" android:src="@drawable/mozac_ic_microphone_24" - android:tint="@color/fx_mobile_icon_color_primary" + app:tint="?attr/colorOnSurface" tools:ignore="AndroidSrcXmlDetector,UseAppTint" /> </RelativeLayout> diff --git a/mobile/android/fenix/app/src/main/res/layout/search_widget_medium.xml b/mobile/android/fenix/app/src/main/res/layout/search_widget_medium.xml @@ -6,6 +6,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="192dp" android:layout_height="50dp" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_gravity="center" android:background="@drawable/rounded_search_widget_background"> @@ -42,6 +43,6 @@ android:contentDescription="@string/search_widget_voice" android:scaleType="centerInside" android:src="@drawable/mozac_ic_microphone_24" - android:tint="@color/fx_mobile_icon_color_primary" + app:tint="?attr/colorOnSurface" tools:ignore="AndroidSrcXmlDetector,UseAppTint" /> </RelativeLayout> diff --git a/mobile/android/fenix/app/src/main/res/layout/search_widget_small.xml b/mobile/android/fenix/app/src/main/res/layout/search_widget_small.xml @@ -5,6 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="100dp" android:layout_height="50dp" + xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@drawable/rounded_search_widget_background" android:orientation="horizontal"> @@ -24,6 +25,6 @@ android:padding="10dp" android:scaleType="centerInside" android:src="@drawable/mozac_ic_microphone_24" - android:tint="@color/fx_mobile_icon_color_primary" + app:tint="?attr/colorOnSurface" tools:ignore="AndroidSrcXmlDetector,UseAppTint" /> </LinearLayout> diff --git a/mobile/android/fenix/app/src/main/res/layout/settings_https_only.xml b/mobile/android/fenix/app/src/main/res/layout/settings_https_only.xml @@ -71,6 +71,7 @@ android:minHeight="48dp" android:background="?android:attr/selectableItemBackground" android:button="@null" + android:textColor="?attr/colorOnSurface" android:drawablePadding="@dimen/radio_button_preference_drawable_padding" android:paddingStart="@dimen/radio_button_preference_horizontal" android:paddingTop="@dimen/radio_button_preference_vertical" @@ -88,6 +89,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:minHeight="48dp" + android:textColor="?attr/colorOnSurface" android:background="?android:attr/selectableItemBackground" android:button="@null" android:drawablePadding="@dimen/radio_button_preference_drawable_padding"