blob: 2bfcbb4a406e400421b3d42af2ddabb24dd08448 [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
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
17package com.android.browser;
18
Leon Scroggins25230d72010-09-28 20:09:25 -040019import com.android.browser.provider.BrowserProvider2;
20
The Android Open Source Project0c908882009-03-03 19:32:16 -080021import android.app.Activity;
Leon Scroggins III052ce662010-09-13 14:44:16 -040022import android.app.LoaderManager;
The Android Open Source Project0c908882009-03-03 19:32:16 -080023import android.content.ContentResolver;
Michael Kolbd40ac1a2010-09-29 00:23:46 -070024import android.content.ContentUris;
Leon Scroggins III052ce662010-09-13 14:44:16 -040025import android.content.ContentValues;
26import android.content.Context;
27import android.content.CursorLoader;
Leon Scroggins III052ce662010-09-13 14:44:16 -040028import android.content.Loader;
Leon Scroggins25230d72010-09-28 20:09:25 -040029import android.content.SharedPreferences;
The Android Open Source Project0c908882009-03-03 19:32:16 -080030import android.content.res.Resources;
Patrick Scott3918d442009-08-04 13:22:29 -040031import android.database.Cursor;
Ben Murdochaac7aa62009-09-17 16:57:40 +010032import android.graphics.Bitmap;
Leon Scroggins02081942010-11-01 17:52:42 -040033import android.graphics.drawable.Drawable;
The Android Open Source Project0c908882009-03-03 19:32:16 -080034import android.net.ParseException;
Michael Kolbd40ac1a2010-09-29 00:23:46 -070035import android.net.Uri;
The Android Open Source Project0c908882009-03-03 19:32:16 -080036import android.net.WebAddress;
John Reckc8490812010-11-22 14:15:36 -080037import android.os.AsyncTask;
The Android Open Source Project0c908882009-03-03 19:32:16 -080038import android.os.Bundle;
Ben Murdoch1794fe22009-09-29 18:14:30 +010039import android.os.Handler;
40import android.os.Message;
Leon Scroggins25230d72010-09-28 20:09:25 -040041import android.preference.PreferenceManager;
Leon Scroggins III052ce662010-09-13 14:44:16 -040042import android.provider.BrowserContract;
Leon Scroggins25230d72010-09-28 20:09:25 -040043import android.text.TextUtils;
Leon Scroggins III052ce662010-09-13 14:44:16 -040044import android.view.KeyEvent;
45import android.view.LayoutInflater;
Leon Scroggins88d08032010-10-21 15:17:10 -040046import android.view.MenuItem;
The Android Open Source Project0c908882009-03-03 19:32:16 -080047import android.view.View;
Leon Scroggins III052ce662010-09-13 14:44:16 -040048import android.view.ViewGroup;
The Android Open Source Project0c908882009-03-03 19:32:16 -080049import android.view.Window;
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -040050import android.view.WindowManager;
Leon Scroggins III052ce662010-09-13 14:44:16 -040051import android.view.inputmethod.EditorInfo;
52import android.view.inputmethod.InputMethodManager;
53import android.widget.AdapterView;
54import android.widget.CursorAdapter;
The Android Open Source Project0c908882009-03-03 19:32:16 -080055import android.widget.EditText;
Leon Scroggins III052ce662010-09-13 14:44:16 -040056import android.widget.ListView;
Leon Scroggins88d08032010-10-21 15:17:10 -040057import android.widget.PopupMenu;
The Android Open Source Project0c908882009-03-03 19:32:16 -080058import android.widget.TextView;
59import android.widget.Toast;
60
Cary Clarkf2407c62009-09-04 12:25:10 -040061import java.net.URI;
62import java.net.URISyntaxException;
Leon Scroggins74dbe012010-10-15 10:54:27 -040063import java.util.Stack;
Leon Scroggins III052ce662010-09-13 14:44:16 -040064
65public class AddBookmarkPage extends Activity
66 implements View.OnClickListener, TextView.OnEditorActionListener,
Leon Scroggins74dbe012010-10-15 10:54:27 -040067 AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor>,
Leon Scroggins88d08032010-10-21 15:17:10 -040068 BreadCrumbView.Controller, PopupMenu.OnMenuItemClickListener {
The Android Open Source Project0c908882009-03-03 19:32:16 -080069
Michael Kolb370a4f32010-10-06 10:45:32 -070070 public static final long DEFAULT_FOLDER_ID = -1;
Leon Scrogginsbc922852010-10-22 12:15:27 -040071 public static final String TOUCH_ICON_URL = "touch_icon_url";
72 // Place on an edited bookmark to remove the saved thumbnail
73 public static final String REMOVE_THUMBNAIL = "remove_thumbnail";
74 public static final String USER_AGENT = "user_agent";
Michael Kolb370a4f32010-10-06 10:45:32 -070075
John Reckc8490812010-11-22 14:15:36 -080076 /* package */ static final String EXTRA_EDIT_BOOKMARK = "bookmark";
77 /* package */ static final String EXTRA_IS_FOLDER = "is_folder";
78
Leon Scroggins74dbe012010-10-15 10:54:27 -040079 private static final int MAX_CRUMBS_SHOWN = 2;
80
The Android Open Source Project0c908882009-03-03 19:32:16 -080081 private final String LOGTAG = "Bookmarks";
Leon Scroggins74dbe012010-10-15 10:54:27 -040082 // Set to true to see the crash on the code I would like to run.
83 private final boolean DEBUG_CRASH = false;
The Android Open Source Project0c908882009-03-03 19:32:16 -080084
Leon Scroggins III052ce662010-09-13 14:44:16 -040085 // IDs for the CursorLoaders that are used.
86 private final int LOADER_ID_FOLDER_CONTENTS = 0;
87 private final int LOADER_ID_ALL_FOLDERS = 1;
88
The Android Open Source Project0c908882009-03-03 19:32:16 -080089 private EditText mTitle;
90 private EditText mAddress;
91 private TextView mButton;
92 private View mCancelButton;
93 private boolean mEditingExisting;
John Reckc8490812010-11-22 14:15:36 -080094 private boolean mEditingFolder;
The Android Open Source Project0c908882009-03-03 19:32:16 -080095 private Bundle mMap;
Patrick Scott3918d442009-08-04 13:22:29 -040096 private String mTouchIconUrl;
Ben Murdochaac7aa62009-09-17 16:57:40 +010097 private String mOriginalUrl;
Leon Scroggins III052ce662010-09-13 14:44:16 -040098 private TextView mFolder;
99 private View mDefaultView;
100 private View mFolderSelector;
101 private EditText mFolderNamer;
102 private View mAddNewFolder;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400103 private View mAddSeparator;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400104 private long mCurrentFolder = 0;
105 private FolderAdapter mAdapter;
Leon Scroggins74dbe012010-10-15 10:54:27 -0400106 private BreadCrumbView mCrumbs;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400107 private TextView mFakeTitle;
108 private View mCrumbHolder;
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400109 private ListView mListView;
Leon Scroggins88d08032010-10-21 15:17:10 -0400110 private boolean mSaveToHomeScreen;
Leon Scroggins02081942010-11-01 17:52:42 -0400111 private long mRootFolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400112
113 private static class Folder {
114 String Name;
115 long Id;
116 Folder(String name, long id) {
117 Name = name;
118 Id = id;
119 }
120 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800121
Ben Murdoch1794fe22009-09-29 18:14:30 +0100122 // Message IDs
123 private static final int SAVE_BOOKMARK = 100;
Leon Scroggins88d08032010-10-21 15:17:10 -0400124 private static final int TOUCH_ICON_DOWNLOADED = 101;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100125
126 private Handler mHandler;
127
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100128 private InputMethodManager getInputMethodManager() {
129 return (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
130 }
131
Leon Scroggins III052ce662010-09-13 14:44:16 -0400132 @Override
Leon Scroggins74dbe012010-10-15 10:54:27 -0400133 public void onTop(int level, Object data) {
134 if (null == data) return;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400135 Folder folderData = (Folder) data;
136 long folder = folderData.Id;
137 Uri uri = BrowserContract.Bookmarks.buildFolderUri(folder);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400138 LoaderManager manager = getLoaderManager();
139 CursorLoader loader = (CursorLoader) ((Loader) manager.getLoader(
140 LOADER_ID_FOLDER_CONTENTS));
141 loader.setUri(uri);
142 loader.forceLoad();
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400143 if (mFolderNamer.getVisibility() == View.VISIBLE) {
144 completeOrCancelFolderNaming(true);
145 }
Leon Scroggins74dbe012010-10-15 10:54:27 -0400146 }
147
Leon Scroggins74dbe012010-10-15 10:54:27 -0400148 @Override
Leon Scroggins III052ce662010-09-13 14:44:16 -0400149 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
150 if (v == mFolderNamer) {
151 if (v.getText().length() > 0) {
152 if (actionId == EditorInfo.IME_NULL) {
153 // Only want to do this once.
154 if (event.getAction() == KeyEvent.ACTION_UP) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400155 completeOrCancelFolderNaming(false);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400156 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400157 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800158 }
Michael Kolb31829b92010-10-01 11:50:21 -0700159 // Steal the key press; otherwise a newline will be added
160 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800161 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400162 return false;
163 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800164
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400165 private void switchToDefaultView(boolean changedFolder) {
166 mFolderSelector.setVisibility(View.GONE);
167 mDefaultView.setVisibility(View.VISIBLE);
168 mCrumbHolder.setVisibility(View.GONE);
169 mFakeTitle.setVisibility(View.VISIBLE);
170 if (changedFolder) {
171 Object data = mCrumbs.getTopData();
172 if (data != null) {
173 Folder folder = (Folder) data;
174 mCurrentFolder = folder.Id;
Leon Scroggins02081942010-11-01 17:52:42 -0400175 int resource = mCurrentFolder == mRootFolder ?
176 R.drawable.ic_menu_bookmarks :
177 com.android.internal.R.drawable.ic_menu_archive;
178 Drawable drawable = getResources().getDrawable(resource);
179 updateFolderLabel(folder.Name, drawable);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400180 }
181 }
182 }
183
Leon Scroggins III052ce662010-09-13 14:44:16 -0400184 @Override
185 public void onClick(View v) {
186 if (v == mButton) {
187 if (mFolderSelector.getVisibility() == View.VISIBLE) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400188 // We are showing the folder selector.
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700189 if (mFolderNamer.getVisibility() == View.VISIBLE) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400190 completeOrCancelFolderNaming(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700191 } else {
192 // User has selected a folder. Go back to the opening page
Leon Scroggins88d08032010-10-21 15:17:10 -0400193 mSaveToHomeScreen = false;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400194 switchToDefaultView(true);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700195 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400196 } else if (save()) {
197 finish();
198 }
199 } else if (v == mCancelButton) {
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700200 if (mFolderNamer.getVisibility() == View.VISIBLE) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400201 completeOrCancelFolderNaming(true);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400202 } else if (mFolderSelector.getVisibility() == View.VISIBLE) {
203 switchToDefaultView(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700204 } else {
205 finish();
206 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400207 } else if (v == mFolder) {
Leon Scroggins26318a12010-11-08 10:08:40 -0500208 PopupMenu popup = new PopupMenu(this, mFolder);
Leon Scroggins88d08032010-10-21 15:17:10 -0400209 popup.getMenuInflater().inflate(R.menu.folder_choice,
210 popup.getMenu());
John Reckc8490812010-11-22 14:15:36 -0800211 if (mEditingFolder) {
212 popup.getMenu().removeItem(R.id.home_screen);
213 }
Leon Scroggins88d08032010-10-21 15:17:10 -0400214 popup.setOnMenuItemClickListener(this);
215 popup.show();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400216 } else if (v == mAddNewFolder) {
217 mFolderNamer.setVisibility(View.VISIBLE);
218 mFolderNamer.setText(R.string.new_folder);
219 mFolderNamer.requestFocus();
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400220 updateList();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700221 mAddNewFolder.setVisibility(View.GONE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400222 mAddSeparator.setVisibility(View.GONE);
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100223 getInputMethodManager().showSoftInput(mFolderNamer,
Leon Scroggins III052ce662010-09-13 14:44:16 -0400224 InputMethodManager.SHOW_IMPLICIT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800225 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400226 }
227
Leon Scroggins88d08032010-10-21 15:17:10 -0400228 @Override
229 public boolean onMenuItemClick(MenuItem item) {
230 switch(item.getItemId()) {
231 case R.id.bookmarks:
Leon Scroggins02081942010-11-01 17:52:42 -0400232 mCurrentFolder = mRootFolder;
233 updateFolderLabel(item.getTitle(), item.getIcon());
Leon Scroggins88d08032010-10-21 15:17:10 -0400234 mSaveToHomeScreen = false;
235 break;
236 case R.id.home_screen:
237 // Create a short cut to the home screen
238 mSaveToHomeScreen = true;
Leon Scroggins02081942010-11-01 17:52:42 -0400239 updateFolderLabel(item.getTitle(), item.getIcon());
Leon Scroggins88d08032010-10-21 15:17:10 -0400240 break;
241 case R.id.other:
242 switchToFolderSelector();
243 break;
244 default:
245 return false;
246 }
247 return true;
248 }
249
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400250 // Refresh the ListView to hide or show the empty view, as necessary.
251 // Should be called after mFolderNamer is shown or hidden.
252 private void updateList() {
253 if (mAdapter.getCount() == 0) {
254 // XXX: Is there a better way to refresh the ListView?
255 mListView.setAdapter(mAdapter);
256 }
257 }
258
259 private void completeOrCancelFolderNaming(boolean cancel) {
260 if (!cancel && !TextUtils.isEmpty(mFolderNamer.getText())) {
Michael Kolb31829b92010-10-01 11:50:21 -0700261 String name = mFolderNamer.getText().toString();
262 long id = addFolderToCurrent(mFolderNamer.getText().toString());
263 descendInto(name, id);
Michael Kolb31829b92010-10-01 11:50:21 -0700264 }
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400265 mFolderNamer.setVisibility(View.GONE);
266 mAddNewFolder.setVisibility(View.VISIBLE);
267 mAddSeparator.setVisibility(View.VISIBLE);
268 getInputMethodManager().hideSoftInputFromWindow(
269 mFolderNamer.getWindowToken(), 0);
270 updateList();
Michael Kolb31829b92010-10-01 11:50:21 -0700271 }
272
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700273 private long addFolderToCurrent(String name) {
274 // Add the folder to the database
275 ContentValues values = new ContentValues();
276 values.put(BrowserContract.Bookmarks.TITLE,
277 name);
278 values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
John Recke89daa92010-11-05 14:39:39 -0700279 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
280 String accountType = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_TYPE, null);
281 String accountName = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, null);
282 if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) {
283 values.put(BrowserContract.Bookmarks.ACCOUNT_TYPE, accountType);
284 values.put(BrowserContract.Bookmarks.ACCOUNT_NAME, accountName);
285 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400286 long currentFolder;
287 Object data = mCrumbs.getTopData();
288 if (data != null) {
289 currentFolder = ((Folder) data).Id;
290 } else {
Leon Scroggins02081942010-11-01 17:52:42 -0400291 currentFolder = mRootFolder;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400292 }
293 values.put(BrowserContract.Bookmarks.PARENT, currentFolder);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700294 Uri uri = getContentResolver().insert(
295 BrowserContract.Bookmarks.CONTENT_URI, values);
296 if (uri != null) {
297 return ContentUris.parseId(uri);
298 } else {
299 return -1;
300 }
301 }
302
Leon Scroggins III052ce662010-09-13 14:44:16 -0400303 private void switchToFolderSelector() {
304 mDefaultView.setVisibility(View.GONE);
305 mFolderSelector.setVisibility(View.VISIBLE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400306 mCrumbHolder.setVisibility(View.VISIBLE);
307 mFakeTitle.setVisibility(View.GONE);
308 mAddNewFolder.setVisibility(View.VISIBLE);
309 mAddSeparator.setVisibility(View.VISIBLE);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400310 }
311
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700312 private void descendInto(String foldername, long id) {
Michael Kolb370a4f32010-10-06 10:45:32 -0700313 if (id != DEFAULT_FOLDER_ID) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400314 mCrumbs.pushView(foldername, new Folder(foldername, id));
Leon Scroggins74dbe012010-10-15 10:54:27 -0400315 mCrumbs.notifyController();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700316 }
317 }
318
Leon Scroggins III052ce662010-09-13 14:44:16 -0400319 @Override
320 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
321 String[] projection;
322 switch (id) {
323 case LOADER_ID_ALL_FOLDERS:
324 projection = new String[] {
325 BrowserContract.Bookmarks._ID,
326 BrowserContract.Bookmarks.PARENT,
327 BrowserContract.Bookmarks.TITLE,
328 BrowserContract.Bookmarks.IS_FOLDER
329 };
330 return new CursorLoader(this,
331 BrowserContract.Bookmarks.CONTENT_URI,
332 projection,
333 BrowserContract.Bookmarks.IS_FOLDER + " != 0",
334 null,
335 null);
336 case LOADER_ID_FOLDER_CONTENTS:
337 projection = new String[] {
338 BrowserContract.Bookmarks._ID,
339 BrowserContract.Bookmarks.TITLE,
340 BrowserContract.Bookmarks.IS_FOLDER
341 };
Leon Scrogginsc1129902010-12-08 15:28:33 -0500342 String where = BrowserContract.Bookmarks.IS_FOLDER + " != 0";
343 if (mEditingFolder) {
344 where += " AND " + BrowserContract.Bookmarks._ID + " != "
345 + mMap.getLong(BrowserContract.Bookmarks._ID);
346 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400347 return new CursorLoader(this,
348 BrowserContract.Bookmarks.buildFolderUri(
349 mCurrentFolder),
350 projection,
Leon Scrogginsc1129902010-12-08 15:28:33 -0500351 where,
Leon Scroggins III052ce662010-09-13 14:44:16 -0400352 null,
353 null);
354 default:
355 throw new AssertionError("Asking for nonexistant loader!");
356 }
357 }
358
359 @Override
360 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
361 switch (loader.getId()) {
362 case LOADER_ID_FOLDER_CONTENTS:
363 mAdapter.changeCursor(cursor);
364 break;
365 case LOADER_ID_ALL_FOLDERS:
366 long parent = mCurrentFolder;
367 int idIndex = cursor.getColumnIndexOrThrow(
368 BrowserContract.Bookmarks._ID);
369 int titleIndex = cursor.getColumnIndexOrThrow(
370 BrowserContract.Bookmarks.TITLE);
371 int parentIndex = cursor.getColumnIndexOrThrow(
372 BrowserContract.Bookmarks.PARENT);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400373 Stack folderStack = new Stack();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700374 while ((parent != BrowserProvider2.FIXED_ID_ROOT) &&
375 (parent != 0)) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400376 // First, find the folder corresponding to the current
377 // folder
378 if (!cursor.moveToFirst()) {
379 throw new AssertionError("No folders in the database!");
380 }
381 long folder;
382 do {
383 folder = cursor.getLong(idIndex);
384 } while (folder != parent && cursor.moveToNext());
385 if (cursor.isAfterLast()) {
386 throw new AssertionError("Folder(id=" + parent
387 + ") holding this bookmark does not exist!");
388 }
389 String name = cursor.getString(titleIndex);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400390 if (parent == mCurrentFolder) {
Leon Scroggins02081942010-11-01 17:52:42 -0400391 Drawable draw = getResources().getDrawable(
392 com.android.internal.R.drawable.ic_menu_archive);
393 updateFolderLabel(name, draw);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400394 }
Leon Scroggins74dbe012010-10-15 10:54:27 -0400395 folderStack.push(new Folder(name, parent));
Leon Scroggins III052ce662010-09-13 14:44:16 -0400396 parent = cursor.getLong(parentIndex);
397 }
Leon Scroggins74dbe012010-10-15 10:54:27 -0400398 while (!folderStack.isEmpty()) {
399 Folder thisFolder = (Folder) folderStack.pop();
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400400 mCrumbs.pushView(thisFolder.Name, thisFolder);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400401 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400402 getLoaderManager().stopLoader(LOADER_ID_ALL_FOLDERS);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400403 break;
404 default:
405 break;
406 }
407 }
408
Leon Scroggins02081942010-11-01 17:52:42 -0400409 /**
410 * Update the name and image to show where the bookmark will be added
411 * @param name Name of the location to save (folder name, bookmarks, or home
412 * screen.
413 * @param drawable Image to show corresponding to the save location.
414 */
415 void updateFolderLabel(CharSequence name, Drawable drawable) {
416 mFolder.setText(name);
417 mFolder.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null,
418 null);
419 }
420
Leon Scroggins III052ce662010-09-13 14:44:16 -0400421 @Override
422 public void onItemClick(AdapterView<?> parent, View view, int position,
423 long id) {
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400424 TextView tv = (TextView) view.findViewById(android.R.id.text1);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400425 // Switch to the folder that was clicked on.
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400426 descendInto(tv.getText().toString(), id);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400427 }
428
429 /**
430 * Shows a list of names of folders.
431 */
432 private class FolderAdapter extends CursorAdapter {
433 public FolderAdapter(Context context) {
434 super(context, null);
435 }
436
437 @Override
438 public void bindView(View view, Context context, Cursor cursor) {
439 ((TextView) view.findViewById(android.R.id.text1)).setText(
440 cursor.getString(cursor.getColumnIndexOrThrow(
441 BrowserContract.Bookmarks.TITLE)));
442 }
443
444 @Override
445 public View newView(Context context, Cursor cursor, ViewGroup parent) {
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700446 View view = LayoutInflater.from(context).inflate(
447 R.layout.folder_list_item, null);
448 view.setBackgroundDrawable(context.getResources().
449 getDrawable(android.R.drawable.list_selector_background));
450 return view;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400451 }
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400452
453 @Override
454 public boolean isEmpty() {
455 // Do not show the empty view if the user is creating a new folder.
456 return super.isEmpty() && mFolderNamer.getVisibility() == View.GONE;
457 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400458 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800459
Leon Scrogginsc1129902010-12-08 15:28:33 -0500460 @Override
The Android Open Source Project0c908882009-03-03 19:32:16 -0800461 protected void onCreate(Bundle icicle) {
462 super.onCreate(icicle);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400463 if (DEBUG_CRASH) {
464 requestWindowFeature(Window.FEATURE_NO_TITLE);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400465 }
Ben Murdocheecb4e62010-07-06 16:30:38 +0100466
467 mMap = getIntent().getExtras();
Ben Murdocheecb4e62010-07-06 16:30:38 +0100468
Leon Scroggins III052ce662010-09-13 14:44:16 -0400469 setContentView(R.layout.browser_add_bookmark);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100470
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400471 Window window = getWindow();
Leon Scroggins74dbe012010-10-15 10:54:27 -0400472 if (!DEBUG_CRASH) {
Leon Scroggins02081942010-11-01 17:52:42 -0400473 setTitle("");
Leon Scroggins74dbe012010-10-15 10:54:27 -0400474 }
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700475
The Android Open Source Project0c908882009-03-03 19:32:16 -0800476 String title = null;
477 String url = null;
Ben Murdocheecb4e62010-07-06 16:30:38 +0100478
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400479 mFakeTitle = (TextView) findViewById(R.id.fake_title);
480
The Android Open Source Project0c908882009-03-03 19:32:16 -0800481 if (mMap != null) {
John Reckc8490812010-11-22 14:15:36 -0800482 Bundle b = mMap.getBundle(EXTRA_EDIT_BOOKMARK);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800483 if (b != null) {
John Reckc8490812010-11-22 14:15:36 -0800484 mEditingFolder = mMap.getBoolean(EXTRA_IS_FOLDER, false);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800485 mMap = b;
486 mEditingExisting = true;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400487 mFakeTitle.setText(R.string.edit_bookmark);
John Reckc8490812010-11-22 14:15:36 -0800488 if (mEditingFolder) {
489 findViewById(R.id.row_address).setVisibility(View.GONE);
490 }
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400491 } else {
492 int gravity = mMap.getInt("gravity", -1);
493 if (gravity != -1) {
494 WindowManager.LayoutParams l = window.getAttributes();
495 l.gravity = gravity;
496 window.setAttributes(l);
497 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800498 }
Leon Scrogginsbc922852010-10-22 12:15:27 -0400499 title = mMap.getString(BrowserContract.Bookmarks.TITLE);
500 url = mOriginalUrl = mMap.getString(BrowserContract.Bookmarks.URL);
501 mTouchIconUrl = mMap.getString(TOUCH_ICON_URL);
Michael Kolb370a4f32010-10-06 10:45:32 -0700502 mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID);
Leon Scroggins25230d72010-09-28 20:09:25 -0400503 }
Leon Scroggins02081942010-11-01 17:52:42 -0400504 mRootFolder = getBookmarksBarId(this);
Michael Kolb370a4f32010-10-06 10:45:32 -0700505 if (mCurrentFolder == DEFAULT_FOLDER_ID) {
Leon Scroggins02081942010-11-01 17:52:42 -0400506 mCurrentFolder = mRootFolder;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800507 }
508
509 mTitle = (EditText) findViewById(R.id.title);
510 mTitle.setText(title);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100511
Leon Scroggins III052ce662010-09-13 14:44:16 -0400512 mAddress = (EditText) findViewById(R.id.address);
513 mAddress.setText(url);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800514
The Android Open Source Project0c908882009-03-03 19:32:16 -0800515 mButton = (TextView) findViewById(R.id.OK);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400516 mButton.setOnClickListener(this);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800517
518 mCancelButton = findViewById(R.id.cancel);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400519 mCancelButton.setOnClickListener(this);
520
521 mFolder = (TextView) findViewById(R.id.folder);
522 mFolder.setOnClickListener(this);
523
524 mDefaultView = findViewById(R.id.default_view);
525 mFolderSelector = findViewById(R.id.folder_selector);
526
527 mFolderNamer = (EditText) findViewById(R.id.folder_namer);
528 mFolderNamer.setOnEditorActionListener(this);
529
530 mAddNewFolder = findViewById(R.id.add_new_folder);
531 mAddNewFolder.setOnClickListener(this);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400532 mAddSeparator = findViewById(R.id.add_divider);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400533
Leon Scroggins74dbe012010-10-15 10:54:27 -0400534 mCrumbs = (BreadCrumbView) findViewById(R.id.crumbs);
535 mCrumbs.setUseBackButton(true);
536 mCrumbs.setController(this);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400537 String name = getString(R.string.bookmarks);
538 mCrumbs.pushView(name, false,
539 new Folder(name, BrowserProvider2.FIXED_ID_ROOT));
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400540 mCrumbHolder = findViewById(R.id.crumb_holder);
John Reck89f73c12010-12-01 10:10:14 -0800541 mCrumbs.setMaxVisible(MAX_CRUMBS_SHOWN);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400542
Leon Scroggins III052ce662010-09-13 14:44:16 -0400543 mAdapter = new FolderAdapter(this);
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400544 mListView = (ListView) findViewById(R.id.list);
545 View empty = findViewById(R.id.empty);
546 mListView.setEmptyView(empty);
547 mListView.setAdapter(mAdapter);
548 mListView.setOnItemClickListener(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400549 LoaderManager manager = getLoaderManager();
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500550 if (mCurrentFolder != BrowserProvider2.FIXED_ID_ROOT) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400551 // Find all the folders
552 manager.initLoader(LOADER_ID_ALL_FOLDERS, null, this);
553 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400554 // Find the contents of the current folder
Leon Scroggins III052ce662010-09-13 14:44:16 -0400555 manager.initLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
556
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700557
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400558 if (!window.getDecorView().isInTouchMode()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800559 mButton.requestFocus();
560 }
561 }
Ben Murdoch1794fe22009-09-29 18:14:30 +0100562
Leon Scroggins25230d72010-09-28 20:09:25 -0400563 // FIXME: Use a CursorLoader
564 private long getBookmarksBarId(Context context) {
565 SharedPreferences prefs
566 = PreferenceManager.getDefaultSharedPreferences(context);
567 String accountName =
568 prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, null);
569 String accountType =
570 prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_TYPE, null);
571 if (TextUtils.isEmpty(accountName) || TextUtils.isEmpty(accountType)) {
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500572 return BrowserProvider2.FIXED_ID_ROOT;
Leon Scroggins25230d72010-09-28 20:09:25 -0400573 }
574 Cursor cursor = null;
575 try {
576 cursor = context.getContentResolver().query(
577 BrowserContract.Bookmarks.CONTENT_URI,
578 new String[] { BrowserContract.Bookmarks._ID },
579 BrowserContract.ChromeSyncColumns.SERVER_UNIQUE + "=? AND "
580 + BrowserContract.Bookmarks.ACCOUNT_NAME + "=? AND "
581 + BrowserContract.Bookmarks.ACCOUNT_TYPE + "=?",
582 new String[] {
583 BrowserContract.ChromeSyncColumns
584 .FOLDER_NAME_BOOKMARKS_BAR,
585 accountName,
586 accountType },
587 null);
588 if (cursor != null && cursor.moveToFirst()) {
589 return cursor.getLong(0);
590 }
591 } finally {
592 if (cursor != null) cursor.close();
593 }
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500594 return BrowserProvider2.FIXED_ID_ROOT;
Leon Scroggins25230d72010-09-28 20:09:25 -0400595 }
596
Leon Scroggins02065b02010-01-04 14:30:13 -0500597 /**
598 * Runnable to save a bookmark, so it can be performed in its own thread.
599 */
600 private class SaveBookmarkRunnable implements Runnable {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400601 // FIXME: This should be an async task.
Leon Scroggins02065b02010-01-04 14:30:13 -0500602 private Message mMessage;
Henrik Baard980e9952010-09-06 18:13:23 +0200603 private Context mContext;
604 public SaveBookmarkRunnable(Context ctx, Message msg) {
605 mContext = ctx;
Leon Scroggins02065b02010-01-04 14:30:13 -0500606 mMessage = msg;
607 }
608 public void run() {
609 // Unbundle bookmark data.
610 Bundle bundle = mMessage.getData();
Leon Scrogginsbc922852010-10-22 12:15:27 -0400611 String title = bundle.getString(BrowserContract.Bookmarks.TITLE);
612 String url = bundle.getString(BrowserContract.Bookmarks.URL);
613 boolean invalidateThumbnail = bundle.getBoolean(REMOVE_THUMBNAIL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500614 Bitmap thumbnail = invalidateThumbnail ? null
Leon Scrogginsbc922852010-10-22 12:15:27 -0400615 : (Bitmap) bundle.getParcelable(BrowserContract.Bookmarks.THUMBNAIL);
616 String touchIconUrl = bundle.getString(TOUCH_ICON_URL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500617
618 // Save to the bookmarks DB.
619 try {
620 final ContentResolver cr = getContentResolver();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400621 Bookmarks.addBookmark(AddBookmarkPage.this, false, url,
622 title, thumbnail, true, mCurrentFolder);
Leon Scroggins02065b02010-01-04 14:30:13 -0500623 if (touchIconUrl != null) {
Henrik Baard980e9952010-09-06 18:13:23 +0200624 new DownloadTouchIcon(mContext, cr, url).execute(mTouchIconUrl);
Leon Scroggins02065b02010-01-04 14:30:13 -0500625 }
626 mMessage.arg1 = 1;
627 } catch (IllegalStateException e) {
628 mMessage.arg1 = 0;
629 }
630 mMessage.sendToTarget();
631 }
632 }
633
John Reckc8490812010-11-22 14:15:36 -0800634 private static class UpdateBookmarkTask extends AsyncTask<ContentValues, Void, Void> {
635 Context mContext;
636 Long mId;
637
638 public UpdateBookmarkTask(Context context, long id) {
639 mContext = context;
640 mId = id;
641 }
642
643 @Override
644 protected Void doInBackground(ContentValues... params) {
645 if (params.length != 1) {
646 throw new IllegalArgumentException("No ContentValues provided!");
647 }
648 Uri uri = ContentUris.withAppendedId(BookmarkUtils.getBookmarksUri(mContext), mId);
649 mContext.getContentResolver().update(
650 uri,
651 params[0], null, null);
652 return null;
653 }
654 }
655
Ben Murdoch1794fe22009-09-29 18:14:30 +0100656 private void createHandler() {
657 if (mHandler == null) {
658 mHandler = new Handler() {
659 @Override
660 public void handleMessage(Message msg) {
661 switch (msg.what) {
662 case SAVE_BOOKMARK:
Leon Scroggins02065b02010-01-04 14:30:13 -0500663 if (1 == msg.arg1) {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100664 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_saved,
665 Toast.LENGTH_LONG).show();
666 } else {
667 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_not_saved,
668 Toast.LENGTH_LONG).show();
669 }
670 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400671 case TOUCH_ICON_DOWNLOADED:
672 Bundle b = msg.getData();
673 sendBroadcast(BookmarkUtils.createAddToHomeIntent(
Leon Scrogginsbc922852010-10-22 12:15:27 -0400674 AddBookmarkPage.this,
675 b.getString(BrowserContract.Bookmarks.URL),
676 b.getString(BrowserContract.Bookmarks.TITLE),
677 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.TOUCH_ICON),
678 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.FAVICON)));
Leon Scroggins88d08032010-10-21 15:17:10 -0400679 break;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100680 }
681 }
682 };
683 }
684 }
685
The Android Open Source Project0c908882009-03-03 19:32:16 -0800686 /**
Ben Murdoch1794fe22009-09-29 18:14:30 +0100687 * Parse the data entered in the dialog and post a message to update the bookmarks database.
The Android Open Source Project0c908882009-03-03 19:32:16 -0800688 */
689 boolean save() {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100690 createHandler();
691
The Android Open Source Project0c908882009-03-03 19:32:16 -0800692 String title = mTitle.getText().toString().trim();
Ben Murdocheecb4e62010-07-06 16:30:38 +0100693 String unfilteredUrl;
Michael Kolb8233fac2010-10-26 16:08:53 -0700694 unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString());
Ben Murdocheecb4e62010-07-06 16:30:38 +0100695
The Android Open Source Project0c908882009-03-03 19:32:16 -0800696 boolean emptyTitle = title.length() == 0;
697 boolean emptyUrl = unfilteredUrl.trim().length() == 0;
698 Resources r = getResources();
John Reckc8490812010-11-22 14:15:36 -0800699 if (emptyTitle || (emptyUrl && !mEditingFolder)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800700 if (emptyTitle) {
701 mTitle.setError(r.getText(R.string.bookmark_needs_title));
702 }
703 if (emptyUrl) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400704 mAddress.setError(r.getText(R.string.bookmark_needs_url));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800705 }
Leon Scroggins III6e3faea2010-09-07 15:22:14 -0400706 return false;
Ben Murdocheecb4e62010-07-06 16:30:38 +0100707
The Android Open Source Project0c908882009-03-03 19:32:16 -0800708 }
Ben Murdochca12cfa2009-11-17 13:57:44 +0000709 String url = unfilteredUrl.trim();
John Reckc8490812010-11-22 14:15:36 -0800710 if (!mEditingFolder) {
711 try {
712 // We allow bookmarks with a javascript: scheme, but these will in most cases
713 // fail URI parsing, so don't try it if that's the kind of bookmark we have.
Ben Murdochca12cfa2009-11-17 13:57:44 +0000714
John Reckc8490812010-11-22 14:15:36 -0800715 if (!url.toLowerCase().startsWith("javascript:")) {
716 URI uriObj = new URI(url);
717 String scheme = uriObj.getScheme();
718 if (!Bookmarks.urlHasAcceptableScheme(url)) {
719 // If the scheme was non-null, let the user know that we
720 // can't save their bookmark. If it was null, we'll assume
721 // they meant http when we parse it in the WebAddress class.
722 if (scheme != null) {
723 mAddress.setError(r.getText(R.string.bookmark_cannot_save_url));
724 return false;
725 }
726 WebAddress address;
727 try {
728 address = new WebAddress(unfilteredUrl);
729 } catch (ParseException e) {
730 throw new URISyntaxException("", "");
731 }
732 if (address.getHost().length() == 0) {
733 throw new URISyntaxException("", "");
734 }
735 url = address.toString();
Ben Murdochca12cfa2009-11-17 13:57:44 +0000736 }
Ben Murdochde353622009-10-12 10:29:00 +0100737 }
John Reckc8490812010-11-22 14:15:36 -0800738 } catch (URISyntaxException e) {
739 mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
740 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800741 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800742 }
Ben Murdochaac7aa62009-09-17 16:57:40 +0100743
Leon Scroggins88d08032010-10-21 15:17:10 -0400744 if (mSaveToHomeScreen) {
745 mEditingExisting = false;
746 }
747
748 boolean urlUnmodified = url.equals(mOriginalUrl);
749
Ben Murdoch1794fe22009-09-29 18:14:30 +0100750 if (mEditingExisting) {
John Reckc8490812010-11-22 14:15:36 -0800751 Long id = mMap.getLong(BrowserContract.Bookmarks._ID);
752 ContentValues values = new ContentValues();
753 values.put(BrowserContract.Bookmarks.TITLE, title);
754 values.put(BrowserContract.Bookmarks.PARENT, mCurrentFolder);
755 if (!mEditingFolder) {
756 values.put(BrowserContract.Bookmarks.URL, url);
757 if (!urlUnmodified) {
758 values.putNull(BrowserContract.Bookmarks.THUMBNAIL);
759 }
760 }
761 if (values.size() > 0) {
762 new UpdateBookmarkTask(getApplicationContext(), id).execute(values);
763 }
764 setResult(RESULT_OK);
Ben Murdoch1794fe22009-09-29 18:14:30 +0100765 } else {
Leon Scroggins88d08032010-10-21 15:17:10 -0400766 Bitmap thumbnail;
767 Bitmap favicon;
768 if (urlUnmodified) {
Leon Scrogginsbc922852010-10-22 12:15:27 -0400769 thumbnail = (Bitmap) mMap.getParcelable(
770 BrowserContract.Bookmarks.THUMBNAIL);
771 favicon = (Bitmap) mMap.getParcelable(
772 BrowserContract.Bookmarks.FAVICON);
Leon Scroggins88d08032010-10-21 15:17:10 -0400773 } else {
774 thumbnail = null;
775 favicon = null;
776 }
777
Ben Murdoch1794fe22009-09-29 18:14:30 +0100778 Bundle bundle = new Bundle();
Leon Scrogginsbc922852010-10-22 12:15:27 -0400779 bundle.putString(BrowserContract.Bookmarks.TITLE, title);
780 bundle.putString(BrowserContract.Bookmarks.URL, url);
781 bundle.putParcelable(BrowserContract.Bookmarks.FAVICON, favicon);
Leon Scroggins88d08032010-10-21 15:17:10 -0400782
783 if (mSaveToHomeScreen) {
784 if (mTouchIconUrl != null && urlUnmodified) {
785 Message msg = Message.obtain(mHandler,
786 TOUCH_ICON_DOWNLOADED);
787 msg.setData(bundle);
788 DownloadTouchIcon icon = new DownloadTouchIcon(this, msg,
Leon Scrogginsbc922852010-10-22 12:15:27 -0400789 mMap.getString(USER_AGENT));
Leon Scroggins88d08032010-10-21 15:17:10 -0400790 icon.execute(mTouchIconUrl);
791 } else {
792 sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url,
793 title, null /*touchIcon*/, favicon));
794 }
795 } else {
Leon Scrogginsbc922852010-10-22 12:15:27 -0400796 bundle.putParcelable(BrowserContract.Bookmarks.THUMBNAIL, thumbnail);
797 bundle.putBoolean(REMOVE_THUMBNAIL, !urlUnmodified);
798 bundle.putString(TOUCH_ICON_URL, mTouchIconUrl);
Leon Scroggins88d08032010-10-21 15:17:10 -0400799 // Post a message to write to the DB.
800 Message msg = Message.obtain(mHandler, SAVE_BOOKMARK);
801 msg.setData(bundle);
802 // Start a new thread so as to not slow down the UI
803 Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg));
804 t.start();
805 }
Ben Murdoch1794fe22009-09-29 18:14:30 +0100806 setResult(RESULT_OK);
Kristian Monsen0a1d8382010-02-01 18:41:07 +0000807 LogTag.logBookmarkAdded(url, "bookmarkview");
The Android Open Source Project0c908882009-03-03 19:32:16 -0800808 }
809 return true;
810 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800811}