FileDocCategorySizeDatePackage
KeyguardUserSwitcher.javaAPI DocAndroid 5.1 API11511Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.policy

KeyguardUserSwitcher

public class KeyguardUserSwitcher extends Object
Manages the user switcher on the Keyguard.

Fields Summary
private static final String
TAG
private static final boolean
ALWAYS_ON
private final Container
mUserSwitcherContainer
private final android.view.ViewGroup
mUserSwitcher
private final com.android.systemui.statusbar.phone.KeyguardStatusBarView
mStatusBarView
private final Adapter
mAdapter
private final com.android.keyguard.AppearAnimationUtils
mAppearAnimationUtils
private final KeyguardUserSwitcherScrim
mBackground
private android.animation.ObjectAnimator
mBgAnimator
private UserSwitcherController
mUserSwitcherController
private boolean
mAnimating
public final android.database.DataSetObserver
mDataSetObserver
Constructors Summary
public KeyguardUserSwitcher(android.content.Context context, android.view.ViewStub userSwitcher, com.android.systemui.statusbar.phone.KeyguardStatusBarView statusBarView, com.android.systemui.statusbar.phone.NotificationPanelView panelView, UserSwitcherController userSwitcherController)


        
               
              
        boolean keyguardUserSwitcherEnabled =
                context.getResources().getBoolean(R.bool.config_keyguardUserSwitcher) || ALWAYS_ON;
        if (userSwitcherController != null && keyguardUserSwitcherEnabled) {
            mUserSwitcherContainer = (Container) userSwitcher.inflate();
            mUserSwitcher = (ViewGroup)
                    mUserSwitcherContainer.findViewById(R.id.keyguard_user_switcher_inner);
            mBackground = new KeyguardUserSwitcherScrim(mUserSwitcher);
            mUserSwitcher.setBackground(mBackground);
            mStatusBarView = statusBarView;
            mStatusBarView.setKeyguardUserSwitcher(this);
            panelView.setKeyguardUserSwitcher(this);
            mAdapter = new Adapter(context, userSwitcherController, this);
            mAdapter.registerDataSetObserver(mDataSetObserver);
            mUserSwitcherController = userSwitcherController;
            mAppearAnimationUtils = new AppearAnimationUtils(context, 400, -0.5f, 0.5f,
                    AnimationUtils.loadInterpolator(
                            context, android.R.interpolator.fast_out_slow_in));
            mUserSwitcherContainer.setKeyguardUserSwitcher(this);
        } else {
            mUserSwitcherContainer = null;
            mUserSwitcher = null;
            mStatusBarView = null;
            mAdapter = null;
            mAppearAnimationUtils = null;
            mBackground = null;
        }
    
Methods Summary
private voidcancelAnimations()

        int count = mUserSwitcher.getChildCount();
        for (int i = 0; i < count; i++) {
            mUserSwitcher.getChildAt(i).animate().cancel();
        }
        if (mBgAnimator != null) {
            mBgAnimator.cancel();
        }
        mUserSwitcher.animate().cancel();
        mAnimating = false;
    
private voidhide(boolean animate)

        if (mUserSwitcher != null && mUserSwitcherContainer.getVisibility() == View.VISIBLE) {
            cancelAnimations();
            if (animate) {
                startDisappearAnimation();
            } else {
                mUserSwitcherContainer.setVisibility(View.GONE);
            }
            mStatusBarView.setKeyguardUserSwitcherShowing(false, animate);
        }
    
public voidhideIfNotSimple(boolean animate)

        if (mUserSwitcherContainer != null && !mUserSwitcherController.isSimpleUserSwitcher()) {
            hide(animate);
        }
    
booleanisAnimating()

        return mAnimating;
    
private voidrefresh()

        final int childCount = mUserSwitcher.getChildCount();
        final int adapterCount = mAdapter.getCount();
        final int N = Math.max(childCount, adapterCount);
        for (int i = 0; i < N; i++) {
            if (i < adapterCount) {
                View oldView = null;
                if (i < childCount) {
                    oldView = mUserSwitcher.getChildAt(i);
                }
                View newView = mAdapter.getView(i, oldView, mUserSwitcher);
                if (oldView == null) {
                    // We ran out of existing views. Add it at the end.
                    mUserSwitcher.addView(newView);
                } else if (oldView != newView) {
                    // We couldn't rebind the view. Replace it.
                    mUserSwitcher.removeViewAt(i);
                    mUserSwitcher.addView(newView, i);
                }
            } else {
                int lastIndex = mUserSwitcher.getChildCount() - 1;
                mUserSwitcher.removeViewAt(lastIndex);
            }
        }
    
public voidsetKeyguard(boolean keyguard, boolean animate)

        if (mUserSwitcher != null) {
            if (keyguard && shouldExpandByDefault()) {
                show(animate);
            } else {
                hide(animate);
            }
        }
    
private booleanshouldExpandByDefault()

return
true if the user switcher should be expanded by default on the lock screen.
see
android.os.UserManager#isUserSwitcherEnabled()

        return (mUserSwitcherController != null) && mUserSwitcherController.isSimpleUserSwitcher();
    
public voidshow(boolean animate)

        if (mUserSwitcher != null && mUserSwitcherContainer.getVisibility() != View.VISIBLE) {
            cancelAnimations();
            mAdapter.refresh();
            mUserSwitcherContainer.setVisibility(View.VISIBLE);
            mStatusBarView.setKeyguardUserSwitcherShowing(true, animate);
            if (animate) {
                startAppearAnimation();
            }
        }
    
private voidstartAppearAnimation()

        int count = mUserSwitcher.getChildCount();
        View[] objects = new View[count];
        for (int i = 0; i < count; i++) {
            objects[i] = mUserSwitcher.getChildAt(i);
        }
        mUserSwitcher.setClipChildren(false);
        mUserSwitcher.setClipToPadding(false);
        mAppearAnimationUtils.startAnimation(objects, new Runnable() {
            @Override
            public void run() {
                mUserSwitcher.setClipChildren(true);
                mUserSwitcher.setClipToPadding(true);
            }
        });
        mAnimating = true;
        mBgAnimator = ObjectAnimator.ofInt(mBackground, "alpha", 0, 255);
        mBgAnimator.setDuration(400);
        mBgAnimator.setInterpolator(PhoneStatusBar.ALPHA_IN);
        mBgAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mBgAnimator = null;
                mAnimating = false;
            }
        });
        mBgAnimator.start();
    
private voidstartDisappearAnimation()

        mAnimating = true;
        mUserSwitcher.animate()
                .alpha(0f)
                .setDuration(300)
                .setInterpolator(PhoneStatusBar.ALPHA_OUT)
                .withEndAction(new Runnable() {
                    @Override
                    public void run() {
                        mUserSwitcherContainer.setVisibility(View.GONE);
                        mUserSwitcher.setAlpha(1f);
                        mAnimating = false;
                    }
                });