mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
Slightly better app filtering
git-svn-id: https://zxing.googlecode.com/svn/trunk@1126 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
d1973dce0a
commit
1cd7c7e44c
|
@ -37,7 +37,11 @@ public final class AppPickerActivity extends ListActivity {
|
|||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
dialog = ProgressDialog.show(this, "", getString(R.string.msg_loading_apps), true, true);
|
||||
new LoadPackagesAsyncTask(this).execute(labelsPackages);
|
||||
if (labelsPackages.isEmpty()) {
|
||||
new LoadPackagesAsyncTask(this).execute(labelsPackages);
|
||||
}
|
||||
// otherwise use last copy we loaded -- apps don't change much, and it takes
|
||||
// forever to load for some reason
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -27,8 +27,24 @@ import java.util.Collections;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Loads a list of packages installed on the device asynchronously.
|
||||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<String[]>> {
|
||||
|
||||
private static final String[] PKG_PREFIX_WHITELIST = {
|
||||
"com.google.android.apps.",
|
||||
};
|
||||
private static final String[] PKG_PREFIX_BLACKLIST = {
|
||||
"com.android.",
|
||||
"android",
|
||||
"com.google.android.",
|
||||
"com.htc",
|
||||
};
|
||||
|
||||
|
||||
private final AppPickerActivity appPickerActivity;
|
||||
|
||||
LoadPackagesAsyncTask(AppPickerActivity appPickerActivity) {
|
||||
|
@ -58,10 +74,20 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<String[]>,Void,List<Str
|
|||
}
|
||||
|
||||
private static boolean isHidden(String packageName) {
|
||||
return packageName == null ||
|
||||
packageName.startsWith("com.android.") ||
|
||||
(packageName.startsWith("com.google.android.") &&
|
||||
!packageName.startsWith("com.google.android.apps."));
|
||||
if (packageName == null) {
|
||||
return true;
|
||||
}
|
||||
for (String prefix : PKG_PREFIX_WHITELIST) {
|
||||
if (packageName.startsWith(prefix)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (String prefix : PKG_PREFIX_BLACKLIST) {
|
||||
if (packageName.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue