Open settings from password fill dialog

This commit is contained in:
Matthew Wong 2015-08-10 16:58:28 -04:00
parent 42a971f348
commit 7c41795ded
5 changed files with 49 additions and 39 deletions

View file

@ -14,12 +14,11 @@ public class AutofillActivity extends AppCompatActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Intent intent = getIntent(); Bundle extras = getIntent().getExtras();
Bundle extras = intent.getExtras();
if (extras != null) { if (extras != null) {
try { try {
PendingIntent pi = intent.getExtras().getParcelable("pending_intent"); PendingIntent pi = extras.getParcelable("pending_intent");
if (pi == null) { if (pi == null) {
return; return;
} }

View file

@ -8,7 +8,6 @@ import android.content.pm.PackageManager;
import android.database.Cursor; import android.database.Cursor;
import android.database.MatrixCursor; import android.database.MatrixCursor;
import android.os.Bundle; import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -22,6 +21,8 @@ import android.widget.TextView;
import com.zeapo.pwdstore.R; import com.zeapo.pwdstore.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -57,6 +58,12 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
editor.remove(packageName).apply(); 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); recyclerAdapter = new AutofillRecyclerAdapter(apps, pm, this);
recyclerView.setAdapter(recyclerAdapter); recyclerView.setAdapter(recyclerAdapter);
@ -95,9 +102,7 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
// should be a better/faster way to do this? // should be a better/faster way to do this?
MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "package", "label"}); MatrixCursor matrixCursor = new MatrixCursor(new String[]{"_id", "package", "label"});
for (ApplicationInfo applicationInfo : allApps) { 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())) {
if (applicationInfo.loadLabel(pm).toString().toLowerCase().contains(newText.toLowerCase())
&& !recyclerAdapter.contains(applicationInfo.packageName)) {
matrixCursor.addRow(new Object[]{0, applicationInfo.packageName, applicationInfo.loadLabel(pm)}); matrixCursor.addRow(new Object[]{0, applicationInfo.packageName, applicationInfo.loadLabel(pm)});
} }
} }
@ -121,19 +126,26 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
Cursor cursor = searchView.getSuggestionsAdapter().getCursor(); Cursor cursor = searchView.getSuggestionsAdapter().getCursor();
String packageName = cursor.getString(1); String packageName = cursor.getString(1);
String appName = cursor.getString(2); String appName = cursor.getString(2);
showDialog(packageName, appName);
// similar to what happens in ViewHolder.onClick but position -1 return true;
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;
} }
}); });
setTitle("Autofill Apps"); 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");
} }
} }

View file

@ -40,13 +40,7 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
@Override @Override
public void onClick(View v) { public void onClick(View v) {
DialogFragment df = new AutofillFragment(); activity.showDialog(packageName, name.getText().toString());
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");
} }
} }
@ -90,15 +84,6 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
return apps.size(); 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) { public void add(String packageName) {
try { try {
ApplicationInfo app = pm.getApplicationInfo(packageName, 0); ApplicationInfo app = pm.getApplicationInfo(packageName, 0);
@ -108,4 +93,13 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
e.printStackTrace(); 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;
}
} }

View file

@ -123,7 +123,7 @@ public class AutofillService extends AccessibilityService {
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
applicationInfo = null; applicationInfo = null;
} }
String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString(); final String appName = (applicationInfo != null ? packageManager.getApplicationLabel(applicationInfo) : "").toString();
items = recursiveFilter(appName, null); items = recursiveFilter(appName, null);
if (items.isEmpty()) { if (items.isEmpty()) {
return; return;
@ -141,7 +141,11 @@ public class AutofillService extends AccessibilityService {
builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() { builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { 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(); dialog = builder.create();

View file

@ -1,15 +1,16 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="40dp"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingLeft="8dp" android:paddingLeft="8dp"
android:paddingRight="8dp"> android:paddingRight="8dp"
android:gravity="center_vertical">
<ImageView <ImageView
android:id="@android:id/icon1" android:id="@android:id/icon1"
android:layout_width="48dp" android:layout_width="24dp"
android:layout_height="48dp"/> android:layout_height="24dp"/>
<TextView android:id="@android:id/text1" <TextView android:id="@android:id/text1"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"