From 5cb380bf471c6c7db1d165183296176d564c1ad3 Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Sun, 27 Dec 2015 06:00:06 -0500 Subject: Don't use ResolveInfo for app settings ui --- .../autofill/AutofillPreferenceActivity.java | 37 ++++++++++++++++------ 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java') 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 adfce0b1..0c721012 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java @@ -1,12 +1,14 @@ package com.zeapo.pwdstore.autofill; import android.app.DialogFragment; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; -import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.NavUtils; import android.support.v4.app.TaskStackBuilder; 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.RecyclerView; import android.support.v7.widget.SearchView; -import android.util.Pair; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.zeapo.pwdstore.R; -import java.util.HashMap; +import java.util.ArrayList; import java.util.List; +import java.util.Map; public class AutofillPreferenceActivity extends AppCompatActivity { @@ -58,6 +60,13 @@ public class AutofillPreferenceActivity extends AppCompatActivity { } 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 { @@ -70,15 +79,25 @@ public class AutofillPreferenceActivity extends AppCompatActivity { protected Void doInBackground(Void... params) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); - List allApps = pm.queryIntentActivities(intent, 0); + List allAppsResolveInfo = pm.queryIntentActivities(intent, 0); + List allApps = new ArrayList<>(); - HashMap> iconMap = new HashMap<>(allApps.size()); - for (ResolveInfo app : allApps) { - iconMap.put(app.activityInfo.packageName - , Pair.create(app.loadIcon(pm), app.loadLabel(pm).toString())); + for (ResolveInfo app : allAppsResolveInfo) { + allApps.add(new AutofillRecyclerAdapter.AppInfo(app.loadLabel(pm).toString() + , app.activityInfo.packageName, app.loadIcon(pm))); + } + + SharedPreferences prefs = getSharedPreferences("autofill_web", Context.MODE_PRIVATE); + Map 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, iconMap, pm, AutofillPreferenceActivity.this); + recyclerAdapter = new AutofillRecyclerAdapter(allApps, pm, AutofillPreferenceActivity.this); return null; } -- cgit v1.2.3