Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 1 | /* |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 2 | * Copyright (C) 2018 The Android Open Source Project |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 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 |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 14 | * limitations under the License. |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 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; |
| 24 | |
Aurimas Liutikas | fd52c14 | 2018-04-17 09:50:46 -0700 | [diff] [blame] | 25 | import androidx.recyclerview.widget.GridLayoutManager; |
jovanak | b803051 | 2018-04-11 15:20:16 -0700 | [diff] [blame] | 26 | |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 27 | import com.android.systemui.R; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Manages the fullscreen user switcher. |
| 31 | */ |
| 32 | public class FullscreenUserSwitcher { |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 33 | private final UserGridRecyclerView mUserGridView; |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 34 | private final View mParent; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 35 | private final int mShortAnimDuration; |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 36 | private final CarStatusBar mStatusBar; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 37 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 38 | public FullscreenUserSwitcher(CarStatusBar statusBar, ViewStub containerStub, Context context) { |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 39 | mStatusBar = statusBar; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 40 | mParent = containerStub.inflate(); |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 41 | // Hide the user grid by default. It will only be made visible by clicking on a cancel |
| 42 | // button in a bouncer. |
| 43 | hide(); |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 44 | View container = mParent.findViewById(R.id.container); |
| 45 | |
| 46 | // Initialize user grid. |
| 47 | mUserGridView = container.findViewById(R.id.user_grid); |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 48 | GridLayoutManager layoutManager = new GridLayoutManager(context, |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 49 | context.getResources().getInteger(R.integer.user_fullscreen_switcher_num_col)); |
Heemin Seog | 0d5e018 | 2019-03-13 13:49:24 -0700 | [diff] [blame] | 50 | mUserGridView.setLayoutManager(layoutManager); |
Aarthi Balachander | d8bf249 | 2018-03-30 11:15:59 -0700 | [diff] [blame] | 51 | mUserGridView.buildAdapter(); |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 52 | mUserGridView.setUserSelectionListener(this::onUserSelected); |
Rakesh Iyer | 5b3278f | 2017-04-19 11:28:26 -0700 | [diff] [blame] | 53 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 54 | mShortAnimDuration = container.getResources() |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 55 | .getInteger(android.R.integer.config_shortAnimTime); |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 56 | } |
| 57 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 58 | /** |
| 59 | * Makes user grid visible. |
| 60 | */ |
jovanak | 0535abc | 2018-04-10 15:14:50 -0700 | [diff] [blame] | 61 | public void show() { |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 62 | mParent.setVisibility(View.VISIBLE); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 65 | /** |
| 66 | * Hides the user grid. |
| 67 | */ |
| 68 | public void hide() { |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 69 | mParent.setVisibility(View.INVISIBLE); |
Aarthi Balachander | 0a427ef | 2018-07-13 15:00:58 -0700 | [diff] [blame] | 70 | } |
| 71 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 72 | /** |
| 73 | * @return {@code true} if user grid is visible, {@code false} otherwise. |
| 74 | */ |
| 75 | public boolean isVisible() { |
Brad Stenning | 3b0d764 | 2019-03-28 11:04:30 -0700 | [diff] [blame] | 76 | return mParent.getVisibility() == View.VISIBLE; |
Xiyuan Xia | cc3a74f6 | 2015-07-22 14:16:34 -0700 | [diff] [blame] | 77 | } |
| 78 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 79 | /** |
| 80 | * Every time user clicks on an item in the switcher, we hide the switcher, either |
| 81 | * gradually or immediately. |
| 82 | * |
| 83 | * We dismiss the entire keyguard if user clicked on the foreground user (user we're already |
| 84 | * logged in as). |
| 85 | */ |
| 86 | private void onUserSelected(UserGridRecyclerView.UserRecord record) { |
| 87 | if (record.mIsForeground) { |
| 88 | hide(); |
| 89 | mStatusBar.dismissKeyguard(); |
| 90 | return; |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 91 | } |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 92 | // Switching is about to happen, since it takes time, fade out the switcher gradually. |
| 93 | fadeOut(); |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 94 | } |
| 95 | |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 96 | private void fadeOut() { |
| 97 | mUserGridView.animate() |
jovanak | 9c17720 | 2018-04-20 12:35:09 -0700 | [diff] [blame] | 98 | .alpha(0.0f) |
| 99 | .setDuration(mShortAnimDuration) |
| 100 | .setListener(new AnimatorListenerAdapter() { |
| 101 | @Override |
| 102 | public void onAnimationEnd(Animator animation) { |
jovanak | 604ad51 | 2018-08-14 18:41:27 -0700 | [diff] [blame] | 103 | hide(); |
| 104 | mUserGridView.setAlpha(1.0f); |
jovanak | 9c17720 | 2018-04-20 12:35:09 -0700 | [diff] [blame] | 105 | } |
| 106 | }); |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 107 | |
Rakesh Iyer | 33d6ce4 | 2017-05-30 11:02:18 -0700 | [diff] [blame] | 108 | } |
Brad Stenning | 8d1a51c | 2018-11-20 17:34:16 -0800 | [diff] [blame] | 109 | } |