blob: de256a8383c6c887cad22d350b2bac1a9b41ea24 [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();
143 updateVisible();
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400144 if (mFolderNamer.getVisibility() == View.VISIBLE) {
145 completeOrCancelFolderNaming(true);
146 }
Leon Scroggins74dbe012010-10-15 10:54:27 -0400147 }
148
149 /**
150 * Update the views shown to only show the two deepest levels of crumbs.
151 * Note that this method depends on internal knowledge of BreadCrumbView.
152 */
153 private void updateVisible() {
154 if (MAX_CRUMBS_SHOWN > 0) {
155 int invisibleCrumbs = mCrumbs.size() - MAX_CRUMBS_SHOWN;
156 // This class always uses a back button, which is the first child.
157 int childIndex = 1;
158 if (invisibleCrumbs > 0) {
159 int crumbIndex = 0;
160 while (crumbIndex < invisibleCrumbs) {
161 // Set the crumb to GONE.
162 mCrumbs.getChildAt(childIndex).setVisibility(View.GONE);
163 childIndex++;
164 // Each crumb is followed by a separator (except the last
165 // one). Also make it GONE
166 mCrumbs.getChildAt(childIndex).setVisibility(View.GONE);
167 childIndex++;
168 // Move to the next crumb.
169 crumbIndex++;
170 }
171 }
172 // Make sure the last two are visible.
173 int childCount = mCrumbs.getChildCount();
174 while (childIndex < childCount) {
175 mCrumbs.getChildAt(childIndex).setVisibility(View.VISIBLE);
176 childIndex++;
177 }
178 }
179 }
180
181 @Override
Leon Scroggins III052ce662010-09-13 14:44:16 -0400182 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
183 if (v == mFolderNamer) {
184 if (v.getText().length() > 0) {
185 if (actionId == EditorInfo.IME_NULL) {
186 // Only want to do this once.
187 if (event.getAction() == KeyEvent.ACTION_UP) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400188 completeOrCancelFolderNaming(false);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400189 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400190 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800191 }
Michael Kolb31829b92010-10-01 11:50:21 -0700192 // Steal the key press; otherwise a newline will be added
193 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800194 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400195 return false;
196 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800197
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400198 private void switchToDefaultView(boolean changedFolder) {
199 mFolderSelector.setVisibility(View.GONE);
200 mDefaultView.setVisibility(View.VISIBLE);
201 mCrumbHolder.setVisibility(View.GONE);
202 mFakeTitle.setVisibility(View.VISIBLE);
203 if (changedFolder) {
204 Object data = mCrumbs.getTopData();
205 if (data != null) {
206 Folder folder = (Folder) data;
207 mCurrentFolder = folder.Id;
Leon Scroggins02081942010-11-01 17:52:42 -0400208 int resource = mCurrentFolder == mRootFolder ?
209 R.drawable.ic_menu_bookmarks :
210 com.android.internal.R.drawable.ic_menu_archive;
211 Drawable drawable = getResources().getDrawable(resource);
212 updateFolderLabel(folder.Name, drawable);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400213 }
214 }
215 }
216
Leon Scroggins III052ce662010-09-13 14:44:16 -0400217 @Override
218 public void onClick(View v) {
219 if (v == mButton) {
220 if (mFolderSelector.getVisibility() == View.VISIBLE) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400221 // We are showing the folder selector.
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700222 if (mFolderNamer.getVisibility() == View.VISIBLE) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400223 completeOrCancelFolderNaming(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700224 } else {
225 // User has selected a folder. Go back to the opening page
Leon Scroggins88d08032010-10-21 15:17:10 -0400226 mSaveToHomeScreen = false;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400227 switchToDefaultView(true);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700228 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400229 } else if (save()) {
230 finish();
231 }
232 } else if (v == mCancelButton) {
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700233 if (mFolderNamer.getVisibility() == View.VISIBLE) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400234 completeOrCancelFolderNaming(true);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400235 } else if (mFolderSelector.getVisibility() == View.VISIBLE) {
236 switchToDefaultView(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700237 } else {
238 finish();
239 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400240 } else if (v == mFolder) {
Leon Scroggins26318a12010-11-08 10:08:40 -0500241 PopupMenu popup = new PopupMenu(this, mFolder);
Leon Scroggins88d08032010-10-21 15:17:10 -0400242 popup.getMenuInflater().inflate(R.menu.folder_choice,
243 popup.getMenu());
John Reckc8490812010-11-22 14:15:36 -0800244 if (mEditingFolder) {
245 popup.getMenu().removeItem(R.id.home_screen);
246 }
Leon Scroggins88d08032010-10-21 15:17:10 -0400247 popup.setOnMenuItemClickListener(this);
248 popup.show();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400249 } else if (v == mAddNewFolder) {
250 mFolderNamer.setVisibility(View.VISIBLE);
251 mFolderNamer.setText(R.string.new_folder);
252 mFolderNamer.requestFocus();
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400253 updateList();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700254 mAddNewFolder.setVisibility(View.GONE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400255 mAddSeparator.setVisibility(View.GONE);
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100256 getInputMethodManager().showSoftInput(mFolderNamer,
Leon Scroggins III052ce662010-09-13 14:44:16 -0400257 InputMethodManager.SHOW_IMPLICIT);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800258 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400259 }
260
Leon Scroggins88d08032010-10-21 15:17:10 -0400261 @Override
262 public boolean onMenuItemClick(MenuItem item) {
263 switch(item.getItemId()) {
264 case R.id.bookmarks:
Leon Scroggins02081942010-11-01 17:52:42 -0400265 mCurrentFolder = mRootFolder;
266 updateFolderLabel(item.getTitle(), item.getIcon());
Leon Scroggins88d08032010-10-21 15:17:10 -0400267 mSaveToHomeScreen = false;
268 break;
269 case R.id.home_screen:
270 // Create a short cut to the home screen
271 mSaveToHomeScreen = true;
Leon Scroggins02081942010-11-01 17:52:42 -0400272 updateFolderLabel(item.getTitle(), item.getIcon());
Leon Scroggins88d08032010-10-21 15:17:10 -0400273 break;
274 case R.id.other:
275 switchToFolderSelector();
276 break;
277 default:
278 return false;
279 }
280 return true;
281 }
282
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400283 // Refresh the ListView to hide or show the empty view, as necessary.
284 // Should be called after mFolderNamer is shown or hidden.
285 private void updateList() {
286 if (mAdapter.getCount() == 0) {
287 // XXX: Is there a better way to refresh the ListView?
288 mListView.setAdapter(mAdapter);
289 }
290 }
291
292 private void completeOrCancelFolderNaming(boolean cancel) {
293 if (!cancel && !TextUtils.isEmpty(mFolderNamer.getText())) {
Michael Kolb31829b92010-10-01 11:50:21 -0700294 String name = mFolderNamer.getText().toString();
295 long id = addFolderToCurrent(mFolderNamer.getText().toString());
296 descendInto(name, id);
Michael Kolb31829b92010-10-01 11:50:21 -0700297 }
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400298 mFolderNamer.setVisibility(View.GONE);
299 mAddNewFolder.setVisibility(View.VISIBLE);
300 mAddSeparator.setVisibility(View.VISIBLE);
301 getInputMethodManager().hideSoftInputFromWindow(
302 mFolderNamer.getWindowToken(), 0);
303 updateList();
Michael Kolb31829b92010-10-01 11:50:21 -0700304 }
305
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700306 private long addFolderToCurrent(String name) {
307 // Add the folder to the database
308 ContentValues values = new ContentValues();
309 values.put(BrowserContract.Bookmarks.TITLE,
310 name);
311 values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
John Recke89daa92010-11-05 14:39:39 -0700312 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
313 String accountType = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_TYPE, null);
314 String accountName = prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, null);
315 if (!TextUtils.isEmpty(accountName) && !TextUtils.isEmpty(accountType)) {
316 values.put(BrowserContract.Bookmarks.ACCOUNT_TYPE, accountType);
317 values.put(BrowserContract.Bookmarks.ACCOUNT_NAME, accountName);
318 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400319 long currentFolder;
320 Object data = mCrumbs.getTopData();
321 if (data != null) {
322 currentFolder = ((Folder) data).Id;
323 } else {
Leon Scroggins02081942010-11-01 17:52:42 -0400324 currentFolder = mRootFolder;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400325 }
326 values.put(BrowserContract.Bookmarks.PARENT, currentFolder);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700327 Uri uri = getContentResolver().insert(
328 BrowserContract.Bookmarks.CONTENT_URI, values);
329 if (uri != null) {
330 return ContentUris.parseId(uri);
331 } else {
332 return -1;
333 }
334 }
335
Leon Scroggins III052ce662010-09-13 14:44:16 -0400336 private void switchToFolderSelector() {
337 mDefaultView.setVisibility(View.GONE);
338 mFolderSelector.setVisibility(View.VISIBLE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400339 mCrumbHolder.setVisibility(View.VISIBLE);
340 mFakeTitle.setVisibility(View.GONE);
341 mAddNewFolder.setVisibility(View.VISIBLE);
342 mAddSeparator.setVisibility(View.VISIBLE);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400343 }
344
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700345 private void descendInto(String foldername, long id) {
Michael Kolb370a4f32010-10-06 10:45:32 -0700346 if (id != DEFAULT_FOLDER_ID) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400347 mCrumbs.pushView(foldername, new Folder(foldername, id));
Leon Scroggins74dbe012010-10-15 10:54:27 -0400348 mCrumbs.notifyController();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700349 }
350 }
351
Leon Scroggins III052ce662010-09-13 14:44:16 -0400352 @Override
353 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
354 String[] projection;
355 switch (id) {
356 case LOADER_ID_ALL_FOLDERS:
357 projection = new String[] {
358 BrowserContract.Bookmarks._ID,
359 BrowserContract.Bookmarks.PARENT,
360 BrowserContract.Bookmarks.TITLE,
361 BrowserContract.Bookmarks.IS_FOLDER
362 };
363 return new CursorLoader(this,
364 BrowserContract.Bookmarks.CONTENT_URI,
365 projection,
366 BrowserContract.Bookmarks.IS_FOLDER + " != 0",
367 null,
368 null);
369 case LOADER_ID_FOLDER_CONTENTS:
370 projection = new String[] {
371 BrowserContract.Bookmarks._ID,
372 BrowserContract.Bookmarks.TITLE,
373 BrowserContract.Bookmarks.IS_FOLDER
374 };
Leon Scroggins III052ce662010-09-13 14:44:16 -0400375 return new CursorLoader(this,
376 BrowserContract.Bookmarks.buildFolderUri(
377 mCurrentFolder),
378 projection,
379 BrowserContract.Bookmarks.IS_FOLDER + " != 0",
380 null,
381 null);
382 default:
383 throw new AssertionError("Asking for nonexistant loader!");
384 }
385 }
386
387 @Override
388 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
389 switch (loader.getId()) {
390 case LOADER_ID_FOLDER_CONTENTS:
391 mAdapter.changeCursor(cursor);
392 break;
393 case LOADER_ID_ALL_FOLDERS:
394 long parent = mCurrentFolder;
395 int idIndex = cursor.getColumnIndexOrThrow(
396 BrowserContract.Bookmarks._ID);
397 int titleIndex = cursor.getColumnIndexOrThrow(
398 BrowserContract.Bookmarks.TITLE);
399 int parentIndex = cursor.getColumnIndexOrThrow(
400 BrowserContract.Bookmarks.PARENT);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400401 Stack folderStack = new Stack();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700402 while ((parent != BrowserProvider2.FIXED_ID_ROOT) &&
403 (parent != 0)) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400404 // First, find the folder corresponding to the current
405 // folder
406 if (!cursor.moveToFirst()) {
407 throw new AssertionError("No folders in the database!");
408 }
409 long folder;
410 do {
411 folder = cursor.getLong(idIndex);
412 } while (folder != parent && cursor.moveToNext());
413 if (cursor.isAfterLast()) {
414 throw new AssertionError("Folder(id=" + parent
415 + ") holding this bookmark does not exist!");
416 }
417 String name = cursor.getString(titleIndex);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400418 if (parent == mCurrentFolder) {
Leon Scroggins02081942010-11-01 17:52:42 -0400419 Drawable draw = getResources().getDrawable(
420 com.android.internal.R.drawable.ic_menu_archive);
421 updateFolderLabel(name, draw);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400422 }
Leon Scroggins74dbe012010-10-15 10:54:27 -0400423 folderStack.push(new Folder(name, parent));
Leon Scroggins III052ce662010-09-13 14:44:16 -0400424 parent = cursor.getLong(parentIndex);
425 }
Leon Scroggins74dbe012010-10-15 10:54:27 -0400426 while (!folderStack.isEmpty()) {
427 Folder thisFolder = (Folder) folderStack.pop();
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400428 mCrumbs.pushView(thisFolder.Name, thisFolder);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400429 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400430 getLoaderManager().stopLoader(LOADER_ID_ALL_FOLDERS);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400431 updateVisible();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400432 break;
433 default:
434 break;
435 }
436 }
437
Leon Scroggins02081942010-11-01 17:52:42 -0400438 /**
439 * Update the name and image to show where the bookmark will be added
440 * @param name Name of the location to save (folder name, bookmarks, or home
441 * screen.
442 * @param drawable Image to show corresponding to the save location.
443 */
444 void updateFolderLabel(CharSequence name, Drawable drawable) {
445 mFolder.setText(name);
446 mFolder.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null,
447 null);
448 }
449
Leon Scroggins III052ce662010-09-13 14:44:16 -0400450 @Override
451 public void onItemClick(AdapterView<?> parent, View view, int position,
452 long id) {
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400453 TextView tv = (TextView) view.findViewById(android.R.id.text1);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400454 // Switch to the folder that was clicked on.
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400455 descendInto(tv.getText().toString(), id);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400456 }
457
458 /**
459 * Shows a list of names of folders.
460 */
461 private class FolderAdapter extends CursorAdapter {
462 public FolderAdapter(Context context) {
463 super(context, null);
464 }
465
466 @Override
467 public void bindView(View view, Context context, Cursor cursor) {
468 ((TextView) view.findViewById(android.R.id.text1)).setText(
469 cursor.getString(cursor.getColumnIndexOrThrow(
470 BrowserContract.Bookmarks.TITLE)));
471 }
472
473 @Override
474 public View newView(Context context, Cursor cursor, ViewGroup parent) {
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700475 View view = LayoutInflater.from(context).inflate(
476 R.layout.folder_list_item, null);
477 view.setBackgroundDrawable(context.getResources().
478 getDrawable(android.R.drawable.list_selector_background));
479 return view;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400480 }
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400481
482 @Override
483 public boolean isEmpty() {
484 // Do not show the empty view if the user is creating a new folder.
485 return super.isEmpty() && mFolderNamer.getVisibility() == View.GONE;
486 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400487 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800488
489 protected void onCreate(Bundle icicle) {
490 super.onCreate(icicle);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400491 if (DEBUG_CRASH) {
492 requestWindowFeature(Window.FEATURE_NO_TITLE);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400493 }
Ben Murdocheecb4e62010-07-06 16:30:38 +0100494
495 mMap = getIntent().getExtras();
Ben Murdocheecb4e62010-07-06 16:30:38 +0100496
Leon Scroggins III052ce662010-09-13 14:44:16 -0400497 setContentView(R.layout.browser_add_bookmark);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100498
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400499 Window window = getWindow();
Leon Scroggins74dbe012010-10-15 10:54:27 -0400500 if (!DEBUG_CRASH) {
Leon Scroggins02081942010-11-01 17:52:42 -0400501 setTitle("");
Leon Scroggins74dbe012010-10-15 10:54:27 -0400502 }
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700503
The Android Open Source Project0c908882009-03-03 19:32:16 -0800504 String title = null;
505 String url = null;
Ben Murdocheecb4e62010-07-06 16:30:38 +0100506
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400507 mFakeTitle = (TextView) findViewById(R.id.fake_title);
508
The Android Open Source Project0c908882009-03-03 19:32:16 -0800509 if (mMap != null) {
John Reckc8490812010-11-22 14:15:36 -0800510 Bundle b = mMap.getBundle(EXTRA_EDIT_BOOKMARK);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800511 if (b != null) {
John Reckc8490812010-11-22 14:15:36 -0800512 mEditingFolder = mMap.getBoolean(EXTRA_IS_FOLDER, false);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800513 mMap = b;
514 mEditingExisting = true;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400515 mFakeTitle.setText(R.string.edit_bookmark);
John Reckc8490812010-11-22 14:15:36 -0800516 if (mEditingFolder) {
517 findViewById(R.id.row_address).setVisibility(View.GONE);
518 }
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400519 } else {
520 int gravity = mMap.getInt("gravity", -1);
521 if (gravity != -1) {
522 WindowManager.LayoutParams l = window.getAttributes();
523 l.gravity = gravity;
524 window.setAttributes(l);
525 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800526 }
Leon Scrogginsbc922852010-10-22 12:15:27 -0400527 title = mMap.getString(BrowserContract.Bookmarks.TITLE);
528 url = mOriginalUrl = mMap.getString(BrowserContract.Bookmarks.URL);
529 mTouchIconUrl = mMap.getString(TOUCH_ICON_URL);
Michael Kolb370a4f32010-10-06 10:45:32 -0700530 mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID);
Leon Scroggins25230d72010-09-28 20:09:25 -0400531 }
Leon Scroggins02081942010-11-01 17:52:42 -0400532 mRootFolder = getBookmarksBarId(this);
Michael Kolb370a4f32010-10-06 10:45:32 -0700533 if (mCurrentFolder == DEFAULT_FOLDER_ID) {
Leon Scroggins02081942010-11-01 17:52:42 -0400534 mCurrentFolder = mRootFolder;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800535 }
536
537 mTitle = (EditText) findViewById(R.id.title);
538 mTitle.setText(title);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100539
Leon Scroggins III052ce662010-09-13 14:44:16 -0400540 mAddress = (EditText) findViewById(R.id.address);
541 mAddress.setText(url);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800542
The Android Open Source Project0c908882009-03-03 19:32:16 -0800543 mButton = (TextView) findViewById(R.id.OK);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400544 mButton.setOnClickListener(this);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800545
546 mCancelButton = findViewById(R.id.cancel);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400547 mCancelButton.setOnClickListener(this);
548
549 mFolder = (TextView) findViewById(R.id.folder);
550 mFolder.setOnClickListener(this);
551
552 mDefaultView = findViewById(R.id.default_view);
553 mFolderSelector = findViewById(R.id.folder_selector);
554
555 mFolderNamer = (EditText) findViewById(R.id.folder_namer);
556 mFolderNamer.setOnEditorActionListener(this);
557
558 mAddNewFolder = findViewById(R.id.add_new_folder);
559 mAddNewFolder.setOnClickListener(this);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400560 mAddSeparator = findViewById(R.id.add_divider);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400561
Leon Scroggins74dbe012010-10-15 10:54:27 -0400562 mCrumbs = (BreadCrumbView) findViewById(R.id.crumbs);
563 mCrumbs.setUseBackButton(true);
564 mCrumbs.setController(this);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400565 String name = getString(R.string.bookmarks);
566 mCrumbs.pushView(name, false,
567 new Folder(name, BrowserProvider2.FIXED_ID_ROOT));
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400568 mCrumbHolder = findViewById(R.id.crumb_holder);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400569
Leon Scroggins III052ce662010-09-13 14:44:16 -0400570 mAdapter = new FolderAdapter(this);
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400571 mListView = (ListView) findViewById(R.id.list);
572 View empty = findViewById(R.id.empty);
573 mListView.setEmptyView(empty);
574 mListView.setAdapter(mAdapter);
575 mListView.setOnItemClickListener(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400576 LoaderManager manager = getLoaderManager();
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500577 if (mCurrentFolder != BrowserProvider2.FIXED_ID_ROOT) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400578 // Find all the folders
579 manager.initLoader(LOADER_ID_ALL_FOLDERS, null, this);
580 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400581 // Find the contents of the current folder
Leon Scroggins III052ce662010-09-13 14:44:16 -0400582 manager.initLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
583
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700584
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400585 if (!window.getDecorView().isInTouchMode()) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800586 mButton.requestFocus();
587 }
588 }
Ben Murdoch1794fe22009-09-29 18:14:30 +0100589
Leon Scroggins25230d72010-09-28 20:09:25 -0400590 // FIXME: Use a CursorLoader
591 private long getBookmarksBarId(Context context) {
592 SharedPreferences prefs
593 = PreferenceManager.getDefaultSharedPreferences(context);
594 String accountName =
595 prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_NAME, null);
596 String accountType =
597 prefs.getString(BrowserBookmarksPage.PREF_ACCOUNT_TYPE, null);
598 if (TextUtils.isEmpty(accountName) || TextUtils.isEmpty(accountType)) {
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500599 return BrowserProvider2.FIXED_ID_ROOT;
Leon Scroggins25230d72010-09-28 20:09:25 -0400600 }
601 Cursor cursor = null;
602 try {
603 cursor = context.getContentResolver().query(
604 BrowserContract.Bookmarks.CONTENT_URI,
605 new String[] { BrowserContract.Bookmarks._ID },
606 BrowserContract.ChromeSyncColumns.SERVER_UNIQUE + "=? AND "
607 + BrowserContract.Bookmarks.ACCOUNT_NAME + "=? AND "
608 + BrowserContract.Bookmarks.ACCOUNT_TYPE + "=?",
609 new String[] {
610 BrowserContract.ChromeSyncColumns
611 .FOLDER_NAME_BOOKMARKS_BAR,
612 accountName,
613 accountType },
614 null);
615 if (cursor != null && cursor.moveToFirst()) {
616 return cursor.getLong(0);
617 }
618 } finally {
619 if (cursor != null) cursor.close();
620 }
Jeff Hamiltona9bad832010-09-24 11:05:30 -0500621 return BrowserProvider2.FIXED_ID_ROOT;
Leon Scroggins25230d72010-09-28 20:09:25 -0400622 }
623
Leon Scroggins02065b02010-01-04 14:30:13 -0500624 /**
625 * Runnable to save a bookmark, so it can be performed in its own thread.
626 */
627 private class SaveBookmarkRunnable implements Runnable {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400628 // FIXME: This should be an async task.
Leon Scroggins02065b02010-01-04 14:30:13 -0500629 private Message mMessage;
Henrik Baard980e9952010-09-06 18:13:23 +0200630 private Context mContext;
631 public SaveBookmarkRunnable(Context ctx, Message msg) {
632 mContext = ctx;
Leon Scroggins02065b02010-01-04 14:30:13 -0500633 mMessage = msg;
634 }
635 public void run() {
636 // Unbundle bookmark data.
637 Bundle bundle = mMessage.getData();
Leon Scrogginsbc922852010-10-22 12:15:27 -0400638 String title = bundle.getString(BrowserContract.Bookmarks.TITLE);
639 String url = bundle.getString(BrowserContract.Bookmarks.URL);
640 boolean invalidateThumbnail = bundle.getBoolean(REMOVE_THUMBNAIL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500641 Bitmap thumbnail = invalidateThumbnail ? null
Leon Scrogginsbc922852010-10-22 12:15:27 -0400642 : (Bitmap) bundle.getParcelable(BrowserContract.Bookmarks.THUMBNAIL);
643 String touchIconUrl = bundle.getString(TOUCH_ICON_URL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500644
645 // Save to the bookmarks DB.
646 try {
647 final ContentResolver cr = getContentResolver();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400648 Bookmarks.addBookmark(AddBookmarkPage.this, false, url,
649 title, thumbnail, true, mCurrentFolder);
Leon Scroggins02065b02010-01-04 14:30:13 -0500650 if (touchIconUrl != null) {
Henrik Baard980e9952010-09-06 18:13:23 +0200651 new DownloadTouchIcon(mContext, cr, url).execute(mTouchIconUrl);
Leon Scroggins02065b02010-01-04 14:30:13 -0500652 }
653 mMessage.arg1 = 1;
654 } catch (IllegalStateException e) {
655 mMessage.arg1 = 0;
656 }
657 mMessage.sendToTarget();
658 }
659 }
660
John Reckc8490812010-11-22 14:15:36 -0800661 private static class UpdateBookmarkTask extends AsyncTask<ContentValues, Void, Void> {
662 Context mContext;
663 Long mId;
664
665 public UpdateBookmarkTask(Context context, long id) {
666 mContext = context;
667 mId = id;
668 }
669
670 @Override
671 protected Void doInBackground(ContentValues... params) {
672 if (params.length != 1) {
673 throw new IllegalArgumentException("No ContentValues provided!");
674 }
675 Uri uri = ContentUris.withAppendedId(BookmarkUtils.getBookmarksUri(mContext), mId);
676 mContext.getContentResolver().update(
677 uri,
678 params[0], null, null);
679 return null;
680 }
681 }
682
Ben Murdoch1794fe22009-09-29 18:14:30 +0100683 private void createHandler() {
684 if (mHandler == null) {
685 mHandler = new Handler() {
686 @Override
687 public void handleMessage(Message msg) {
688 switch (msg.what) {
689 case SAVE_BOOKMARK:
Leon Scroggins02065b02010-01-04 14:30:13 -0500690 if (1 == msg.arg1) {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100691 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_saved,
692 Toast.LENGTH_LONG).show();
693 } else {
694 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_not_saved,
695 Toast.LENGTH_LONG).show();
696 }
697 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400698 case TOUCH_ICON_DOWNLOADED:
699 Bundle b = msg.getData();
700 sendBroadcast(BookmarkUtils.createAddToHomeIntent(
Leon Scrogginsbc922852010-10-22 12:15:27 -0400701 AddBookmarkPage.this,
702 b.getString(BrowserContract.Bookmarks.URL),
703 b.getString(BrowserContract.Bookmarks.TITLE),
704 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.TOUCH_ICON),
705 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.FAVICON)));
Leon Scroggins88d08032010-10-21 15:17:10 -0400706 break;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100707 }
708 }
709 };
710 }
711 }
712
The Android Open Source Project0c908882009-03-03 19:32:16 -0800713 /**
Ben Murdoch1794fe22009-09-29 18:14:30 +0100714 * 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 -0800715 */
716 boolean save() {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100717 createHandler();
718
The Android Open Source Project0c908882009-03-03 19:32:16 -0800719 String title = mTitle.getText().toString().trim();
Ben Murdocheecb4e62010-07-06 16:30:38 +0100720 String unfilteredUrl;
Michael Kolb8233fac2010-10-26 16:08:53 -0700721 unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString());
Ben Murdocheecb4e62010-07-06 16:30:38 +0100722
The Android Open Source Project0c908882009-03-03 19:32:16 -0800723 boolean emptyTitle = title.length() == 0;
724 boolean emptyUrl = unfilteredUrl.trim().length() == 0;
725 Resources r = getResources();
John Reckc8490812010-11-22 14:15:36 -0800726 if (emptyTitle || (emptyUrl && !mEditingFolder)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800727 if (emptyTitle) {
728 mTitle.setError(r.getText(R.string.bookmark_needs_title));
729 }
730 if (emptyUrl) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400731 mAddress.setError(r.getText(R.string.bookmark_needs_url));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800732 }
Leon Scroggins III6e3faea2010-09-07 15:22:14 -0400733 return false;
Ben Murdocheecb4e62010-07-06 16:30:38 +0100734
The Android Open Source Project0c908882009-03-03 19:32:16 -0800735 }
Ben Murdochca12cfa2009-11-17 13:57:44 +0000736 String url = unfilteredUrl.trim();
John Reckc8490812010-11-22 14:15:36 -0800737 if (!mEditingFolder) {
738 try {
739 // We allow bookmarks with a javascript: scheme, but these will in most cases
740 // fail URI parsing, so don't try it if that's the kind of bookmark we have.
Ben Murdochca12cfa2009-11-17 13:57:44 +0000741
John Reckc8490812010-11-22 14:15:36 -0800742 if (!url.toLowerCase().startsWith("javascript:")) {
743 URI uriObj = new URI(url);
744 String scheme = uriObj.getScheme();
745 if (!Bookmarks.urlHasAcceptableScheme(url)) {
746 // If the scheme was non-null, let the user know that we
747 // can't save their bookmark. If it was null, we'll assume
748 // they meant http when we parse it in the WebAddress class.
749 if (scheme != null) {
750 mAddress.setError(r.getText(R.string.bookmark_cannot_save_url));
751 return false;
752 }
753 WebAddress address;
754 try {
755 address = new WebAddress(unfilteredUrl);
756 } catch (ParseException e) {
757 throw new URISyntaxException("", "");
758 }
759 if (address.getHost().length() == 0) {
760 throw new URISyntaxException("", "");
761 }
762 url = address.toString();
Ben Murdochca12cfa2009-11-17 13:57:44 +0000763 }
Ben Murdochde353622009-10-12 10:29:00 +0100764 }
John Reckc8490812010-11-22 14:15:36 -0800765 } catch (URISyntaxException e) {
766 mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
767 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800768 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800769 }
Ben Murdochaac7aa62009-09-17 16:57:40 +0100770
Leon Scroggins88d08032010-10-21 15:17:10 -0400771 if (mSaveToHomeScreen) {
772 mEditingExisting = false;
773 }
774
775 boolean urlUnmodified = url.equals(mOriginalUrl);
776
Ben Murdoch1794fe22009-09-29 18:14:30 +0100777 if (mEditingExisting) {
John Reckc8490812010-11-22 14:15:36 -0800778 Long id = mMap.getLong(BrowserContract.Bookmarks._ID);
779 ContentValues values = new ContentValues();
780 values.put(BrowserContract.Bookmarks.TITLE, title);
781 values.put(BrowserContract.Bookmarks.PARENT, mCurrentFolder);
782 if (!mEditingFolder) {
783 values.put(BrowserContract.Bookmarks.URL, url);
784 if (!urlUnmodified) {
785 values.putNull(BrowserContract.Bookmarks.THUMBNAIL);
786 }
787 }
788 if (values.size() > 0) {
789 new UpdateBookmarkTask(getApplicationContext(), id).execute(values);
790 }
791 setResult(RESULT_OK);
Ben Murdoch1794fe22009-09-29 18:14:30 +0100792 } else {
Leon Scroggins88d08032010-10-21 15:17:10 -0400793 Bitmap thumbnail;
794 Bitmap favicon;
795 if (urlUnmodified) {
Leon Scrogginsbc922852010-10-22 12:15:27 -0400796 thumbnail = (Bitmap) mMap.getParcelable(
797 BrowserContract.Bookmarks.THUMBNAIL);
798 favicon = (Bitmap) mMap.getParcelable(
799 BrowserContract.Bookmarks.FAVICON);
Leon Scroggins88d08032010-10-21 15:17:10 -0400800 } else {
801 thumbnail = null;
802 favicon = null;
803 }
804
Ben Murdoch1794fe22009-09-29 18:14:30 +0100805 Bundle bundle = new Bundle();
Leon Scrogginsbc922852010-10-22 12:15:27 -0400806 bundle.putString(BrowserContract.Bookmarks.TITLE, title);
807 bundle.putString(BrowserContract.Bookmarks.URL, url);
808 bundle.putParcelable(BrowserContract.Bookmarks.FAVICON, favicon);
Leon Scroggins88d08032010-10-21 15:17:10 -0400809
810 if (mSaveToHomeScreen) {
811 if (mTouchIconUrl != null && urlUnmodified) {
812 Message msg = Message.obtain(mHandler,
813 TOUCH_ICON_DOWNLOADED);
814 msg.setData(bundle);
815 DownloadTouchIcon icon = new DownloadTouchIcon(this, msg,
Leon Scrogginsbc922852010-10-22 12:15:27 -0400816 mMap.getString(USER_AGENT));
Leon Scroggins88d08032010-10-21 15:17:10 -0400817 icon.execute(mTouchIconUrl);
818 } else {
819 sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url,
820 title, null /*touchIcon*/, favicon));
821 }
822 } else {
Leon Scrogginsbc922852010-10-22 12:15:27 -0400823 bundle.putParcelable(BrowserContract.Bookmarks.THUMBNAIL, thumbnail);
824 bundle.putBoolean(REMOVE_THUMBNAIL, !urlUnmodified);
825 bundle.putString(TOUCH_ICON_URL, mTouchIconUrl);
Leon Scroggins88d08032010-10-21 15:17:10 -0400826 // Post a message to write to the DB.
827 Message msg = Message.obtain(mHandler, SAVE_BOOKMARK);
828 msg.setData(bundle);
829 // Start a new thread so as to not slow down the UI
830 Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg));
831 t.start();
832 }
Ben Murdoch1794fe22009-09-29 18:14:30 +0100833 setResult(RESULT_OK);
Kristian Monsen0a1d8382010-02-01 18:41:07 +0000834 LogTag.logBookmarkAdded(url, "bookmarkview");
The Android Open Source Project0c908882009-03-03 19:32:16 -0800835 }
836 return true;
837 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800838}