The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 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.android.browser; |
| 18 | |
| 19 | import android.app.Activity; |
| 20 | import android.app.AlertDialog; |
| 21 | import android.content.DialogInterface; |
| 22 | import android.content.Intent; |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 23 | import android.content.SharedPreferences; |
| 24 | import android.content.SharedPreferences.Editor; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 25 | import android.graphics.Bitmap; |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 26 | import android.graphics.BitmapFactory; |
| 27 | import android.graphics.Canvas; |
| 28 | import android.graphics.Color; |
| 29 | import android.graphics.Paint; |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 30 | import android.graphics.Path; |
| 31 | import android.graphics.PorterDuff; |
| 32 | import android.graphics.PorterDuffXfermode; |
Patrick Scott | c0fdde9 | 2010-02-25 14:40:11 -0500 | [diff] [blame] | 33 | import android.graphics.Rect; |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 34 | import android.graphics.RectF; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 35 | import android.net.Uri; |
| 36 | import android.os.Bundle; |
| 37 | import android.os.Handler; |
| 38 | import android.os.Message; |
| 39 | import android.os.ServiceManager; |
| 40 | import android.provider.Browser; |
| 41 | import android.text.IClipboard; |
| 42 | import android.util.Log; |
| 43 | import android.view.ContextMenu; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 44 | import android.view.Menu; |
| 45 | import android.view.MenuInflater; |
| 46 | import android.view.MenuItem; |
| 47 | import android.view.View; |
| 48 | import android.view.ViewGroup; |
| 49 | import android.view.ContextMenu.ContextMenuInfo; |
| 50 | import android.widget.AdapterView; |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 51 | import android.widget.GridView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 52 | import android.widget.ListView; |
Leon Scroggins | feb941d | 2009-05-28 17:27:38 -0400 | [diff] [blame] | 53 | import android.widget.Toast; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 54 | |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 55 | /*package*/ enum BookmarkViewMode { NONE, GRID, LIST } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 56 | /** |
| 57 | * View showing the user's bookmarks in the browser. |
| 58 | */ |
| 59 | public class BrowserBookmarksPage extends Activity implements |
| 60 | View.OnCreateContextMenuListener { |
| 61 | |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 62 | private BookmarkViewMode mViewMode = BookmarkViewMode.NONE; |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 63 | private GridView mGridPage; |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 64 | private ListView mVerticalList; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 65 | private BrowserBookmarksAdapter mBookmarksAdapter; |
| 66 | private static final int BOOKMARKS_SAVE = 1; |
Leon Scroggins | 190095d | 2009-08-17 17:01:38 -0400 | [diff] [blame] | 67 | private boolean mDisableNewWindow; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 68 | private BookmarkItem mContextHeader; |
| 69 | private AddNewBookmark mAddHeader; |
| 70 | private boolean mCanceled = false; |
| 71 | private boolean mCreateShortcut; |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 72 | private boolean mMostVisited; |
| 73 | private View mEmptyView; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 74 | // XXX: There is no public string defining this intent so if Home changes |
| 75 | // the value, we have to update this string. |
| 76 | private static final String INSTALL_SHORTCUT = |
| 77 | "com.android.launcher.action.INSTALL_SHORTCUT"; |
| 78 | |
| 79 | private final static String LOGTAG = "browser"; |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 80 | private final static String PREF_BOOKMARK_VIEW_MODE = "pref_bookmark_view_mode"; |
| 81 | private final static String PREF_MOST_VISITED_VIEW_MODE = "pref_most_visited_view_mode"; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 82 | |
| 83 | @Override |
| 84 | public boolean onContextItemSelected(MenuItem item) { |
| 85 | // It is possible that the view has been canceled when we get to |
| 86 | // this point as back has a higher priority |
| 87 | if (mCanceled) { |
| 88 | return true; |
| 89 | } |
| 90 | AdapterView.AdapterContextMenuInfo i = |
| 91 | (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); |
| 92 | // If we have no menu info, we can't tell which item was selected. |
| 93 | if (i == null) { |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | switch (item.getItemId()) { |
| 98 | case R.id.new_context_menu_id: |
| 99 | saveCurrentPage(); |
| 100 | break; |
| 101 | case R.id.open_context_menu_id: |
| 102 | loadUrl(i.position); |
| 103 | break; |
| 104 | case R.id.edit_context_menu_id: |
| 105 | editBookmark(i.position); |
| 106 | break; |
| 107 | case R.id.shortcut_context_menu_id: |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 108 | final Intent send = createShortcutIntent(i.position); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 109 | send.setAction(INSTALL_SHORTCUT); |
| 110 | sendBroadcast(send); |
| 111 | break; |
| 112 | case R.id.delete_context_menu_id: |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 113 | if (mMostVisited) { |
| 114 | Browser.deleteFromHistory(getContentResolver(), |
| 115 | getUrl(i.position)); |
| 116 | refreshList(); |
| 117 | } else { |
| 118 | displayRemoveBookmarkDialog(i.position); |
| 119 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 120 | break; |
| 121 | case R.id.new_window_context_menu_id: |
| 122 | openInNewWindow(i.position); |
| 123 | break; |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 124 | case R.id.share_link_context_menu_id: |
Leon Scroggins | 96afcb1 | 2009-12-10 12:35:56 -0500 | [diff] [blame] | 125 | BrowserActivity.sharePage(BrowserBookmarksPage.this, |
| 126 | mBookmarksAdapter.getTitle(i.position), getUrl(i.position), |
| 127 | getFavicon(i.position), |
| 128 | mBookmarksAdapter.getScreenshot(i.position)); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 129 | break; |
| 130 | case R.id.copy_url_context_menu_id: |
| 131 | copy(getUrl(i.position)); |
Leon Scroggins | feb941d | 2009-05-28 17:27:38 -0400 | [diff] [blame] | 132 | break; |
| 133 | case R.id.homepage_context_menu_id: |
| 134 | BrowserSettings.getInstance().setHomePage(this, |
| 135 | getUrl(i.position)); |
| 136 | Toast.makeText(this, R.string.homepage_set, |
| 137 | Toast.LENGTH_LONG).show(); |
| 138 | break; |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 139 | // Only for the Most visited page |
| 140 | case R.id.save_to_bookmarks_menu_id: |
Leon Scroggins | c1f5759 | 2009-08-14 14:16:10 -0400 | [diff] [blame] | 141 | boolean isBookmark; |
| 142 | String name; |
| 143 | String url; |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 144 | if (mViewMode == BookmarkViewMode.GRID) { |
Leon Scroggins | c1f5759 | 2009-08-14 14:16:10 -0400 | [diff] [blame] | 145 | isBookmark = mBookmarksAdapter.getIsBookmark(i.position); |
| 146 | name = mBookmarksAdapter.getTitle(i.position); |
| 147 | url = mBookmarksAdapter.getUrl(i.position); |
| 148 | } else { |
| 149 | HistoryItem historyItem = ((HistoryItem) i.targetView); |
| 150 | isBookmark = historyItem.isBookmark(); |
| 151 | name = historyItem.getName(); |
| 152 | url = historyItem.getUrl(); |
| 153 | } |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 154 | // If the site is bookmarked, the item becomes remove from |
| 155 | // bookmarks. |
Leon Scroggins | c1f5759 | 2009-08-14 14:16:10 -0400 | [diff] [blame] | 156 | if (isBookmark) { |
Andrei Popescu | c952619 | 2009-09-23 15:52:16 +0100 | [diff] [blame] | 157 | Bookmarks.removeFromBookmarks(this, getContentResolver(), url, name); |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 158 | } else { |
Leon Scroggins | c1f5759 | 2009-08-14 14:16:10 -0400 | [diff] [blame] | 159 | Browser.saveBookmark(this, name, url); |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 160 | } |
| 161 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 162 | default: |
| 163 | return super.onContextItemSelected(item); |
| 164 | } |
| 165 | return true; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public void onCreateContextMenu(ContextMenu menu, View v, |
| 170 | ContextMenuInfo menuInfo) { |
| 171 | AdapterView.AdapterContextMenuInfo i = |
| 172 | (AdapterView.AdapterContextMenuInfo) menuInfo; |
| 173 | |
| 174 | MenuInflater inflater = getMenuInflater(); |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 175 | if (mMostVisited) { |
| 176 | inflater.inflate(R.menu.historycontext, menu); |
| 177 | } else { |
| 178 | inflater.inflate(R.menu.bookmarkscontext, menu); |
| 179 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 180 | |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 181 | if (0 == i.position && !mMostVisited) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 182 | menu.setGroupVisible(R.id.CONTEXT_MENU, false); |
| 183 | if (mAddHeader == null) { |
| 184 | mAddHeader = new AddNewBookmark(BrowserBookmarksPage.this); |
| 185 | } else if (mAddHeader.getParent() != null) { |
| 186 | ((ViewGroup) mAddHeader.getParent()). |
| 187 | removeView(mAddHeader); |
| 188 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 189 | mAddHeader.setUrl(getIntent().getStringExtra("url")); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 190 | menu.setHeaderView(mAddHeader); |
| 191 | return; |
| 192 | } |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 193 | if (mMostVisited) { |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 194 | if ((mViewMode == BookmarkViewMode.LIST |
| 195 | && ((HistoryItem) i.targetView).isBookmark()) |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 196 | || mBookmarksAdapter.getIsBookmark(i.position)) { |
| 197 | MenuItem item = menu.findItem( |
| 198 | R.id.save_to_bookmarks_menu_id); |
| 199 | item.setTitle(R.string.remove_from_bookmarks); |
| 200 | } |
| 201 | } else { |
| 202 | // The historycontext menu has no ADD_MENU group. |
| 203 | menu.setGroupVisible(R.id.ADD_MENU, false); |
| 204 | } |
Leon Scroggins | 190095d | 2009-08-17 17:01:38 -0400 | [diff] [blame] | 205 | if (mDisableNewWindow) { |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 206 | menu.findItem(R.id.new_window_context_menu_id).setVisible( |
| 207 | false); |
| 208 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 209 | if (mContextHeader == null) { |
| 210 | mContextHeader = new BookmarkItem(BrowserBookmarksPage.this); |
| 211 | } else if (mContextHeader.getParent() != null) { |
| 212 | ((ViewGroup) mContextHeader.getParent()). |
| 213 | removeView(mContextHeader); |
| 214 | } |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 215 | if (mViewMode == BookmarkViewMode.GRID) { |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 216 | mBookmarksAdapter.populateBookmarkItem(mContextHeader, |
| 217 | i.position); |
| 218 | } else { |
| 219 | BookmarkItem b = (BookmarkItem) i.targetView; |
| 220 | b.copyTo(mContextHeader); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 221 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 222 | menu.setHeaderView(mContextHeader); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Create a new BrowserBookmarksPage. |
| 227 | */ |
| 228 | @Override |
| 229 | protected void onCreate(Bundle icicle) { |
| 230 | super.onCreate(icicle); |
| 231 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 232 | if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) { |
| 233 | mCreateShortcut = true; |
| 234 | } |
Leon Scroggins | 190095d | 2009-08-17 17:01:38 -0400 | [diff] [blame] | 235 | mDisableNewWindow = getIntent().getBooleanExtra("disable_new_window", |
| 236 | false); |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 237 | mMostVisited = getIntent().getBooleanExtra("mostVisited", false); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 238 | |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 239 | if (mCreateShortcut) { |
| 240 | setTitle(R.string.browser_bookmarks_page_bookmarks_text); |
| 241 | } |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 242 | mHandler.obtainMessage(CREATE_ADAPTER).sendToTarget(); |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 243 | |
| 244 | setContentView(R.layout.empty_history); |
| 245 | mEmptyView = findViewById(R.id.empty_view); |
| 246 | mEmptyView.setVisibility(View.GONE); |
| 247 | |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 248 | SharedPreferences p = getPreferences(MODE_PRIVATE); |
| 249 | |
| 250 | // See if the user has set a preference for the view mode of their |
| 251 | // bookmarks. Otherwise default to grid mode. |
| 252 | BookmarkViewMode preference = BookmarkViewMode.NONE; |
| 253 | if (mMostVisited) { |
Leon Scroggins | b3968bb | 2009-10-16 09:04:16 -0400 | [diff] [blame] | 254 | // For the most visited page, only use list mode. |
| 255 | preference = BookmarkViewMode.LIST; |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 256 | } else { |
| 257 | preference = BookmarkViewMode.values()[p.getInt( |
| 258 | PREF_BOOKMARK_VIEW_MODE, BookmarkViewMode.GRID.ordinal())]; |
| 259 | } |
| 260 | switchViewMode(preference); |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 261 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 262 | |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 263 | /** |
| 264 | * Set the ContentView to be either the grid of thumbnails or the vertical |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 265 | * list. |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 266 | */ |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 267 | private void switchViewMode(BookmarkViewMode viewMode) { |
| 268 | if (mViewMode == viewMode) { |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 269 | return; |
| 270 | } |
| 271 | |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 272 | mViewMode = viewMode; |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 273 | |
| 274 | // Update the preferences to make the new view mode sticky. |
| 275 | Editor ed = getPreferences(MODE_PRIVATE).edit(); |
| 276 | if (mMostVisited) { |
| 277 | ed.putInt(PREF_MOST_VISITED_VIEW_MODE, mViewMode.ordinal()); |
| 278 | } else { |
| 279 | ed.putInt(PREF_BOOKMARK_VIEW_MODE, mViewMode.ordinal()); |
| 280 | } |
| 281 | ed.commit(); |
| 282 | |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 283 | if (mBookmarksAdapter != null) { |
| 284 | mBookmarksAdapter.switchViewMode(viewMode); |
| 285 | } |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 286 | if (mViewMode == BookmarkViewMode.GRID) { |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 287 | if (mGridPage == null) { |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 288 | mGridPage = new GridView(this); |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 289 | if (mBookmarksAdapter != null) { |
| 290 | mGridPage.setAdapter(mBookmarksAdapter); |
| 291 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 292 | mGridPage.setOnItemClickListener(mListener); |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 293 | mGridPage.setNumColumns(GridView.AUTO_FIT); |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 294 | mGridPage.setColumnWidth( |
| 295 | BrowserActivity.getDesiredThumbnailWidth(this)); |
Leon Scroggins | 89c6d36 | 2009-07-15 16:54:37 -0400 | [diff] [blame] | 296 | mGridPage.setFocusable(true); |
| 297 | mGridPage.setFocusableInTouchMode(true); |
| 298 | mGridPage.setSelector(android.R.drawable.gallery_thumb); |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 299 | float density = getResources().getDisplayMetrics().density; |
| 300 | mGridPage.setVerticalSpacing((int) (14 * density)); |
| 301 | mGridPage.setHorizontalSpacing((int) (8 * density)); |
| 302 | mGridPage.setStretchMode(GridView.STRETCH_SPACING); |
Leon Scroggins | bbe6d5b | 2009-09-28 12:01:00 -0400 | [diff] [blame] | 303 | mGridPage.setScrollBarStyle(View.SCROLLBARS_INSIDE_INSET); |
Leon Scroggins | f855161 | 2009-09-24 16:06:02 -0400 | [diff] [blame] | 304 | mGridPage.setDrawSelectorOnTop(true); |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 305 | if (mMostVisited) { |
| 306 | mGridPage.setEmptyView(mEmptyView); |
| 307 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 308 | if (!mCreateShortcut) { |
| 309 | mGridPage.setOnCreateContextMenuListener(this); |
| 310 | } |
| 311 | } |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 312 | addContentView(mGridPage, FULL_SCREEN_PARAMS); |
| 313 | if (mVerticalList != null) { |
| 314 | ViewGroup parent = (ViewGroup) mVerticalList.getParent(); |
| 315 | if (parent != null) { |
| 316 | parent.removeView(mVerticalList); |
| 317 | } |
| 318 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 319 | } else { |
| 320 | if (null == mVerticalList) { |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 321 | ListView listView = new ListView(this); |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 322 | if (mBookmarksAdapter != null) { |
| 323 | listView.setAdapter(mBookmarksAdapter); |
| 324 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 325 | listView.setDrawSelectorOnTop(false); |
| 326 | listView.setVerticalScrollBarEnabled(true); |
| 327 | listView.setOnItemClickListener(mListener); |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 328 | if (mMostVisited) { |
| 329 | listView.setEmptyView(mEmptyView); |
| 330 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 331 | if (!mCreateShortcut) { |
| 332 | listView.setOnCreateContextMenuListener(this); |
| 333 | } |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 334 | mVerticalList = listView; |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 335 | } |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 336 | addContentView(mVerticalList, FULL_SCREEN_PARAMS); |
| 337 | if (mGridPage != null) { |
| 338 | ViewGroup parent = (ViewGroup) mGridPage.getParent(); |
| 339 | if (parent != null) { |
| 340 | parent.removeView(mGridPage); |
| 341 | } |
| 342 | } |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 343 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 346 | private static final ViewGroup.LayoutParams FULL_SCREEN_PARAMS |
| 347 | = new ViewGroup.LayoutParams( |
Romain Guy | 15b8ec6 | 2010-01-08 15:06:43 -0800 | [diff] [blame] | 348 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 349 | ViewGroup.LayoutParams.MATCH_PARENT); |
Leon Scroggins | d87f85e | 2009-08-18 14:13:31 -0400 | [diff] [blame] | 350 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 351 | private static final int SAVE_CURRENT_PAGE = 1000; |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 352 | private static final int CREATE_ADAPTER = 1001; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 353 | private final Handler mHandler = new Handler() { |
| 354 | @Override |
| 355 | public void handleMessage(Message msg) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 356 | switch (msg.what) { |
| 357 | case SAVE_CURRENT_PAGE: |
| 358 | saveCurrentPage(); |
| 359 | break; |
| 360 | case CREATE_ADAPTER: |
| 361 | Intent intent = getIntent(); |
| 362 | mBookmarksAdapter = new BrowserBookmarksAdapter( |
| 363 | BrowserBookmarksPage.this, |
| 364 | intent.getStringExtra("url"), |
| 365 | intent.getStringExtra("title"), |
| 366 | (Bitmap) intent.getParcelableExtra("thumbnail"), |
| 367 | mCreateShortcut, |
| 368 | mMostVisited); |
| 369 | mBookmarksAdapter.switchViewMode(mViewMode); |
| 370 | if (mGridPage != null) { |
| 371 | mGridPage.setAdapter(mBookmarksAdapter); |
| 372 | } |
| 373 | if (mVerticalList != null) { |
| 374 | mVerticalList.setAdapter(mBookmarksAdapter); |
| 375 | } |
| 376 | break; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | }; |
| 380 | |
| 381 | private AdapterView.OnItemClickListener mListener = new AdapterView.OnItemClickListener() { |
| 382 | public void onItemClick(AdapterView parent, View v, int position, long id) { |
| 383 | // It is possible that the view has been canceled when we get to |
| 384 | // this point as back has a higher priority |
| 385 | if (mCanceled) { |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 386 | android.util.Log.e(LOGTAG, "item clicked when dismissing"); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 387 | return; |
| 388 | } |
| 389 | if (!mCreateShortcut) { |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 390 | if (0 == position && !mMostVisited) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 391 | // XXX: Work-around for a framework issue. |
| 392 | mHandler.sendEmptyMessage(SAVE_CURRENT_PAGE); |
| 393 | } else { |
| 394 | loadUrl(position); |
| 395 | } |
| 396 | } else { |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 397 | final Intent intent = createShortcutIntent(position); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 398 | setResultToParent(RESULT_OK, intent); |
| 399 | finish(); |
| 400 | } |
| 401 | } |
| 402 | }; |
| 403 | |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 404 | private Intent createShortcutIntent(int position) { |
| 405 | String url = getUrl(position); |
| 406 | String title = getBookmarkTitle(position); |
| 407 | Bitmap touchIcon = getTouchIcon(position); |
| 408 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 409 | final Intent i = new Intent(); |
The Android Open Source Project | f59ec87 | 2009-03-13 13:04:24 -0700 | [diff] [blame] | 410 | final Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, |
| 411 | Uri.parse(url)); |
| 412 | long urlHash = url.hashCode(); |
| 413 | long uniqueId = (urlHash << 32) | shortcutIntent.hashCode(); |
| 414 | shortcutIntent.putExtra(Browser.EXTRA_APPLICATION_ID, |
| 415 | Long.toString(uniqueId)); |
| 416 | i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 417 | i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title); |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 418 | // Use the apple-touch-icon if available |
| 419 | if (touchIcon != null) { |
| 420 | // Make a copy so we can modify the pixels. |
| 421 | Bitmap copy = touchIcon.copy(Bitmap.Config.ARGB_8888, true); |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 422 | Canvas canvas = new Canvas(copy); |
| 423 | |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 424 | // Construct a path from a round rect. This will allow drawing with |
| 425 | // an inverse fill so we can punch a hole using the round rect. |
| 426 | Path path = new Path(); |
| 427 | path.setFillType(Path.FillType.INVERSE_WINDING); |
Patrick Scott | 59ce830 | 2009-09-18 16:29:38 -0400 | [diff] [blame] | 428 | RectF rect = new RectF(0, 0, touchIcon.getWidth(), |
| 429 | touchIcon.getHeight()); |
| 430 | rect.inset(1, 1); |
| 431 | path.addRoundRect(rect, 8f, 8f, Path.Direction.CW); |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 432 | |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 433 | // Construct a paint that clears the outside of the rectangle and |
| 434 | // draw. |
| 435 | Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); |
| 436 | paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); |
| 437 | canvas.drawPath(path, paint); |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 438 | |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 439 | i.putExtra(Intent.EXTRA_SHORTCUT_ICON, copy); |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 440 | } else { |
| 441 | Bitmap favicon = getFavicon(position); |
| 442 | if (favicon == null) { |
| 443 | i.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, |
| 444 | Intent.ShortcutIconResource.fromContext( |
| 445 | BrowserBookmarksPage.this, |
| 446 | R.drawable.ic_launcher_shortcut_browser_bookmark)); |
| 447 | } else { |
| 448 | Bitmap icon = BitmapFactory.decodeResource(getResources(), |
Patrick Scott | c0fdde9 | 2010-02-25 14:40:11 -0500 | [diff] [blame] | 449 | R.drawable.ic_launcher_shortcut_browser_bookmark_icon); |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 450 | |
| 451 | // Make a copy of the regular icon so we can modify the pixels. |
| 452 | Bitmap copy = icon.copy(Bitmap.Config.ARGB_8888, true); |
| 453 | Canvas canvas = new Canvas(copy); |
| 454 | |
| 455 | // Make a Paint for the white background rectangle and for |
| 456 | // filtering the favicon. |
| 457 | Paint p = new Paint(Paint.ANTI_ALIAS_FLAG |
| 458 | | Paint.FILTER_BITMAP_FLAG); |
| 459 | p.setStyle(Paint.Style.FILL_AND_STROKE); |
| 460 | p.setColor(Color.WHITE); |
| 461 | |
Patrick Scott | c0fdde9 | 2010-02-25 14:40:11 -0500 | [diff] [blame] | 462 | final float density = |
| 463 | getResources().getDisplayMetrics().density; |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 464 | // Create a rectangle that is slightly wider than the favicon |
Patrick Scott | 4aff3aa | 2009-10-05 09:32:46 -0400 | [diff] [blame] | 465 | final float iconSize = 16 * density; // 16x16 favicon |
Patrick Scott | c0fdde9 | 2010-02-25 14:40:11 -0500 | [diff] [blame] | 466 | final float padding = 2 * density; // white padding around icon |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 467 | final float rectSize = iconSize + 2 * padding; |
Patrick Scott | c0fdde9 | 2010-02-25 14:40:11 -0500 | [diff] [blame] | 468 | |
| 469 | final Rect iconBounds = |
| 470 | new Rect(0, 0, icon.getWidth(), icon.getHeight()); |
| 471 | final float x = iconBounds.exactCenterX() - (rectSize / 2); |
| 472 | // Note: Subtract 2 dip from the y position since the box is |
| 473 | // slightly higher than center. Use padding since it is already |
| 474 | // 2 * density. |
| 475 | final float y = iconBounds.exactCenterY() - (rectSize / 2) |
| 476 | - padding; |
| 477 | RectF r = new RectF(x, y, x + rectSize, y + rectSize); |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 478 | |
| 479 | // Draw a white rounded rectangle behind the favicon |
| 480 | canvas.drawRoundRect(r, 2, 2, p); |
| 481 | |
| 482 | // Draw the favicon in the same rectangle as the rounded |
| 483 | // rectangle but inset by the padding |
| 484 | // (results in a 16x16 favicon). |
| 485 | r.inset(padding, padding); |
| 486 | canvas.drawBitmap(favicon, null, r, p); |
| 487 | i.putExtra(Intent.EXTRA_SHORTCUT_ICON, copy); |
| 488 | } |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 489 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 490 | // Do not allow duplicate items |
| 491 | i.putExtra("duplicate", false); |
| 492 | return i; |
| 493 | } |
| 494 | |
| 495 | private void saveCurrentPage() { |
| 496 | Intent i = new Intent(BrowserBookmarksPage.this, |
| 497 | AddBookmarkPage.class); |
| 498 | i.putExtras(getIntent()); |
| 499 | startActivityForResult(i, BOOKMARKS_SAVE); |
| 500 | } |
| 501 | |
| 502 | private void loadUrl(int position) { |
| 503 | Intent intent = (new Intent()).setAction(getUrl(position)); |
| 504 | setResultToParent(RESULT_OK, intent); |
| 505 | finish(); |
| 506 | } |
| 507 | |
| 508 | @Override |
| 509 | public boolean onCreateOptionsMenu(Menu menu) { |
| 510 | boolean result = super.onCreateOptionsMenu(menu); |
Leon Scroggins | b3968bb | 2009-10-16 09:04:16 -0400 | [diff] [blame] | 511 | if (!mCreateShortcut && !mMostVisited) { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 512 | MenuInflater inflater = getMenuInflater(); |
| 513 | inflater.inflate(R.menu.bookmarks, menu); |
| 514 | return true; |
| 515 | } |
| 516 | return result; |
| 517 | } |
| 518 | |
| 519 | @Override |
Leon Scroggins | 0c78650 | 2009-08-04 16:04:55 -0400 | [diff] [blame] | 520 | public boolean onPrepareOptionsMenu(Menu menu) { |
Leon Scroggins | 8382d99 | 2009-08-19 11:25:14 -0400 | [diff] [blame] | 521 | boolean result = super.onPrepareOptionsMenu(menu); |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 522 | if (mCreateShortcut || mMostVisited || mBookmarksAdapter == null |
Leon Scroggins | b3968bb | 2009-10-16 09:04:16 -0400 | [diff] [blame] | 523 | || mBookmarksAdapter.getCount() == 0) { |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 524 | // No need to show the menu if there are no items. |
Leon Scroggins | 8382d99 | 2009-08-19 11:25:14 -0400 | [diff] [blame] | 525 | return result; |
Leon Scroggins | a5d669e | 2009-08-05 14:07:58 -0400 | [diff] [blame] | 526 | } |
Leon Scroggins | fdd10d7 | 2009-09-25 13:01:45 -0400 | [diff] [blame] | 527 | MenuItem switchItem = menu.findItem(R.id.switch_mode_menu_id); |
| 528 | int titleResId; |
| 529 | int iconResId; |
| 530 | if (mViewMode == BookmarkViewMode.GRID) { |
| 531 | titleResId = R.string.switch_to_list; |
| 532 | iconResId = R.drawable.ic_menu_list; |
| 533 | } else { |
| 534 | titleResId = R.string.switch_to_thumbnails; |
| 535 | iconResId = R.drawable.ic_menu_thumbnail; |
| 536 | } |
| 537 | switchItem.setTitle(titleResId); |
| 538 | switchItem.setIcon(iconResId); |
Leon Scroggins | 0c78650 | 2009-08-04 16:04:55 -0400 | [diff] [blame] | 539 | return true; |
| 540 | } |
| 541 | |
| 542 | @Override |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 543 | public boolean onOptionsItemSelected(MenuItem item) { |
| 544 | switch (item.getItemId()) { |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 545 | case R.id.new_context_menu_id: |
| 546 | saveCurrentPage(); |
| 547 | break; |
| 548 | |
| 549 | case R.id.switch_mode_menu_id: |
Ben Murdoch | 328ea87 | 2009-09-16 13:33:29 +0100 | [diff] [blame] | 550 | if (mViewMode == BookmarkViewMode.GRID) { |
| 551 | switchViewMode(BookmarkViewMode.LIST); |
| 552 | } else { |
| 553 | switchViewMode(BookmarkViewMode.GRID); |
| 554 | } |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 555 | break; |
| 556 | |
| 557 | default: |
| 558 | return super.onOptionsItemSelected(item); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 559 | } |
| 560 | return true; |
| 561 | } |
| 562 | |
| 563 | private void openInNewWindow(int position) { |
| 564 | Bundle b = new Bundle(); |
| 565 | b.putBoolean("new_window", true); |
| 566 | setResultToParent(RESULT_OK, |
| 567 | (new Intent()).setAction(getUrl(position)).putExtras(b)); |
| 568 | |
| 569 | finish(); |
| 570 | } |
| 571 | |
| 572 | |
| 573 | private void editBookmark(int position) { |
| 574 | Intent intent = new Intent(BrowserBookmarksPage.this, |
| 575 | AddBookmarkPage.class); |
| 576 | intent.putExtra("bookmark", getRow(position)); |
| 577 | startActivityForResult(intent, BOOKMARKS_SAVE); |
| 578 | } |
| 579 | |
| 580 | @Override |
| 581 | protected void onActivityResult(int requestCode, int resultCode, |
| 582 | Intent data) { |
| 583 | switch(requestCode) { |
| 584 | case BOOKMARKS_SAVE: |
| 585 | if (resultCode == RESULT_OK) { |
| 586 | Bundle extras; |
| 587 | if (data != null && (extras = data.getExtras()) != null) { |
| 588 | // If there are extras, then we need to save |
| 589 | // the edited bookmark. This is done in updateRow() |
| 590 | String title = extras.getString("title"); |
| 591 | String url = extras.getString("url"); |
| 592 | if (title != null && url != null) { |
| 593 | mBookmarksAdapter.updateRow(extras); |
| 594 | } |
| 595 | } else { |
| 596 | // extras == null then a new bookmark was added to |
| 597 | // the database. |
| 598 | refreshList(); |
| 599 | } |
| 600 | } |
| 601 | break; |
| 602 | default: |
| 603 | break; |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | private void displayRemoveBookmarkDialog(int position) { |
| 608 | // Put up a dialog asking if the user really wants to |
| 609 | // delete the bookmark |
| 610 | final int deletePos = position; |
| 611 | new AlertDialog.Builder(this) |
| 612 | .setTitle(R.string.delete_bookmark) |
| 613 | .setIcon(android.R.drawable.ic_dialog_alert) |
| 614 | .setMessage(getText(R.string.delete_bookmark_warning).toString().replace( |
| 615 | "%s", getBookmarkTitle(deletePos))) |
| 616 | .setPositiveButton(R.string.ok, |
| 617 | new DialogInterface.OnClickListener() { |
| 618 | public void onClick(DialogInterface dialog, int whichButton) { |
| 619 | deleteBookmark(deletePos); |
| 620 | } |
| 621 | }) |
| 622 | .setNegativeButton(R.string.cancel, null) |
| 623 | .show(); |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | * Refresh the shown list after the database has changed. |
| 628 | */ |
Leon Scroggins | 892df31 | 2009-07-14 14:48:02 -0400 | [diff] [blame] | 629 | private void refreshList() { |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 630 | mBookmarksAdapter.refreshList(); |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * Return a hashmap representing the currently highlighted row. |
| 635 | */ |
| 636 | public Bundle getRow(int position) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 637 | return mBookmarksAdapter == null ? null |
| 638 | : mBookmarksAdapter.getRow(position); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /** |
| 642 | * Return the url of the currently highlighted row. |
| 643 | */ |
| 644 | public String getUrl(int position) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 645 | return mBookmarksAdapter == null ? null |
| 646 | : mBookmarksAdapter.getUrl(position); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 647 | } |
| 648 | |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 649 | /** |
| 650 | * Return the favicon of the currently highlighted row. |
| 651 | */ |
| 652 | public Bitmap getFavicon(int position) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 653 | return mBookmarksAdapter == null ? null |
| 654 | : mBookmarksAdapter.getFavicon(position); |
Patrick Scott | e09761e | 2009-03-24 20:43:37 -0700 | [diff] [blame] | 655 | } |
| 656 | |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 657 | private Bitmap getTouchIcon(int position) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 658 | return mBookmarksAdapter == null ? null |
| 659 | : mBookmarksAdapter.getTouchIcon(position); |
Patrick Scott | 3918d44 | 2009-08-04 13:22:29 -0400 | [diff] [blame] | 660 | } |
| 661 | |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 662 | private void copy(CharSequence text) { |
| 663 | try { |
| 664 | IClipboard clip = IClipboard.Stub.asInterface(ServiceManager.getService("clipboard")); |
| 665 | if (clip != null) { |
| 666 | clip.setClipboardText(text); |
| 667 | } |
| 668 | } catch (android.os.RemoteException e) { |
| 669 | Log.e(LOGTAG, "Copy failed", e); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | public String getBookmarkTitle(int position) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 674 | return mBookmarksAdapter == null ? null |
| 675 | : mBookmarksAdapter.getTitle(position); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /** |
| 679 | * Delete the currently highlighted row. |
| 680 | */ |
| 681 | public void deleteBookmark(int position) { |
Leon Scroggins | ea00257 | 2009-11-24 15:21:18 -0500 | [diff] [blame] | 682 | if (mBookmarksAdapter == null) return; |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 683 | mBookmarksAdapter.deleteRow(position); |
| 684 | } |
Grace Kloba | 5942df0 | 2009-09-18 11:48:29 -0700 | [diff] [blame] | 685 | |
| 686 | @Override |
| 687 | public void onBackPressed() { |
| 688 | setResultToParent(RESULT_CANCELED, null); |
| 689 | mCanceled = true; |
| 690 | super.onBackPressed(); |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 691 | } |
| 692 | |
Leon Scroggins | fde9746 | 2010-01-11 13:06:21 -0500 | [diff] [blame] | 693 | // This Activity is generally a sub-Activity of |
| 694 | // CombinedBookmarkHistoryActivity. In that situation, we need to pass our |
| 695 | // result code up to our parent. However, if someone calls this Activity |
| 696 | // directly, then this has no parent, and it needs to set it on itself. |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 697 | private void setResultToParent(int resultCode, Intent data) { |
Leon Scroggins | fde9746 | 2010-01-11 13:06:21 -0500 | [diff] [blame] | 698 | Activity parent = getParent(); |
| 699 | if (parent == null) { |
| 700 | setResult(resultCode, data); |
| 701 | } else { |
| 702 | ((CombinedBookmarkHistoryActivity) parent).setResultFromChild( |
| 703 | resultCode, data); |
| 704 | } |
The Android Open Source Project | 0c90888 | 2009-03-03 19:32:16 -0800 | [diff] [blame] | 705 | } |
| 706 | } |