From ebe1f831e7659b63b76c2b39498b68d1fec61673 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Fri, 14 Aug 2015 16:51:39 -0400 Subject: strings & enable service preference --- .../java/com/zeapo/pwdstore/UserPreference.java | 51 +++++++++++++++++++++- .../zeapo/pwdstore/autofill/AutofillFragment.java | 5 ++- .../pwdstore/autofill/AutofillRecyclerAdapter.java | 4 +- .../zeapo/pwdstore/autofill/AutofillService.java | 6 +-- app/src/main/res/layout/autofill_row_layout.xml | 2 - app/src/main/res/layout/fragment_autofill.xml | 8 ++-- app/src/main/res/values-cs/strings.xml | 2 +- app/src/main/res/values/strings.xml | 15 ++++++- app/src/main/res/xml/preference.xml | 14 +++--- 9 files changed, 85 insertions(+), 22 deletions(-) (limited to 'app/src/main') 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 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 - - diff --git a/app/src/main/res/layout/fragment_autofill.xml b/app/src/main/res/layout/fragment_autofill.xml index e5534f41..af2b7017 100644 --- a/app/src/main/res/layout/fragment_autofill.xml +++ b/app/src/main/res/layout/fragment_autofill.xml @@ -16,7 +16,7 @@ @@ -24,7 +24,7 @@ @@ -32,7 +32,7 @@ Zpráva : \n Rekurzivní filtrování Rekurzivní hledání hesel v aktuálním adresáři. + Zaplnit schránku 20krát Uložit dvacet náhodných textů do schránky namísto pouze jednoho. Užitečné pro telefony Samsug, které nabízejí funkci historie schránky. - Zaplnit schránku 20krát Generovat diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fa5358e2..447139fb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -117,8 +117,14 @@ Message : \n Recursive filtering Recursively find passwords of the current directory. + Enable autofill + Tap OK to go to Accessibility settings. Once there, tap Password Store under Services then tap the switch in the top right to turn it on or off. + Per-app settings + Customize autofill settings for specific apps. + Automatically match by default + Default to \'Automatically match\' for apps without custom settings. Otherwise, \'Never match.\' + Clear clipboard 20 times Store nonsense in the clipboard 20 times instead of just once. Useful on Samsung phones that feature clipboard history. - Clear clipboard 20 times Generate @@ -155,5 +161,10 @@ "Category: " - Auto-fills password fields in apps. Only works for Android versions 4.3 and up. Does not rely on the clipboard for Android versions 5.0 and up. + Autofills password fields in apps. Only works for Android versions 4.3 and up. Does not rely on the clipboard for Android versions 5.0 and up. + Fill + Use default setting + Automatically match + Match with… + Never match diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index e8ba80cc..1c977992 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -72,15 +72,19 @@ + + android:summary="@string/pref_autofill_apps_hint" + android:title="@string/pref_autofill_apps_title"/> + android:summary="@string/pref_autofill_default_hint" + android:title="@string/pref_autofill_default_title"/> @@ -88,6 +92,6 @@ android:defaultValue="false" android:key="clear_clipboard_20x" android:summary="@string/pref_clear_clipboard_hint" - android:title="@string/pref_clear_clipboard" /> + android:title="@string/pref_clear_clipboard_title" /> \ No newline at end of file -- cgit v1.2.3