Don't use ResolveInfo for app settings ui
This commit is contained in:
parent
94ee36a38d
commit
5cb380bf47
5 changed files with 90 additions and 41 deletions
|
@ -38,6 +38,8 @@ public class AutofillFragment extends DialogFragment {
|
||||||
// need to interact with the recyclerAdapter which is a member of activity
|
// need to interact with the recyclerAdapter which is a member of activity
|
||||||
final AutofillPreferenceActivity callingActivity = (AutofillPreferenceActivity) getActivity();
|
final AutofillPreferenceActivity callingActivity = (AutofillPreferenceActivity) getActivity();
|
||||||
LayoutInflater inflater = callingActivity.getLayoutInflater();
|
LayoutInflater inflater = callingActivity.getLayoutInflater();
|
||||||
|
|
||||||
|
// if... hide textview
|
||||||
final View view = inflater.inflate(R.layout.fragment_autofill, null);
|
final View view = inflater.inflate(R.layout.fragment_autofill, null);
|
||||||
|
|
||||||
builder.setView(view);
|
builder.setView(view);
|
||||||
|
@ -74,6 +76,7 @@ public class AutofillFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// if... autofill_web
|
||||||
SharedPreferences prefs
|
SharedPreferences prefs
|
||||||
= getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
|
= getActivity().getApplicationContext().getSharedPreferences("autofill", Context.MODE_PRIVATE);
|
||||||
String preference = prefs.getString(packageName, "");
|
String preference = prefs.getString(packageName, "");
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package com.zeapo.pwdstore.autofill;
|
package com.zeapo.pwdstore.autofill;
|
||||||
|
|
||||||
import android.app.DialogFragment;
|
import android.app.DialogFragment;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.design.widget.FloatingActionButton;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
@ -14,15 +16,15 @@ 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;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.zeapo.pwdstore.R;
|
import com.zeapo.pwdstore.R;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class AutofillPreferenceActivity extends AppCompatActivity {
|
public class AutofillPreferenceActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
@ -58,6 +60,13 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
setTitle("Autofill Apps");
|
setTitle("Autofill Apps");
|
||||||
|
|
||||||
|
final FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||||
|
fab.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private class populateTask extends AsyncTask<Void, Void, Void> {
|
private class populateTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
@ -70,15 +79,25 @@ public class AutofillPreferenceActivity extends AppCompatActivity {
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||||
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
intent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||||
List<ResolveInfo> allApps = pm.queryIntentActivities(intent, 0);
|
List<ResolveInfo> allAppsResolveInfo = pm.queryIntentActivities(intent, 0);
|
||||||
|
List<AutofillRecyclerAdapter.AppInfo> allApps = new ArrayList<>();
|
||||||
|
|
||||||
HashMap<String, Pair<Drawable, String>> iconMap = new HashMap<>(allApps.size());
|
for (ResolveInfo app : allAppsResolveInfo) {
|
||||||
for (ResolveInfo app : allApps) {
|
allApps.add(new AutofillRecyclerAdapter.AppInfo(app.loadLabel(pm).toString()
|
||||||
iconMap.put(app.activityInfo.packageName
|
, app.activityInfo.packageName, app.loadIcon(pm)));
|
||||||
, Pair.create(app.loadIcon(pm), app.loadLabel(pm).toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
recyclerAdapter = new AutofillRecyclerAdapter(allApps, iconMap, pm, AutofillPreferenceActivity.this);
|
SharedPreferences prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE);
|
||||||
|
Map<String, ?> prefsMap = prefs.getAll();
|
||||||
|
for (String key : prefsMap.keySet()) {
|
||||||
|
try {
|
||||||
|
allApps.add(new AutofillRecyclerAdapter.AppInfo(null, key, pm.getApplicationIcon("com.android.browser")));
|
||||||
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
|
allApps.add(new AutofillRecyclerAdapter.AppInfo(null, key, null));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recyclerAdapter = new AutofillRecyclerAdapter(allApps, pm, AutofillPreferenceActivity.this);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,10 @@ package com.zeapo.pwdstore.autofill;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.v7.util.SortedList;
|
import android.support.v7.util.SortedList;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.util.SortedListAdapterCallback;
|
import android.support.v7.widget.util.SortedListAdapterCallback;
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -18,13 +16,12 @@ 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.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapter.ViewHolder> {
|
public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecyclerAdapter.ViewHolder> {
|
||||||
private SortedList<ResolveInfo> apps;
|
|
||||||
private ArrayList<ResolveInfo> allApps;
|
private SortedList<AppInfo> apps;
|
||||||
private HashMap<String, Pair<Drawable, String>> iconMap;
|
private ArrayList<AppInfo> allApps;
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private AutofillPreferenceActivity activity;
|
private AutofillPreferenceActivity activity;
|
||||||
|
|
||||||
|
@ -51,28 +48,39 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public AutofillRecyclerAdapter(List<ResolveInfo> allApps, HashMap<String, Pair<Drawable, String>> iconMap
|
public static class AppInfo {
|
||||||
, final PackageManager pm, AutofillPreferenceActivity activity) {
|
public String label;
|
||||||
SortedList.Callback<ResolveInfo> callback = new SortedListAdapterCallback<ResolveInfo>(this) {
|
public String packageName;
|
||||||
|
public Drawable icon;
|
||||||
|
|
||||||
|
public AppInfo(String label, String packageName, Drawable icon) {
|
||||||
|
this.label = label;
|
||||||
|
this.packageName = packageName;
|
||||||
|
this.icon = icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutofillRecyclerAdapter(List<AppInfo> allApps, final PackageManager pm
|
||||||
|
, AutofillPreferenceActivity activity) {
|
||||||
|
SortedList.Callback<AppInfo> callback = new SortedListAdapterCallback<AppInfo>(this) {
|
||||||
@Override
|
@Override
|
||||||
public int compare(ResolveInfo o1, ResolveInfo o2) {
|
public int compare(AppInfo o1, AppInfo o2) {
|
||||||
return o1.loadLabel(pm).toString().toLowerCase().compareTo(o2.loadLabel(pm).toString().toLowerCase());
|
return o1.label.toLowerCase().compareTo(o2.label.toLowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areContentsTheSame(ResolveInfo oldItem, ResolveInfo newItem) {
|
public boolean areContentsTheSame(AppInfo oldItem, AppInfo newItem) {
|
||||||
return oldItem.loadLabel(pm).toString().equals(newItem.loadLabel(pm).toString());
|
return oldItem.label.equals(newItem.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean areItemsTheSame(ResolveInfo item1, ResolveInfo item2) {
|
public boolean areItemsTheSame(AppInfo item1, AppInfo item2) {
|
||||||
return item1.loadLabel(pm).toString().equals(item2.loadLabel(pm).toString());
|
return item1.packageName.equals(item2.packageName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.apps = new SortedList<>(ResolveInfo.class, callback);
|
this.apps = new SortedList<>(AppInfo.class, callback);
|
||||||
this.apps.addAll(allApps);
|
this.apps.addAll(allApps);
|
||||||
this.allApps = new ArrayList<>(allApps);
|
this.allApps = new ArrayList<>(allApps);
|
||||||
this.iconMap = new HashMap<>(iconMap);
|
|
||||||
this.pm = pm;
|
this.pm = pm;
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
@ -86,11 +94,11 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(AutofillRecyclerAdapter.ViewHolder holder, int position) {
|
public void onBindViewHolder(AutofillRecyclerAdapter.ViewHolder holder, int position) {
|
||||||
ResolveInfo app = apps.get(position);
|
AppInfo app = apps.get(position);
|
||||||
holder.packageName = app.activityInfo.packageName;
|
holder.packageName = app.packageName;
|
||||||
|
|
||||||
holder.icon.setImageDrawable(iconMap.get(holder.packageName).first);
|
holder.icon.setImageDrawable(app.icon);
|
||||||
holder.name.setText(iconMap.get(holder.packageName).second);
|
holder.name.setText(app.label);
|
||||||
|
|
||||||
holder.secondary.setVisibility(View.VISIBLE);
|
holder.secondary.setVisibility(View.VISIBLE);
|
||||||
holder.view.setBackgroundResource(R.color.grey_white_1000);
|
holder.view.setBackgroundResource(R.color.grey_white_1000);
|
||||||
|
@ -126,7 +134,7 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
|
||||||
|
|
||||||
public int getPosition(String packageName) {
|
public int getPosition(String packageName) {
|
||||||
for (int i = 0; i < apps.size(); i++) {
|
for (int i = 0; i < apps.size(); i++) {
|
||||||
if (apps.get(i).activityInfo.packageName.equals(packageName)) {
|
if (apps.get(i).packageName.equals(packageName)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,8 +147,8 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter<AutofillRecycl
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
apps.beginBatchedUpdates();
|
apps.beginBatchedUpdates();
|
||||||
for (ResolveInfo app : allApps) {
|
for (AppInfo app : allApps) {
|
||||||
if (app.loadLabel(pm).toString().toLowerCase().contains(s.toLowerCase())) {
|
if (app.label.toLowerCase().contains(s.toLowerCase())) {
|
||||||
apps.add(app);
|
apps.add(app);
|
||||||
} else {
|
} else {
|
||||||
apps.remove(app);
|
apps.remove(app);
|
||||||
|
|
|
@ -159,6 +159,9 @@ public class AutofillService extends AccessibilityService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String searchWebView(AccessibilityNodeInfo source) {
|
private String searchWebView(AccessibilityNodeInfo source) {
|
||||||
|
if (source == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
for (int i = 0; i < source.getChildCount(); i++) {
|
for (int i = 0; i < source.getChildCount(); i++) {
|
||||||
AccessibilityNodeInfo u = source.getChild(i);
|
AccessibilityNodeInfo u = source.getChild(i);
|
||||||
if (u == null) {
|
if (u == null) {
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout 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="match_parent"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<android.support.v7.widget.RecyclerView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/autofill_recycler"
|
android:id="@+id/autofill_recycler"
|
||||||
|
@ -17,4 +18,19 @@
|
||||||
android:layout_centerInParent="true"
|
android:layout_centerInParent="true"
|
||||||
android:indeterminate="true"
|
android:indeterminate="true"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
<android.support.design.widget.FloatingActionButton
|
||||||
|
android:id="@+id/fab"
|
||||||
|
android:src="@drawable/ic_action_new"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
app:elevation="6dp"
|
||||||
|
app:pressedTranslationZ="12dp"
|
||||||
|
app:backgroundTint="@color/blue_grey_500"
|
||||||
|
app:rippleColor="@color/blue_grey_50"
|
||||||
|
app:borderWidth="0dp"
|
||||||
|
android:layout_margin="@dimen/fab_compat_margin"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_alignParentRight="true"/>
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
Loading…
Add table
Add a link
Reference in a new issue