@Override protected void onDestroy() { if (loadingView != null) { loadingView.cancel(true); } super.onDestroy(); }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { /** * Use this hook instead of onBackPressed(), because onBackPressed() is not available in API 4. */ if (keyCode == KeyEvent.KEYCODE_BACK && LockPatternType.COMPARE_PATTERN == lockPatternType) { if (loadingView != null) { loadingView.cancel(true); } finishWithNegativeResult(RESULT_CANCELED); return true; } return super.onKeyDown(keyCode, event); }
private void executeLockPatternTask(final List<LockPatternView.Cell> pattern) { View view = progressView; if (view == null) { view = new Space(this); } final boolean hasExtra = getIntent().hasExtra(EXTRA_PATTERN); loadingView = new LoadingView<Void, Void, Object>(this, view) { @Override protected Object doInBackground(Void... params) { switch (lockPatternType) { case CREATE_PATTERN: if (!hasExtra) { return encrypter != null ? encrypter.encrypt(BaseActivity.this, pattern) : LockPatternUtils.patternToSha1(pattern).toCharArray(); } else { if (encrypter != null) { return pattern.equals( encrypter.decrypt( BaseActivity.this, getIntent().getCharArrayExtra(EXTRA_PATTERN))); } else { return Arrays.equals( getIntent().getCharArrayExtra(EXTRA_PATTERN), LockPatternUtils.patternToSha1(pattern).toCharArray()); } } case COMPARE_PATTERN: char[] currentPattern = getIntent().getCharArrayExtra(EXTRA_PATTERN); if (currentPattern == null) currentPattern = AlpSettings.Security.getPattern(BaseActivity.this); if (currentPattern != null) { if (encrypter != null) { return pattern.equals(encrypter.decrypt(BaseActivity.this, currentPattern)); } else { return Arrays.equals( currentPattern, LockPatternUtils.patternToSha1(pattern).toCharArray()); } } break; case VERIFY_CAPTCHA: return pattern.equals(getIntent().getParcelableArrayListExtra(EXTRA_PATTERN)); } return false; } @Override protected void onPostExecute(Object result) { super.onPostExecute(result); switch (lockPatternType) { case CREATE_PATTERN: if (!hasExtra) { getIntent().putExtra(EXTRA_PATTERN, (char[]) result); doLockPatternResult(ResuleType.PATTERN_CREATE); } else { if (!(Boolean) result) { lockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong); lockPatternView.postDelayed( mLockPatternViewReloader, DELAY_TIME_TO_RELOAD_LOCK_PATTERN_VIEW); doLockPatternResult(ResuleType.COMPARE_FAIL); } else { doLockPatternResult(ResuleType.COMPARE_OK); } } break; case COMPARE_PATTERN: case VERIFY_CAPTCHA: retryCount++; if (!(Boolean) result) { if (retryCount >= maxRetries) { // finishWithNegativeResult(RESULT_FAILED); } else { lockPatternView.setDisplayMode(LockPatternView.DisplayMode.Wrong); lockPatternView.postDelayed( mLockPatternViewReloader, DELAY_TIME_TO_RELOAD_LOCK_PATTERN_VIEW); } doLockPatternResult(ResuleType.COMPARE_FAIL); } else { // finishWithResultOk(null); doLockPatternResult(ResuleType.COMPARE_OK); } break; } } }; loadingView.execute(); }