From 8135f3a9d306f5cd23c1a4f86c86a577060487c3 Mon Sep 17 00:00:00 2001 From: Geoffrey Borggaard Date: Wed, 28 Aug 2013 22:13:10 -0400 Subject: [PATCH] UX improvements to the restrictions PIN As per Rachel. Remove the title, change the hint text. Don't make the dialog disappear after failed attempts. Bug: 10542734 Change-Id: I1cae3d74bd4da06364626d63faf945f629cf6537 --- .../internal/app/RestrictionsPinActivity.java | 88 +++++++++++-------- .../app/RestrictionsPinSetupActivity.java | 21 +---- .../res/layout/restrictions_pin_challenge.xml | 83 +++++++++++------ core/res/res/values/strings.xml | 10 ++- core/res/res/values/symbols.xml | 6 +- 5 files changed, 122 insertions(+), 86 deletions(-) diff --git a/core/java/com/android/internal/app/RestrictionsPinActivity.java b/core/java/com/android/internal/app/RestrictionsPinActivity.java index f8ce10873a50a..211247488ff38 100644 --- a/core/java/com/android/internal/app/RestrictionsPinActivity.java +++ b/core/java/com/android/internal/app/RestrictionsPinActivity.java @@ -16,9 +16,7 @@ package com.android.internal.app; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.os.Bundle; import android.os.UserManager; import android.text.Editable; @@ -26,7 +24,8 @@ import android.text.TextWatcher; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.View; -import android.view.WindowManager; +import android.view.View.OnClickListener; +import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; @@ -38,14 +37,15 @@ import com.android.internal.R; * challenge for an existing PIN. The PIN is maintained by UserManager. */ public class RestrictionsPinActivity extends AlertActivity - implements DialogInterface.OnClickListener, TextWatcher, OnEditorActionListener { + implements OnClickListener, TextWatcher, OnEditorActionListener { protected UserManager mUserManager; protected boolean mHasRestrictionsPin; protected EditText mPinText; protected TextView mPinErrorMessage; - protected TextView mPinMessage; + private Button mOkButton; + private Button mCancelButton; @Override public void onCreate(Bundle icicle) { @@ -59,19 +59,20 @@ public class RestrictionsPinActivity extends AlertActivity protected void initUi() { AlertController.AlertParams ap = mAlertParams; - ap.mTitle = getString(R.string.restr_pin_enter_pin); - ap.mPositiveButtonText = getString(R.string.ok); - ap.mNegativeButtonText = getString(R.string.cancel); - ap.mPositiveButtonListener = this; - ap.mNegativeButtonListener = this; + ap.mTitle = getString(R.string.restr_pin_enter_admin_pin); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); ap.mView = inflater.inflate(R.layout.restrictions_pin_challenge, null); - mPinMessage = (TextView) ap.mView.findViewById(R.id.pin_message); - mPinText = (EditText) ap.mView.findViewById(R.id.pin_text); mPinErrorMessage = (TextView) ap.mView.findViewById(R.id.pin_error_message); + mPinText = (EditText) ap.mView.findViewById(R.id.pin_text); + mOkButton = (Button) ap.mView.findViewById(R.id.pin_ok_button); + mCancelButton = (Button) ap.mView.findViewById(R.id.pin_cancel_button); + mPinText.addTextChangedListener(this); + + mOkButton.setOnClickListener(this); + mCancelButton.setOnClickListener(this); } protected boolean verifyingPin() { @@ -84,8 +85,7 @@ public class RestrictionsPinActivity extends AlertActivity setPositiveButtonState(false); boolean hasPin = mUserManager.hasRestrictionsPin(); if (hasPin) { - mPinMessage.setVisibility(View.GONE); - mPinErrorMessage.setVisibility(View.GONE); + mPinErrorMessage.setVisibility(View.INVISIBLE); mPinText.setOnEditorActionListener(this); updatePinTimer(-1); } else if (verifyingPin()) { @@ -94,39 +94,37 @@ public class RestrictionsPinActivity extends AlertActivity } } - private void setPositiveButtonState(boolean enabled) { - mAlert.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enabled); + protected void setPositiveButtonState(boolean enabled) { + mOkButton.setEnabled(enabled); } - private void updatePinTimer(int pinTimerMs) { + private boolean updatePinTimer(int pinTimerMs) { if (pinTimerMs < 0) { pinTimerMs = mUserManager.checkRestrictionsPin(null); } + boolean enableInput; if (pinTimerMs >= 200) { - final int seconds = (pinTimerMs + 200) / 1000; - final String formatString = getResources().getQuantityString( - R.plurals.restr_pin_countdown, - seconds); - mPinErrorMessage.setText(String.format(formatString, seconds)); + // Do the count down timer for less than a minute, otherwise just say try again later. + if (pinTimerMs <= 60000) { + final int seconds = (pinTimerMs + 200) / 1000; + final String formatString = getResources().getQuantityString( + R.plurals.restr_pin_countdown, + seconds); + mPinErrorMessage.setText(String.format(formatString, seconds)); + } else { + mPinErrorMessage.setText(R.string.restr_pin_try_later); + } + enableInput = false; mPinErrorMessage.setVisibility(View.VISIBLE); - mPinText.setEnabled(false); mPinText.setText(""); - setPositiveButtonState(false); mPinText.postDelayed(mCountdownRunnable, Math.min(1000, pinTimerMs)); } else { - mPinErrorMessage.setVisibility(View.INVISIBLE); - mPinText.setEnabled(true); - mPinText.setText(""); - } - } - - public void onClick(DialogInterface dialog, int which) { - setResult(RESULT_CANCELED); - if (which == AlertDialog.BUTTON_POSITIVE) { - performPositiveButtonAction(); - } else if (which == AlertDialog.BUTTON_NEGATIVE) { - finish(); + enableInput = true; + mPinErrorMessage.setText(R.string.restr_pin_incorrect); } + mPinText.setEnabled(enableInput); + setPositiveButtonState(enableInput); + return enableInput; } protected void performPositiveButtonAction() { @@ -135,7 +133,10 @@ public class RestrictionsPinActivity extends AlertActivity setResult(RESULT_OK); finish(); } else if (result >= 0) { + mPinErrorMessage.setText(R.string.restr_pin_incorrect); + mPinErrorMessage.setVisibility(View.VISIBLE); updatePinTimer(result); + mPinText.setText(""); } } @@ -161,7 +162,20 @@ public class RestrictionsPinActivity extends AlertActivity private Runnable mCountdownRunnable = new Runnable() { public void run() { - updatePinTimer(-1); + if (updatePinTimer(-1)) { + // If we are no longer counting down, clear the message. + mPinErrorMessage.setVisibility(View.INVISIBLE); + } } }; + + @Override + public void onClick(View v) { + if (v == mOkButton) { + performPositiveButtonAction(); + } else if (v == mCancelButton) { + setResult(RESULT_CANCELED); + finish(); + } + } } diff --git a/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java b/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java index 1d092920628fb..f7fc6c67ed83e 100644 --- a/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java +++ b/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java @@ -16,9 +16,7 @@ package com.android.internal.app; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.os.UserManager; import android.text.Editable; import android.text.TextUtils; @@ -44,17 +42,13 @@ public class RestrictionsPinSetupActivity extends RestrictionsPinActivity { ap.mTitle = getString(R.string.restr_pin_enter_pin); ap.mPositiveButtonText = getString(R.string.ok); ap.mNegativeButtonText = getString(R.string.cancel); - ap.mPositiveButtonListener = this; - ap.mNegativeButtonListener = this; LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); ap.mView = inflater.inflate(R.layout.restrictions_pin_setup, null); mPinText = (EditText) ap.mView.findViewById(R.id.pin_text); - mPinMessage = (TextView) ap.mView.findViewById(R.id.pin_message); mNewPinText = (EditText) ap.mView.findViewById(R.id.pin_new_text); mConfirmPinText = (EditText) ap.mView.findViewById(R.id.pin_confirm_text); - mPinErrorMessage = (TextView) ap.mView.findViewById(R.id.pin_error_message); mNewPinText.addTextChangedListener(this); mConfirmPinText.addTextChangedListener(this); @@ -72,19 +66,7 @@ public class RestrictionsPinSetupActivity extends RestrictionsPinActivity { return false; } - private void setPositiveButtonState(boolean enabled) { - mAlert.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enabled); - } - - public void onClick(DialogInterface dialog, int which) { - setResult(RESULT_CANCELED); - if (which == AlertDialog.BUTTON_POSITIVE) { - performPositiveButtonAction(); - } else if (which == AlertDialog.BUTTON_NEGATIVE) { - finish(); - } - } - + @Override protected void performPositiveButtonAction() { if (mHasRestrictionsPin) { int result = mUserManager.checkRestrictionsPin(mPinText.getText().toString()); @@ -115,7 +97,6 @@ public class RestrictionsPinSetupActivity extends RestrictionsPinActivity { boolean showError = !TextUtils.isEmpty(pin1) && !TextUtils.isEmpty(pin2); // TODO: Check recovery email address as well setPositiveButtonState(match); - mPinErrorMessage.setVisibility((match || !showError) ? View.INVISIBLE : View.VISIBLE); } @Override diff --git a/core/res/res/layout/restrictions_pin_challenge.xml b/core/res/res/layout/restrictions_pin_challenge.xml index 954af92c60b75..f41924cf13f63 100644 --- a/core/res/res/layout/restrictions_pin_challenge.xml +++ b/core/res/res/layout/restrictions_pin_challenge.xml @@ -18,42 +18,73 @@ - - + android:padding="8dip" + android:orientation="vertical"> - + + + + + - - - + android:minHeight="@dimen/alert_dialog_button_bar_height" + android:orientation="vertical" + android:divider="?android:attr/dividerHorizontal" + android:showDividers="beginning" + android:dividerPadding="0dip"> + +