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.content.Intent;
|
||||||
import android.provider.Browser;
|
import android.provider.Browser;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ListAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
import com.google.zxing.client.android.common.executor.AsyncTaskExecInterface;
|
import com.google.zxing.client.android.common.executor.AsyncTaskExecInterface;
|
||||||
import com.google.zxing.client.android.common.executor.AsyncTaskExecManager;
|
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 {
|
public final class AppPickerActivity extends ListActivity {
|
||||||
|
|
||||||
private final List<AppInfo> labelsPackages;
|
|
||||||
private LoadPackagesAsyncTask backgroundTask;
|
private LoadPackagesAsyncTask backgroundTask;
|
||||||
private final AsyncTaskExecInterface taskExec;
|
private final AsyncTaskExecInterface taskExec;
|
||||||
|
|
||||||
public AppPickerActivity() {
|
public AppPickerActivity() {
|
||||||
labelsPackages = Collections.synchronizedList(new ArrayList<AppInfo>());
|
|
||||||
taskExec = new AsyncTaskExecManager().build();
|
taskExec = new AsyncTaskExecManager().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
labelsPackages.clear();
|
|
||||||
backgroundTask = new LoadPackagesAsyncTask(this);
|
backgroundTask = new LoadPackagesAsyncTask(this);
|
||||||
taskExec.execute(backgroundTask, labelsPackages);
|
taskExec.execute(backgroundTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,8 +54,9 @@ public final class AppPickerActivity extends ListActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View view, int position, long id) {
|
protected void onListItemClick(ListView l, View view, int position, long id) {
|
||||||
if (position >= 0 && position < labelsPackages.size()) {
|
ListAdapter adapter = getListAdapter();
|
||||||
String packageName = labelsPackages.get(position).getPackageName();
|
if (position >= 0 && position < adapter.getCount()) {
|
||||||
|
String packageName = ((AppInfo) adapter.getItem(position)).getPackageName();
|
||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
|
||||||
intent.putExtra(Browser.BookmarkColumns.URL, "market://details?id=" + packageName);
|
intent.putExtra(Browser.BookmarkColumns.URL, "market://details?id=" + packageName);
|
||||||
|
|
|
@ -28,6 +28,7 @@ import android.widget.ImageView;
|
||||||
import android.widget.ListAdapter;
|
import android.widget.ListAdapter;
|
||||||
import com.google.zxing.client.android.R;
|
import com.google.zxing.client.android.R;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author Sean Owen
|
* @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 = {
|
private static final String[] PKG_PREFIX_WHITELIST = {
|
||||||
"com.google.android.apps.",
|
"com.google.android.apps.",
|
||||||
|
@ -55,8 +56,8 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<AppInfo>,Object,List<Ap
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<AppInfo> doInBackground(List<AppInfo>... objects) {
|
protected List<AppInfo> doInBackground(Void... objects) {
|
||||||
List<AppInfo> labelsPackages = objects[0];
|
List<AppInfo> labelsPackages = new ArrayList<AppInfo>();
|
||||||
PackageManager packageManager = activity.getPackageManager();
|
PackageManager packageManager = activity.getPackageManager();
|
||||||
List<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
|
List<ApplicationInfo> appInfos = packageManager.getInstalledApplications(0);
|
||||||
for (ApplicationInfo appInfo : appInfos) {
|
for (ApplicationInfo appInfo : appInfos) {
|
||||||
|
@ -69,9 +70,7 @@ final class LoadPackagesAsyncTask extends AsyncTask<List<AppInfo>,Object,List<Ap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
synchronized (labelsPackages) {
|
Collections.sort(labelsPackages);
|
||||||
Collections.sort(labelsPackages);
|
|
||||||
}
|
|
||||||
return labelsPackages;
|
return labelsPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue