Merge "Request focus when pin is visible" into pi-dev

This commit is contained in:
android-build-team Robot
2018-05-02 07:28:33 +00:00
committed by Android (Google) Code Review
4 changed files with 86 additions and 23 deletions

View File

@@ -140,12 +140,6 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView
mImm.hideSoftInputFromWindow(getWindowToken(), 0); mImm.hideSoftInputFromWindow(getWindowToken(), 0);
} }
@Override
public void reset() {
super.reset();
mPasswordEntry.requestFocus();
}
private void updateSwitchImeButton() { private void updateSwitchImeButton() {
// If there's more than one IME, enable the IME switcher button // If there's more than one IME, enable the IME switcher button
final boolean wasVisible = mSwitchImeButton.getVisibility() == View.VISIBLE; final boolean wasVisible = mSwitchImeButton.getVisibility() == View.VISIBLE;
@@ -193,8 +187,6 @@ public class KeyguardPasswordView extends KeyguardAbsKeyInputView
// Set selected property on so the view can send accessibility events. // Set selected property on so the view can send accessibility events.
mPasswordEntry.setSelected(true); mPasswordEntry.setSelected(true);
mPasswordEntry.requestFocus();
mSwitchImeButton = findViewById(R.id.switch_ime_button); mSwitchImeButton = findViewById(R.id.switch_ime_button);
mSwitchImeButton.setOnClickListener(new OnClickListener() { mSwitchImeButton.setOnClickListener(new OnClickListener() {
@Override @Override

View File

@@ -23,13 +23,16 @@ import android.view.KeyEvent;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import com.android.internal.annotations.VisibleForTesting;
/** /**
* A Pin based Keyguard input view * A Pin based Keyguard input view
*/ */
public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
implements View.OnKeyListener, View.OnTouchListener { implements View.OnKeyListener, View.OnTouchListener {
protected PasswordTextView mPasswordEntry; @VisibleForTesting
PasswordTextView mPasswordEntry;
private View mOkButton; private View mOkButton;
private View mDeleteButton; private View mDeleteButton;
private View mButton0; private View mButton0;
@@ -51,12 +54,6 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
super(context, attrs); super(context, attrs);
} }
@Override
public void reset() {
mPasswordEntry.requestFocus();
super.reset();
}
@Override @Override
protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
// send focus to the password field // send focus to the password field
@@ -237,6 +234,12 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
super.onFinishInflate(); super.onFinishInflate();
} }
@Override
public void onResume(int reason) {
super.onResume(reason);
mPasswordEntry.requestFocus();
}
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {

View File

@@ -54,6 +54,8 @@ public class KeyguardBouncer {
private static final String TAG = "KeyguardBouncer"; private static final String TAG = "KeyguardBouncer";
static final float ALPHA_EXPANSION_THRESHOLD = 0.95f; static final float ALPHA_EXPANSION_THRESHOLD = 0.95f;
private static final float EXPANSION_HIDDEN = 1f;
private static final float EXPANSION_VISIBLE = 0f;
protected final Context mContext; protected final Context mContext;
protected final ViewMediatorCallback mCallback; protected final ViewMediatorCallback mCallback;
@@ -71,10 +73,15 @@ public class KeyguardBouncer {
} }
}; };
private final Runnable mRemoveViewRunnable = this::removeView; private final Runnable mRemoveViewRunnable = this::removeView;
protected KeyguardHostView mKeyguardView;
private final Runnable mResetRunnable = ()-> {
if (mKeyguardView != null) {
mKeyguardView.reset();
}
};
private int mStatusBarHeight; private int mStatusBarHeight;
private float mExpansion; private float mExpansion = EXPANSION_HIDDEN;
protected KeyguardHostView mKeyguardView;
protected ViewGroup mRoot; protected ViewGroup mRoot;
private boolean mShowingSoon; private boolean mShowingSoon;
private int mBouncerPromptReason; private int mBouncerPromptReason;
@@ -96,7 +103,7 @@ public class KeyguardBouncer {
} }
public void show(boolean resetSecuritySelection) { public void show(boolean resetSecuritySelection) {
show(resetSecuritySelection, true /* notifyFalsing */); show(resetSecuritySelection, true /* animated */);
} }
/** /**
@@ -120,8 +127,7 @@ public class KeyguardBouncer {
// Later, at the end of the animation, when the bouncer is at the top of the screen, // Later, at the end of the animation, when the bouncer is at the top of the screen,
// onFullyShown() will be called and FalsingManager will stop recording touches. // onFullyShown() will be called and FalsingManager will stop recording touches.
if (animated) { if (animated) {
mFalsingManager.onBouncerShown(); setExpansion(EXPANSION_VISIBLE);
setExpansion(0);
} }
if (resetSecuritySelection) { if (resetSecuritySelection) {
@@ -152,6 +158,7 @@ public class KeyguardBouncer {
mShowingSoon = true; mShowingSoon = true;
// Split up the work over multiple frames. // Split up the work over multiple frames.
DejankUtils.removeCallbacks(mResetRunnable);
DejankUtils.postAfterTraversal(mShowRunnable); DejankUtils.postAfterTraversal(mShowRunnable);
mCallback.onBouncerVisiblityChanged(true /* shown */); mCallback.onBouncerVisiblityChanged(true /* shown */);
@@ -181,6 +188,7 @@ public class KeyguardBouncer {
mRoot.setVisibility(View.INVISIBLE); mRoot.setVisibility(View.INVISIBLE);
} }
mFalsingManager.onBouncerHidden(); mFalsingManager.onBouncerHidden();
DejankUtils.postAfterTraversal(mResetRunnable);
} }
} }
@@ -210,6 +218,9 @@ public class KeyguardBouncer {
mKeyguardView.requestLayout(); mKeyguardView.requestLayout();
} }
mShowingSoon = false; mShowingSoon = false;
if (mExpansion == EXPANSION_VISIBLE) {
mKeyguardView.onResume();
}
StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED, StatsLog.write(StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED,
StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SHOWN); StatsLog.KEYGUARD_BOUNCER_STATE_CHANGED__STATE__SHOWN);
} }
@@ -303,7 +314,7 @@ public class KeyguardBouncer {
public boolean isShowing() { public boolean isShowing() {
return (mShowingSoon || (mRoot != null && mRoot.getVisibility() == View.VISIBLE)) return (mShowingSoon || (mRoot != null && mRoot.getVisibility() == View.VISIBLE))
&& mExpansion == 0 && !isAnimatingAway(); && mExpansion == EXPANSION_VISIBLE && !isAnimatingAway();
} }
/** /**
@@ -337,10 +348,10 @@ public class KeyguardBouncer {
mKeyguardView.setTranslationY(fraction * mKeyguardView.getHeight()); mKeyguardView.setTranslationY(fraction * mKeyguardView.getHeight());
} }
if (fraction == 0 && oldExpansion != 0) { if (fraction == EXPANSION_VISIBLE && oldExpansion != EXPANSION_VISIBLE) {
onFullyShown(); onFullyShown();
mExpansionCallback.onFullyShown(); mExpansionCallback.onFullyShown();
} else if (fraction == 1 && oldExpansion != 0) { } else if (fraction == EXPANSION_HIDDEN && oldExpansion != EXPANSION_HIDDEN) {
onFullyHidden(); onFullyHidden();
mExpansionCallback.onFullyHidden(); mExpansionCallback.onFullyHidden();
} }

View File

@@ -0,0 +1,57 @@
/*
* 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
*/
package com.android.keyguard;
import static org.mockito.Mockito.verify;
import android.support.test.filters.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;
import com.android.systemui.SysuiTestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@SmallTest
@RunWith(AndroidTestingRunner.class)
@RunWithLooper(setAsMainLooper = true)
public class KeyguardPinBasedInputViewTest extends SysuiTestCase {
@Mock
private PasswordTextView mPasswordTextView;
private KeyguardPinBasedInputView mKeyguardPinView;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
LayoutInflater inflater = LayoutInflater.from(getContext());
mKeyguardPinView =
(KeyguardPinBasedInputView) inflater.inflate(R.layout.keyguard_pin_view, null);
mKeyguardPinView.mPasswordEntry = mPasswordTextView;
}
@Test
public void onResume_requestsFocus() {
mKeyguardPinView.onResume(KeyguardSecurityView.SCREEN_ON);
verify(mPasswordTextView).requestFocus();
}
}