summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/ConfirmLockPattern.java
diff options
context:
space:
mode:
authorJim Miller <jaggies@google.com>2010-12-07 20:41:41 -0800
committerJim Miller <jaggies@google.com>2010-12-08 16:45:52 -0800
commit17e9e1933055b207473b488595b2887bfcaea32e (patch)
tree7b3f0f0ac2d5fcf62ea7dc4300f7927488250cab /src/com/android/settings/ConfirmLockPattern.java
parent1c7e49ba670ad70822d34234e3677fef53e94569 (diff)
downloadpackages_apps_Settings-17e9e1933055b207473b488595b2887bfcaea32e.zip
packages_apps_Settings-17e9e1933055b207473b488595b2887bfcaea32e.tar.gz
packages_apps_Settings-17e9e1933055b207473b488595b2887bfcaea32e.tar.bz2
Fix 3148496: Initial pass at fragmentizing lockscreen settings.
This converts most of the existing activities to fragments and wraps them in PreferenceActivities so they can be launched as before (e.g. by a DevicePolicyManager) Upload after sync/rebase. Change-Id: I4f351b75d9fca0498bcb04b4e11ff3b70765a4ba
Diffstat (limited to 'src/com/android/settings/ConfirmLockPattern.java')
-rw-r--r--src/com/android/settings/ConfirmLockPattern.java397
1 files changed, 210 insertions, 187 deletions
diff --git a/src/com/android/settings/ConfirmLockPattern.java b/src/com/android/settings/ConfirmLockPattern.java
index 8d44875..25e8370 100644
--- a/src/com/android/settings/ConfirmLockPattern.java
+++ b/src/com/android/settings/ConfirmLockPattern.java
@@ -22,12 +22,16 @@ import com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient;
import com.android.internal.widget.LockPatternView.Cell;
import android.app.Activity;
+import android.app.Fragment;
import android.content.Intent;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.os.Bundle;
+import android.preference.PreferenceActivity;
import android.widget.TextView;
-import android.view.Window;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
import java.util.List;
@@ -37,7 +41,7 @@ import java.util.List;
* Sets an activity result of {@link Activity#RESULT_OK} when the user
* successfully confirmed their pattern.
*/
-public class ConfirmLockPattern extends Activity {
+public class ConfirmLockPattern extends PreferenceActivity {
/**
* Names of {@link CharSequence} fields within the originating {@link Intent}
@@ -45,30 +49,11 @@ public class ConfirmLockPattern extends Activity {
* The view will use the system-defined resource strings for any labels that
* the caller does not supply.
*/
- public static final String HEADER_TEXT = "com.android.settings.ConfirmLockPattern.header";
- public static final String FOOTER_TEXT = "com.android.settings.ConfirmLockPattern.footer";
- public static final String HEADER_WRONG_TEXT = "com.android.settings.ConfirmLockPattern.header_wrong";
- public static final String FOOTER_WRONG_TEXT = "com.android.settings.ConfirmLockPattern.footer_wrong";
-
- // how long we wait to clear a wrong pattern
- private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 2000;
-
- private static final String KEY_NUM_WRONG_ATTEMPTS = "num_wrong_attempts";
-
- private LockPatternView mLockPatternView;
- private LockPatternUtils mLockPatternUtils;
- private int mNumWrongConfirmAttempts;
- private CountDownTimer mCountdownTimer;
-
- private TextView mHeaderTextView;
- private TextView mFooterTextView;
-
- // caller-supplied text for various prompts
- private CharSequence mHeaderText;
- private CharSequence mFooterText;
- private CharSequence mHeaderWrongText;
- private CharSequence mFooterWrongText;
-
+ public static final String PACKAGE = "com.android.settings";
+ public static final String HEADER_TEXT = PACKAGE + ".ConfirmLockPattern.header";
+ public static final String FOOTER_TEXT = PACKAGE + ".ConfirmLockPattern.footer";
+ public static final String HEADER_WRONG_TEXT = PACKAGE + ".ConfirmLockPattern.header_wrong";
+ public static final String FOOTER_WRONG_TEXT = PACKAGE + ".ConfirmLockPattern.footer_wrong";
private enum Stage {
NeedToUnlock,
@@ -77,194 +62,232 @@ public class ConfirmLockPattern extends Activity {
}
@Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- mLockPatternUtils = new LockPatternUtils(this);
-
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.confirm_lock_pattern);
-
- mHeaderTextView = (TextView) findViewById(R.id.headerText);
- mLockPatternView = (LockPatternView) findViewById(R.id.lockPattern);
- mFooterTextView = (TextView) findViewById(R.id.footerText);
-
- // make it so unhandled touch events within the unlock screen go to the
- // lock pattern view.
- final LinearLayoutWithDefaultTouchRecepient topLayout
- = (LinearLayoutWithDefaultTouchRecepient) findViewById(
- R.id.topLayout);
- topLayout.setDefaultTouchRecepient(mLockPatternView);
-
- Intent intent = getIntent();
- if (intent != null) {
- mHeaderText = intent.getCharSequenceExtra(HEADER_TEXT);
- mFooterText = intent.getCharSequenceExtra(FOOTER_TEXT);
- mHeaderWrongText = intent.getCharSequenceExtra(HEADER_WRONG_TEXT);
- mFooterWrongText = intent.getCharSequenceExtra(FOOTER_WRONG_TEXT);
- }
-
- mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled());
- mLockPatternView.setOnPatternListener(mConfirmExistingLockPatternListener);
- updateStage(Stage.NeedToUnlock);
-
- if (savedInstanceState != null) {
- mNumWrongConfirmAttempts = savedInstanceState.getInt(KEY_NUM_WRONG_ATTEMPTS);
- } else {
- // on first launch, if no lock pattern is set, then finish with
- // success (don't want user to get stuck confirming something that
- // doesn't exist).
- if (!mLockPatternUtils.savedPatternExists()) {
- setResult(RESULT_OK);
- finish();
- }
- }
+ public Intent getIntent() {
+ Intent modIntent = new Intent(super.getIntent());
+ modIntent.putExtra(EXTRA_SHOW_FRAGMENT, ConfirmLockPatternFragment.class.getName());
+ modIntent.putExtra(EXTRA_NO_HEADERS, true);
+ return modIntent;
}
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- // deliberately not calling super since we are managing this in full
- outState.putInt(KEY_NUM_WRONG_ATTEMPTS, mNumWrongConfirmAttempts);
- }
+ public static class ConfirmLockPatternFragment extends Fragment {
- @Override
- protected void onPause() {
- super.onPause();
+ // how long we wait to clear a wrong pattern
+ private static final int WRONG_PATTERN_CLEAR_TIMEOUT_MS = 2000;
+
+ private static final String KEY_NUM_WRONG_ATTEMPTS = "num_wrong_attempts";
+
+ private LockPatternView mLockPatternView;
+ private LockPatternUtils mLockPatternUtils;
+ private int mNumWrongConfirmAttempts;
+ private CountDownTimer mCountdownTimer;
+
+ private TextView mHeaderTextView;
+ private TextView mFooterTextView;
+
+ // caller-supplied text for various prompts
+ private CharSequence mHeaderText;
+ private CharSequence mFooterText;
+ private CharSequence mHeaderWrongText;
+ private CharSequence mFooterWrongText;
+
+ // required constructor for fragments
+ public ConfirmLockPatternFragment() {
- if (mCountdownTimer != null) {
- mCountdownTimer.cancel();
}
- }
- @Override
- protected void onResume() {
- super.onResume();
-
- // if the user is currently locked out, enforce it.
- long deadline = mLockPatternUtils.getLockoutAttemptDeadline();
- if (deadline != 0) {
- handleAttemptLockout(deadline);
- } else if (!mLockPatternView.isEnabled()) {
- // The deadline has passed, but the timer was cancelled...
- // Need to clean up.
- mNumWrongConfirmAttempts = 0;
- updateStage(Stage.NeedToUnlock);
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mLockPatternUtils = new LockPatternUtils(getActivity());
}
- }
- private void updateStage(Stage stage) {
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ View view = inflater.inflate(R.layout.confirm_lock_pattern, null);
+ mHeaderTextView = (TextView) view.findViewById(R.id.headerText);
+ mLockPatternView = (LockPatternView) view.findViewById(R.id.lockPattern);
+ mFooterTextView = (TextView) view.findViewById(R.id.footerText);
+
+ // make it so unhandled touch events within the unlock screen go to the
+ // lock pattern view.
+ final LinearLayoutWithDefaultTouchRecepient topLayout
+ = (LinearLayoutWithDefaultTouchRecepient) view.findViewById(R.id.topLayout);
+ topLayout.setDefaultTouchRecepient(mLockPatternView);
+
+ Intent intent = getActivity().getIntent();
+ if (intent != null) {
+ mHeaderText = intent.getCharSequenceExtra(HEADER_TEXT);
+ mFooterText = intent.getCharSequenceExtra(FOOTER_TEXT);
+ mHeaderWrongText = intent.getCharSequenceExtra(HEADER_WRONG_TEXT);
+ mFooterWrongText = intent.getCharSequenceExtra(FOOTER_WRONG_TEXT);
+ }
- switch (stage) {
- case NeedToUnlock:
- if (mHeaderText != null) {
- mHeaderTextView.setText(mHeaderText);
- } else {
- mHeaderTextView.setText(R.string.lockpattern_need_to_unlock);
- }
- if (mFooterText != null) {
- mFooterTextView.setText(mFooterText);
- } else {
- mFooterTextView.setText(R.string.lockpattern_need_to_unlock_footer);
- }
+ mLockPatternView.setTactileFeedbackEnabled(mLockPatternUtils.isTactileFeedbackEnabled());
+ mLockPatternView.setOnPatternListener(mConfirmExistingLockPatternListener);
+ updateStage(Stage.NeedToUnlock);
- mLockPatternView.setEnabled(true);
- mLockPatternView.enableInput();
- break;
- case NeedToUnlockWrong:
- if (mHeaderWrongText != null) {
- mHeaderTextView.setText(mHeaderWrongText);
- } else {
- mHeaderTextView.setText(R.string.lockpattern_need_to_unlock_wrong);
- }
- if (mFooterWrongText != null) {
- mFooterTextView.setText(mFooterWrongText);
- } else {
- mFooterTextView.setText(R.string.lockpattern_need_to_unlock_wrong_footer);
+ if (savedInstanceState != null) {
+ mNumWrongConfirmAttempts = savedInstanceState.getInt(KEY_NUM_WRONG_ATTEMPTS);
+ } else {
+ // on first launch, if no lock pattern is set, then finish with
+ // success (don't want user to get stuck confirming something that
+ // doesn't exist).
+ if (!mLockPatternUtils.savedPatternExists()) {
+ getActivity().setResult(Activity.RESULT_OK);
+ getActivity().finish();
}
-
- mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
- mLockPatternView.setEnabled(true);
- mLockPatternView.enableInput();
- break;
- case LockedOut:
- mLockPatternView.clearPattern();
- // enabled = false means: disable input, and have the
- // appearance of being disabled.
- mLockPatternView.setEnabled(false); // appearance of being disabled
- break;
+ }
+ return view;
}
- }
- private Runnable mClearPatternRunnable = new Runnable() {
- public void run() {
- mLockPatternView.clearPattern();
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ // deliberately not calling super since we are managing this in full
+ outState.putInt(KEY_NUM_WRONG_ATTEMPTS, mNumWrongConfirmAttempts);
}
- };
- // clear the wrong pattern unless they have started a new one
- // already
- private void postClearPatternRunnable() {
- mLockPatternView.removeCallbacks(mClearPatternRunnable);
- mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS);
- }
+ @Override
+ public void onPause() {
+ super.onPause();
- /**
- * The pattern listener that responds according to a user confirming
- * an existing lock pattern.
- */
- private LockPatternView.OnPatternListener mConfirmExistingLockPatternListener = new LockPatternView.OnPatternListener() {
+ if (mCountdownTimer != null) {
+ mCountdownTimer.cancel();
+ }
+ }
- public void onPatternStart() {
- mLockPatternView.removeCallbacks(mClearPatternRunnable);
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ // if the user is currently locked out, enforce it.
+ long deadline = mLockPatternUtils.getLockoutAttemptDeadline();
+ if (deadline != 0) {
+ handleAttemptLockout(deadline);
+ } else if (!mLockPatternView.isEnabled()) {
+ // The deadline has passed, but the timer was cancelled...
+ // Need to clean up.
+ mNumWrongConfirmAttempts = 0;
+ updateStage(Stage.NeedToUnlock);
+ }
}
- public void onPatternCleared() {
- mLockPatternView.removeCallbacks(mClearPatternRunnable);
+ private void updateStage(Stage stage) {
+
+ switch (stage) {
+ case NeedToUnlock:
+ if (mHeaderText != null) {
+ mHeaderTextView.setText(mHeaderText);
+ } else {
+ mHeaderTextView.setText(R.string.lockpattern_need_to_unlock);
+ }
+ if (mFooterText != null) {
+ mFooterTextView.setText(mFooterText);
+ } else {
+ mFooterTextView.setText(R.string.lockpattern_need_to_unlock_footer);
+ }
+
+ mLockPatternView.setEnabled(true);
+ mLockPatternView.enableInput();
+ break;
+ case NeedToUnlockWrong:
+ if (mHeaderWrongText != null) {
+ mHeaderTextView.setText(mHeaderWrongText);
+ } else {
+ mHeaderTextView.setText(R.string.lockpattern_need_to_unlock_wrong);
+ }
+ if (mFooterWrongText != null) {
+ mFooterTextView.setText(mFooterWrongText);
+ } else {
+ mFooterTextView.setText(R.string.lockpattern_need_to_unlock_wrong_footer);
+ }
+
+ mLockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong);
+ mLockPatternView.setEnabled(true);
+ mLockPatternView.enableInput();
+ break;
+ case LockedOut:
+ mLockPatternView.clearPattern();
+ // enabled = false means: disable input, and have the
+ // appearance of being disabled.
+ mLockPatternView.setEnabled(false); // appearance of being disabled
+ break;
+ }
}
- public void onPatternCellAdded(List<Cell> pattern) {
+ private Runnable mClearPatternRunnable = new Runnable() {
+ public void run() {
+ mLockPatternView.clearPattern();
+ }
+ };
+ // clear the wrong pattern unless they have started a new one
+ // already
+ private void postClearPatternRunnable() {
+ mLockPatternView.removeCallbacks(mClearPatternRunnable);
+ mLockPatternView.postDelayed(mClearPatternRunnable, WRONG_PATTERN_CLEAR_TIMEOUT_MS);
}
- public void onPatternDetected(List<LockPatternView.Cell> pattern) {
- if (mLockPatternUtils.checkPattern(pattern)) {
- setResult(RESULT_OK);
- finish();
- } else {
- if (pattern.size() >= LockPatternUtils.MIN_PATTERN_REGISTER_FAIL &&
- ++mNumWrongConfirmAttempts >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) {
- long deadline = mLockPatternUtils.setLockoutAttemptDeadline();
- handleAttemptLockout(deadline);
- } else {
- updateStage(Stage.NeedToUnlockWrong);
- postClearPatternRunnable();
- }
+ /**
+ * The pattern listener that responds according to a user confirming
+ * an existing lock pattern.
+ */
+ private LockPatternView.OnPatternListener mConfirmExistingLockPatternListener
+ = new LockPatternView.OnPatternListener() {
+
+ public void onPatternStart() {
+ mLockPatternView.removeCallbacks(mClearPatternRunnable);
}
- }
- };
-
-
- private void handleAttemptLockout(long elapsedRealtimeDeadline) {
- updateStage(Stage.LockedOut);
- long elapsedRealtime = SystemClock.elapsedRealtime();
- mCountdownTimer = new CountDownTimer(
- elapsedRealtimeDeadline - elapsedRealtime,
- LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) {
-
- @Override
- public void onTick(long millisUntilFinished) {
- mHeaderTextView.setText(R.string.lockpattern_too_many_failed_confirmation_attempts_header);
- final int secondsCountdown = (int) (millisUntilFinished / 1000);
- mFooterTextView.setText(getString(
- R.string.lockpattern_too_many_failed_confirmation_attempts_footer,
- secondsCountdown));
+
+ public void onPatternCleared() {
+ mLockPatternView.removeCallbacks(mClearPatternRunnable);
}
- @Override
- public void onFinish() {
- mNumWrongConfirmAttempts = 0;
- updateStage(Stage.NeedToUnlock);
+ public void onPatternCellAdded(List<Cell> pattern) {
+
}
- }.start();
+
+ public void onPatternDetected(List<LockPatternView.Cell> pattern) {
+ if (mLockPatternUtils.checkPattern(pattern)) {
+ getActivity().setResult(Activity.RESULT_OK);
+ getActivity().finish();
+ } else {
+ if (pattern.size() >= LockPatternUtils.MIN_PATTERN_REGISTER_FAIL &&
+ ++mNumWrongConfirmAttempts
+ >= LockPatternUtils.FAILED_ATTEMPTS_BEFORE_TIMEOUT) {
+ long deadline = mLockPatternUtils.setLockoutAttemptDeadline();
+ handleAttemptLockout(deadline);
+ } else {
+ updateStage(Stage.NeedToUnlockWrong);
+ postClearPatternRunnable();
+ }
+ }
+ }
+ };
+
+
+ private void handleAttemptLockout(long elapsedRealtimeDeadline) {
+ updateStage(Stage.LockedOut);
+ long elapsedRealtime = SystemClock.elapsedRealtime();
+ mCountdownTimer = new CountDownTimer(
+ elapsedRealtimeDeadline - elapsedRealtime,
+ LockPatternUtils.FAILED_ATTEMPT_COUNTDOWN_INTERVAL_MS) {
+
+ @Override
+ public void onTick(long millisUntilFinished) {
+ mHeaderTextView.setText(R.string.lockpattern_too_many_failed_confirmation_attempts_header);
+ final int secondsCountdown = (int) (millisUntilFinished / 1000);
+ mFooterTextView.setText(getString(
+ R.string.lockpattern_too_many_failed_confirmation_attempts_footer,
+ secondsCountdown));
+ }
+
+ @Override
+ public void onFinish() {
+ mNumWrongConfirmAttempts = 0;
+ updateStage(Stage.NeedToUnlock);
+ }
+ }.start();
+ }
}
}