From b75190fcd7926c3994f8191996661c19b7b12466 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Tue, 11 Aug 2015 18:32:16 -0400 Subject: Add 'automatically match by default' setting; respect it & per-app settings when creating autofill dialog --- .../zeapo/pwdstore/autofill/AutofillFragment.java | 9 +++++++-- .../autofill/AutofillPreferenceActivity.java | 4 ++++ .../pwdstore/autofill/AutofillRecyclerAdapter.java | 7 ++++++- .../com/zeapo/pwdstore/autofill/AutofillService.java | 20 ++++++++++++++++++-- app/src/main/res/xml/preference.xml | 5 +++++ 5 files changed, 40 insertions(+), 5 deletions(-) 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 3e00edfb..ea4b0a2f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillFragment.java @@ -3,6 +3,7 @@ package com.zeapo.pwdstore.autofill; import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; +import android.preference.PreferenceManager; import android.support.v7.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; @@ -39,9 +40,14 @@ public class AutofillFragment extends DialogFragment { String appName = getArguments().getString("appName"); builder.setTitle(appName); + + // when an app is added for the first time, the radio button selection should reflect + // the autofill_default setting: hence, defValue + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(callingActivity); + String defValue = settings.getBoolean("autofill_default", true) ? "first" : "never"; SharedPreferences prefs = getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE); - String preference = prefs.getString(packageName, "first"); + String preference = prefs.getString(packageName, defValue); switch (preference) { case "first": ((RadioButton) view.findViewById(R.id.first)).toggle(); @@ -57,7 +63,6 @@ public class AutofillFragment extends DialogFragment { View.OnClickListener matchPassword = new View.OnClickListener() { @Override public void onClick(View v) { - // TODO figure out UI for this Intent intent = new Intent(getActivity(), PasswordStore.class); intent.putExtra("matchWith", true); startActivityForResult(intent, MATCH_WITH); diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java index 89d3474e..10684f45 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java @@ -8,6 +8,7 @@ import android.content.pm.PackageManager; import android.database.Cursor; import android.database.MatrixCursor; import android.os.Bundle; +import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -100,6 +101,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity { @Override public boolean onQueryTextChange(String newText) { // should be a better/faster way to do this? + // TODO do this async probably. it lags. MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "package", "label"}); for (ApplicationInfo applicationInfo : allApps) { if (applicationInfo.loadLabel(pm).toString().toLowerCase().contains(newText.toLowerCase())) { @@ -147,5 +149,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity { args.putInt("position", recyclerAdapter.getPosition(packageName)); df.setArguments(args); df.show(getFragmentManager(), "autofill_dialog"); + + // TODO if called from dialog 'Settings' button, should activity finish at OK? } } 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 1b5e63b7..bd2835e5 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; +import android.preference.PreferenceManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -59,9 +60,13 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter(); + items.add(PasswordItem.newPassword(file.getName(), file)); + } if (items.isEmpty()) { return; } diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index 9a42bb3e..44e38916 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -76,6 +76,11 @@ android:key="autofill_apps" android:summary="Customize autofill settings for specific apps." android:title="Per-app settings"/> + -- cgit v1.2.3