From 8388d8530a63d1484607aa83faa27a99adb40f8e Mon Sep 17 00:00:00 2001 From: Matthew Wong Date: Fri, 14 Aug 2015 13:31:23 -0400 Subject: Load icons & labels async beforehand as well --- .../pwdstore/autofill/AutofillPreferenceActivity.java | 12 +++++++++++- .../zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java | 15 +++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) (limited to 'app/src') 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 1170d7b7..16867bcd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillPreferenceActivity.java @@ -4,6 +4,7 @@ import android.app.DialogFragment; import android.content.Intent; 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.v4.app.NavUtils; @@ -13,12 +14,14 @@ 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.List; public class AutofillPreferenceActivity extends AppCompatActivity { @@ -60,7 +63,14 @@ public class AutofillPreferenceActivity extends AppCompatActivity { Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); List allApps = pm.queryIntentActivities(intent, 0); - recyclerAdapter = new AutofillRecyclerAdapter(allApps, pm, AutofillPreferenceActivity.this); + + HashMap> iconMap = new HashMap<>(allApps.size()); + for (ResolveInfo app : allApps) { + iconMap.put(app.activityInfo.packageName + , Pair.create(app.loadIcon(pm), app.loadLabel(pm).toString())); + } + + recyclerAdapter = new AutofillRecyclerAdapter(allApps, iconMap, pm, AutofillPreferenceActivity.this); return null; } 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 2162b53d..01916650 100644 --- a/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/autofill/AutofillRecyclerAdapter.java @@ -4,9 +4,11 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.graphics.drawable.Drawable; import android.support.v7.util.SortedList; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.util.SortedListAdapterCallback; +import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -16,11 +18,13 @@ import android.widget.TextView; import com.zeapo.pwdstore.R; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class AutofillRecyclerAdapter extends RecyclerView.Adapter { private SortedList apps; private ArrayList allApps; + private HashMap> iconMap; private PackageManager pm; private AutofillPreferenceActivity activity; @@ -47,11 +51,12 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter allApps, final PackageManager pm, AutofillPreferenceActivity activity) { + public AutofillRecyclerAdapter(List allApps, HashMap> iconMap + , final PackageManager pm, AutofillPreferenceActivity activity) { SortedList.Callback callback = new SortedListAdapterCallback(this) { @Override public int compare(ResolveInfo o1, ResolveInfo o2) { - return o1.loadLabel(pm).toString().compareTo(o2.loadLabel(pm).toString()); + return o1.loadLabel(pm).toString().toLowerCase().compareTo(o2.loadLabel(pm).toString().toLowerCase()); } @Override @@ -67,6 +72,7 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter(ResolveInfo.class, callback); this.apps.addAll(allApps); this.allApps = new ArrayList<>(allApps); + this.iconMap = new HashMap<>(iconMap); this.pm = pm; this.activity = activity; } @@ -81,10 +87,11 @@ public class AutofillRecyclerAdapter extends RecyclerView.Adapter