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

Commit 8bae0d70 authored by Ben Murdoch's avatar Ben Murdoch
Browse files

Migrate to setting TextAppearance on user switcher.

Currently the active user in the user switcher is identified
in the UI by rendering the username in a bolder typeface. As
we are exploring other treatments, switch to using text appearance
instead.

Test: Manual
Bug: 136122305

Change-Id: Ib143805aee4a28037414fa939382ae84b748f472
parent 4bfcfe79
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -29,7 +29,8 @@
        android:background="@drawable/ripple_drawable"
        android:clipChildren="false"
        android:clipToPadding="false"
        sysui:activatedFontFamily="sans-serif-medium">
        sysui:regularTextAppearance="@style/TextAppearance.StatusBar.Expanded.UserSwitcher"
        sysui:activatedTextAppearance="@style/TextAppearance.StatusBar.Expanded.UserSwitcher.Activated">
    <TextView android:id="@+id/user_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
+2 −3
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@
        android:clipToPadding="false"
        android:focusable="true"
        android:background="@drawable/ripple_drawable"
        systemui:activatedFontFamily="sans-serif-medium">
        systemui:regularTextAppearance="@style/TextAppearance.QS.UserSwitcher"
        systemui:activatedTextAppearance="@style/TextAppearance.QS.UserSwitcher.Activated">

    <com.android.systemui.statusbar.phone.UserAvatarView
            android:id="@+id/user_picture"
@@ -52,8 +53,6 @@
                android:id="@+id/user_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="@dimen/qs_detail_item_secondary_text_size"
                android:textColor="?android:attr/textColorSecondary"
                android:gravity="center_horizontal" />
        <ImageView
                android:id="@+id/restricted_padlock"
+2 −2
Original line number Diff line number Diff line
@@ -63,8 +63,8 @@
        <attr name="badgeMargin" format="dimension" />
    </declare-styleable>
    <declare-styleable name="UserDetailItemView">
        <attr name="regularFontFamily" format="string" />
        <attr name="activatedFontFamily" format="string" />
        <attr name="regularTextAppearance" format="string" />
        <attr name="activatedTextAppearance" format="string" />
    </declare-styleable>
    <declare-styleable name="DateView">
        <attr name="datePattern" format="string" />
+15 −0
Original line number Diff line number Diff line
@@ -134,6 +134,11 @@
        <item name="android:textColor">?android:attr/textColorSecondary</item>
    </style>

    <style name="TextAppearance.StatusBar.Expanded.UserSwitcher.Activated">
        <item name="android:fontWeight">700</item>
        <item name="android:textStyle">bold</item>
    </style>

    <style name="TextAppearance" />

    <style name="TextAppearance.QS">
@@ -216,6 +221,16 @@
        <item name="android:fontFamily">@*android:string/config_bodyFontFamily</item>
    </style>

    <style name="TextAppearance.QS.UserSwitcher">
        <item name="android:textSize">@dimen/qs_detail_item_secondary_text_size</item>
        <item name="android:textColor">?android:attr/textColorSecondary</item>
    </style>

    <style name="TextAppearance.QS.UserSwitcher.Activated">
        <item name="android:fontWeight">700</item>
        <item name="android:textStyle">bold</item>
    </style>

    <!-- This is hard coded to be sans-serif-condensed to match the icons -->
    <style name="TextAppearance.RATBadge" parent="@style/TextAppearance.QS.TileLabel.Secondary">
        <item name="android:fontFamily">sans-serif-condensed</item>
+17 −15
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -43,8 +42,8 @@ public class UserDetailItemView extends LinearLayout {

    private UserAvatarView mAvatar;
    private TextView mName;
    private Typeface mRegularTypeface;
    private Typeface mActivatedTypeface;
    private int mActivatedStyle;
    private int mRegularStyle;
    private View mRestrictedPadlock;

    public UserDetailItemView(Context context) {
@@ -68,10 +67,10 @@ public class UserDetailItemView extends LinearLayout {
        final int N = a.getIndexCount();
        for (int i = 0; i < N; i++) {
            int attr = a.getIndex(i);
            if (attr == R.styleable.UserDetailItemView_regularFontFamily) {
                mRegularTypeface = Typeface.create(a.getString(attr), 0 /* style */);
            } else if (attr == R.styleable.UserDetailItemView_activatedFontFamily) {
                mActivatedTypeface = Typeface.create(a.getString(attr), 0 /* style */);
            if (attr == R.styleable.UserDetailItemView_regularTextAppearance) {
                mRegularStyle = a.getResourceId(attr, 0);
            } else if (attr == R.styleable.UserDetailItemView_activatedTextAppearance) {
                mActivatedStyle = a.getResourceId(attr, 0);
            }
        }
        a.recycle();
@@ -115,13 +114,16 @@ public class UserDetailItemView extends LinearLayout {
    protected void onFinishInflate() {
        mAvatar = findViewById(R.id.user_picture);
        mName = findViewById(R.id.user_name);
        if (mRegularTypeface == null) {
            mRegularTypeface = mName.getTypeface();

        if (mRegularStyle == 0) {
            mRegularStyle = mName.getExplicitStyle();
        }
        if (mActivatedTypeface == null) {
            mActivatedTypeface = mName.getTypeface();

        if (mActivatedStyle == 0) {
            mActivatedStyle = mName.getExplicitStyle();
        }
        updateTypeface();

        updateTextStyle();
        mRestrictedPadlock = findViewById(R.id.restricted_padlock);
    }

@@ -134,12 +136,12 @@ public class UserDetailItemView extends LinearLayout {
    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        updateTypeface();
        updateTextStyle();
    }

    private void updateTypeface() {
    private void updateTextStyle() {
        boolean activated = ArrayUtils.contains(getDrawableState(), android.R.attr.state_activated);
        mName.setTypeface(activated ? mActivatedTypeface : mRegularTypeface);
        mName.setTextAppearance(activated ? mActivatedStyle : mRegularStyle);
    }

    @Override