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

Commit 160502be authored by Alex Chau's avatar Alex Chau Committed by Android (Google) Code Review
Browse files

Merge "Show logout button on keyguard"

parents d8be2394 ff7653d0
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -33,6 +33,23 @@
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/widget_vertical_padding"
        android:orientation="vertical">
        <TextView
            android:id="@+id/logout"
            android:layout_height="@dimen/logout_button_layout_height"
            android:layout_width="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_centerHorizontal="true"
            android:layout_marginBottom="@dimen/logout_button_margin_bottom"
            android:gravity="center"
            android:paddingLeft="@dimen/logout_button_padding_horizontal"
            android:paddingRight="@dimen/logout_button_padding_horizontal"
            android:background="@drawable/logout_button_background"
            android:fontFamily="roboto-medium"
            android:textAllCaps="true"
            android:textColor="?android:attr/textColorPrimary"
            android:textSize="13sp"
            android:text="@*android:string/global_action_logout" />

        <RelativeLayout
            android:id="@+id/keyguard_clock_container"
            android:layout_width="match_parent"
+23 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Copyright (C) 2018 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
  -->

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <solid android:color="@color/logout_button_bg_color"/>
    <corners android:radius="@dimen/logout_button_corner_radius"/>
</shape>
+2 −0
Original line number Diff line number Diff line
@@ -166,4 +166,6 @@
    <color name="fingerprint_dialog_dim_color">#80000000</color> <!-- 50% black -->
    <color name="fingerprint_error_message_color">#ff5722</color>

    <!-- Logout button -->
    <color name="logout_button_bg_color">#ccffffff</color>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -925,4 +925,10 @@
    <integer name="wired_charging_aod_text_animation_duration_up">300</integer>
    <!-- Wired charging on AOD, text animation distance -->
    <integer name="wired_charging_aod_text_animation_distance">-30</integer>

    <!-- Logout button -->
    <dimen name="logout_button_layout_height">32dp</dimen>
    <dimen name="logout_button_padding_horizontal">16dp</dimen>
    <dimen name="logout_button_margin_bottom">12dp</dimen>
    <dimen name="logout_button_corner_radius">2dp</dimen>
</resources>
+49 −2
Original line number Diff line number Diff line
@@ -16,13 +16,16 @@

package com.android.keyguard;

import android.app.ActivityManager;
import android.app.AlarmManager;
import android.app.IActivityManager;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.os.RemoteException;
import android.os.UserHandle;
import android.support.v4.graphics.ColorUtils;
import android.text.TextUtils;
@@ -51,9 +54,11 @@ public class KeyguardStatusView extends GridLayout {

    private final LockPatternUtils mLockPatternUtils;
    private final AlarmManager mAlarmManager;
    private final IActivityManager mIActivityManager;
    private final float mSmallClockScale;
    private final float mWidgetPadding;

    private TextView mLogoutView;
    private TextClock mClockView;
    private View mClockSeparator;
    private TextView mOwnerInfo;
@@ -80,6 +85,7 @@ public class KeyguardStatusView extends GridLayout {
                if (DEBUG) Slog.v(TAG, "refresh statusview showing:" + showing);
                refresh();
                updateOwnerInfo();
                updateLogoutView();
            }
        }

@@ -97,6 +103,12 @@ public class KeyguardStatusView extends GridLayout {
        public void onUserSwitchComplete(int userId) {
            refresh();
            updateOwnerInfo();
            updateLogoutView();
        }

        @Override
        public void onLogoutEnabledChanged() {
            updateLogoutView();
        }
    };

@@ -111,6 +123,7 @@ public class KeyguardStatusView extends GridLayout {
    public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        mIActivityManager = ActivityManager.getService();
        mLockPatternUtils = new LockPatternUtils(getContext());
        mHandler = new Handler(Looper.myLooper());
        mSmallClockScale = getResources().getDimension(R.dimen.widget_small_font_size)
@@ -145,6 +158,9 @@ public class KeyguardStatusView extends GridLayout {
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mLogoutView = findViewById(R.id.logout);
        mLogoutView.setOnClickListener(this::onLogoutClicked);

        mClockContainer = findViewById(R.id.keyguard_clock_container);
        mClockView = findViewById(R.id.clock_view);
        mClockView.setShowCurrentUserTime(true);
@@ -164,6 +180,7 @@ public class KeyguardStatusView extends GridLayout {
        setEnableMarquee(shouldMarquee);
        refresh();
        updateOwnerInfo();
        updateLogoutView();

        // Disable elegant text height because our fancy colon makes the ymin value huge for no
        // reason.
@@ -213,14 +230,28 @@ public class KeyguardStatusView extends GridLayout {
    }

    public int getClockBottom() {
        return mKeyguardSlice.getVisibility() == VISIBLE ? mKeyguardSlice.getBottom()
                : mClockView.getBottom();
        if (mOwnerInfo != null && mOwnerInfo.getVisibility() == VISIBLE) {
            return mOwnerInfo.getBottom();
        } else {
            return mClockContainer.getBottom();
        }
    }

    public int getLogoutButtonHeight() {
        return mLogoutView.getVisibility() == VISIBLE ? mLogoutView.getHeight() : 0;
    }

    public float getClockTextSize() {
        return mClockView.getTextSize();
    }

    private void updateLogoutView() {
        mLogoutView.setVisibility(shouldShowLogout() ? VISIBLE : GONE);
        // Logout button will stay in language of user 0 if we don't set that manually.
        mLogoutView.setText(mContext.getResources().getString(
                com.android.internal.R.string.global_action_logout));
    }

    private void updateOwnerInfo() {
        if (mOwnerInfo == null) return;
        String ownerInfo = getOwnerInfo();
@@ -309,6 +340,7 @@ public class KeyguardStatusView extends GridLayout {
        mDarkAmount = darkAmount;

        boolean dark = darkAmount == 1;
        mLogoutView.setAlpha(dark ? 0 : 1);
        final int N = mClockContainer.getChildCount();
        for (int i = 0; i < N; i++) {
            View child = mClockContainer.getChildAt(i);
@@ -340,4 +372,19 @@ public class KeyguardStatusView extends GridLayout {
            child.setAlpha(mDarkAmount == 1 && mPulsing ? 0.8f : 1);
        }
    }

    private boolean shouldShowLogout() {
        return KeyguardUpdateMonitor.getInstance(mContext).isLogoutEnabled()
                && KeyguardUpdateMonitor.getCurrentUser() != UserHandle.USER_SYSTEM;
    }

    private void onLogoutClicked(View view) {
        int currentUserId = KeyguardUpdateMonitor.getCurrentUser();
        try {
            mIActivityManager.switchUser(UserHandle.USER_SYSTEM);
            mIActivityManager.stopUser(currentUserId, true /*force*/, null);
        } catch (RemoteException re) {
            Log.e(TAG, "Failed to logout user", re);
        }
    }
}
Loading