mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
App picker can be further simplified
git-svn-id: https://zxing.googlecode.com/svn/trunk@2617 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
ac23123ebf
commit
7f111e76f4
|
@ -20,32 +20,26 @@ import android.app.ListActivity;
|
|||
import android.content.Intent;
|
||||
import android.provider.Browser;
|
||||
import android.view.View;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.google.zxing.client.android.common.executor.AsyncTaskExecInterface;
|
||||
import com.google.zxing.client.android.common.executor.AsyncTaskExecManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class AppPickerActivity extends ListActivity {
|
||||
|
||||
private final List<AppInfo> labelsPackages;
|
||||
private LoadPackagesAsyncTask backgroundTask;
|
||||
private final AsyncTaskExecInterface taskExec;
|
||||
|
||||
public AppPickerActivity() {
|
||||
labelsPackages = Collections.synchronizedList(new ArrayList<AppInfo>());
|
||||
taskExec = new AsyncTaskExecManager().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
labelsPackages.clear();
|
||||
backgroundTask = new LoadPackagesAsyncTask(this);
|
||||
taskExec.execute(backgroundTask, labelsPackages);
|
||||
taskExec.execute(backgroundTask);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,8 +54,9 @@ public final class AppPickerActivity extends ListActivity {
|
|||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View view, int position, long id) {
|
||||
if (position >= 0 && position < labelsPackages.size()) {
|
||||
String packageName = labelsPackages.get(position).getPackageName();
|
||||
ListAdapter adapter = getListAdapter();
|
||||
if (position >= 0 && position < adapter.getCount()) {
|
||||
String packageName = ((AppInfo) adapter.getItem(position)).getPackageName();
|
||||
Intent intent = new Intent();
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||
intent.putExtra(Browser.BookmarkColumns.URL, "market://details?id=" + packageName);
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.widget.ImageView;
|
|||
import android.widget.ListAdapter;
|
||||
import com.google.zxing.client.android.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,7 +37,7 @@ import java.util.List;
|
|||
*
|
||||
* @author Sean Owen
|
||||
*/
|
||||
final class LoadPackagesAsyncTask extends AsyncTask<List<AppInfo>,Object,List<AppInfo>> {
|
||||
final class LoadPackagesAsyncTask extends AsyncTask<Void,Void,List<AppInfo>> {
|
||||
|
||||
private static final String[] PKG_PREFIX_WHITELIST = {
|
||||
"com.google.android.apps.",
|
||||
|
@ -55,8 +56,8 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<AppInfo>,Object,List<Ap
|
|||
}
|
||||
|
||||
@Override
|
||||
protected List<AppInfo> doInBackground(List<AppInfo>... objects) {
|
||||
List<AppInfo> labelsPackages = objects[0];
|
||||
protected List<AppInfo> doInBackground(Void... objects) {
|
||||
List<AppInfo> labelsPackages = new ArrayList<AppInfo>();
|
||||
PackageManager packageManager = activity.getPackageManager();
|
||||
List<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
|
||||
for (ApplicationInfo appInfo : appInfos) {
|
||||
|
@ -69,9 +70,7 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<AppInfo>,Object,List<Ap
|
|||
}
|
||||
}
|
||||
}
|
||||
synchronized (labelsPackages) {
|
||||
Collections.sort(labelsPackages);
|
||||
}
|
||||
return labelsPackages;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue