Merge "Tweak FingerprintDialog layout"

This commit is contained in:
TreeHugger Robot
2018-02-21 03:34:20 +00:00
committed by Android (Google) Code Review
7 changed files with 153 additions and 154 deletions

View File

@@ -1,25 +0,0 @@
<?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">
<solid android:color="@color/fingerprint_dialog_bg_color" />
<corners android:radius="1dp"
android:topLeftRadius="16dp"
android:topRightRadius="16dp"
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"/>
</shape>

View File

@@ -35,131 +35,105 @@
android:layout_height="wrap_content"
android:orientation="vertical"
android:elevation="2dp"
android:background="@drawable/fingerprint_dialog_bg">
android:background="@color/fingerprint_dialog_bg_color">
<RelativeLayout
<TextView
android:id="@+id/title"
android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:elevation="2dp">
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="24dp"
android:gravity="center"
android:textSize="20sp"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:textColor="@color/fingerprint_dialog_text_dark_color"/>
<ImageView
android:id="@+id/icon"
android:layout_width="@dimen/fingerprint_dialog_icon_size"
android:layout_height="@dimen/fingerprint_dialog_icon_size"
android:layout_marginTop="16dp"
android:layout_marginStart="16dp"
android:scaleType="centerInside" />
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:textSize="20sp"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:textColor="@color/fingerprint_dialog_text_color"/>
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon"
android:layout_below="@+id/title"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="4dp"
android:textSize="12sp"
android:maxLines="2"
android:textColor="@color/fingerprint_dialog_text_color"/>
</RelativeLayout>
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:gravity="center_horizontal"
android:textSize="14sp"
android:maxLines="1"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:textColor="@color/fingerprint_dialog_text_light_color"/>
<TextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:paddingTop="16dp"
android:paddingBottom="20dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:paddingTop="24dp"
android:textSize="16sp"
android:maxLines="4"
android:textColor="@color/fingerprint_dialog_text_color"/>
android:textColor="@color/fingerprint_dialog_text_dark_color"/>
<ImageView
android:id="@+id/fingerprint_icon"
android:layout_width="@dimen/fingerprint_dialog_fp_icon_size"
android:layout_height="@dimen/fingerprint_dialog_fp_icon_size"
android:layout_gravity="center_horizontal"
android:scaleType="centerInside"
android:contentDescription="@string/accessibility_fingerprint_dialog_fingerprint_icon"
android:src="@drawable/fingerprint_icon"/>
android:layout_marginTop="32dp"
android:scaleType="fitXY"
android:contentDescription="@string/accessibility_fingerprint_dialog_fingerprint_icon" />
<TextView
android:id="@+id/error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd = "16dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:paddingTop="16dp"
android:paddingBottom="60dp"
android:paddingBottom="24dp"
android:textSize="12sp"
android:visibility="invisible"
android:gravity="center_horizontal"
android:accessibilityLiveRegion="polite"
android:text="@string/fingerprint_dialog_touch_sensor"
android:contentDescription="@string/accessibility_fingerprint_dialog_help_area"
android:textColor="@color/fingerprint_error_message_color"/>
android:textColor="@color/fingerprint_dialog_text_light_color"/>
<LinearLayout android:id="@+id/buttonPanel"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="54dip"
android:orientation="vertical" >
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="4dip"
android:paddingStart="2dip"
android:paddingEnd="2dip"
android:measureWithLargestChild="true">
<LinearLayout android:id="@+id/leftSpacer"
android:layout_weight="0.25"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
<!-- Positive Button -->
<Button android:id="@+id/button1"
android:layout_width="0dip"
android:layout_gravity="start"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content"/>
<!-- Negative Button -->
<Button android:id="@+id/button2"
android:layout_width="0dip"
android:layout_gravity="end"
android:layout_weight="1"
style="?android:attr/buttonBarButtonStyle"
android:maxLines="2"
android:layout_height="wrap_content" />
<LinearLayout android:id="@+id/rightSpacer"
android:layout_width="0dip"
android:layout_weight="0.25"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone" />
</LinearLayout>
android:layout_height="72dip"
android:paddingTop="16dp"
android:layout_gravity="center_vertical"
style="?android:attr/buttonBarStyle"
android:orientation="horizontal"
android:measureWithLargestChild="true">
<Space android:id="@+id/leftSpacer"
android:layout_width="24dp"
android:layout_height="match_parent"
android:visibility="visible" />
<!-- Negative Button -->
<Button android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored"
android:layout_marginStart="-12dp"
android:gravity="start|center_vertical"
android:maxLines="2" />
<!-- Positive Button -->
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="@*android:style/Widget.DeviceDefault.Button.Borderless.Colored"
android:layout_marginEnd="12dp"
android:maxLines="2" />
<Space android:id="@+id/rightSpacer"
android:layout_width="24dip"
android:layout_height="match_parent"
android:visibility="gone" />
</LinearLayout>
</LinearLayout>

View File

@@ -161,9 +161,11 @@
<!-- Fingerprint dialog colors -->
<color name="fingerprint_dialog_bg_color">#f4ffffff</color> <!-- 96% white -->
<color name="fingerprint_dialog_text_color">#ff424242</color> <!-- gray 800-->
<color name="fingerprint_dialog_text_dark_color">#ff212121</color>
<color name="fingerprint_dialog_text_light_color">#ff757575</color>
<color name="fingerprint_dialog_dim_color">#80000000</color> <!-- 50% black -->
<color name="fingerprint_error_message_color">#ff5722</color>
<color name="fingerprint_dialog_error_message_color">#ffff5722</color>
<color name="fingerprint_dialog_fingerprint_color">#ff009688</color>
<!-- Logout button -->
<color name="logout_button_bg_color">#ccffffff</color>

View File

@@ -895,7 +895,7 @@
<dimen name="smart_reply_button_font_size">14sp</dimen>
<dimen name="smart_reply_button_line_spacing_extra">6sp</dimen> <!-- Total line height 20sp. -->
<dimen name="fingerprint_dialog_icon_size">44dp</dimen>
<!-- Fingerprint Dialog values -->
<dimen name="fingerprint_dialog_fp_icon_size">60dp</dimen>
<dimen name="fingerprint_dialog_animation_translation_offset">350dp</dimen>

View File

@@ -259,6 +259,8 @@
<!-- Button name for "Cancel". [CHAR LIMIT=NONE] -->
<string name="cancel">Cancel</string>
<!-- Message shown when the system-provided fingerprint dialog is shown, asking for authentication -->
<string name="fingerprint_dialog_touch_sensor">Touch the fingerprint sensor</string>
<!-- Content description of the fingerprint icon when the system-provided fingerprint dialog is showing, for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
<string name="accessibility_fingerprint_dialog_fingerprint_icon">Fingerprint icon</string>
<!-- Content description of the application icon when the system-provided fingerprint dialog is showing, for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->

View File

