2 * Copyright (C) 2008 ZXing authors
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.google.zxing.client.android.share;
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.view.View;
25 import android.widget.ListAdapter;
26 import android.widget.ListView;
27 import android.widget.SimpleCursorAdapter;
28 import com.google.zxing.client.android.R;
31 * This class is only needed because I can't successfully send an ACTION_PICK intent to
32 * com.android.browser.BrowserBookmarksPage. It can go away if that starts working in the future.
34 * @author dswitkin@google.com (Daniel Switkin)
36 final class BookmarkPickerActivity extends ListActivity {
37 private static final String[] BOOKMARK_PROJECTION = {
38 Browser.BookmarkColumns.TITLE,
39 Browser.BookmarkColumns.URL
42 private static final int[] TWO_LINE_VIEW_IDS = {
47 private static final int TITLE_COLUMN = 0;
48 private static final int URL_COLUMN = 1;
50 // Without this selection, we'd get all the history entries too
51 private static final String BOOKMARK_SELECTION = "bookmark = 1";
53 private Cursor cursor;
56 protected void onCreate(Bundle icicle) {
57 super.onCreate(icicle);
59 cursor = getContentResolver().query(Browser.BOOKMARKS_URI, BOOKMARK_PROJECTION,
60 BOOKMARK_SELECTION, null, null);
61 startManagingCursor(cursor);
63 ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.bookmark_picker_list_item,
64 cursor, BOOKMARK_PROJECTION, TWO_LINE_VIEW_IDS);
65 setListAdapter(adapter);
69 protected void onListItemClick(ListView l, View view, int position, long id) {
70 if (cursor.moveToPosition(position)) {
71 Intent intent = new Intent();
72 intent.putExtra(Browser.BookmarkColumns.TITLE, cursor.getString(TITLE_COLUMN));
73 intent.putExtra(Browser.BookmarkColumns.URL, cursor.getString(URL_COLUMN));
74 setResult(RESULT_OK, intent);
76 setResult(RESULT_CANCELED);