Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ba41bfb5 authored by Arc Wang's avatar Arc Wang Committed by Automerger Merge Worker
Browse files

Merge "Fix profile tab text contrast problem" into sc-dev am: 8c8b79da am: 1966d6c3

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15165937

Change-Id: I85ed053c2d843fe04ad20c4495bc29dc558fed32
parents 3c77faf5 1966d6c3
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static android.content.Intent.EXTRA_USER_ID;
import android.annotation.IntDef;
import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserManager;
@@ -113,6 +114,7 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
        viewPager.setAdapter(new ProfileSelectFragment.ViewPagerAdapter(this));
        final TabLayout tabs = tabContainer.findViewById(R.id.tabs);
        tabs.setupWithViewPager(viewPager);
        setupTabTextColor(tabs);
        tabContainer.setVisibility(View.VISIBLE);
        final TabLayout.Tab tab = tabs.getTabAt(selectedTab);
        tab.select();
@@ -129,6 +131,30 @@ public abstract class ProfileSelectFragment extends DashboardFragment {
        return mContentView;
    }

    /**
     * TabLayout uses ColorStateList of 2 states, selected state and empty state.
     * It's expected to use textColorSecondary default state color as empty state tabTextColor.
     *
     * However, TabLayout uses textColorSecondary by a not expected state.
     * This method sets tabTextColor with the color of expected textColorSecondary state.
     */
    private void setupTabTextColor(TabLayout tabLayout) {
        final ColorStateList defaultColorStateList = tabLayout.getTabTextColors();
        final ColorStateList resultColorStateList = new ColorStateList(
                new int[][]{
                    new int[]{android.R.attr.state_selected},
                    new int[]{}
                },
                new int[] {
                    defaultColorStateList.getColorForState(new int[]{android.R.attr.state_selected},
                            Utils.getColorAttrDefaultColor(getContext(),
                            com.android.internal.R.attr.colorAccentPrimaryVariant)),
                    Utils.getColorAttrDefaultColor(getContext(), android.R.attr.textColorSecondary)
                }
        );
        tabLayout.setTabTextColors(resultColorStateList);
    }

    @Override
    public int getMetricsCategory() {
        return METRICS_CATEGORY_UNKNOWN;