Merge "UX improvements to the restrictions PIN" into klp-dev

This commit is contained in:
Geoffrey Borggaard
2013-09-04 00:41:26 +00:00
committed by Android (Google) Code Review
5 changed files with 122 additions and 86 deletions

View File

@@ -16,9 +16,7 @@
package com.android.internal.app; package com.android.internal.app;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserManager; import android.os.UserManager;
import android.text.Editable; import android.text.Editable;
@@ -26,7 +24,8 @@ import android.text.TextWatcher;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.WindowManager; import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener; 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. * challenge for an existing PIN. The PIN is maintained by UserManager.
*/ */
public class RestrictionsPinActivity extends AlertActivity public class RestrictionsPinActivity extends AlertActivity
implements DialogInterface.OnClickListener, TextWatcher, OnEditorActionListener { implements OnClickListener, TextWatcher, OnEditorActionListener {
protected UserManager mUserManager; protected UserManager mUserManager;
protected boolean mHasRestrictionsPin; protected boolean mHasRestrictionsPin;
protected EditText mPinText; protected EditText mPinText;
protected TextView mPinErrorMessage; protected TextView mPinErrorMessage;
protected TextView mPinMessage; private Button mOkButton;
private Button mCancelButton;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
@@ -59,19 +59,20 @@ public class RestrictionsPinActivity extends AlertActivity
protected void initUi() { protected void initUi() {
AlertController.AlertParams ap = mAlertParams; AlertController.AlertParams ap = mAlertParams;
ap.mTitle = getString(R.string.restr_pin_enter_pin); ap.mTitle = getString(R.string.restr_pin_enter_admin_pin);
ap.mPositiveButtonText = getString(R.string.ok);
ap.mNegativeButtonText = getString(R.string.cancel);
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
LayoutInflater inflater = LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ap.mView = inflater.inflate(R.layout.restrictions_pin_challenge, null); 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); 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); mPinText.addTextChangedListener(this);
mOkButton.setOnClickListener(this);
mCancelButton.setOnClickListener(this);
} }
protected boolean verifyingPin() { protected boolean verifyingPin() {
@@ -84,8 +85,7 @@ public class RestrictionsPinActivity extends AlertActivity
setPositiveButtonState(false); setPositiveButtonState(false);
boolean hasPin = mUserManager.hasRestrictionsPin(); boolean hasPin = mUserManager.hasRestrictionsPin();
if (hasPin) { if (hasPin) {
mPinMessage.setVisibility(View.GONE); mPinErrorMessage.setVisibility(View.INVISIBLE);
mPinErrorMessage.setVisibility(View.GONE);
mPinText.setOnEditorActionListener(this); mPinText.setOnEditorActionListener(this);
updatePinTimer(-1); updatePinTimer(-1);
} else if (verifyingPin()) { } else if (verifyingPin()) {
@@ -94,39 +94,37 @@ public class RestrictionsPinActivity extends AlertActivity
} }
} }
private void setPositiveButtonState(boolean enabled) { protected void setPositiveButtonState(boolean enabled) {
mAlert.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(enabled); mOkButton.setEnabled(enabled);
} }
private void updatePinTimer(int pinTimerMs) { private boolean updatePinTimer(int pinTimerMs) {
if (pinTimerMs < 0) { if (pinTimerMs < 0) {
pinTimerMs = mUserManager.checkRestrictionsPin(null); pinTimerMs = mUserManager.checkRestrictionsPin(null);
} }
boolean enableInput;
if (pinTimerMs >= 200) { if (pinTimerMs >= 200) {
final int seconds = (pinTimerMs + 200) / 1000; // Do the count down timer for less than a minute, otherwise just say try again later.
final String formatString = getResources().getQuantityString( if (pinTimerMs <= 60000) {
R.plurals.restr_pin_countdown, final int seconds = (pinTimerMs + 200) / 1000;
seconds); final String formatString = getResources().getQuantityString(
mPinErrorMessage.setText(String.format(formatString, seconds)); 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); mPinErrorMessage.setVisibility(View.VISIBLE);
mPinText.setEnabled(false);
mPinText.setText(""); mPinText.setText("");
setPositiveButtonState(false);
mPinText.postDelayed(mCountdownRunnable, Math.min(1000, pinTimerMs)); mPinText.postDelayed(mCountdownRunnable, Math.min(1000, pinTimerMs));
} else { } else {
mPinErrorMessage.setVisibility(View.INVISIBLE); enableInput = true;
mPinText.setEnabled(true); mPinErrorMessage.setText(R.string.restr_pin_incorrect);
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();
} }
mPinText.setEnabled(enableInput);
setPositiveButtonState(enableInput);
return enableInput;
} }
protected void performPositiveButtonAction() { protected void performPositiveButtonAction() {
@@ -135,7 +133,10 @@ public class RestrictionsPinActivity extends AlertActivity
setResult(RESULT_OK); setResult(RESULT_OK);
finish(); finish();
} else if (result >= 0) { } else if (result >= 0) {
mPinErrorMessage.setText(R.string.restr_pin_incorrect);
mPinErrorMessage.setVisibility(View.VISIBLE);
updatePinTimer(result); updatePinTimer(result);
mPinText.setText("");
} }
} }
@@ -161,7 +162,20 @@ public class RestrictionsPinActivity extends AlertActivity
private Runnable mCountdownRunnable = new Runnable() { private Runnable mCountdownRunnable = new Runnable() {
public void run() { 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();
}
}
} }

