Minor changes from code inspection results
[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.DialogInterface;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.provider.Browser;
25 import android.view.View;
26 import android.widget.ListView;
27 import com.google.zxing.client.android.R;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 public final class AppPickerActivity extends ListActivity {
33
34   private final List<String[]> labelsPackages = new ArrayList<String[]>();
35   private DialogInterface dialog;
36
37   @Override
38   protected void onCreate(Bundle icicle) {
39     super.onCreate(icicle);
40     dialog = ProgressDialog.show(this, "", getString(R.string.msg_loading_apps), true, true);
41     if (labelsPackages.isEmpty()) {
42       new LoadPackagesAsyncTask(this).execute(labelsPackages);
43     }
44     // otherwise use last copy we loaded -- apps don't change much, and it takes
45     // forever to load for some reason
46   }
47
48   @Override
49   protected void onListItemClick(ListView l, View view, int position, long id) {
50     if (position >= 0 && position < labelsPackages.size()) {
51       String url = "market://search?q=pname:" + labelsPackages.get(position)[1];
52       Intent intent = new Intent();
53       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);      
54       intent.putExtra(Browser.BookmarkColumns.URL, url);
55       setResult(RESULT_OK, intent);
56     } else {
57       setResult(RESULT_CANCELED);
58     }
59     finish();
60   }
61
62   DialogInterface getProgressDialog() {
63     return dialog;
64   }
65
66 }