blob: 10d02e5a34915cb61ee43c9986d59c5d360e9a47 [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
Bijan Amirzada41242f22014-03-21 12:12:18 -070017package com.android.browser;
The Android Open Source Project0c908882009-03-03 19:32:16 -080018
19import android.app.Activity;
luxiaoldbe4a622013-07-19 17:14:06 +080020import android.app.AlertDialog;
Leon Scroggins III052ce662010-09-13 14:44:16 -040021import android.app.LoaderManager;
John Reck2eec4c32011-05-11 15:55:32 -070022import android.app.LoaderManager.LoaderCallbacks;
23import android.content.AsyncTaskLoader;
The Android Open Source Project0c908882009-03-03 19:32:16 -080024import android.content.ContentResolver;
Michael Kolbd40ac1a2010-09-29 00:23:46 -070025import android.content.ContentUris;
Leon Scroggins III052ce662010-09-13 14:44:16 -040026import android.content.ContentValues;
27import android.content.Context;
28import android.content.CursorLoader;
luxiaoldbe4a622013-07-19 17:14:06 +080029import android.content.DialogInterface;
Leon Scroggins III052ce662010-09-13 14:44:16 -040030import android.content.Loader;
The Android Open Source Project0c908882009-03-03 19:32:16 -080031import android.content.res.Resources;
Patrick Scott3918d442009-08-04 13:22:29 -040032import android.database.Cursor;
Ben Murdochaac7aa62009-09-17 16:57:40 +010033import android.graphics.Bitmap;
Leon Scroggins02081942010-11-01 17:52:42 -040034import android.graphics.drawable.Drawable;
The Android Open Source Project0c908882009-03-03 19:32:16 -080035import android.net.ParseException;
Michael Kolbd40ac1a2010-09-29 00:23:46 -070036import android.net.Uri;
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.text.TextUtils;
Leon Scroggins162f8352010-10-18 15:02:44 -040042import android.util.AttributeSet;
Leon Scroggins III052ce662010-09-13 14:44:16 -040043import android.view.KeyEvent;
44import android.view.LayoutInflater;
The Android Open Source Project0c908882009-03-03 19:32:16 -080045import android.view.View;
Leon Scroggins III052ce662010-09-13 14:44:16 -040046import android.view.ViewGroup;
The Android Open Source Project0c908882009-03-03 19:32:16 -080047import android.view.Window;
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -040048import android.view.WindowManager;
Leon Scroggins III052ce662010-09-13 14:44:16 -040049import android.view.inputmethod.EditorInfo;
50import android.view.inputmethod.InputMethodManager;
51import android.widget.AdapterView;
John Reck2eec4c32011-05-11 15:55:32 -070052import android.widget.AdapterView.OnItemSelectedListener;
53import android.widget.ArrayAdapter;
Leon Scroggins III052ce662010-09-13 14:44:16 -040054import 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;
John Reck2eec4c32011-05-11 15:55:32 -070057import android.widget.Spinner;
The Android Open Source Project0c908882009-03-03 19:32:16 -080058import android.widget.TextView;
59import android.widget.Toast;
60
Bijan Amirzada41242f22014-03-21 12:12:18 -070061import com.android.browser.BrowserUtils;
62import com.android.browser.R;
63import com.android.browser.addbookmark.FolderSpinner;
64import com.android.browser.addbookmark.FolderSpinnerAdapter;
65import com.android.browser.platformsupport.BrowserContract;
66import com.android.browser.platformsupport.WebAddress;
67import com.android.browser.platformsupport.BrowserContract.Accounts;
68import com.android.browser.reflect.ReflectHelper;
luxiaoldbe4a622013-07-19 17:14:06 +080069
Cary Clarkf2407c62009-09-04 12:25:10 -040070import java.net.URI;
71import java.net.URISyntaxException;
Leon Scroggins III052ce662010-09-13 14:44:16 -040072
73public class AddBookmarkPage extends Activity
74 implements View.OnClickListener, TextView.OnEditorActionListener,
Leon Scroggins74dbe012010-10-15 10:54:27 -040075 AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor>,
John Reck2eec4c32011-05-11 15:55:32 -070076 BreadCrumbView.Controller, FolderSpinner.OnSetSelectionListener,
77 OnItemSelectedListener {
The Android Open Source Project0c908882009-03-03 19:32:16 -080078
Michael Kolb370a4f32010-10-06 10:45:32 -070079 public static final long DEFAULT_FOLDER_ID = -1;
Leon Scrogginsbc922852010-10-22 12:15:27 -040080 public static final String TOUCH_ICON_URL = "touch_icon_url";
81 // Place on an edited bookmark to remove the saved thumbnail
82 public static final String REMOVE_THUMBNAIL = "remove_thumbnail";
83 public static final String USER_AGENT = "user_agent";
Leon Scrogginsbdff8a72011-02-11 15:49:04 -050084 public static final String CHECK_FOR_DUPE = "check_for_dupe";
Michael Kolb370a4f32010-10-06 10:45:32 -070085
John Reckc8490812010-11-22 14:15:36 -080086 /* package */ static final String EXTRA_EDIT_BOOKMARK = "bookmark";
87 /* package */ static final String EXTRA_IS_FOLDER = "is_folder";
88
kaiyiz3d7e4d52013-09-17 17:56:27 +080089 private static final int MAX_CRUMBS_SHOWN = 1;
Leon Scroggins74dbe012010-10-15 10:54:27 -040090
The Android Open Source Project0c908882009-03-03 19:32:16 -080091 private final String LOGTAG = "Bookmarks";
92
Leon Scroggins III052ce662010-09-13 14:44:16 -040093 // IDs for the CursorLoaders that are used.
John Reck2eec4c32011-05-11 15:55:32 -070094 private final int LOADER_ID_ACCOUNTS = 0;
95 private final int LOADER_ID_FOLDER_CONTENTS = 1;
96 private final int LOADER_ID_EDIT_INFO = 2;
Leon Scroggins III052ce662010-09-13 14:44:16 -040097
The Android Open Source Project0c908882009-03-03 19:32:16 -080098 private EditText mTitle;
99 private EditText mAddress;
100 private TextView mButton;
101 private View mCancelButton;
102 private boolean mEditingExisting;
John Reckc8490812010-11-22 14:15:36 -0800103 private boolean mEditingFolder;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800104 private Bundle mMap;
Patrick Scott3918d442009-08-04 13:22:29 -0400105 private String mTouchIconUrl;
Ben Murdochaac7aa62009-09-17 16:57:40 +0100106 private String mOriginalUrl;
Leon Scroggins504433a2011-01-13 12:26:52 -0500107 private FolderSpinner mFolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400108 private View mDefaultView;
109 private View mFolderSelector;
110 private EditText mFolderNamer;
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500111 private View mFolderCancel;
Leon Scroggins162f8352010-10-18 15:02:44 -0400112 private boolean mIsFolderNamerShowing;
113 private View mFolderNamerHolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400114 private View mAddNewFolder;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400115 private View mAddSeparator;
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500116 private long mCurrentFolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400117 private FolderAdapter mAdapter;
Leon Scroggins74dbe012010-10-15 10:54:27 -0400118 private BreadCrumbView mCrumbs;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400119 private TextView mFakeTitle;
120 private View mCrumbHolder;
Leon Scroggins162f8352010-10-18 15:02:44 -0400121 private CustomListView mListView;
Leon Scroggins88d08032010-10-21 15:17:10 -0400122 private boolean mSaveToHomeScreen;
Leon Scroggins02081942010-11-01 17:52:42 -0400123 private long mRootFolder;
Leon Scroggins905250c2010-12-17 15:25:33 -0500124 private TextView mTopLevelLabel;
125 private Drawable mHeaderIcon;
Leon Scroggins75630672011-01-13 17:56:15 -0500126 private View mRemoveLink;
127 private View mFakeTitleHolder;
Leon Scroggins2f24e992011-02-11 14:02:10 -0500128 private FolderSpinnerAdapter mFolderAdapter;
John Reck2eec4c32011-05-11 15:55:32 -0700129 private Spinner mAccountSpinner;
130 private ArrayAdapter<BookmarkAccount> mAccountAdapter;
luxiaoldbe4a622013-07-19 17:14:06 +0800131 // add for carrier which requires same title or address can not exist.
132 private long mDuplicateId;
133 private Context mDuplicateContext;
John Reck2eec4c32011-05-11 15:55:32 -0700134
Leon Scroggins III052ce662010-09-13 14:44:16 -0400135 private static class Folder {
136 String Name;
137 long Id;
138 Folder(String name, long id) {
139 Name = name;
140 Id = id;
141 }
142 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800143
Ben Murdoch1794fe22009-09-29 18:14:30 +0100144 // Message IDs
145 private static final int SAVE_BOOKMARK = 100;
Leon Scroggins88d08032010-10-21 15:17:10 -0400146 private static final int TOUCH_ICON_DOWNLOADED = 101;
Leon Scroggins75630672011-01-13 17:56:15 -0500147 private static final int BOOKMARK_DELETED = 102;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100148
149 private Handler mHandler;
150
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100151 private InputMethodManager getInputMethodManager() {
152 return (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
153 }
154
Leon Scroggins8baaa632010-12-08 19:46:53 -0500155 private Uri getUriForFolder(long folder) {
John Reck903a0722011-11-09 17:53:10 -0800156 BookmarkAccount account =
157 (BookmarkAccount) mAccountSpinner.getSelectedItem();
158 if (folder == mRootFolder && account != null) {
159 return BookmarksLoader.addAccount(
160 BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER,
161 account.accountType, account.accountName);
162 }
John Reck2eec4c32011-05-11 15:55:32 -0700163 return BrowserContract.Bookmarks.buildFolderUri(folder);
Leon Scroggins8baaa632010-12-08 19:46:53 -0500164 }
165
Leon Scroggins III052ce662010-09-13 14:44:16 -0400166 @Override
John Reck71efc2b2011-05-09 16:54:28 -0700167 public void onTop(BreadCrumbView view, int level, Object data) {
Leon Scroggins74dbe012010-10-15 10:54:27 -0400168 if (null == data) return;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400169 Folder folderData = (Folder) data;
170 long folder = folderData.Id;
Leon Scroggins74dbe012010-10-15 10:54:27 -0400171 LoaderManager manager = getLoaderManager();
John Reck2eec4c32011-05-11 15:55:32 -0700172 CursorLoader loader = (CursorLoader) ((Loader<?>) manager.getLoader(
Leon Scroggins74dbe012010-10-15 10:54:27 -0400173 LOADER_ID_FOLDER_CONTENTS));
Leon Scroggins8baaa632010-12-08 19:46:53 -0500174 loader.setUri(getUriForFolder(folder));
Leon Scroggins74dbe012010-10-15 10:54:27 -0400175 loader.forceLoad();
Leon Scroggins162f8352010-10-18 15:02:44 -0400176 if (mIsFolderNamerShowing) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400177 completeOrCancelFolderNaming(true);
178 }
Leon Scroggins905250c2010-12-17 15:25:33 -0500179 setShowBookmarkIcon(level == 1);
180 }
181
182 /**
183 * Show or hide the icon for bookmarks next to "Bookmarks" in the crumb view.
184 * @param show True if the icon should visible, false otherwise.
185 */
186 private void setShowBookmarkIcon(boolean show) {
187 Drawable drawable = show ? mHeaderIcon: null;
188 mTopLevelLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400189 }
190
Leon Scroggins74dbe012010-10-15 10:54:27 -0400191 @Override
Leon Scroggins III052ce662010-09-13 14:44:16 -0400192 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
193 if (v == mFolderNamer) {
194 if (v.getText().length() > 0) {
195 if (actionId == EditorInfo.IME_NULL) {
196 // Only want to do this once.
197 if (event.getAction() == KeyEvent.ACTION_UP) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400198 completeOrCancelFolderNaming(false);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400199 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400200 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800201 }
Michael Kolb31829b92010-10-01 11:50:21 -0700202 // Steal the key press; otherwise a newline will be added
Vivek Sekhar5e631472014-03-31 23:59:10 -0700203 // return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800204 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400205 return false;
206 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800207
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400208 private void switchToDefaultView(boolean changedFolder) {
209 mFolderSelector.setVisibility(View.GONE);
210 mDefaultView.setVisibility(View.VISIBLE);
211 mCrumbHolder.setVisibility(View.GONE);
Leon Scroggins75630672011-01-13 17:56:15 -0500212 mFakeTitleHolder.setVisibility(View.VISIBLE);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400213 if (changedFolder) {
214 Object data = mCrumbs.getTopData();
215 if (data != null) {
216 Folder folder = (Folder) data;
217 mCurrentFolder = folder.Id;
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500218 if (mCurrentFolder == mRootFolder) {
219 // The Spinner changed to show "Other folder ..." Change
220 // it back to "Bookmarks", which is position 0 if we are
221 // editing a folder, 1 otherwise.
Leon Scroggins504433a2011-01-13 12:26:52 -0500222 mFolder.setSelectionIgnoringSelectionChange(mEditingFolder ? 0 : 1);
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500223 } else {
John Reck2eec4c32011-05-11 15:55:32 -0700224 mFolderAdapter.setOtherFolderDisplayText(folder.Name);
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500225 }
226 }
227 } else {
228 // The user canceled selecting a folder. Revert back to the earlier
229 // selection.
230 if (mSaveToHomeScreen) {
Leon Scroggins504433a2011-01-13 12:26:52 -0500231 mFolder.setSelectionIgnoringSelectionChange(0);
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500232 } else {
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500233 if (mCurrentFolder == mRootFolder) {
234 mFolder.setSelectionIgnoringSelectionChange(mEditingFolder ? 0 : 1);
235 } else {
236 Object data = mCrumbs.getTopData();
237 if (data != null && ((Folder) data).Id == mCurrentFolder) {
John Reck2eec4c32011-05-11 15:55:32 -0700238 // We are showing the correct folder hierarchy. The
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500239 // folder selector will say "Other folder..." Change it
240 // to say the name of the folder once again.
John Reck2eec4c32011-05-11 15:55:32 -0700241 mFolderAdapter.setOtherFolderDisplayText(((Folder) data).Name);
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500242 } else {
John Reck2eec4c32011-05-11 15:55:32 -0700243 // We are not showing the correct folder hierarchy.
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500244 // Clear the Crumbs and find the proper folder
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500245 setupTopCrumb();
246 LoaderManager manager = getLoaderManager();
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500247 manager.restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
248
249 }
250 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400251 }
252 }
253 }
254
Leon Scroggins III052ce662010-09-13 14:44:16 -0400255 @Override
256 public void onClick(View v) {
257 if (v == mButton) {
258 if (mFolderSelector.getVisibility() == View.VISIBLE) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400259 // We are showing the folder selector.
Leon Scroggins162f8352010-10-18 15:02:44 -0400260 if (mIsFolderNamerShowing) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400261 completeOrCancelFolderNaming(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700262 } else {
263 // User has selected a folder. Go back to the opening page
Leon Scroggins88d08032010-10-21 15:17:10 -0400264 mSaveToHomeScreen = false;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400265 switchToDefaultView(true);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700266 }
luxiaoldbe4a622013-07-19 17:14:06 +0800267 } else {
268 // add for carrier which requires same title or address can not
269 // exist.
270 if (mSaveToHomeScreen) {
271 if (save()) {
272 return;
273 }
274 } else {
275 onSaveWithConfirm();
276 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400277 }
278 } else if (v == mCancelButton) {
Leon Scroggins162f8352010-10-18 15:02:44 -0400279 if (mIsFolderNamerShowing) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400280 completeOrCancelFolderNaming(true);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400281 } else if (mFolderSelector.getVisibility() == View.VISIBLE) {
282 switchToDefaultView(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700283 } else {
284 finish();
285 }
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500286 } else if (v == mFolderCancel) {
287 completeOrCancelFolderNaming(true);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400288 } else if (v == mAddNewFolder) {
Leon Scroggins162f8352010-10-18 15:02:44 -0400289 setShowFolderNamer(true);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400290 mFolderNamer.setText(R.string.new_folder);
291 mFolderNamer.requestFocus();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700292 mAddNewFolder.setVisibility(View.GONE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400293 mAddSeparator.setVisibility(View.GONE);
Leon Scroggins162f8352010-10-18 15:02:44 -0400294 InputMethodManager imm = getInputMethodManager();
295 // Set the InputMethodManager to focus on the ListView so that it
296 // can transfer the focus to mFolderNamer.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800297 //imm.focusIn(mListView);
298 Object[] params = {mListView};
299 Class[] type = new Class[] {View.class};
300 ReflectHelper.invokeMethod(imm, "focusIn", type, params);
Leon Scroggins162f8352010-10-18 15:02:44 -0400301 imm.showSoftInput(mFolderNamer, InputMethodManager.SHOW_IMPLICIT);
Leon Scroggins75630672011-01-13 17:56:15 -0500302 } else if (v == mRemoveLink) {
303 if (!mEditingExisting) {
304 throw new AssertionError("Remove button should not be shown for"
305 + " new bookmarks");
306 }
307 long id = mMap.getLong(BrowserContract.Bookmarks._ID);
308 createHandler();
309 Message msg = Message.obtain(mHandler, BOOKMARK_DELETED);
310 BookmarkUtils.displayRemoveBookmarkDialog(id,
311 mTitle.getText().toString(), this, msg);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800312 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400313 }
314
Leon Scroggins504433a2011-01-13 12:26:52 -0500315 // FolderSpinner.OnSetSelectionListener
316
Leon Scroggins88d08032010-10-21 15:17:10 -0400317 @Override
Leon Scroggins504433a2011-01-13 12:26:52 -0500318 public void onSetSelection(long id) {
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500319 int intId = (int) id;
320 switch (intId) {
321 case FolderSpinnerAdapter.ROOT_FOLDER:
Leon Scroggins02081942010-11-01 17:52:42 -0400322 mCurrentFolder = mRootFolder;
Leon Scroggins88d08032010-10-21 15:17:10 -0400323 mSaveToHomeScreen = false;
324 break;
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500325 case FolderSpinnerAdapter.HOME_SCREEN:
Leon Scroggins88d08032010-10-21 15:17:10 -0400326 // Create a short cut to the home screen
327 mSaveToHomeScreen = true;
Leon Scroggins88d08032010-10-21 15:17:10 -0400328 break;
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500329 case FolderSpinnerAdapter.OTHER_FOLDER:
Leon Scroggins88d08032010-10-21 15:17:10 -0400330 switchToFolderSelector();
331 break;
Leon Scroggins2f24e992011-02-11 14:02:10 -0500332 case FolderSpinnerAdapter.RECENT_FOLDER:
333 mCurrentFolder = mFolderAdapter.recentFolderId();
334 mSaveToHomeScreen = false;
335 // In case the user decides to select OTHER_FOLDER
336 // and choose a different one, so that we will start from
337 // the correct place.
338 LoaderManager manager = getLoaderManager();
Leon Scroggins2f24e992011-02-11 14:02:10 -0500339 manager.restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
Leon Scroggins0b95ad42011-02-23 15:23:48 -0500340 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400341 default:
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500342 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400343 }
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500344 }
345
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500346 /**
347 * Finish naming a folder, and close the IME
348 * @param cancel If true, the new folder is not created. If false, the new
349 * folder is created and the user is taken inside it.
350 */
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400351 private void completeOrCancelFolderNaming(boolean cancel) {
352 if (!cancel && !TextUtils.isEmpty(mFolderNamer.getText())) {
Michael Kolb31829b92010-10-01 11:50:21 -0700353 String name = mFolderNamer.getText().toString();
354 long id = addFolderToCurrent(mFolderNamer.getText().toString());
355 descendInto(name, id);
Michael Kolb31829b92010-10-01 11:50:21 -0700356 }
Leon Scroggins162f8352010-10-18 15:02:44 -0400357 setShowFolderNamer(false);
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400358 mAddNewFolder.setVisibility(View.VISIBLE);
359 mAddSeparator.setVisibility(View.VISIBLE);
360 getInputMethodManager().hideSoftInputFromWindow(
Leon Scroggins162f8352010-10-18 15:02:44 -0400361 mListView.getWindowToken(), 0);
Michael Kolb31829b92010-10-01 11:50:21 -0700362 }
363
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700364 private long addFolderToCurrent(String name) {
365 // Add the folder to the database
366 ContentValues values = new ContentValues();
367 values.put(BrowserContract.Bookmarks.TITLE,
368 name);
369 values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400370 long currentFolder;
371 Object data = mCrumbs.getTopData();
372 if (data != null) {
373 currentFolder = ((Folder) data).Id;
374 } else {
Leon Scroggins02081942010-11-01 17:52:42 -0400375 currentFolder = mRootFolder;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400376 }
377 values.put(BrowserContract.Bookmarks.PARENT, currentFolder);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700378 Uri uri = getContentResolver().insert(
379 BrowserContract.Bookmarks.CONTENT_URI, values);
380 if (uri != null) {
381 return ContentUris.parseId(uri);
382 } else {
383 return -1;
384 }
385 }
386
Leon Scroggins III052ce662010-09-13 14:44:16 -0400387 private void switchToFolderSelector() {
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500388 // Set the list to the top in case it is scrolled.
389 mListView.setSelection(0);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400390 mDefaultView.setVisibility(View.GONE);
391 mFolderSelector.setVisibility(View.VISIBLE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400392 mCrumbHolder.setVisibility(View.VISIBLE);
Leon Scroggins75630672011-01-13 17:56:15 -0500393 mFakeTitleHolder.setVisibility(View.GONE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400394 mAddNewFolder.setVisibility(View.VISIBLE);
395 mAddSeparator.setVisibility(View.VISIBLE);
John Reck95f88e42011-09-26 09:25:43 -0700396 getInputMethodManager().hideSoftInputFromWindow(
397 mListView.getWindowToken(), 0);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400398 }
399
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700400 private void descendInto(String foldername, long id) {
Michael Kolb370a4f32010-10-06 10:45:32 -0700401 if (id != DEFAULT_FOLDER_ID) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400402 mCrumbs.pushView(foldername, new Folder(foldername, id));
Leon Scroggins74dbe012010-10-15 10:54:27 -0400403 mCrumbs.notifyController();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700404 }
405 }
406
John Reck2eec4c32011-05-11 15:55:32 -0700407 private LoaderCallbacks<EditBookmarkInfo> mEditInfoLoaderCallbacks =
408 new LoaderCallbacks<EditBookmarkInfo>() {
409
410 @Override
411 public void onLoaderReset(Loader<EditBookmarkInfo> loader) {
412 // Don't care
413 }
414
415 @Override
416 public void onLoadFinished(Loader<EditBookmarkInfo> loader,
417 EditBookmarkInfo info) {
418 boolean setAccount = false;
419 if (info.id != -1) {
420 mEditingExisting = true;
421 showRemoveButton();
422 mFakeTitle.setText(R.string.edit_bookmark);
423 mTitle.setText(info.title);
424 mFolderAdapter.setOtherFolderDisplayText(info.parentTitle);
425 mMap.putLong(BrowserContract.Bookmarks._ID, info.id);
426 setAccount = true;
427 setAccount(info.accountName, info.accountType);
428 mCurrentFolder = info.parentId;
429 onCurrentFolderFound();
430 }
John Reck37894a92011-05-13 12:47:53 -0700431 // TODO: Detect if lastUsedId is a subfolder of info.id in the
432 // editing folder case. For now, just don't show the last used
433 // folder at all to prevent any chance of the user adding a parent
434 // folder to a child folder
435 if (info.lastUsedId != -1 && info.lastUsedId != info.id
436 && !mEditingFolder) {
John Reck2eec4c32011-05-11 15:55:32 -0700437 if (setAccount && info.lastUsedId != mRootFolder
438 && TextUtils.equals(info.lastUsedAccountName, info.accountName)
439 && TextUtils.equals(info.lastUsedAccountType, info.accountType)) {
440 mFolderAdapter.addRecentFolder(info.lastUsedId, info.lastUsedTitle);
441 } else if (!setAccount) {
442 setAccount = true;
443 setAccount(info.lastUsedAccountName, info.lastUsedAccountType);
444 if (info.lastUsedId != mRootFolder) {
445 mFolderAdapter.addRecentFolder(info.lastUsedId,
446 info.lastUsedTitle);
447 }
448 }
449 }
450 if (!setAccount) {
451 mAccountSpinner.setSelection(0);
452 }
453 }
454
455 @Override
456 public Loader<EditBookmarkInfo> onCreateLoader(int id, Bundle args) {
457 return new EditBookmarkInfoLoader(AddBookmarkPage.this, mMap);
458 }
459 };
460
461 void setAccount(String accountName, String accountType) {
462 for (int i = 0; i < mAccountAdapter.getCount(); i++) {
463 BookmarkAccount account = mAccountAdapter.getItem(i);
464 if (TextUtils.equals(account.accountName, accountName)
465 && TextUtils.equals(account.accountType, accountType)) {
John Reck2eec4c32011-05-11 15:55:32 -0700466 mAccountSpinner.setSelection(i);
John Reck903a0722011-11-09 17:53:10 -0800467 onRootFolderFound(account.rootFolderId);
John Reck2eec4c32011-05-11 15:55:32 -0700468 return;
469 }
470 }
471 }
472
Leon Scroggins III052ce662010-09-13 14:44:16 -0400473 @Override
474 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
475 String[] projection;
476 switch (id) {
John Reck2eec4c32011-05-11 15:55:32 -0700477 case LOADER_ID_ACCOUNTS:
478 return new AccountsLoader(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400479 case LOADER_ID_FOLDER_CONTENTS:
480 projection = new String[] {
481 BrowserContract.Bookmarks._ID,
482 BrowserContract.Bookmarks.TITLE,
483 BrowserContract.Bookmarks.IS_FOLDER
484 };
Leon Scrogginsc1129902010-12-08 15:28:33 -0500485 String where = BrowserContract.Bookmarks.IS_FOLDER + " != 0";
John Reck1dd8cd42011-05-13 11:22:09 -0700486 String whereArgs[] = null;
Leon Scrogginsc1129902010-12-08 15:28:33 -0500487 if (mEditingFolder) {
John Reck1dd8cd42011-05-13 11:22:09 -0700488 where += " AND " + BrowserContract.Bookmarks._ID + " != ?";
489 whereArgs = new String[] { Long.toString(mMap.getLong(
490 BrowserContract.Bookmarks._ID)) };
491 }
492 long currentFolder;
493 Object data = mCrumbs.getTopData();
494 if (data != null) {
495 currentFolder = ((Folder) data).Id;
496 } else {
497 currentFolder = mRootFolder;
Leon Scrogginsc1129902010-12-08 15:28:33 -0500498 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400499 return new CursorLoader(this,
John Reck1dd8cd42011-05-13 11:22:09 -0700500 getUriForFolder(currentFolder),
Leon Scroggins III052ce662010-09-13 14:44:16 -0400501 projection,
Leon Scrogginsc1129902010-12-08 15:28:33 -0500502 where,
John Reck1dd8cd42011-05-13 11:22:09 -0700503 whereArgs,
Leon Scroggins8baaa632010-12-08 19:46:53 -0500504 BrowserContract.Bookmarks._ID + " ASC");
Leon Scroggins III052ce662010-09-13 14:44:16 -0400505 default:
506 throw new AssertionError("Asking for nonexistant loader!");
507 }
508 }
509
510 @Override
511 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
512 switch (loader.getId()) {
John Reck2eec4c32011-05-11 15:55:32 -0700513 case LOADER_ID_ACCOUNTS:
514 mAccountAdapter.clear();
515 while (cursor.moveToNext()) {
516 mAccountAdapter.add(new BookmarkAccount(this, cursor));
Leon Scroggins504433a2011-01-13 12:26:52 -0500517 }
John Reck2eec4c32011-05-11 15:55:32 -0700518 getLoaderManager().destroyLoader(LOADER_ID_ACCOUNTS);
519 getLoaderManager().restartLoader(LOADER_ID_EDIT_INFO, null,
520 mEditInfoLoaderCallbacks);
Leon Scroggins504433a2011-01-13 12:26:52 -0500521 break;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400522 case LOADER_ID_FOLDER_CONTENTS:
523 mAdapter.changeCursor(cursor);
524 break;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400525 }
526 }
527
Dianne Hackborn39772c82010-12-16 00:43:54 -0800528 public void onLoaderReset(Loader<Cursor> loader) {
529 switch (loader.getId()) {
530 case LOADER_ID_FOLDER_CONTENTS:
531 mAdapter.changeCursor(null);
532 break;
533 }
534 }
535
Leon Scroggins02081942010-11-01 17:52:42 -0400536 /**
Leon Scroggins8baaa632010-12-08 19:46:53 -0500537 * Move cursor to the position that has folderToFind as its "_id".
538 * @param cursor Cursor containing folders in the bookmarks database
539 * @param folderToFind "_id" of the folder to move to.
540 * @param idIndex Index in cursor of "_id"
541 * @throws AssertionError if cursor is empty or there is no row with folderToFind
542 * as its "_id".
543 */
544 void moveCursorToFolder(Cursor cursor, long folderToFind, int idIndex)
545 throws AssertionError {
546 if (!cursor.moveToFirst()) {
547 throw new AssertionError("No folders in the database!");
548 }
549 long folder;
550 do {
551 folder = cursor.getLong(idIndex);
552 } while (folder != folderToFind && cursor.moveToNext());
553 if (cursor.isAfterLast()) {
554 throw new AssertionError("Folder(id=" + folderToFind
555 + ") holding this bookmark does not exist!");
556 }
557 }
558
Leon Scroggins III052ce662010-09-13 14:44:16 -0400559 @Override
560 public void onItemClick(AdapterView<?> parent, View view, int position,
561 long id) {
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400562 TextView tv = (TextView) view.findViewById(android.R.id.text1);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400563 // Switch to the folder that was clicked on.
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400564 descendInto(tv.getText().toString(), id);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400565 }
566
Leon Scroggins162f8352010-10-18 15:02:44 -0400567 private void setShowFolderNamer(boolean show) {
568 if (show != mIsFolderNamerShowing) {
569 mIsFolderNamerShowing = show;
570 if (show) {
571 // Set the selection to the folder namer so it will be in
572 // view.
573 mListView.addFooterView(mFolderNamerHolder);
574 } else {
575 mListView.removeFooterView(mFolderNamerHolder);
576 }
577 // Refresh the list.
578 mListView.setAdapter(mAdapter);
579 if (show) {
580 mListView.setSelection(mListView.getCount() - 1);
581 }
582 }
583 }
584
Leon Scroggins III052ce662010-09-13 14:44:16 -0400585 /**
586 * Shows a list of names of folders.
587 */
588 private class FolderAdapter extends CursorAdapter {
589 public FolderAdapter(Context context) {
590 super(context, null);
591 }
592
593 @Override
594 public void bindView(View view, Context context, Cursor cursor) {
595 ((TextView) view.findViewById(android.R.id.text1)).setText(
596 cursor.getString(cursor.getColumnIndexOrThrow(
597 BrowserContract.Bookmarks.TITLE)));
598 }
599
600 @Override
601 public View newView(Context context, Cursor cursor, ViewGroup parent) {
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700602 View view = LayoutInflater.from(context).inflate(
603 R.layout.folder_list_item, null);
604 view.setBackgroundDrawable(context.getResources().
605 getDrawable(android.R.drawable.list_selector_background));
606 return view;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400607 }
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400608
609 @Override
610 public boolean isEmpty() {
611 // Do not show the empty view if the user is creating a new folder.
Leon Scroggins162f8352010-10-18 15:02:44 -0400612 return super.isEmpty() && !mIsFolderNamerShowing;
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400613 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400614 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800615
Leon Scrogginsc1129902010-12-08 15:28:33 -0500616 @Override
The Android Open Source Project0c908882009-03-03 19:32:16 -0800617 protected void onCreate(Bundle icicle) {
618 super.onCreate(icicle);
Leon Scroggins7453ff22010-12-15 16:03:59 -0500619 requestWindowFeature(Window.FEATURE_NO_TITLE);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100620
621 mMap = getIntent().getExtras();
Ben Murdocheecb4e62010-07-06 16:30:38 +0100622
Leon Scroggins III052ce662010-09-13 14:44:16 -0400623 setContentView(R.layout.browser_add_bookmark);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100624
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400625 Window window = getWindow();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700626
The Android Open Source Project0c908882009-03-03 19:32:16 -0800627 String title = null;
628 String url = null;
Ben Murdocheecb4e62010-07-06 16:30:38 +0100629
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400630 mFakeTitle = (TextView) findViewById(R.id.fake_title);
631
The Android Open Source Project0c908882009-03-03 19:32:16 -0800632 if (mMap != null) {
John Reckc8490812010-11-22 14:15:36 -0800633 Bundle b = mMap.getBundle(EXTRA_EDIT_BOOKMARK);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800634 if (b != null) {
John Reckc8490812010-11-22 14:15:36 -0800635 mEditingFolder = mMap.getBoolean(EXTRA_IS_FOLDER, false);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800636 mMap = b;
637 mEditingExisting = true;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400638 mFakeTitle.setText(R.string.edit_bookmark);
John Reckc8490812010-11-22 14:15:36 -0800639 if (mEditingFolder) {
640 findViewById(R.id.row_address).setVisibility(View.GONE);
Leon Scroggins75630672011-01-13 17:56:15 -0500641 } else {
642 showRemoveButton();
John Reckc8490812010-11-22 14:15:36 -0800643 }
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400644 } else {
645 int gravity = mMap.getInt("gravity", -1);
646 if (gravity != -1) {
647 WindowManager.LayoutParams l = window.getAttributes();
648 l.gravity = gravity;
649 window.setAttributes(l);
650 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800651 }
Leon Scrogginsbc922852010-10-22 12:15:27 -0400652 title = mMap.getString(BrowserContract.Bookmarks.TITLE);
653 url = mOriginalUrl = mMap.getString(BrowserContract.Bookmarks.URL);
654 mTouchIconUrl = mMap.getString(TOUCH_ICON_URL);
Michael Kolb370a4f32010-10-06 10:45:32 -0700655 mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID);
Leon Scroggins25230d72010-09-28 20:09:25 -0400656 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800657
658 mTitle = (EditText) findViewById(R.id.title);
659 mTitle.setText(title);
luxiaoldbe4a622013-07-19 17:14:06 +0800660 BrowserUtils.maxLengthFilter(AddBookmarkPage.this, mTitle, BrowserUtils.FILENAME_MAX_LENGTH);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100661
Leon Scroggins III052ce662010-09-13 14:44:16 -0400662 mAddress = (EditText) findViewById(R.id.address);
663 mAddress.setText(url);
luxiaoldbe4a622013-07-19 17:14:06 +0800664 BrowserUtils.maxLengthFilter(AddBookmarkPage.this, mAddress, BrowserUtils.ADDRESS_MAX_LENGTH);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800665
The Android Open Source Project0c908882009-03-03 19:32:16 -0800666 mButton = (TextView) findViewById(R.id.OK);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400667 mButton.setOnClickListener(this);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800668
669 mCancelButton = findViewById(R.id.cancel);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400670 mCancelButton.setOnClickListener(this);
671
Leon Scroggins504433a2011-01-13 12:26:52 -0500672 mFolder = (FolderSpinner) findViewById(R.id.folder);
John Reck2eec4c32011-05-11 15:55:32 -0700673 mFolderAdapter = new FolderSpinnerAdapter(this, !mEditingFolder);
Leon Scroggins2f24e992011-02-11 14:02:10 -0500674 mFolder.setAdapter(mFolderAdapter);
Leon Scroggins504433a2011-01-13 12:26:52 -0500675 mFolder.setOnSetSelectionListener(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400676
677 mDefaultView = findViewById(R.id.default_view);
678 mFolderSelector = findViewById(R.id.folder_selector);
679
Leon Scroggins162f8352010-10-18 15:02:44 -0400680 mFolderNamerHolder = getLayoutInflater().inflate(R.layout.new_folder_layout, null);
681 mFolderNamer = (EditText) mFolderNamerHolder.findViewById(R.id.folder_namer);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400682 mFolderNamer.setOnEditorActionListener(this);
luxiaoldbe4a622013-07-19 17:14:06 +0800683
684 // add for carrier test about warning limit of edit text
685 BrowserUtils.maxLengthFilter(AddBookmarkPage.this, mFolderNamer,
686 BrowserUtils.FILENAME_MAX_LENGTH);
687
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500688 mFolderCancel = mFolderNamerHolder.findViewById(R.id.close);
689 mFolderCancel.setOnClickListener(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400690
691 mAddNewFolder = findViewById(R.id.add_new_folder);
692 mAddNewFolder.setOnClickListener(this);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400693 mAddSeparator = findViewById(R.id.add_divider);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400694
Leon Scroggins74dbe012010-10-15 10:54:27 -0400695 mCrumbs = (BreadCrumbView) findViewById(R.id.crumbs);
696 mCrumbs.setUseBackButton(true);
697 mCrumbs.setController(this);
Michael Kolb5a72f182011-01-13 20:35:06 -0800698 mHeaderIcon = getResources().getDrawable(R.drawable.ic_folder_holo_dark);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400699 mCrumbHolder = findViewById(R.id.crumb_holder);
John Reck89f73c12010-12-01 10:10:14 -0800700 mCrumbs.setMaxVisible(MAX_CRUMBS_SHOWN);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400701
Leon Scroggins III052ce662010-09-13 14:44:16 -0400702 mAdapter = new FolderAdapter(this);
Leon Scroggins162f8352010-10-18 15:02:44 -0400703 mListView = (CustomListView) findViewById(R.id.list);
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400704 View empty = findViewById(R.id.empty);
705 mListView.setEmptyView(empty);
706 mListView.setAdapter(mAdapter);
707 mListView.setOnItemClickListener(this);
Leon Scroggins162f8352010-10-18 15:02:44 -0400708 mListView.addEditText(mFolderNamer);
Leon Scroggins504433a2011-01-13 12:26:52 -0500709
John Reck2eec4c32011-05-11 15:55:32 -0700710 mAccountAdapter = new ArrayAdapter<BookmarkAccount>(this,
711 android.R.layout.simple_spinner_item);
712 mAccountAdapter.setDropDownViewResource(
713 android.R.layout.simple_spinner_dropdown_item);
714 mAccountSpinner = (Spinner) findViewById(R.id.accounts);
715 mAccountSpinner.setAdapter(mAccountAdapter);
716 mAccountSpinner.setOnItemSelectedListener(this);
717
718
Leon Scroggins75630672011-01-13 17:56:15 -0500719 mFakeTitleHolder = findViewById(R.id.title_holder);
720
Leon Scroggins504433a2011-01-13 12:26:52 -0500721 if (!window.getDecorView().isInTouchMode()) {
722 mButton.requestFocus();
723 }
724
John Reck2eec4c32011-05-11 15:55:32 -0700725 getLoaderManager().restartLoader(LOADER_ID_ACCOUNTS, null, this);
Leon Scroggins504433a2011-01-13 12:26:52 -0500726 }
727
Leon Scroggins75630672011-01-13 17:56:15 -0500728 private void showRemoveButton() {
729 findViewById(R.id.remove_divider).setVisibility(View.VISIBLE);
730 mRemoveLink = findViewById(R.id.remove);
731 mRemoveLink.setVisibility(View.VISIBLE);
732 mRemoveLink.setOnClickListener(this);
733 }
734
Leon Scroggins504433a2011-01-13 12:26:52 -0500735 // Called once we have determined which folder is the root folder
736 private void onRootFolderFound(long root) {
737 mRootFolder = root;
John Reck2eec4c32011-05-11 15:55:32 -0700738 mCurrentFolder = mRootFolder;
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500739 setupTopCrumb();
John Reck2eec4c32011-05-11 15:55:32 -0700740 onCurrentFolderFound();
Leon Scroggins504433a2011-01-13 12:26:52 -0500741 }
742
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500743 private void setupTopCrumb() {
John Reck2eec4c32011-05-11 15:55:32 -0700744 mCrumbs.clear();
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500745 String name = getString(R.string.bookmarks);
746 mTopLevelLabel = (TextView) mCrumbs.pushView(name, false,
747 new Folder(name, mRootFolder));
748 // To better match the other folders.
749 mTopLevelLabel.setCompoundDrawablePadding(6);
750 }
751
Leon Scroggins504433a2011-01-13 12:26:52 -0500752 private void onCurrentFolderFound() {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400753 LoaderManager manager = getLoaderManager();
Leon Scroggins8baaa632010-12-08 19:46:53 -0500754 if (mCurrentFolder != mRootFolder) {
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500755 // Since we're not in the root folder, change the selection to other
756 // folder now. The text will get changed once we select the correct
757 // folder.
Leon Scroggins504433a2011-01-13 12:26:52 -0500758 mFolder.setSelectionIgnoringSelectionChange(mEditingFolder ? 1 : 2);
Leon Scroggins905250c2010-12-17 15:25:33 -0500759 } else {
760 setShowBookmarkIcon(true);
Leon Scroggins504433a2011-01-13 12:26:52 -0500761 if (!mEditingFolder) {
762 // Initially the "Bookmarks" folder should be showing, rather than
763 // the home screen. In the editing folder case, home screen is not
764 // an option, so "Bookmarks" folder is already at the top.
765 mFolder.setSelectionIgnoringSelectionChange(FolderSpinnerAdapter.ROOT_FOLDER);
766 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400767 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400768 // Find the contents of the current folder
John Reck2eec4c32011-05-11 15:55:32 -0700769 manager.restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
Leon Scroggins8baaa632010-12-08 19:46:53 -0500770 }
771
Leon Scroggins02065b02010-01-04 14:30:13 -0500772 /**
773 * Runnable to save a bookmark, so it can be performed in its own thread.
774 */
775 private class SaveBookmarkRunnable implements Runnable {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400776 // FIXME: This should be an async task.
Leon Scroggins02065b02010-01-04 14:30:13 -0500777 private Message mMessage;
Henrik Baard980e9952010-09-06 18:13:23 +0200778 private Context mContext;
779 public SaveBookmarkRunnable(Context ctx, Message msg) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100780 mContext = ctx.getApplicationContext();
Leon Scroggins02065b02010-01-04 14:30:13 -0500781 mMessage = msg;
782 }
783 public void run() {
784 // Unbundle bookmark data.
785 Bundle bundle = mMessage.getData();
Leon Scrogginsbc922852010-10-22 12:15:27 -0400786 String title = bundle.getString(BrowserContract.Bookmarks.TITLE);
787 String url = bundle.getString(BrowserContract.Bookmarks.URL);
788 boolean invalidateThumbnail = bundle.getBoolean(REMOVE_THUMBNAIL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500789 Bitmap thumbnail = invalidateThumbnail ? null
Leon Scrogginsbc922852010-10-22 12:15:27 -0400790 : (Bitmap) bundle.getParcelable(BrowserContract.Bookmarks.THUMBNAIL);
791 String touchIconUrl = bundle.getString(TOUCH_ICON_URL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500792
793 // Save to the bookmarks DB.
794 try {
795 final ContentResolver cr = getContentResolver();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400796 Bookmarks.addBookmark(AddBookmarkPage.this, false, url,
John Reckaf262e72011-07-25 13:55:44 -0700797 title, thumbnail, mCurrentFolder);
Leon Scroggins02065b02010-01-04 14:30:13 -0500798 if (touchIconUrl != null) {
Henrik Baard980e9952010-09-06 18:13:23 +0200799 new DownloadTouchIcon(mContext, cr, url).execute(mTouchIconUrl);
Leon Scroggins02065b02010-01-04 14:30:13 -0500800 }
801 mMessage.arg1 = 1;
802 } catch (IllegalStateException e) {
803 mMessage.arg1 = 0;
804 }
805 mMessage.sendToTarget();
806 }
807 }
808
John Reckc8490812010-11-22 14:15:36 -0800809 private static class UpdateBookmarkTask extends AsyncTask<ContentValues, Void, Void> {
810 Context mContext;
811 Long mId;
812
813 public UpdateBookmarkTask(Context context, long id) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100814 mContext = context.getApplicationContext();
John Reckc8490812010-11-22 14:15:36 -0800815 mId = id;
816 }
817
818 @Override
819 protected Void doInBackground(ContentValues... params) {
820 if (params.length != 1) {
821 throw new IllegalArgumentException("No ContentValues provided!");
822 }
823 Uri uri = ContentUris.withAppendedId(BookmarkUtils.getBookmarksUri(mContext), mId);
824 mContext.getContentResolver().update(
825 uri,
826 params[0], null, null);
827 return null;
828 }
829 }
830
Ben Murdoch1794fe22009-09-29 18:14:30 +0100831 private void createHandler() {
832 if (mHandler == null) {
833 mHandler = new Handler() {
834 @Override
835 public void handleMessage(Message msg) {
836 switch (msg.what) {
837 case SAVE_BOOKMARK:
Leon Scroggins02065b02010-01-04 14:30:13 -0500838 if (1 == msg.arg1) {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100839 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_saved,
840 Toast.LENGTH_LONG).show();
841 } else {
842 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_not_saved,
843 Toast.LENGTH_LONG).show();
844 }
845 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400846 case TOUCH_ICON_DOWNLOADED:
847 Bundle b = msg.getData();
848 sendBroadcast(BookmarkUtils.createAddToHomeIntent(
Leon Scrogginsbc922852010-10-22 12:15:27 -0400849 AddBookmarkPage.this,
850 b.getString(BrowserContract.Bookmarks.URL),
851 b.getString(BrowserContract.Bookmarks.TITLE),
852 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.TOUCH_ICON),
853 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.FAVICON)));
Leon Scroggins88d08032010-10-21 15:17:10 -0400854 break;
Leon Scroggins75630672011-01-13 17:56:15 -0500855 case BOOKMARK_DELETED:
856 finish();
857 break;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100858 }
859 }
860 };
861 }
862 }
863
luxiaoldbe4a622013-07-19 17:14:06 +0800864 static void deleteDuplicateBookmark(final Context context, final long id) {
865 Uri uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI, id);
866 context.getContentResolver().delete(uri, null, null);
867 }
868
869 private void onSaveWithConfirm() {
870 String title = mTitle.getText().toString().trim();
871 String unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString());
872 String url = unfilteredUrl.trim();
873 Long id = mMap.getLong(BrowserContract.Bookmarks._ID);
874 int duplicateCount;
875 final ContentResolver cr = getContentResolver();
876
877 Cursor cursor = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
878 BookmarksLoader.PROJECTION,
879 "( title = ? OR url = ? ) AND parent = ?",
880 new String[] {
881 title, url, Long.toString(mCurrentFolder)
882 },
883 null);
884
885 if (cursor == null) {
886 save();
887 return;
888 }
889
890 duplicateCount = cursor.getCount();
891 if (duplicateCount <= 0) {
892 cursor.close();
893 save();
894 return;
895 } else {
896 try {
897 while (cursor.moveToNext()) {
898 mDuplicateId = cursor.getLong(BookmarksLoader.COLUMN_INDEX_ID);
899 mDuplicateContext = AddBookmarkPage.this;
900 }
901 } catch (IllegalStateException e) {
902 e.printStackTrace();
903 } finally {
904 if (cursor != null)
905 cursor.close();
906 }
907 }
908
909 if (mEditingExisting && duplicateCount == 1 && mDuplicateId == id) {
910 save();
911 return;
912 }
913
914 new AlertDialog.Builder(this)
915 .setTitle(getString(R.string.save_to_bookmarks_title))
916 .setMessage(getString(R.string.overwrite_bookmark_msg))
917 .setNegativeButton(android.R.string.cancel, null)
918 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
919 public void onClick(DialogInterface dialog, int which) {
920 if (mDuplicateContext == null) {
921 return;
922 }
923 deleteDuplicateBookmark(mDuplicateContext, mDuplicateId);
924 save();
925 }
926 })
927 .show();
928 }
929
The Android Open Source Project0c908882009-03-03 19:32:16 -0800930 /**
Ben Murdoch1794fe22009-09-29 18:14:30 +0100931 * 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 -0800932 */
933 boolean save() {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100934 createHandler();
935
The Android Open Source Project0c908882009-03-03 19:32:16 -0800936 String title = mTitle.getText().toString().trim();
luxiaoldbe4a622013-07-19 17:14:06 +0800937 String unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString());
Ben Murdocheecb4e62010-07-06 16:30:38 +0100938
The Android Open Source Project0c908882009-03-03 19:32:16 -0800939 boolean emptyTitle = title.length() == 0;
940 boolean emptyUrl = unfilteredUrl.trim().length() == 0;
941 Resources r = getResources();
John Reckc8490812010-11-22 14:15:36 -0800942 if (emptyTitle || (emptyUrl && !mEditingFolder)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800943 if (emptyTitle) {
944 mTitle.setError(r.getText(R.string.bookmark_needs_title));
945 }
946 if (emptyUrl) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400947 mAddress.setError(r.getText(R.string.bookmark_needs_url));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800948 }
Leon Scroggins III6e3faea2010-09-07 15:22:14 -0400949 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800950 }
Ben Murdochca12cfa2009-11-17 13:57:44 +0000951 String url = unfilteredUrl.trim();
John Reckc8490812010-11-22 14:15:36 -0800952 if (!mEditingFolder) {
953 try {
954 // We allow bookmarks with a javascript: scheme, but these will in most cases
955 // fail URI parsing, so don't try it if that's the kind of bookmark we have.
Ben Murdochca12cfa2009-11-17 13:57:44 +0000956
John Reckc8490812010-11-22 14:15:36 -0800957 if (!url.toLowerCase().startsWith("javascript:")) {
958 URI uriObj = new URI(url);
959 String scheme = uriObj.getScheme();
960 if (!Bookmarks.urlHasAcceptableScheme(url)) {
961 // If the scheme was non-null, let the user know that we
962 // can't save their bookmark. If it was null, we'll assume
963 // they meant http when we parse it in the WebAddress class.
964 if (scheme != null) {
965 mAddress.setError(r.getText(R.string.bookmark_cannot_save_url));
966 return false;
967 }
968 WebAddress address;
969 try {
970 address = new WebAddress(unfilteredUrl);
971 } catch (ParseException e) {
972 throw new URISyntaxException("", "");
973 }
974 if (address.getHost().length() == 0) {
975 throw new URISyntaxException("", "");
976 }
977 url = address.toString();
Ben Murdochca12cfa2009-11-17 13:57:44 +0000978 }
Ben Murdochde353622009-10-12 10:29:00 +0100979 }
John Reckc8490812010-11-22 14:15:36 -0800980 } catch (URISyntaxException e) {
981 mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
982 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800983 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800984 }
Ben Murdochaac7aa62009-09-17 16:57:40 +0100985
Leon Scroggins88d08032010-10-21 15:17:10 -0400986 if (mSaveToHomeScreen) {
987 mEditingExisting = false;
988 }
989
990 boolean urlUnmodified = url.equals(mOriginalUrl);
991
Ben Murdoch1794fe22009-09-29 18:14:30 +0100992 if (mEditingExisting) {
John Reckc8490812010-11-22 14:15:36 -0800993 Long id = mMap.getLong(BrowserContract.Bookmarks._ID);
994 ContentValues values = new ContentValues();
995 values.put(BrowserContract.Bookmarks.TITLE, title);
996 values.put(BrowserContract.Bookmarks.PARENT, mCurrentFolder);
997 if (!mEditingFolder) {
998 values.put(BrowserContract.Bookmarks.URL, url);
999 if (!urlUnmodified) {
1000 values.putNull(BrowserContract.Bookmarks.THUMBNAIL);
1001 }
1002 }
1003 if (values.size() > 0) {
1004 new UpdateBookmarkTask(getApplicationContext(), id).execute(values);
1005 }
1006 setResult(RESULT_OK);
Ben Murdoch1794fe22009-09-29 18:14:30 +01001007 } else {
Leon Scroggins88d08032010-10-21 15:17:10 -04001008 Bitmap thumbnail;
1009 Bitmap favicon;
1010 if (urlUnmodified) {
Leon Scrogginsbc922852010-10-22 12:15:27 -04001011 thumbnail = (Bitmap) mMap.getParcelable(
1012 BrowserContract.Bookmarks.THUMBNAIL);
1013 favicon = (Bitmap) mMap.getParcelable(
1014 BrowserContract.Bookmarks.FAVICON);
Leon Scroggins88d08032010-10-21 15:17:10 -04001015 } else {
1016 thumbnail = null;
1017 favicon = null;
1018 }
1019
Ben Murdoch1794fe22009-09-29 18:14:30 +01001020 Bundle bundle = new Bundle();
Leon Scrogginsbc922852010-10-22 12:15:27 -04001021 bundle.putString(BrowserContract.Bookmarks.TITLE, title);
1022 bundle.putString(BrowserContract.Bookmarks.URL, url);
1023 bundle.putParcelable(BrowserContract.Bookmarks.FAVICON, favicon);
Leon Scroggins88d08032010-10-21 15:17:10 -04001024
1025 if (mSaveToHomeScreen) {
1026 if (mTouchIconUrl != null && urlUnmodified) {
1027 Message msg = Message.obtain(mHandler,
1028 TOUCH_ICON_DOWNLOADED);
1029 msg.setData(bundle);
1030 DownloadTouchIcon icon = new DownloadTouchIcon(this, msg,
Leon Scrogginsbc922852010-10-22 12:15:27 -04001031 mMap.getString(USER_AGENT));
Leon Scroggins88d08032010-10-21 15:17:10 -04001032 icon.execute(mTouchIconUrl);
1033 } else {
1034 sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url,
1035 title, null /*touchIcon*/, favicon));
1036 }
1037 } else {
Leon Scrogginsbc922852010-10-22 12:15:27 -04001038 bundle.putParcelable(BrowserContract.Bookmarks.THUMBNAIL, thumbnail);
1039 bundle.putBoolean(REMOVE_THUMBNAIL, !urlUnmodified);
1040 bundle.putString(TOUCH_ICON_URL, mTouchIconUrl);
Leon Scroggins88d08032010-10-21 15:17:10 -04001041 // Post a message to write to the DB.
1042 Message msg = Message.obtain(mHandler, SAVE_BOOKMARK);
1043 msg.setData(bundle);
1044 // Start a new thread so as to not slow down the UI
1045 Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg));
1046 t.start();
1047 }
Ben Murdoch1794fe22009-09-29 18:14:30 +01001048 setResult(RESULT_OK);
Kristian Monsen0a1d8382010-02-01 18:41:07 +00001049 LogTag.logBookmarkAdded(url, "bookmarkview");
The Android Open Source Project0c908882009-03-03 19:32:16 -08001050 }
luxiaoldbe4a622013-07-19 17:14:06 +08001051 finish();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001052 return true;
1053 }
Leon Scroggins162f8352010-10-18 15:02:44 -04001054
John Reck2eec4c32011-05-11 15:55:32 -07001055 @Override
1056 public void onItemSelected(AdapterView<?> parent, View view, int position,
1057 long id) {
1058 if (mAccountSpinner == parent) {
1059 long root = mAccountAdapter.getItem(position).rootFolderId;
1060 if (root != mRootFolder) {
1061 onRootFolderFound(root);
John Recke890c902011-07-11 17:44:43 -07001062 mFolderAdapter.clearRecentFolder();
John Reck2eec4c32011-05-11 15:55:32 -07001063 }
1064 }
1065 }
1066
1067 @Override
1068 public void onNothingSelected(AdapterView<?> parent) {
1069 // Don't care
1070 }
1071
Leon Scroggins162f8352010-10-18 15:02:44 -04001072 /*
1073 * Class used as a proxy for the InputMethodManager to get to mFolderNamer
1074 */
1075 public static class CustomListView extends ListView {
1076 private EditText mEditText;
1077
1078 public void addEditText(EditText editText) {
1079 mEditText = editText;
1080 }
1081
1082 public CustomListView(Context context) {
1083 super(context);
1084 }
1085
1086 public CustomListView(Context context, AttributeSet attrs) {
1087 super(context, attrs);
1088 }
1089
1090 public CustomListView(Context context, AttributeSet attrs, int defStyle) {
1091 super(context, attrs, defStyle);
1092 }
1093
1094 @Override
1095 public boolean checkInputConnectionProxy(View view) {
1096 return view == mEditText;
1097 }
1098 }
John Reck2eec4c32011-05-11 15:55:32 -07001099
John Reck3bf3cfb2011-10-17 18:00:05 -07001100 static class AccountsLoader extends CursorLoader {
John Reck2eec4c32011-05-11 15:55:32 -07001101
1102 static final String[] PROJECTION = new String[] {
1103 Accounts.ACCOUNT_NAME,
1104 Accounts.ACCOUNT_TYPE,
1105 Accounts.ROOT_ID,
1106 };
1107
1108 static final int COLUMN_INDEX_ACCOUNT_NAME = 0;
1109 static final int COLUMN_INDEX_ACCOUNT_TYPE = 1;
1110 static final int COLUMN_INDEX_ROOT_ID = 2;
1111
1112 public AccountsLoader(Context context) {
John Reck1e9815d2011-08-08 17:45:05 -07001113 super(context, Accounts.CONTENT_URI, PROJECTION, null, null, null);
John Reck2eec4c32011-05-11 15:55:32 -07001114 }
1115
1116 }
1117
John Reck9b8cd1e2011-05-25 18:14:01 -07001118 public static class BookmarkAccount {
John Reck2eec4c32011-05-11 15:55:32 -07001119
1120 private String mLabel;
1121 String accountName, accountType;
John Reck9b8cd1e2011-05-25 18:14:01 -07001122 public long rootFolderId;
John Reck2eec4c32011-05-11 15:55:32 -07001123
1124 public BookmarkAccount(Context context, Cursor cursor) {
1125 accountName = cursor.getString(
1126 AccountsLoader.COLUMN_INDEX_ACCOUNT_NAME);
1127 accountType = cursor.getString(
1128 AccountsLoader.COLUMN_INDEX_ACCOUNT_TYPE);
1129 rootFolderId = cursor.getLong(
1130 AccountsLoader.COLUMN_INDEX_ROOT_ID);
1131 mLabel = accountName;
1132 if (TextUtils.isEmpty(mLabel)) {
1133 mLabel = context.getString(R.string.local_bookmarks);
1134 }
1135 }
1136
1137 @Override
1138 public String toString() {
1139 return mLabel;
1140 }
1141 }
1142
1143 static class EditBookmarkInfo {
1144 long id = -1;
1145 long parentId = -1;
1146 String parentTitle;
1147 String title;
1148 String accountName;
1149 String accountType;
1150
1151 long lastUsedId = -1;
1152 String lastUsedTitle;
1153 String lastUsedAccountName;
1154 String lastUsedAccountType;
1155 }
1156
1157 static class EditBookmarkInfoLoader extends AsyncTaskLoader<EditBookmarkInfo> {
1158
1159 private Context mContext;
1160 private Bundle mMap;
1161
1162 public EditBookmarkInfoLoader(Context context, Bundle bundle) {
1163 super(context);
Ben Murdoch914c5592011-08-01 13:58:47 +01001164 mContext = context.getApplicationContext();
John Reck2eec4c32011-05-11 15:55:32 -07001165 mMap = bundle;
1166 }
1167
1168 @Override
1169 public EditBookmarkInfo loadInBackground() {
1170 final ContentResolver cr = mContext.getContentResolver();
1171 EditBookmarkInfo info = new EditBookmarkInfo();
1172 Cursor c = null;
1173
1174 try {
1175 // First, let's lookup the bookmark (check for dupes, get needed info)
1176 String url = mMap.getString(BrowserContract.Bookmarks.URL);
1177 info.id = mMap.getLong(BrowserContract.Bookmarks._ID, -1);
1178 boolean checkForDupe = mMap.getBoolean(CHECK_FOR_DUPE);
1179 if (checkForDupe && info.id == -1 && !TextUtils.isEmpty(url)) {
1180 c = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
1181 new String[] { BrowserContract.Bookmarks._ID},
1182 BrowserContract.Bookmarks.URL + "=?",
1183 new String[] { url }, null);
1184 if (c.getCount() == 1 && c.moveToFirst()) {
1185 info.id = c.getLong(0);
1186 }
1187 c.close();
1188 }
1189 if (info.id != -1) {
1190 c = cr.query(ContentUris.withAppendedId(
1191 BrowserContract.Bookmarks.CONTENT_URI, info.id),
1192 new String[] {
1193 BrowserContract.Bookmarks.PARENT,
1194 BrowserContract.Bookmarks.ACCOUNT_NAME,
1195 BrowserContract.Bookmarks.ACCOUNT_TYPE,
1196 BrowserContract.Bookmarks.TITLE},
1197 null, null, null);
1198 if (c.moveToFirst()) {
1199 info.parentId = c.getLong(0);
1200 info.accountName = c.getString(1);
1201 info.accountType = c.getString(2);
1202 info.title = c.getString(3);
1203 }
1204 c.close();
1205 c = cr.query(ContentUris.withAppendedId(
1206 BrowserContract.Bookmarks.CONTENT_URI, info.parentId),
1207 new String[] {
1208 BrowserContract.Bookmarks.TITLE,},
1209 null, null, null);
1210 if (c.moveToFirst()) {
1211 info.parentTitle = c.getString(0);
1212 }
1213 c.close();
1214 }
1215
1216 // Figure out the last used folder/account
1217 c = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
1218 new String[] {
1219 BrowserContract.Bookmarks.PARENT,
1220 }, null, null,
1221 BrowserContract.Bookmarks.DATE_MODIFIED + " DESC LIMIT 1");
1222 if (c.moveToFirst()) {
1223 long parent = c.getLong(0);
1224 c.close();
1225 c = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
1226 new String[] {
1227 BrowserContract.Bookmarks.TITLE,
1228 BrowserContract.Bookmarks.ACCOUNT_NAME,
1229 BrowserContract.Bookmarks.ACCOUNT_TYPE},
1230 BrowserContract.Bookmarks._ID + "=?", new String[] {
1231 Long.toString(parent)}, null);
1232 if (c.moveToFirst()) {
1233 info.lastUsedId = parent;
1234 info.lastUsedTitle = c.getString(0);
1235 info.lastUsedAccountName = c.getString(1);
1236 info.lastUsedAccountType = c.getString(2);
1237 }
1238 c.close();
1239 }
1240 } finally {
1241 if (c != null) {
1242 c.close();
1243 }
1244 }
1245
1246 return info;
1247 }
1248
1249 @Override
1250 protected void onStartLoading() {
1251 forceLoad();
1252 }
1253
1254 }
1255
The Android Open Source Project0c908882009-03-03 19:32:16 -08001256}