PageRenderTime 18ms CodeModel.GetById 7ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/WebAccess/src/com/ideal/webreader/BookmarksActivity.java

http://eyes-free.googlecode.com/
Java | 97 lines | 66 code | 13 blank | 18 comment | 0 complexity | 7d2c926825866f1b3d1fd0bf69f6f3f3 MD5 | raw file
 1/*
 2 * Copyright (C) 2010 The IDEAL Group
 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
17package com.ideal.webreader;
18
19import com.ideal.webaccess.R;
20
21import android.app.Activity;
22import android.app.ListActivity;
23import android.content.Intent;
24import android.database.Cursor;
25import android.net.Uri;
26import android.os.Bundle;
27import android.provider.BaseColumns;
28import android.provider.Browser;
29import android.view.ContextMenu;
30import android.view.MenuItem;
31import android.view.View;
32import android.view.ContextMenu.ContextMenuInfo;
33import android.widget.ListView;
34import android.widget.SimpleCursorAdapter;
35import android.widget.AdapterView.AdapterContextMenuInfo;
36
37/**
38 * This class lists the users bookmarks.
39 */
40public class BookmarksActivity extends ListActivity {
41    private Cursor mCur;
42
43    @Override
44    public void onCreate(Bundle savedInstanceState) {
45        super.onCreate(savedInstanceState);
46        setContentView(R.layout.bookmarks);
47        String[] projection = new String[] {
48                BaseColumns._ID, Browser.BookmarkColumns.BOOKMARK, Browser.BookmarkColumns.TITLE,
49                Browser.BookmarkColumns.URL
50        };
51        String[] displayFields = new String[] {
52                Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL
53        };
54        int[] displayViews = new int[] {
55                android.R.id.text1, android.R.id.text2
56        };
57
58        String whereClause = Browser.BookmarkColumns.BOOKMARK + " = '1'";
59
60        mCur = managedQuery(android.provider.Browser.BOOKMARKS_URI, projection, whereClause, null,
61                null);
62        setListAdapter(new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, mCur,
63                displayFields, displayViews));
64
65        ListView lv = this.getListView();
66
67        registerForContextMenu(lv);
68
69        this.setResult(Activity.RESULT_CANCELED);
70    }
71
72    @Override
73    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
74        super.onCreateContextMenu(menu, v, menuInfo);
75        menu.add("Delete");
76    }
77
78    @Override
79    public boolean onContextItemSelected(MenuItem item) {
80        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
81        getContentResolver().delete(
82                Uri.parse(android.provider.Browser.BOOKMARKS_URI.toString() + "/" + info.id), null,
83                null);
84        return true;
85    }
86
87    @Override
88    public void onListItemClick(ListView l, View v, int position, long id) {
89        super.onListItemClick(l, v, position, id);
90        mCur.moveToPosition(position);
91        String url = mCur.getString(3);
92        Intent data = new Intent();
93        data.putExtra("URL", url);
94        this.setResult(Activity.RESULT_OK, data);
95        finish();
96    }
97}