]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - BarCodeScanner/mobile/src/main/java/cz/cvut/fel/dce/barcodescanner/share/BookmarkPickerActivity.java
Initial commit
[hornmich/skoda-qr-demo.git] / BarCodeScanner / mobile / src / main / java / cz / cvut / fel / dce / barcodescanner / share / BookmarkPickerActivity.java
1 /*
2  * Copyright (C) 2008 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 cz.cvut.fel.dce.barcodescanner.share;
18
19 import android.app.ListActivity;
20 import android.content.Intent;
21 import android.database.Cursor;
22 import android.os.Bundle;
23 import android.provider.Browser;
24 import android.util.Log;
25 import android.view.View;
26 import android.widget.ListView;
27
28 /**
29  * This class is only needed because I can't successfully send an ACTION_PICK intent to
30  * com.android.browser.BrowserBookmarksPage. It can go away if that starts working in the future.
31  *
32  * @author dswitkin@google.com (Daniel Switkin)
33  */
34 public final class BookmarkPickerActivity extends ListActivity {
35
36   private static final String TAG = BookmarkPickerActivity.class.getSimpleName();
37
38   private static final String[] BOOKMARK_PROJECTION = {
39       Browser.BookmarkColumns.TITLE,
40       Browser.BookmarkColumns.URL
41   };
42
43   static final int TITLE_COLUMN = 0;
44   static final int URL_COLUMN = 1;
45
46   private static final String BOOKMARK_SELECTION = 
47       Browser.BookmarkColumns.BOOKMARK + " = 1 AND " + Browser.BookmarkColumns.URL + " IS NOT NULL";
48
49   private Cursor cursor;
50
51   @Override
52   protected void onCreate(Bundle icicle) {
53     super.onCreate(icicle);
54     cursor = getContentResolver().query(Browser.BOOKMARKS_URI, BOOKMARK_PROJECTION,
55         BOOKMARK_SELECTION, null, null);
56     if (cursor == null) {
57       Log.w(TAG, "No cursor returned for bookmark query");
58       finish();
59       return;
60     }
61     setListAdapter(new BookmarkAdapter(this, cursor));
62   }
63   
64   @Override
65   protected void onDestroy() {
66     if (cursor != null) {
67       cursor.close();
68     }
69     super.onDestroy();
70   }
71
72   @Override
73   protected void onListItemClick(ListView l, View view, int position, long id) {
74     if (!cursor.isClosed() && cursor.moveToPosition(position)) {
75       Intent intent = new Intent();
76       intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
77       intent.putExtra(Browser.BookmarkColumns.TITLE, cursor.getString(TITLE_COLUMN));
78       intent.putExtra(Browser.BookmarkColumns.URL, cursor.getString(URL_COLUMN));
79       setResult(RESULT_OK, intent);
80     } else {
81       setResult(RESULT_CANCELED);
82     }
83     finish();
84   }
85 }