View File

@@ -16,9 +16,7 @@
package com.android.internal.app; package com.android.internal.app;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.os.UserManager; import android.os.UserManager;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
@@ -44,17 +42,13 @@ public class RestrictionsPinSetupActivity extends RestrictionsPinActivity {
ap.mTitle = getString(R.string.restr_pin_enter_pin); ap.mTitle = getString(R.string.restr_pin_enter_pin);
ap.mPositiveButtonText = getString(R.string.ok); ap.mPositiveButtonText = getString(R.string.ok);
ap.mNegativeButtonText = getString(R.string.cancel); ap.mNegativeButtonText = getString(R.string.cancel);
ap.mPositiveButtonListener = this;
ap.mNegativeButtonListener = this;
LayoutInflater inflater = LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ap.mView = inflater.inflate(R.layout.restrictions_pin_setup, null); ap.mView = inflater.inflate(R.layout.restrictions_pin_setup, null);
mPinText = (EditText) ap.mView.findViewById(R.id.pin_text); 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); mNewPinText = (EditText) ap.mView.findViewById(R.id.pin_new_text);
mConfirmPinText = (EditText) ap.mView.findViewById(R.id.pin_confirm_text); mConfirmPinText = (EditText) ap.mView.findViewById(R.id.pin_confirm_text);
mPinErrorMessage = (TextView) ap.mView.findViewById(R.id.pin_error_message);
mNewPinText.addTextChangedListener(this); mNewPinText.addTextChangedListener(this);
mConfirmPinText.addTextChangedListener(this); mConfirmPinText.addTextChangedListener(this);
@@ -72,19 +66,7 @@ public class RestrictionsPinSetupActivity extends RestrictionsPinActivity {
return false; return false;
} }
private void setPositiveButtonState(boolean enabled) { @Override
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();
}
}
protected void performPositiveButtonAction() { protected void performPositiveButtonAction() {
if (mHasRestrictionsPin) { if (mHasRestrictionsPin) {
int result = mUserManager.checkRestrictionsPin(mPinText.getText().toString()); int result = mUserManager.checkRestrictionsPin(mPinText.getText().toString());
@@ -115,7 +97,6 @@ public class RestrictionsPinSetupActivity extends RestrictionsPinActivity {
boolean showError = !TextUtils.isEmpty(pin1) && !TextUtils.isEmpty(pin2); boolean showError = !TextUtils.isEmpty(pin1) && !TextUtils.isEmpty(pin2);
// TODO: Check recovery email address as well // TODO: Check recovery email address as well
setPositiveButtonState(match); setPositiveButtonState(match);
mPinErrorMessage.setVisibility((match || !showError) ? View.INVISIBLE : View.VISIBLE);
} }
@Override @Override

View File

@@ -18,42 +18,73 @@
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="48dp"
android:layout_marginBottom="48dp"
android:overScrollMode="ifContentScrolls"> android:overScrollMode="ifContentScrolls">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="8dip"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
<TextView android:id="@+id/pin_message"
style="?android:attr/textAppearanceMedium"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/restr_pin_create_pin" android:padding="8dip"
android:textColor="?android:attr/textColorSecondary" /> android:orientation="vertical">
<EditText android:id="@+id/pin_text" <EditText android:id="@+id/pin_text"
style="?android:attr/textAppearanceMedium" android:layout_marginLeft="8dip"
android:layout_marginBottom="16dp" android:layout_marginStart="8dip"
android:layout_marginRight="8dip"
android:layout_marginEnd="8dip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword"
android:textColor="?android:attr/textColorPrimary" />
<TextView android:id="@+id/pin_error_message"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/restr_pin_incorrect"
android:gravity="center"/>
</LinearLayout>
<LinearLayout android:id="@+id/buttonPanel"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/restr_pin_enter_pin" android:minHeight="@dimen/alert_dialog_button_bar_height"
android:inputType="numberPassword" android:orientation="vertical"
android:textColor="?android:attr/textColorPrimary" /> android:divider="?android:attr/dividerHorizontal"
android:showDividers="beginning"
<TextView android:id="@+id/pin_error_message" android:dividerPadding="0dip">
style="?android:attr/textAppearanceSmall" <LinearLayout
android:layout_marginBottom="16dp" style="?android:attr/buttonBarStyle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/restr_pin_error_doesnt_match" android:orientation="horizontal"
android:textColor="#FFFF0000" /> android:layoutDirection="locale"
android:measureWithLargestChild="true">
<Button android:id="@+id/pin_cancel_button"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:layout_weight="1"
android:maxLines="2"
android:minHeight="@dimen/alert_dialog_button_bar_height"
style="?android:attr/buttonBarButtonStyle"
android:textSize="14sp"
android:layout_height="wrap_content"
android:text="@string/cancel" />
<Button android:id="@+id/pin_ok_button"
android:layout_width="wrap_content"
android:layout_gravity="end"
android:layout_weight="1"
android:maxLines="2"
style="?android:attr/buttonBarButtonStyle"
android:textSize="14sp"
android:minHeight="@dimen/alert_dialog_button_bar_height"
android:layout_height="wrap_content"
android:text="@string/ok" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>

View File

@@ -4296,8 +4296,12 @@
<!-- Print fail reason: unknown. [CHAR LIMIT=25] --> <!-- Print fail reason: unknown. [CHAR LIMIT=25] -->
<string name="reason_unknown">unknown</string> <string name="reason_unknown">unknown</string>
<!-- PIN entry dialog title for entering the administrator PIN [CHAR LIMIT=none] -->
<string name="restr_pin_enter_admin_pin">Enter administrator PIN</string>
<!-- PIN entry dialog label/hint for PIN [CHAR LIMIT=none] --> <!-- PIN entry dialog label/hint for PIN [CHAR LIMIT=none] -->
<string name="restr_pin_enter_pin">Enter PIN</string> <string name="restr_pin_enter_pin">Enter PIN</string>
<!-- PIN entry dialog label/hint for incorrect PIN entry [CHAR LIMIT=none] -->
<string name="restr_pin_incorrect">Incorrect</string>
<!-- PIN entry dialog label/hint for old PIN [CHAR LIMIT=none] --> <!-- PIN entry dialog label/hint for old PIN [CHAR LIMIT=none] -->
<string name="restr_pin_enter_old_pin">Current PIN</string> <string name="restr_pin_enter_old_pin">Current PIN</string>
<!-- PIN entry dialog label for new PIN [CHAR LIMIT=none] --> <!-- PIN entry dialog label for new PIN [CHAR LIMIT=none] -->
@@ -4313,9 +4317,11 @@
<!-- PIN entry dialog countdown message for next chance to enter the PIN [CHAR LIMIT=none] --> <!-- PIN entry dialog countdown message for next chance to enter the PIN [CHAR LIMIT=none] -->
<!-- Phrase describing a time duration using seconds [CHAR LIMIT=16] --> <!-- Phrase describing a time duration using seconds [CHAR LIMIT=16] -->
<plurals name="restr_pin_countdown"> <plurals name="restr_pin_countdown">
<item quantity="one">Incorrect PIN. Try again in 1 second.</item> <item quantity="one">Try again in 1 second</item>
<item quantity="other">Incorrect PIN. Try again in <xliff:g id="count">%d</xliff:g> seconds.</item> <item quantity="other">Try again in <xliff:g id="count">%d</xliff:g> seconds</item>
</plurals> </plurals>
<!-- PIN entry dialog tells the user to not enter a PIN for a while. [CHAR LIMIT=none] -->
<string name="restr_pin_try_later">Try again later</string>
<!-- Toast bar message when hiding the transient navigation bar [CHAR LIMIT=35] --> <!-- Toast bar message when hiding the transient navigation bar [CHAR LIMIT=35] -->
<string name="transient_navigation_confirmation">Swipe edge of screen to reveal bar</string> <string name="transient_navigation_confirmation">Swipe edge of screen to reveal bar</string>

View File

@@ -212,7 +212,8 @@
<java-symbol type="id" name="sms_short_code_remember_undo_instruction" /> <java-symbol type="id" name="sms_short_code_remember_undo_instruction" />
<java-symbol type="id" name="breadcrumb_section" /> <java-symbol type="id" name="breadcrumb_section" />
<java-symbol type="id" name="action_bar_spinner" /> <java-symbol type="id" name="action_bar_spinner" />
<java-symbol type="id" name="pin_message" /> <java-symbol type="id" name="pin_cancel_button" />
<java-symbol type="id" name="pin_ok_button" />
<java-symbol type="id" name="pin_text" /> <java-symbol type="id" name="pin_text" />
<java-symbol type="id" name="pin_new_text" /> <java-symbol type="id" name="pin_new_text" />
<java-symbol type="id" name="pin_confirm_text" /> <java-symbol type="id" name="pin_confirm_text" />
@@ -871,7 +872,10 @@
<java-symbol type="string" name="mediaSize_na_ledger" /> <java-symbol type="string" name="mediaSize_na_ledger" />
<java-symbol type="string" name="mediaSize_na_tabloid" /> <java-symbol type="string" name="mediaSize_na_tabloid" />
<java-symbol type="string" name="reason_unknown" /> <java-symbol type="string" name="reason_unknown" />
<java-symbol type="string" name="restr_pin_enter_admin_pin" />
<java-symbol type="string" name="restr_pin_enter_pin" /> <java-symbol type="string" name="restr_pin_enter_pin" />
<java-symbol type="string" name="restr_pin_incorrect" />
<java-symbol type="string" name="restr_pin_try_later" />
<java-symbol type="string" name="write_fail_reason_cancelled" /> <java-symbol type="string" name="write_fail_reason_cancelled" />
<java-symbol type="string" name="write_fail_reason_cannot_write" /> <java-symbol type="string" name="write_fail_reason_cannot_write" />
<java-symbol type="string" name="transient_navigation_confirmation" /> <java-symbol type="string" name="transient_navigation_confirmation" />