Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.car; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 18 | |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 21 | import android.content.Context; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 22 | import android.view.View; |
| 23 | import android.view.ViewStub; |
Rakesh Iyer | 97ff858 | 2017-05-22 17:47:52 -0700 | [diff] [blame] | 24 | import android.widget.ProgressBar; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 25 | |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 26 | import android.support.v7.widget.GridLayoutManager; |
| 27 | import android.support.v7.widget.RecyclerView; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 28 | import com.android.systemui.R; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 29 | import com.android.systemui.statusbar.phone.StatusBar; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Manages the fullscreen user switcher. |
| 33 | */ |
| 34 | public class FullscreenUserSwitcher { |
Rakesh Iyer | 97ff858 | 2017-05-22 17:47:52 -0700 | [diff] [blame] | 35 | private final View mContainer; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 36 | private final View mParent; |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 37 | private final UserGridRecyclerView mUserGridView; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 38 | private final ProgressBar mSwitchingUsers; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 39 | private final int mShortAnimDuration; |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 40 | private final StatusBar mStatusBar; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 41 | |
| 42 | private boolean mShowing; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 43 | |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 44 | public FullscreenUserSwitcher(StatusBar statusBar, ViewStub containerStub, Context context) { |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 45 | mStatusBar = statusBar; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 46 | mParent = containerStub.inflate(); |
| 47 | mContainer = mParent.findViewById(R.id.container); |
Rakesh Iyer | 5b3278f | 2017-04-19 11:28:26 -0700 | [diff] [blame] | 48 | mUserGridView = mContainer.findViewById(R.id.user_grid); |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 49 | GridLayoutManager layoutManager = new GridLayoutManager(context, |
| 50 | context.getResources().getInteger(R.integer.user_fullscreen_switcher_num_col)); |
| 51 | mUserGridView.setLayoutManager(layoutManager); |
| 52 | mUserGridView.buildAdapter(); |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 53 | mUserGridView.setUserSelectionListener(this::onUserSelected); |
Rakesh Iyer | 5b3278f | 2017-04-19 11:28:26 -0700 | [diff] [blame] | 54 | |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 55 | mShortAnimDuration = mContainer.getResources() |
| 56 | .getInteger(android.R.integer.config_shortAnimTime); |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 57 | |
| 58 | mSwitchingUsers = mParent.findViewById(R.id.switching_users); |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 59 | } |
| 60 | |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 61 | public void show() { |
| 62 | if (mShowing) { |
| 63 | return; |
| 64 | } |
| 65 | mShowing = true; |
| 66 | mParent.setVisibility(View.VISIBLE); |
| 67 | } |
| 68 | |
| 69 | public void hide() { |
| 70 | mShowing = false; |
| 71 | toggleSwitchInProgress(false); |
| 72 | mParent.setVisibility(View.GONE); |
| 73 | } |
| 74 | |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 75 | public void onUserSwitched(int newUserId) { |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 76 | mParent.post(this::showOfflineAuthUi); |
| 77 | } |
| 78 | |
| 79 | private void onUserSelected(UserGridRecyclerView.UserRecord record) { |
| 80 | if (record.mIsForeground) { |
| 81 | showOfflineAuthUi(); |
| 82 | return; |
| 83 | } |
| 84 | toggleSwitchInProgress(true); |
| 85 | } |
| 86 | |
| 87 | private void showOfflineAuthUi() { |
| 88 | mStatusBar.executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */, |
| 89 | true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */); |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 92 | private void toggleSwitchInProgress(boolean inProgress) { |
| 93 | if (inProgress) { |
| 94 | crossFade(mSwitchingUsers, mContainer); |
| 95 | } else { |
| 96 | crossFade(mContainer, mSwitchingUsers); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | private void crossFade(View incoming, View outgoing) { |
| 101 | incoming.animate() |
| 102 | .alpha(1.0f) |
| 103 | .setDuration(mShortAnimDuration) |
| 104 | .setListener(new AnimatorListenerAdapter() { |
| 105 | @Override |
| 106 | public void onAnimationStart(Animator animator) { |
| 107 | incoming.setAlpha(0.0f); |
| 108 | incoming.setVisibility(View.VISIBLE); |
| 109 | } |
| 110 | }); |
| 111 | |
| 112 | outgoing.animate() |
| 113 | .alpha(0.0f) |
| 114 | .setDuration(mShortAnimDuration) |
| 115 | .setListener(new AnimatorListenerAdapter() { |
| 116 | @Override |
| 117 | public void onAnimationEnd(Animator animation) { |
| 118 | outgoing.setVisibility(View.GONE); |
| 119 | } |
| 120 | }); |
| 121 | } |
Rakesh Iyer | 97ff858 | 2017-05-22 17:47:52 -0700 | [diff] [blame] | 122 | } |