+
+
+ /**
+ * Processes the pass code entered by the user just after the last digit was in.
+ *
+ * Takes into account the action requested to the activity, the currently saved pass code and the previously
+ * typed pass code, if any.
+ */
+ private void processFullPassCode() {
+ if (ACTION_REQUEST.equals(getIntent().getAction())) {
+ if (checkPassCode()) {
+ /// pass code accepted in request, user is allowed to access the app
+ finish();
+
+ } else {
+ showErrorAndRestart(R.string.pass_code_wrong, R.string.pass_code_enter_pass_code, View.INVISIBLE);
+ }
+
+ } else if (ACTION_DISABLE.equals(getIntent().getAction())) {
+ if (checkPassCode()) {
+ /// pass code accepted when disabling, pass code is removed
+ SharedPreferences.Editor appPrefs = PreferenceManager
+ .getDefaultSharedPreferences(getApplicationContext()).edit();
+ appPrefs.putBoolean("set_pincode", false); // TODO remove; this should be unnecessary, was done before entering in the activity
+ appPrefs.commit();
+
+ Toast.makeText(PassCodeActivity.this, R.string.pass_code_removed, Toast.LENGTH_LONG).show();
+ finish();
+
+ } else {
+ showErrorAndRestart(R.string.pass_code_wrong, R.string.pass_code_enter_pass_code, View.INVISIBLE);
+ }
+
+ } else if (ACTION_ENABLE.equals(getIntent().getAction())) {
+ /// enabling pass code
+ if (!mConfirmingPassCode) {
+ requestPassCodeConfirmation();
+
+ } else if (confirmPassCode()) {
+ /// confirmed: user typed the same pass code twice
+ savePassCodeAndExit();
+
+ } else {
+ showErrorAndRestart(
+ R.string.pass_code_mismatch, R.string.pass_code_configure_your_pass_code, View.VISIBLE
+ );
+ }
+ }
+ }
+
+
+ private void showErrorAndRestart(int errorMessage, int headerMessage, int explanationVisibility) {
+ Arrays.fill(mPassCodeDigits, null);
+ CharSequence errorSeq = getString(errorMessage);
+ Toast.makeText(this, errorSeq, Toast.LENGTH_LONG).show();
+ mPassCodeHdr.setText(headerMessage); // TODO check if really needed
+ mPassCodeHdrExplanation.setVisibility(explanationVisibility); // TODO check if really needed
+ clearBoxes();
+ }
+
+
+ /**
+ * Ask to the user for retyping the pass code just entered before saving it as the current pass code.
+ */
+ protected void requestPassCodeConfirmation(){
+ clearBoxes();