HAFRDialog: Add ability to only show Launcher Apps

Change-Id: I79499be92fb75ecf85357cccbf9193971789459a
Signed-off-by: Hưng Phan <phandinhhungvp2001@gmail.com>
This commit is contained in:
Christian Oder
2018-02-20 19:28:57 +01:00
committed by Hưng Phan
parent cebca8ba7d
commit 0387fc2a5f
2 changed files with 17 additions and 4 deletions

View File

@@ -35,6 +35,7 @@ public abstract class HAFRAppChooserAdapter extends BaseAdapter implements Filte
protected List<PackageInfo> mTemporarylist; protected List<PackageInfo> mTemporarylist;
boolean isUpdating; boolean isUpdating;
boolean hasLauncherFilter = false;
public HAFRAppChooserAdapter(Context context) { public HAFRAppChooserAdapter(Context context) {
mContext = context; mContext = context;
@@ -60,12 +61,16 @@ public abstract class HAFRAppChooserAdapter extends BaseAdapter implements Filte
item.icon = info.applicationInfo.loadIcon(mPackageManager); item.icon = info.applicationInfo.loadIcon(mPackageManager);
item.packageName = info.packageName; item.packageName = info.packageName;
final int index = Collections.binarySearch(temp, item); final int index = Collections.binarySearch(temp, item);
final boolean isLauncherApp =
mPackageManager.getLaunchIntentForPackage(info.packageName) != null;
if (!hasLauncherFilter || isLauncherApp) {
if (index < 0) { if (index < 0) {
temp.add((-index - 1), item); temp.add((-index - 1), item);
} else { } else {
temp.add((index + 1), item); temp.add((index + 1), item);
} }
} }
}
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
@@ -179,4 +184,8 @@ public abstract class HAFRAppChooserAdapter extends BaseAdapter implements Filte
ImageView icon; ImageView icon;
TextView pkg; TextView pkg;
} }
protected void setLauncherFilter(boolean enabled) {
hasLauncherFilter = enabled;
}
} }

View File

@@ -76,5 +76,9 @@ public abstract class HAFRAppChooserDialog extends Dialog {
show(); show();
} }
public void setLauncherFilter(boolean enabled) {
dAdapter.setLauncherFilter(enabled);
}
public abstract void onListViewItemClick(HAFRAppChooserAdapter.AppItem info, int id); public abstract void onListViewItemClick(HAFRAppChooserAdapter.AppItem info, int id);
} }