summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorMatthew Wong <wongma@protonmail.ch>2015-08-14 16:51:39 -0400
committerMatthew Wong <wongma@protonmail.ch>2015-08-14 17:38:18 -0400
commitebe1f831e7659b63b76c2b39498b68d1fec61673 (patch)
tree7a74bb999bb882f27bf8e0e31a082f6df10bd0ea /app/src/main/java
parentb1807197f85c4d6ceccc3ca23654bb184f9caa13 (diff)
strings & enable service preference
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/UserPreference.java51
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java5
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java4
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java6
4 files changed, 58 insertions, 8 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
index cb2d2881..283d5f47 100644
--- a/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
+++ b/app/src/main/java/com/zeapo/pwdstore/UserPreference.java
@@ -1,17 +1,22 @@
package com.zeapo.pwdstore;
-import android.app.AlertDialog;
+import android.accessibilityservice.AccessibilityServiceInfo;
import android.app.DialogFragment;
+import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
+import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
+import android.provider.Settings;
+import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
+import android.view.accessibility.AccessibilityManager;
import android.widget.Toast;
import com.google.common.base.Function;
@@ -33,6 +38,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
public class UserPreference extends AppCompatActivity {
@@ -192,6 +198,30 @@ public class UserPreference extends AppCompatActivity {
return true;
}
});
+
+ findPreference("autofill_enable").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ new AlertDialog.Builder(callingActivity).
+ setTitle(R.string.pref_autofill_enable_title).
+ setMessage(R.string.pref_autofill_enable_msg).
+ setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
+ startActivity(intent);
+ }
+ }).
+ setNegativeButton(R.string.dialog_cancel,new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ ((CheckBoxPreference) findPreference("autofill_enable"))
+ .setChecked(((UserPreference) getActivity()).isServiceEnabled());
+ }
+ }).show();
+ return false;
+ }
+ });
}
@Override
@@ -199,6 +229,10 @@ public class UserPreference extends AppCompatActivity {
super.onStart();
final SharedPreferences sharedPreferences = getPreferenceManager().getSharedPreferences();
findPreference("ssh_see_key").setEnabled(sharedPreferences.getBoolean("use_generated_key", false));
+
+ // see if the autofill service is enabled and check the preference accordingly
+ ((CheckBoxPreference) findPreference("autofill_enable"))
+ .setChecked(((UserPreference) getActivity()).isServiceEnabled());
}
}
@@ -278,6 +312,21 @@ public class UserPreference extends AppCompatActivity {
sshKey.close();
}
+ // Returns whether the autofill service is enabled
+ private boolean isServiceEnabled() {
+ AccessibilityManager am = (AccessibilityManager) this
+ .getSystemService(Context.ACCESSIBILITY_SERVICE);
+ List<AccessibilityServiceInfo> runningServices = am
+ .getEnabledAccessibilityServiceList(AccessibilityServiceInfo.FEEDBACK_GENERIC);
+ for (AccessibilityServiceInfo service : runningServices) {
+ if ("com.zeapo.pwdstore/.autofill.AutofillService".equals(service.getId())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (resultCode == RESULT_OK) {
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
index c2a30ffe..8cf58206 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java
@@ -68,6 +68,7 @@ public class AutofillFragment extends DialogFragment {
View.OnClickListener matchPassword = new View.OnClickListener() {
@Override
public void onClick(View v) {
+ ((RadioButton) view.findViewById(R.id.match)).toggle();
Intent intent = new Intent(getActivity(), PasswordStore.class);
intent.putExtra("matchWith", true);
startActivityForResult(intent, MATCH_WITH);
@@ -77,7 +78,7 @@ public class AutofillFragment extends DialogFragment {
view.findViewById(R.id.matched).setOnClickListener(matchPassword);
final SharedPreferences.Editor editor = prefs.edit();
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ builder.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
RadioGroup radioGroup = (RadioGroup) view.findViewById(R.id.autofill_radiogroup);
@@ -105,7 +106,7 @@ public class AutofillFragment extends DialogFragment {
}
}
});
- builder.setNegativeButton("Cancel", null);
+ builder.setNegativeButton(R.string.dialog_cancel, null);
return builder.create();
}
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
index 01916650..8971c0af 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java
@@ -105,10 +105,10 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
holder.view.setBackgroundResource(R.color.indigo_50);
break;
case "first":
- holder.secondary.setText("Automatically match");
+ holder.secondary.setText(R.string.autofill_apps_first);
break;
case "never":
- holder.secondary.setText("Never match");
+ holder.secondary.setText(R.string.autofill_apps_never);
break;
default:
holder.secondary.setText("Match with " + preference);
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
index 1e64e8c8..cd318394 100644
--- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
+++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java
@@ -152,8 +152,8 @@ public class AutofillService extends AccessibilityService {
if (dialog == null) {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.Theme_AppCompat_Dialog);
- builder.setNegativeButton("Cancel", null);
- builder.setPositiveButton("Fill", new DialogInterface.OnClickListener() {
+ builder.setNegativeButton(R.string.dialog_cancel, null);
+ builder.setPositiveButton(R.string.autofill_fill, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
decryptAndVerify();
@@ -161,7 +161,7 @@ public class AutofillService extends AccessibilityService {
});
builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() {
@Override
- public void onClick(DialogInterface dialog, int which) {
+ public void onClick(DialogInterface dialog, int which) { //TODO make icon? gear?
// the user will have to return to the app themselves.
Intent intent = new Intent(AutofillService.this, AutofillPreferenceActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);