DO NOT MERGE Intercept back button on user switcher screen

The back button on the user switcher screen should go back to the
lockscreen of the current user.

Bug: 178505273
Test: manual (press back button from user switcher screen while it has
rotary focus)

Change-Id: I30b8619a26e8b0c1ca9632b3bb656d187dad91b9
This commit is contained in:
Heemin Seog
2021-02-24 10:30:16 -08:00
parent 6628f4e7b8
commit a287650f94
3 changed files with 105 additions and 25 deletions

View File

@@ -14,36 +14,29 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<FrameLayout
<com.android.systemui.car.userswitcher.UserSwitcherContainer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fullscreen_user_switcher"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/car_user_switcher_background_color">
android:background="@color/car_user_switcher_background_color"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
<include
layout="@layout/car_status_bar_header"
android:layout_alignParentTop="true"
android:orientation="vertical">
<include
layout="@layout/car_status_bar_header"
android:layout_alignParentTop="true"
android:theme="@android:style/Theme"/>
android:theme="@android:style/Theme"/>
<FrameLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.android.systemui.car.userswitcher.UserGridRecyclerView
android:id="@+id/user_grid"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.android.systemui.car.userswitcher.UserGridRecyclerView
android:id="@+id/user_grid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="@dimen/car_user_switcher_margin_top"/>
</FrameLayout>
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="@dimen/car_user_switcher_margin_top"/>
</FrameLayout>
</LinearLayout>
</FrameLayout>
</com.android.systemui.car.userswitcher.UserSwitcherContainer>

View File

@@ -22,6 +22,7 @@ import android.car.Car;
import android.car.user.CarUserManager;
import android.content.Context;
import android.content.res.Resources;
import android.view.KeyEvent;
import android.view.View;
import androidx.recyclerview.widget.GridLayoutManager;
@@ -67,6 +68,19 @@ public class FullScreenUserSwitcherViewController extends OverlayViewController
@Override
protected void onFinishInflate() {
// Intercept back button.
UserSwitcherContainer container = getLayout().findViewById(R.id.container);
container.setKeyEventHandler(event -> {
if (event.getKeyCode() != KeyEvent.KEYCODE_BACK) {
return false;
}
if (event.getAction() == KeyEvent.ACTION_UP && getLayout().isVisibleToUser()) {
getLayout().setVisibility(View.GONE);
}
return true;
});
// Initialize user grid.
mUserGridView = getLayout().findViewById(R.id.user_grid);
GridLayoutManager layoutManager = new GridLayoutManager(mContext,
@@ -79,7 +93,7 @@ public class FullScreenUserSwitcherViewController extends OverlayViewController
@Override
protected boolean shouldFocusWindow() {
return false;
return true;
}
@Override

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.systemui.car.userswitcher;
import android.content.Context;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/** Container for the user switcher which intercepts the key events. */
public class UserSwitcherContainer extends LinearLayout {
private KeyEventHandler mKeyEventHandler;
public UserSwitcherContainer(@NonNull Context context) {
super(context);
}
public UserSwitcherContainer(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public UserSwitcherContainer(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public UserSwitcherContainer(@NonNull Context context, @Nullable AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if (super.dispatchKeyEvent(event)) {
return true;
}
if (mKeyEventHandler != null) {
return mKeyEventHandler.dispatchKeyEvent(event);
}
return false;
}
/** Sets a {@link KeyEventHandler} to help interact with the notification panel. */
public void setKeyEventHandler(KeyEventHandler keyEventHandler) {
mKeyEventHandler = keyEventHandler;
}
/** An interface to help interact with the notification panel. */
public interface KeyEventHandler {
/** Allows handling of a {@link KeyEvent} if it wasn't already handled by the superclass. */
boolean dispatchKeyEvent(KeyEvent event);
}
}