diff options
author | Matthew Wong <wongma@protonmail.ch> | 2015-08-10 16:58:28 -0400 |
---|---|---|
committer | Matthew Wong <wongma@protonmail.ch> | 2015-08-14 17:36:50 -0400 |
commit | 7c41795ded9aff01c46cc798687e62736d2233e7 (patch) | |
tree | 543850c202ccc52df6e3269bb52e2e304859002f | |
parent | 42a971f348b8c512db4603f4ca0b31c436651225 (diff) |
Open settings from password fill dialog
5 files changed, 49 insertions, 39 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java index 5a097d07..d8e50ebd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java @@ -14,12 +14,11 @@ public class AutofillActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Intent intent = getIntent(); - Bundle extras = intent.getExtras(); + Bundle extras = getIntent().getExtras(); if (extras != null) { try { - PendingIntent pi = intent.getExtras().getParcelable("pending_intent"); + PendingIntent pi = extras.getParcelable("pending_intent"); if (pi == null) { return; } 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 9dac9a07..89d3474e 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java @@ -8,7 +8,6 @@ import android.content.pm.PackageManager; import android.database.Cursor; import android.database.MatrixCursor; import android.os.Bundle; -import android.os.PersistableBundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; @@ -22,6 +21,8 @@ import android.widget.TextView; import com.zeapo.pwdstore.R; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Map; @@ -57,6 +58,12 @@ public class AutofillPreferenceActivity extends AppCompatActivity { editor.remove(packageName).apply(); } } + Collections.sort(apps, new Comparator<ApplicationInfo>() { + @Override + public int compare(ApplicationInfo lhs, ApplicationInfo rhs) { + return lhs.loadLabel(pm).toString().compareTo(rhs.loadLabel(pm).toString()); + } + }); recyclerAdapter = new AutofillRecyclerAdapter(apps, pm, this); recyclerView.setAdapter(recyclerAdapter); @@ -95,9 +102,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity { // should be a better/faster way to do this? MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "package", "label"}); for (ApplicationInfo applicationInfo : allApps) { - // exclude apps that already have settings; the search is just for adding - if (applicationInfo.loadLabel(pm).toString().toLowerCase().contains(newText.toLowerCase()) - && !recyclerAdapter.contains(applicationInfo.packageName)) { + if (applicationInfo.loadLabel(pm).toString().toLowerCase().contains(newText.toLowerCase())) { matrixCursor.addRow(new Object[]{0, applicationInfo.packageName, applicationInfo.loadLabel(pm)}); } } @@ -121,19 +126,26 @@ public class AutofillPreferenceActivity extends AppCompatActivity { Cursor cursor = searchView.getSuggestionsAdapter().getCursor(); String packageName = cursor.getString(1); String appName = cursor.getString(2); - - // similar to what happens in ViewHolder.onClick but position -1 - DialogFragment df = new AutofillFragment(); - Bundle args = new Bundle(); - args.putString("packageName", packageName); - args.putString("appName", appName); - args.putInt("position", -1); - df.setArguments(args); - df.show(getFragmentManager(), "autofill_dialog"); - return false; + showDialog(packageName, appName); + return true; } }); setTitle("Autofill Apps"); + + Bundle extras = getIntent().getExtras(); + if (extras != null) { + showDialog(extras.getString("packageName"), extras.getString("appName")); + } + } + + public void showDialog(String packageName, String appName) { + DialogFragment df = new AutofillFragment(); + Bundle args = new Bundle(); + args.putString("packageName", packageName); + args.putString("appName", appName); + args.putInt("position", recyclerAdapter.getPosition(packageName)); + df.setArguments(args); + df.show(getFragmentManager(), "autofill_dialog"); } } 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 b43f5d6e..26680152 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java @@ -40,13 +40,7 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl @Override public void onClick(View v) { - DialogFragment df = new AutofillFragment(); - Bundle args = new Bundle(); - args.putString("packageName", packageName); - args.putString("appName", name.getText().toString()); - args.putInt("position", getAdapterPosition()); - df.setArguments(args); - df.show(activity.getFragmentManager(), "autofill_dialog"); + activity.showDialog(packageName, name.getText().toString()); } } @@ -90,15 +84,6 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl return apps.size(); } - public boolean contains(String packageName) { - for (ApplicationInfo app : apps) { - if (app.packageName.equals(packageName)) { - return true; - } - } - return false; - } - public void add(String packageName) { try { ApplicationInfo app = pm.getApplicationInfo(packageName, 0); @@ -108,4 +93,13 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl e.printStackTrace(); } } + + public int getPosition(String packageName) { + for (int i = 0; i < apps.size(); i++) { + if (apps.get(i).packageName.equals(packageName)) { + return i; + } + } + return -1; + } } 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 b30277ba..37066b8f 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java @@ -123,7 +123,7 @@ public class AutofillService extends AccessibilityService { } catch (PackageManager.NameNotFoundException e) { applicationInfo = null; } - String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString(); + final String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString(); items = recursiveFilter(appName, null); if (items.isEmpty()) { return; @@ -141,7 +141,11 @@ public class AutofillService extends AccessibilityService { builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - + Intent intent = new Intent(AutofillService.this, AutofillPreferenceActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + intent.putExtra("packageName", info.getPackageName()); + intent.putExtra("appName", appName); + startActivity(intent); } }); dialog = builder.create(); diff --git a/app/src/main/res/layout/app_list_item.xml b/app/src/main/res/layout/app_list_item.xml index 7df28cc6..1a6c6e9b 100644 --- a/app/src/main/res/layout/app_list_item.xml +++ b/app/src/main/res/layout/app_list_item.xml @@ -1,15 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="40dp" android:orientation="horizontal" android:paddingLeft="8dp" - android:paddingRight="8dp"> + android:paddingRight="8dp" + android:gravity="center_vertical"> <ImageView android:id="@android:id/icon1" - android:layout_width="48dp" - android:layout_height="48dp"/> + android:layout_width="24dp" + android:layout_height="24dp"/> <TextView android:id="@android:id/text1" xmlns:android="http://schemas.android.com/apk/res/android" |