@@ -211,7 +211,7 @@ public class FingerprintDialogImpl extends SystemUI implements CommandQueue.Call
}
private void handleClearMessage() {
mDialogView.clearMessage();
mDialogView.resetMessage();
}
private void handleUserCanceled() {

View File

@@ -16,17 +16,18 @@
package com.android.systemui.fingerprint;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.drawable.AnimatedVectorDrawable;
import android.graphics.drawable.Drawable;
import android.hardware.fingerprint.FingerprintDialog;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
@@ -41,8 +42,6 @@ import android.widget.TextView;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.PackageManagerWrapper;
/**
* This class loads the view for the system-provided dialog. The view consists of:
@@ -55,28 +54,39 @@ public class FingerprintDialogView extends LinearLayout {
private static final int ANIMATION_DURATION = 250; // ms
private static final int STATE_NONE = 0;
private static final int STATE_FINGERPRINT = 1;
private static final int STATE_FINGERPRINT_ERROR = 2;
private static final int STATE_FINGERPRINT_AUTHENTICATED = 3;
private final IBinder mWindowToken = new Binder();
private final ActivityManagerWrapper mActivityManagerWrapper;
private final PackageManagerWrapper mPackageManageWrapper;
private final Interpolator mLinearOutSlowIn;
private final Interpolator mFastOutLinearIn;
private final float mAnimationTranslationOffset;
private final int mErrorTextColor;
private final int mTextColor;
private final int mFingerprintColor;
private ViewGroup mLayout;
private final TextView mErrorText;
private Handler mHandler;
private Bundle mBundle;
private final LinearLayout mDialog;
private int mLastState;
public FingerprintDialogView(Context context, Handler handler) {
super(context);
mHandler = handler;
mActivityManagerWrapper = ActivityManagerWrapper.getInstance();
mPackageManageWrapper = PackageManagerWrapper.getInstance();
mLinearOutSlowIn = Interpolators.LINEAR_OUT_SLOW_IN;
mFastOutLinearIn = Interpolators.FAST_OUT_LINEAR_IN;
mAnimationTranslationOffset = getResources()
.getDimension(R.dimen.fingerprint_dialog_animation_translation_offset);
mErrorTextColor = Color.parseColor(
getResources().getString(R.color.fingerprint_dialog_error_message_color));
mTextColor = Color.parseColor(
getResources().getString(R.color.fingerprint_dialog_text_light_color));
mFingerprintColor = Color.parseColor(
getResources().getString(R.color.fingerprint_dialog_fingerprint_color));
// Create the dialog
LayoutInflater factory = LayoutInflater.from(getContext());
@@ -112,7 +122,7 @@ public class FingerprintDialogView extends LinearLayout {
space.setClickable(true);
space.setOnTouchListener((View view, MotionEvent event) -> {
mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG, true /* userCanceled*/)
mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG, true /* userCanceled */)
.sendToTarget();
return true;
});
@@ -137,16 +147,16 @@ public class FingerprintDialogView extends LinearLayout {
final TextView subtitle = mLayout.findViewById(R.id.subtitle);
final TextView description = mLayout.findViewById(R.id.description);
final Button negative = mLayout.findViewById(R.id.button2);
final ImageView image = mLayout.findViewById(R.id.icon);
final Button positive = mLayout.findViewById(R.id.button1);
final ImageView fingerprint_icon = mLayout.findViewById(R.id.fingerprint_icon);
mLastState = STATE_NONE;
updateFingerprintIcon(STATE_FINGERPRINT);
title.setText(mBundle.getCharSequence(FingerprintDialog.KEY_TITLE));
title.setSelected(true);
subtitle.setText(mBundle.getCharSequence(FingerprintDialog.KEY_SUBTITLE));
description.setText(mBundle.getCharSequence(FingerprintDialog.KEY_DESCRIPTION));
negative.setText(mBundle.getCharSequence(FingerprintDialog.KEY_NEGATIVE_TEXT));
setAppIcon(image);
final CharSequence positiveText =
mBundle.getCharSequence(FingerprintDialog.KEY_POSITIVE_TEXT);
@@ -183,39 +193,75 @@ public class FingerprintDialogView extends LinearLayout {
mBundle = bundle;
}
protected void clearMessage() {
mErrorText.setVisibility(View.INVISIBLE);
// Clears the temporary message and shows the help message.
protected void resetMessage() {
updateFingerprintIcon(STATE_FINGERPRINT);
mErrorText.setText(R.string.fingerprint_dialog_touch_sensor);
mErrorText.setTextColor(mTextColor);
}
private void showMessage(String message) {
// Shows an error/help message
private void showTemporaryMessage(String message) {
mHandler.removeMessages(FingerprintDialogImpl.MSG_CLEAR_MESSAGE);
updateFingerprintIcon(STATE_FINGERPRINT_ERROR);
mErrorText.setText(message);
mErrorText.setTextColor(mErrorTextColor);
mErrorText.setContentDescription(message);
mErrorText.setVisibility(View.VISIBLE);
mHandler.sendMessageDelayed(mHandler.obtainMessage(FingerprintDialogImpl.MSG_CLEAR_MESSAGE),
FingerprintDialog.HIDE_DIALOG_DELAY);
}
public void showHelpMessage(String message) {
showMessage(message);
showTemporaryMessage(message);
}
public void showErrorMessage(String error) {
showMessage(error);
showTemporaryMessage(error);
mHandler.sendMessageDelayed(mHandler.obtainMessage(FingerprintDialogImpl.MSG_HIDE_DIALOG,
false /* userCanceled */), FingerprintDialog.HIDE_DIALOG_DELAY);
}
private void setAppIcon(ImageView image) {
final ActivityManager.RunningTaskInfo taskInfo = mActivityManagerWrapper.getRunningTask();
final ComponentName cn = taskInfo.topActivity;
final int userId = mActivityManagerWrapper.getCurrentUserId();
final ActivityInfo activityInfo = mPackageManageWrapper.getActivityInfo(cn, userId);
image.setImageDrawable(mActivityManagerWrapper.getBadgedActivityIcon(activityInfo, userId));
image.setContentDescription(
getResources().getString(R.string.accessibility_fingerprint_dialog_app_icon)
+ " "
+ mActivityManagerWrapper.getBadgedActivityLabel(activityInfo, userId));
private void updateFingerprintIcon(int newState) {
Drawable icon = getAnimationResForTransition(mLastState, newState);
if (icon == null) {
Log.e(TAG, "Animation not found");
return;
}
if (newState == STATE_FINGERPRINT) {
icon.setColorFilter(mFingerprintColor, PorterDuff.Mode.SRC_IN);
}
final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable
? (AnimatedVectorDrawable) icon
: null;
final ImageView fingerprint_icon = mLayout.findViewById(R.id.fingerprint_icon);
fingerprint_icon.setImageDrawable(icon);
if (animation != null) {
animation.forceAnimationOnUI();
animation.start();
}
mLastState = newState;
}
private Drawable getAnimationResForTransition(int oldState, int newState) {
int iconRes;
if (oldState == STATE_NONE && newState == STATE_FINGERPRINT) {
iconRes = R.drawable.lockscreen_fingerprint_draw_on_animation;
} else if (oldState == STATE_FINGERPRINT && newState == STATE_FINGERPRINT_ERROR) {
iconRes = R.drawable.lockscreen_fingerprint_fp_to_error_state_animation;
} else if (oldState == STATE_FINGERPRINT_ERROR && newState == STATE_FINGERPRINT) {
iconRes = R.drawable.lockscreen_fingerprint_error_state_to_fp_animation;
} else if (oldState == STATE_FINGERPRINT && newState == STATE_FINGERPRINT_AUTHENTICATED) {
iconRes = R.drawable.lockscreen_fingerprint_draw_off_animation;
} else {
return null;
}
return mContext.getDrawable(iconRes);
}
public WindowManager.LayoutParams getLayoutParams() {