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