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