|
@@ -24,6 +24,7 @@ package com.owncloud.android.ui.activity;
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
+import android.content.Intent;
|
|
import android.content.SharedPreferences;
|
|
import android.content.SharedPreferences;
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
import android.preference.PreferenceManager;
|
|
import android.preference.PreferenceManager;
|
|
@@ -45,18 +46,18 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
|
|
|
|
private static final String TAG = PassCodeActivity.class.getSimpleName();
|
|
private static final String TAG = PassCodeActivity.class.getSimpleName();
|
|
|
|
|
|
- public final static String ACTION_ENABLE = PassCodeActivity.class.getCanonicalName() +
|
|
|
|
- ".ENABLE";
|
|
|
|
- public final static String ACTION_DISABLE = PassCodeActivity.class.getCanonicalName() +
|
|
|
|
- ".DISABLE";
|
|
|
|
- public final static String ACTION_REQUEST = PassCodeActivity.class.getCanonicalName() +
|
|
|
|
- ".REQUEST";
|
|
|
|
|
|
+ public final static String ACTION_REQUEST_WITH_RESULT = "ACTION_REQUEST_WITH_RESULT";
|
|
|
|
+ public final static String ACTION_CHECK_WITH_RESULT = "ACTION_CHECK_WITH_RESULT";
|
|
|
|
+ public final static String ACTION_CHECK = "ACTION_CHECK";
|
|
|
|
+
|
|
|
|
+ public final static String KEY_PASSCODE = "KEY_PASSCODE";
|
|
|
|
+ public final static String KEY_CHECK_RESULT = "KEY_CHECK_RESULT";
|
|
|
|
|
|
private Button mBCancel;
|
|
private Button mBCancel;
|
|
private TextView mPassCodeHdr;
|
|
private TextView mPassCodeHdr;
|
|
private TextView mPassCodeHdrExplanation;
|
|
private TextView mPassCodeHdrExplanation;
|
|
private EditText[] mPassCodeEditTexts = new EditText[4];
|
|
private EditText[] mPassCodeEditTexts = new EditText[4];
|
|
-
|
|
|
|
|
|
+
|
|
private String [] mPassCodeDigits = {"","","",""};
|
|
private String [] mPassCodeDigits = {"","","",""};
|
|
private static String KEY_PASSCODE_DIGITS = "PASSCODE_DIGITS";
|
|
private static String KEY_PASSCODE_DIGITS = "PASSCODE_DIGITS";
|
|
private boolean mConfirmingPassCode = false;
|
|
private boolean mConfirmingPassCode = false;
|
|
@@ -88,13 +89,13 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
mPassCodeEditTexts[2] = (EditText) findViewById(R.id.txt2);
|
|
mPassCodeEditTexts[2] = (EditText) findViewById(R.id.txt2);
|
|
mPassCodeEditTexts[3] = (EditText) findViewById(R.id.txt3);
|
|
mPassCodeEditTexts[3] = (EditText) findViewById(R.id.txt3);
|
|
|
|
|
|
- if (ACTION_REQUEST.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ if (ACTION_CHECK.equals(getIntent().getAction())) {
|
|
/// this is a pass code request; the user has to input the right value
|
|
/// this is a pass code request; the user has to input the right value
|
|
mPassCodeHdr.setText(R.string.pass_code_enter_pass_code);
|
|
mPassCodeHdr.setText(R.string.pass_code_enter_pass_code);
|
|
mPassCodeHdrExplanation.setVisibility(View.INVISIBLE);
|
|
mPassCodeHdrExplanation.setVisibility(View.INVISIBLE);
|
|
setCancelButtonEnabled(false); // no option to cancel
|
|
setCancelButtonEnabled(false); // no option to cancel
|
|
|
|
|
|
- } else if (ACTION_ENABLE.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ } else if (ACTION_REQUEST_WITH_RESULT.equals(getIntent().getAction())) {
|
|
if (savedInstanceState != null) {
|
|
if (savedInstanceState != null) {
|
|
mConfirmingPassCode = savedInstanceState.getBoolean(PassCodeActivity.KEY_CONFIRMING_PASSCODE);
|
|
mConfirmingPassCode = savedInstanceState.getBoolean(PassCodeActivity.KEY_CONFIRMING_PASSCODE);
|
|
mPassCodeDigits = savedInstanceState.getStringArray(PassCodeActivity.KEY_PASSCODE_DIGITS);
|
|
mPassCodeDigits = savedInstanceState.getStringArray(PassCodeActivity.KEY_PASSCODE_DIGITS);
|
|
@@ -112,7 +113,7 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
setCancelButtonEnabled(true);
|
|
setCancelButtonEnabled(true);
|
|
}
|
|
}
|
|
|
|
|
|
- } else if (ACTION_DISABLE.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ } else if (ACTION_CHECK_WITH_RESULT.equals(getIntent().getAction())) {
|
|
/// pass code preference has just been disabled in Preferences;
|
|
/// pass code preference has just been disabled in Preferences;
|
|
// will confirm user knows pass code, then remove it
|
|
// will confirm user knows pass code, then remove it
|
|
mPassCodeHdr.setText(R.string.pass_code_remove_your_pass_code);
|
|
mPassCodeHdr.setText(R.string.pass_code_remove_your_pass_code);
|
|
@@ -284,7 +285,7 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
* the previously typed pass code, if any.
|
|
* the previously typed pass code, if any.
|
|
*/
|
|
*/
|
|
private void processFullPassCode() {
|
|
private void processFullPassCode() {
|
|
- if (ACTION_REQUEST.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ if (ACTION_CHECK.equals(getIntent().getAction())) {
|
|
if (checkPassCode()) {
|
|
if (checkPassCode()) {
|
|
/// pass code accepted in request, user is allowed to access the app
|
|
/// pass code accepted in request, user is allowed to access the app
|
|
finish();
|
|
finish();
|
|
@@ -294,24 +295,20 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
View.INVISIBLE);
|
|
View.INVISIBLE);
|
|
}
|
|
}
|
|
|
|
|
|
- } else if (ACTION_DISABLE.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ } else if (ACTION_CHECK_WITH_RESULT.equals(getIntent().getAction())) {
|
|
if (checkPassCode()) {
|
|
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();
|
|
|
|
|
|
|
|
|
|
+ Intent resultIntent = new Intent();
|
|
|
|
+ resultIntent.putExtra(KEY_CHECK_RESULT, true);
|
|
|
|
+ setResult(RESULT_OK, resultIntent);
|
|
|
|
+
|
|
|
|
+ finish();
|
|
} else {
|
|
} else {
|
|
showErrorAndRestart(R.string.pass_code_wrong, R.string.pass_code_enter_pass_code,
|
|
showErrorAndRestart(R.string.pass_code_wrong, R.string.pass_code_enter_pass_code,
|
|
View.INVISIBLE);
|
|
View.INVISIBLE);
|
|
}
|
|
}
|
|
|
|
|
|
- } else if (ACTION_ENABLE.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ } else if (ACTION_REQUEST_WITH_RESULT.equals(getIntent().getAction())) {
|
|
/// enabling pass code
|
|
/// enabling pass code
|
|
if (!mConfirmingPassCode) {
|
|
if (!mConfirmingPassCode) {
|
|
requestPassCodeConfirmation();
|
|
requestPassCodeConfirmation();
|
|
@@ -403,7 +400,7 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
|
|
|
|
/**
|
|
/**
|
|
* Overrides click on the BACK arrow to correctly cancel ACTION_ENABLE or ACTION_DISABLE, while
|
|
* Overrides click on the BACK arrow to correctly cancel ACTION_ENABLE or ACTION_DISABLE, while
|
|
- * preventing than ACTION_REQUEST may be worked around.
|
|
|
|
|
|
+ * preventing than ACTION_CHECK may be worked around.
|
|
*
|
|
*
|
|
* @param keyCode Key code of the key that triggered the down event.
|
|
* @param keyCode Key code of the key that triggered the down event.
|
|
* @param event Event triggered.
|
|
* @param event Event triggered.
|
|
@@ -412,8 +409,8 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
@Override
|
|
@Override
|
|
public boolean onKeyDown(int keyCode, KeyEvent event){
|
|
public boolean onKeyDown(int keyCode, KeyEvent event){
|
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount()== 0){
|
|
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount()== 0){
|
|
- if (ACTION_ENABLE.equals(getIntent().getAction()) ||
|
|
|
|
- ACTION_DISABLE.equals(getIntent().getAction())) {
|
|
|
|
|
|
+ if (ACTION_REQUEST_WITH_RESULT.equals(getIntent().getAction()) ||
|
|
|
|
+ ACTION_CHECK_WITH_RESULT.equals(getIntent().getAction())) {
|
|
revertActionAndExit();
|
|
revertActionAndExit();
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
@@ -427,16 +424,12 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
protected void savePassCodeAndExit() {
|
|
protected void savePassCodeAndExit() {
|
|
SharedPreferences.Editor appPrefs = PreferenceManager
|
|
SharedPreferences.Editor appPrefs = PreferenceManager
|
|
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
|
.getDefaultSharedPreferences(getApplicationContext()).edit();
|
|
-
|
|
|
|
- appPrefs.putString("PrefPinCode1", mPassCodeDigits[0]);
|
|
|
|
- appPrefs.putString("PrefPinCode2", mPassCodeDigits[1]);
|
|
|
|
- appPrefs.putString("PrefPinCode3", mPassCodeDigits[2]);
|
|
|
|
- appPrefs.putString("PrefPinCode4", mPassCodeDigits[3]);
|
|
|
|
- appPrefs.putBoolean("set_pincode", true); /// TODO remove; unnecessary,
|
|
|
|
- // Preferences did it before entering here
|
|
|
|
- appPrefs.commit();
|
|
|
|
-
|
|
|
|
- Toast.makeText(this, R.string.pass_code_stored, Toast.LENGTH_LONG).show();
|
|
|
|
|
|
+
|
|
|
|
+ Intent resultIntent = new Intent();
|
|
|
|
+ resultIntent.putExtra(KEY_PASSCODE,
|
|
|
|
+ mPassCodeDigits[0] + mPassCodeDigits[1] + mPassCodeDigits[2] + mPassCodeDigits[3]);
|
|
|
|
+
|
|
|
|
+ setResult(RESULT_OK, resultIntent);
|
|
finish();
|
|
finish();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -467,7 +460,6 @@ public class PassCodeActivity extends AppCompatActivity {
|
|
outState.putStringArray(PassCodeActivity.KEY_PASSCODE_DIGITS, mPassCodeDigits);
|
|
outState.putStringArray(PassCodeActivity.KEY_PASSCODE_DIGITS, mPassCodeDigits);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private class PassCodeDigitTextWatcher implements TextWatcher {
|
|
private class PassCodeDigitTextWatcher implements TextWatcher {
|
|
|
|
|
|
private int mIndex = -1;
|
|
private int mIndex = -1;
|