64709197856d6acf0edff651a100c6e23a3f3c21
[zxing.git] / android / src / com / google / zxing / client / android / share / AppPickerActivity.java
1 /*
2  * Copyright (C) 2009 ZXing authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.google.zxing.client.android.share;
18
19 import android.app.ListActivity;
20 import android.app.ProgressDialog;
21 import android.content.Intent;
22 import android.os.Bundle;
23 import android.provider.Browser;
24 import android.view.View;
25 import android.widget.ListView;
26 import com.google.zxing.client.android.R;
27
28 import java.util.ArrayList;
29 import java.util.List;
30
31 public final class AppPickerActivity extends ListActivity {
32
33   private final List<String[]> labelsPackages = new ArrayList<String[]>();
34   private ProgressDialog dialog;
35
36   @Override
37   protected void onCreate(Bundle icicle) {
38     super.onCreate(icicle);
39     dialog = ProgressDialog.show(this, "", getString(R.string.msg_loading_apps), true, true);
40     if (labelsPackages.isEmpty()) {
41       new LoadPackagesAsyncTask(this).execute(labelsPackages);
42     }
43     // otherwise use last copy we loaded -- apps don't change much, and it takes
44     // forever to load for some reason
45   }
46
47   @Override
48   protected void onListItemClick(ListView l, View view, int position, long id) {
49     if (position >= 0 && position < labelsPackages.size()) {
50       String url = "market://search?q=pname:" + labelsPackages.get(position)[1];
51       Intent intent = new Intent();
52       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);      
53       intent.putExtra(Browser.BookmarkColumns.URL, url);
54       setResult(RESULT_OK, intent);
55     } else {
56       setResult(RESULT_CANCELED);
57     }
58     finish();
59   }
60
61   ProgressDialog getProgressDialog() {
62     return dialog;
63   }
64
65 }