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

Commit 204fbcbb authored by Bryan Eyler's avatar Bryan Eyler
Browse files

Update user names on changes in settings/user.

- Refreshes the names when changes occur due to user switching or name
  change.
- Refreshes the views to be shown when the status bar is hidden.

Bug: 67374389
Bug: 67376674
Bug: 67382914

Change-Id: I3b60bf1dbd59e0e288950ec314a551fff8e59fee
(cherry picked from commit 695ede356b0f80a1c37329cd5ebbc6aaebe784ba)
parent ba88b3e7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/quick_settings_container"
    android:clipChildren="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/car_qs_background_primary"
@@ -49,6 +50,7 @@
            android:layout_width="match_parent"
            android:layout_height="@dimen/car_page_indicator_dot_diameter"
            android:layout_marginBottom="@dimen/car_page_indicator_margin_bottom"
            android:alpha="0"
            android:layout_alignParentBottom="true" />

    </RelativeLayout>
+19 −4
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public class CarQSFragment extends Fragment implements QS {
    private UserGridView mUserGridView;
    private PageIndicator mPageIndicator;
    private AnimatorSet mAnimatorSet;
    private UserSwitchCallback mUserSwitchCallback;

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
@@ -80,7 +81,9 @@ public class CarQSFragment extends Fragment implements QS {
        mPageIndicator = view.findViewById(R.id.user_switcher_page_indicator);
        mPageIndicator.setupWithViewPager(mUserGridView);

        mFooter.setUserSwitchCallback(new UserSwitchCallback());
        mUserSwitchCallback = new UserSwitchCallback();
        mFooter.setUserSwitchCallback(mUserSwitchCallback);
        mUserGridView.setUserSwitchCallback(mUserSwitchCallback);
    }

    @Override
@@ -107,11 +110,13 @@ public class CarQSFragment extends Fragment implements QS {
    @Override
    public void setHeaderListening(boolean listening) {
        mFooter.setListening(listening);
        mUserGridView.setListening(listening);
    }

    @Override
    public void setListening(boolean listening) {
        mFooter.setListening(listening);
        mUserGridView.setListening(listening);
    }

    @Override
@@ -213,6 +218,19 @@ public class CarQSFragment extends Fragment implements QS {
            mShowing = false;
            animateHeightChange(false /* opening */);
        }

        public void resetShowing() {
            if (mShowing) {
                for (int i = 0; i < mUserGridView.getChildCount(); i++) {
                    ViewGroup podContainer = (ViewGroup) mUserGridView.getChildAt(i);
                    // Need to bring the last child to the front to maintain the order in the pod
                    // container. Why? ¯\_(ツ)_/¯
                    if (podContainer.getChildCount() > 0) {
                        podContainer.getChildAt(podContainer.getChildCount() - 1).bringToFront();
                    }
                }
            }
        }
    }

    private void updateUserSwitcherHeight(int height) {
@@ -288,9 +306,6 @@ public class CarQSFragment extends Fragment implements QS {
        // to have all values start at the beginning.
        setupInitialValues(mAnimatorSet);

        // The animation comes from above areas normally occupied by the rest of the QS panel.
        mPanel.setClipChildren(false);

        mAnimatorSet.start();
    }

+77 −24
Original line number Diff line number Diff line
@@ -33,19 +33,31 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.qs.car.CarQSFragment;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserSwitcherController;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

/**
 * Displays a ViewPager with icons for the users in the system to allow switching between users.
 * One of the uses of this is for the lock screen in auto.
 */
public class UserGridView extends ViewPager {
public class UserGridView extends ViewPager implements
        UserInfoController.OnUserInfoChangedListener {
    private StatusBar mStatusBar;
    private UserSwitcherController mUserSwitcherController;
    private Adapter mAdapter;
    private UserSelectionListener mUserSelectionListener;
    private UserInfoController mUserInfoController;
    private Vector mUserContainers;
    private CarQSFragment.UserSwitchCallback mUserSwitchCallback;

    public UserGridView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -54,11 +66,54 @@ public class UserGridView extends ViewPager {
    public void init(StatusBar statusBar, UserSwitcherController userSwitcherController) {
        mStatusBar = statusBar;
        mUserSwitcherController = userSwitcherController;
        mAdapter = new Adapter(mUserSwitcherController);
        mUserInfoController = Dependency.get(UserInfoController.class);
        refreshContainers();
    }

    private void refreshContainers() {
        mUserContainers = new Vector();

        Context context = getContext();
        LayoutInflater inflater = LayoutInflater.from(context);

        for (int i = 0; i < mAdapter.getCount(); i++) {
            ViewGroup pods = (ViewGroup) inflater.inflate(
                    R.layout.car_fullscreen_user_pod_container, null);

            int iconsPerPage = mAdapter.getIconsPerPage();
            int limit = Math.min(mUserSwitcherController.getUsers().size(), (i + 1) * iconsPerPage);
            for (int j = i * iconsPerPage; j < limit; j++) {
                View v = mAdapter.makeUserPod(inflater, context, j, pods);
                pods.addView(v);
                // This is hacky, but the dividers on the pod container LinearLayout don't seem
                // to work for whatever reason.  Instead, set a right margin on the pod if it's not
                // the right-most pod and there is more than one pod in the container.
                if (i < limit - 1 && limit > 1) {
                    ViewGroup.MarginLayoutParams params =
                            (ViewGroup.MarginLayoutParams) v.getLayoutParams();
                    params.setMargins(0, 0, getResources().getDimensionPixelSize(
                            R.dimen.car_fullscreen_user_pod_margin_between), 0);
                    v.setLayoutParams(params);
                }
            }
            mUserContainers.add(pods);
        }

        mAdapter = new Adapter(mUserSwitcherController);
        addOnLayoutChangeListener(mAdapter);
        setAdapter(mAdapter);
    }

    @Override
    public void onUserInfoChanged(String name, Drawable picture, String userAccount) {
        refreshContainers();
    }

    public void setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback) {
        mUserSwitchCallback = callback;
    }

    public void onUserSwitched(int newUserId) {
        // Bring up security view after user switch is completed.
        post(this::showOfflineAuthUi);
@@ -68,6 +123,14 @@ public class UserGridView extends ViewPager {
        mUserSelectionListener = userSelectionListener;
    }

    public void setListening(boolean listening) {
        if (listening) {
            mUserInfoController.addCallback(this);
        } else {
            mUserInfoController.removeCallback(this);
        }
    }

    void showOfflineAuthUi() {
        // TODO: Show keyguard UI in-place.
        mStatusBar.executeRunnableDismissingKeyguard(null, null, true, true, true);
@@ -142,30 +205,20 @@ public class UserGridView extends ViewPager {
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            Context context = getContext();
            LayoutInflater inflater = LayoutInflater.from(context);

            ViewGroup pods = (ViewGroup) inflater.inflate(
                    R.layout.car_fullscreen_user_pod_container, null);

            int iconsPerPage = getIconsPerPage();
            int limit = Math.min(mUserAdapter.getCount(), (position + 1) * iconsPerPage);
            for (int i = position * iconsPerPage; i < limit; i++) {
                View v = makeUserPod(inflater, context, i, pods);
                pods.addView(v);
                // This is hacky, but the dividers on the pod container LinearLayout don't seem
                // to work for whatever reason.  Instead, set a right margin on the pod if it's not
                // the right-most pod and there is more than one pod in the container.
                if (i < limit - 1 && limit > 1) {
                    ViewGroup.MarginLayoutParams params =
                            (ViewGroup.MarginLayoutParams) v.getLayoutParams();
                    params.setMargins(0, 0, mPodMarginBetween, 0);
                    v.setLayoutParams(params);
        public void finishUpdate(ViewGroup container) {
            if (mUserSwitchCallback != null) {
                mUserSwitchCallback.resetShowing();
            }
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            if (position < mUserContainers.size()) {
                container.addView((View) mUserContainers.get(position));
                return mUserContainers.get(position);
            } else {
                return null;
            }
            container.addView(pods);
            return pods;
        }

        /**
@@ -276,7 +329,7 @@ public class UserGridView extends ViewPager {
    }

    private final class WrappedBaseUserAdapter extends UserSwitcherController.BaseUserAdapter {
        private Adapter mContainer;
        private final Adapter mContainer;

        public WrappedBaseUserAdapter(UserSwitcherController controller, Adapter container) {
            super(controller);