Merge "DO NOT MERGE Intercept back button on user switcher screen" into rvc-qpr-dev
This commit is contained in:
@@ -14,36 +14,29 @@
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
-->
|
-->
|
||||||
<FrameLayout
|
<com.android.systemui.car.userswitcher.UserSwitcherContainer
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
android:layout_height="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
|
<include
|
||||||
android:id="@+id/container"
|
layout="@layout/car_status_bar_header"
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:orientation="vertical">
|
android:theme="@android:style/Theme"/>
|
||||||
|
|
||||||
<include
|
|
||||||
layout="@layout/car_status_bar_header"
|
|
||||||
android:layout_alignParentTop="true"
|
|
||||||
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_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="wrap_content"
|
||||||
<com.android.systemui.car.userswitcher.UserGridRecyclerView
|
android:layout_gravity="center_vertical"
|
||||||
android:id="@+id/user_grid"
|
android:layout_marginTop="@dimen/car_user_switcher_margin_top"/>
|
||||||
android:layout_width="match_parent"
|
</FrameLayout>
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginTop="@dimen/car_user_switcher_margin_top"/>
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</com.android.systemui.car.userswitcher.UserSwitcherContainer>
|
||||||
</FrameLayout>
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import android.car.Car;
|
|||||||
import android.car.user.CarUserManager;
|
import android.car.user.CarUserManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
@@ -67,6 +68,19 @@ public class FullScreenUserSwitcherViewController extends OverlayViewController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onFinishInflate() {
|
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.
|
// Initialize user grid.
|
||||||
mUserGridView = getLayout().findViewById(R.id.user_grid);
|
mUserGridView = getLayout().findViewById(R.id.user_grid);
|
||||||
GridLayoutManager layoutManager = new GridLayoutManager(mContext,
|
GridLayoutManager layoutManager = new GridLayoutManager(mContext,
|
||||||
@@ -79,7 +93,7 @@ public class FullScreenUserSwitcherViewController extends OverlayViewController
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean shouldFocusWindow() {
|
protected boolean shouldFocusWindow() {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user