summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/com/android/internal/app/RestrictionsPinSetupActivity.java')
-rw-r--r--core/java/com/android/internal/app/RestrictionsPinSetupActivity.java104
1 files changed, 103 insertions, 1 deletions
diff --git a/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java b/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java
index 35f2967..1d09292 100644
--- a/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java
+++ b/core/java/com/android/internal/app/RestrictionsPinSetupActivity.java
@@ -16,13 +16,115 @@
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;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import com.android.internal.R;
+
/**
* This activity is launched by Settings and other apps to either create a new PIN or
- * challenge for an existing PIN. The PIN is maintained by UserManager.
+ * change an existing PIN. The PIN is maintained by UserManager.
*/
public class RestrictionsPinSetupActivity extends RestrictionsPinActivity {
+ private EditText mNewPinText;
+ private EditText mConfirmPinText;
+
+ 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;
+ 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);
+
+ if (!mHasRestrictionsPin) {
+ mPinText.setVisibility(View.GONE);
+ }
+ }
+
+ public void onResume() {
+ super.onResume();
+ setPositiveButtonState(false);
+ }
+
protected boolean verifyingPin() {
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();
+ }
+ }
+
+ protected void performPositiveButtonAction() {
+ if (mHasRestrictionsPin) {
+ int result = mUserManager.checkRestrictionsPin(mPinText.getText().toString());
+ if (result != UserManager.PIN_VERIFICATION_SUCCESS) {
+ // TODO: Set message that existing pin doesn't match
+ return;
+ }
+ }
+ if (mUserManager.changeRestrictionsPin(mNewPinText.getText().toString())) {
+ // TODO: Send message to PIN recovery agent about the recovery email address
+ setResult(RESULT_OK);
+ finish();
+ }
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ CharSequence pin = mPinText.getText();
+ CharSequence pin1 = mNewPinText.getText();
+ CharSequence pin2 = mConfirmPinText.getText();
+ boolean match = pin1 != null && pin2 != null && pin1.length() >= 4
+ && pin1.toString().equals(pin2.toString())
+ && (!mHasRestrictionsPin || (pin != null && pin.length() >= 4));
+ 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
+ public void afterTextChanged(Editable s) {
+ }
+
+ @Override
+ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
+ performPositiveButtonAction();
+ return true;
+ }
}