Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit de086933 authored by Heemin Seog's avatar Heemin Seog Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Intercept back button on user switcher screen" into rvc-qpr-dev

parents 1e3abbf0 a287650f
Loading
Loading
Loading
Loading
+17 −24
Original line number Diff line number Diff line
@@ -14,18 +14,12 @@
     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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/car_user_switcher_background_color">

    <LinearLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        android:layout_alignParentTop="true"
    android:background="@color/car_user_switcher_background_color"
    android:orientation="vertical">

    <include
@@ -45,5 +39,4 @@
            android:layout_marginTop="@dimen/car_user_switcher_margin_top"/>
    </FrameLayout>

    </LinearLayout>
</FrameLayout>
</com.android.systemui.car.userswitcher.UserSwitcherContainer>
+15 −1
Original line number Diff line number Diff line
@@ -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
+73 −0
Original line number Diff line number Diff line
/*
 * 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);
    }
}