@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lock_setup); lockPatternView = (LockPatternView) findViewById(R.id.lock_pattern); lockPatternView.setOnPatternListener(this); leftButton = (Button) findViewById(R.id.left_btn); rightButton = (Button) findViewById(R.id.right_btn); step = STEP_1; updateView(); }
private void updateView() { switch (step) { case STEP_1: leftButton.setText(R.string.cancel); rightButton.setText(""); rightButton.setEnabled(false); choosePattern = null; confirm = false; lockPatternView.clearPattern(); lockPatternView.enableInput(); break; case STEP_2: leftButton.setText(R.string.try_again); rightButton.setText(R.string.goon); rightButton.setEnabled(true); lockPatternView.disableInput(); break; case STEP_3: leftButton.setText(R.string.cancel); rightButton.setText(""); rightButton.setEnabled(false); lockPatternView.clearPattern(); lockPatternView.enableInput(); break; case STEP_4: leftButton.setText(R.string.cancel); if (confirm) { rightButton.setText(R.string.confirm); rightButton.setEnabled(true); lockPatternView.disableInput(); } else { rightButton.setText(""); lockPatternView.setDisplayMode(DisplayMode.Wrong); lockPatternView.enableInput(); rightButton.setEnabled(false); } break; default: break; } }
@Override public void onPatternDetected(List<Cell> pattern) { Log.d(TAG, "onPatternDetected"); if (pattern.size() < LockPatternView.MIN_LOCK_PATTERN_SIZE) { Toast.makeText(this, R.string.lockpattern_recording_incorrect_too_short, Toast.LENGTH_LONG) .show(); lockPatternView.setDisplayMode(DisplayMode.Wrong); return; } if (choosePattern == null) { choosePattern = new ArrayList<Cell>(pattern); // Log.d(TAG, "choosePattern = "+choosePattern.toString()); // Log.d(TAG, "choosePattern.size() = "+choosePattern.size()); Log.d(TAG, "choosePattern = " + Arrays.toString(choosePattern.toArray())); step = STEP_2; updateView(); return; } // [(row=1,clmn=0), (row=2,clmn=0), (row=1,clmn=1), (row=0,clmn=2)] // [(row=1,clmn=0), (row=2,clmn=0), (row=1,clmn=1), (row=0,clmn=2)] Log.d(TAG, "choosePattern = " + Arrays.toString(choosePattern.toArray())); Log.d(TAG, "pattern = " + Arrays.toString(pattern.toArray())); if (choosePattern.equals(pattern)) { // Log.d(TAG, "pattern = "+pattern.toString()); // Log.d(TAG, "pattern.size() = "+pattern.size()); Log.d(TAG, "pattern = " + Arrays.toString(pattern.toArray())); confirm = true; } else { confirm = false; } step = STEP_4; updateView(); }
private void initView() { lockPatternView = (LockPatternView) findViewById(R.id.lock_pattern); lockPatternView.setOnPatternListener(this); backBtn = (Button) this.findViewById(R.id.backBtn); backBtn.setOnClickListener(this); skipTextView = (TextView) this.findViewById(R.id.skipTextView); skipTextView.setOnClickListener(this); tipTextView = (TextView) this.findViewById(R.id.tipTextView); resetTextView = (TextView) this.findViewById(R.id.resetTextView); resetTextView.setOnClickListener(this); resetTextView.setVisibility(View.INVISIBLE); if (type == TYPE_MANAGE) { skipTextView.setVisibility(View.INVISIBLE); } if (type == TYPE_REGISTER) { backBtn.setVisibility(View.INVISIBLE); } }
// 绘制完成 @Override public void onPatternDetected(List<Cell> pattern) { Log.e(TAG, "onPatternDetected"); // 小于四个点。 if (pattern.size() < LockPatternView.MIN_LOCK_PATTERN_SIZE) { tipTextView.setText("最少连接" + LockPatternView.MIN_LOCK_PATTERN_SIZE + "个点,请重新绘制"); resetTextView.setVisibility(View.VISIBLE); resetTextView.setVisibility(View.INVISIBLE); lockPatternView.clearPattern(); return; } if (choosePattern == null) { choosePattern = new ArrayList<Cell>(pattern); Log.e(TAG, "choosePattern = " + Arrays.toString(choosePattern.toArray())); step = STEP_2; updateView(); return; } Log.e(TAG, "choosePattern = " + Arrays.toString(choosePattern.toArray())); Log.e(TAG, "pattern = " + Arrays.toString(pattern.toArray())); // 如果两次绘制相同 if (choosePattern.equals(pattern)) { Log.e(TAG, "pattern = " + Arrays.toString(pattern.toArray())); confirm = true; } else { confirm = false; } step = STEP_3; updateView(); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.left_btn: if (step == STEP_1 || step == STEP_3 || step == STEP_4) { finish(); } else if (step == STEP_2) { step = STEP_1; updateView(); } break; case R.id.right_btn: if (step == STEP_2) { step = STEP_3; updateView(); } else if (step == STEP_4) { Log.d("", "-----------------------------s---s----------------" + choosePattern); SharedPreferences preferences = getSharedPreferences(LOCK, MODE_PRIVATE); preferences .edit() .putString(LOCK_KEY, LockPatternView.patternToString(choosePattern)) .commit(); Intent intent = new Intent(this, LockActivity.class); startActivity(intent); finish(); } break; default: break; } }
private void updateView() { switch (step) { case STEP_1: { choosePattern = null; confirm = false; lockPatternView.clearPattern(); lockPatternView.enableInput(); resetTextView.setVisibility(View.INVISIBLE); tipTextView.setText("绘制解锁图案"); tipTextView.setVisibility(View.VISIBLE); } break; case STEP_2: { tipTextView.setText("再次绘制解锁图案"); tipTextView.setVisibility(View.VISIBLE); lockPatternView.clearPattern(); lockPatternView.enableInput(); } break; case STEP_3: { // 与第一次绘制的图案相同,成功! if (confirm) { lockPatternView.disableInput(); GestureLockUtil.setGestureLock(LockPatternView.patternToString(choosePattern)); // 跳转到别的界面 if (type == TYPE_MANAGE) { this.setResult(RESULT_OK); this.finish(); } else if (type == TYPE_REGISTER) { Intent intent = new Intent(this, KeeperMainActivity.class); this.startActivity(intent); this.finish(); } } else { // 与第一次绘制的图案不同, resetTextView.setVisibility(View.VISIBLE); tipTextView.setText("与上一次绘制不一致,请重新绘制"); tipTextView.setVisibility(View.VISIBLE); shakeTip(); lockPatternView.setDisplayMode(DisplayMode.Wrong); clearWrongMode(); lockPatternView.enableInput(); } } break; default: break; } }