summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillActivity.java5
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java40
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java26
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/autofill/AutofillService.java8
-rw-r--r--app/src/main/res/layout/app_list_item.xml9
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"