blob: 73a1ebf6ff3ea939fc798d0a5a4665111ac5041e [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;
luxiaoldbe4a622013-07-19 17:14:06 +080041import android.provider.Browser;
Leon Scroggins25230d72010-09-28 20:09:25 -040042import android.text.TextUtils;
Leon Scroggins162f8352010-10-18 15:02:44 -040043import android.util.AttributeSet;
Leon Scroggins III052ce662010-09-13 14:44:16 -040044import android.view.KeyEvent;
45import android.view.LayoutInflater;
The Android Open Source Project0c908882009-03-03 19:32:16 -080046import android.view.View;
Leon Scroggins III052ce662010-09-13 14:44:16 -040047import android.view.ViewGroup;
The Android Open Source Project0c908882009-03-03 19:32:16 -080048import android.view.Window;
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -040049import android.view.WindowManager;
Leon Scroggins III052ce662010-09-13 14:44:16 -040050import android.view.inputmethod.EditorInfo;
51import android.view.inputmethod.InputMethodManager;
52import android.widget.AdapterView;
John Reck2eec4c32011-05-11 15:55:32 -070053import android.widget.AdapterView.OnItemSelectedListener;
54import android.widget.ArrayAdapter;
Leon Scroggins III052ce662010-09-13 14:44:16 -040055import android.widget.CursorAdapter;
The Android Open Source Project0c908882009-03-03 19:32:16 -080056import android.widget.EditText;
Leon Scroggins III052ce662010-09-13 14:44:16 -040057import android.widget.ListView;
John Reck2eec4c32011-05-11 15:55:32 -070058import android.widget.Spinner;
The Android Open Source Project0c908882009-03-03 19:32:16 -080059import android.widget.TextView;
60import android.widget.Toast;
61
Bijan Amirzada41242f22014-03-21 12:12:18 -070062import com.android.browser.BrowserUtils;
63import com.android.browser.R;
64import com.android.browser.addbookmark.FolderSpinner;
65import com.android.browser.addbookmark.FolderSpinnerAdapter;
66import com.android.browser.platformsupport.BrowserContract;
67import com.android.browser.platformsupport.WebAddress;
68import com.android.browser.platformsupport.BrowserContract.Accounts;
69import com.android.browser.reflect.ReflectHelper;
luxiaoldbe4a622013-07-19 17:14:06 +080070
Cary Clarkf2407c62009-09-04 12:25:10 -040071import java.net.URI;
72import java.net.URISyntaxException;
Leon Scroggins III052ce662010-09-13 14:44:16 -040073
74public class AddBookmarkPage extends Activity
75 implements View.OnClickListener, TextView.OnEditorActionListener,
Leon Scroggins74dbe012010-10-15 10:54:27 -040076 AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor>,
John Reck2eec4c32011-05-11 15:55:32 -070077 BreadCrumbView.Controller, FolderSpinner.OnSetSelectionListener,
78 OnItemSelectedListener {
The Android Open Source Project0c908882009-03-03 19:32:16 -080079
Michael Kolb370a4f32010-10-06 10:45:32 -070080 public static final long DEFAULT_FOLDER_ID = -1;
Leon Scrogginsbc922852010-10-22 12:15:27 -040081 public static final String TOUCH_ICON_URL = "touch_icon_url";
82 // Place on an edited bookmark to remove the saved thumbnail
83 public static final String REMOVE_THUMBNAIL = "remove_thumbnail";
84 public static final String USER_AGENT = "user_agent";
Leon Scrogginsbdff8a72011-02-11 15:49:04 -050085 public static final String CHECK_FOR_DUPE = "check_for_dupe";
Michael Kolb370a4f32010-10-06 10:45:32 -070086
John Reckc8490812010-11-22 14:15:36 -080087 /* package */ static final String EXTRA_EDIT_BOOKMARK = "bookmark";
88 /* package */ static final String EXTRA_IS_FOLDER = "is_folder";
89
kaiyiz3d7e4d52013-09-17 17:56:27 +080090 private static final int MAX_CRUMBS_SHOWN = 1;
Leon Scroggins74dbe012010-10-15 10:54:27 -040091
The Android Open Source Project0c908882009-03-03 19:32:16 -080092 private final String LOGTAG = "Bookmarks";
93
Leon Scroggins III052ce662010-09-13 14:44:16 -040094 // IDs for the CursorLoaders that are used.
John Reck2eec4c32011-05-11 15:55:32 -070095 private final int LOADER_ID_ACCOUNTS = 0;
96 private final int LOADER_ID_FOLDER_CONTENTS = 1;
97 private final int LOADER_ID_EDIT_INFO = 2;
Leon Scroggins III052ce662010-09-13 14:44:16 -040098
The Android Open Source Project0c908882009-03-03 19:32:16 -080099 private EditText mTitle;
100 private EditText mAddress;
101 private TextView mButton;
102 private View mCancelButton;
103 private boolean mEditingExisting;
John Reckc8490812010-11-22 14:15:36 -0800104 private boolean mEditingFolder;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800105 private Bundle mMap;
Patrick Scott3918d442009-08-04 13:22:29 -0400106 private String mTouchIconUrl;
Ben Murdochaac7aa62009-09-17 16:57:40 +0100107 private String mOriginalUrl;
Leon Scroggins504433a2011-01-13 12:26:52 -0500108 private FolderSpinner mFolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400109 private View mDefaultView;
110 private View mFolderSelector;
111 private EditText mFolderNamer;
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500112 private View mFolderCancel;
Leon Scroggins162f8352010-10-18 15:02:44 -0400113 private boolean mIsFolderNamerShowing;
114 private View mFolderNamerHolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400115 private View mAddNewFolder;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400116 private View mAddSeparator;
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500117 private long mCurrentFolder;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400118 private FolderAdapter mAdapter;
Leon Scroggins74dbe012010-10-15 10:54:27 -0400119 private BreadCrumbView mCrumbs;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400120 private TextView mFakeTitle;
121 private View mCrumbHolder;
Leon Scroggins162f8352010-10-18 15:02:44 -0400122 private CustomListView mListView;
Leon Scroggins88d08032010-10-21 15:17:10 -0400123 private boolean mSaveToHomeScreen;
Leon Scroggins02081942010-11-01 17:52:42 -0400124 private long mRootFolder;
Leon Scroggins905250c2010-12-17 15:25:33 -0500125 private TextView mTopLevelLabel;
126 private Drawable mHeaderIcon;
Leon Scroggins75630672011-01-13 17:56:15 -0500127 private View mRemoveLink;
128 private View mFakeTitleHolder;
Leon Scroggins2f24e992011-02-11 14:02:10 -0500129 private FolderSpinnerAdapter mFolderAdapter;
John Reck2eec4c32011-05-11 15:55:32 -0700130 private Spinner mAccountSpinner;
131 private ArrayAdapter<BookmarkAccount> mAccountAdapter;
luxiaoldbe4a622013-07-19 17:14:06 +0800132 // add for carrier which requires same title or address can not exist.
133 private long mDuplicateId;
134 private Context mDuplicateContext;
John Reck2eec4c32011-05-11 15:55:32 -0700135
Leon Scroggins III052ce662010-09-13 14:44:16 -0400136 private static class Folder {
137 String Name;
138 long Id;
139 Folder(String name, long id) {
140 Name = name;
141 Id = id;
142 }
143 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800144
Ben Murdoch1794fe22009-09-29 18:14:30 +0100145 // Message IDs
146 private static final int SAVE_BOOKMARK = 100;
Leon Scroggins88d08032010-10-21 15:17:10 -0400147 private static final int TOUCH_ICON_DOWNLOADED = 101;
Leon Scroggins75630672011-01-13 17:56:15 -0500148 private static final int BOOKMARK_DELETED = 102;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100149
150 private Handler mHandler;
151
Bjorn Bringertb1402a52010-10-12 10:53:12 +0100152 private InputMethodManager getInputMethodManager() {
153 return (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
154 }
155
Leon Scroggins8baaa632010-12-08 19:46:53 -0500156 private Uri getUriForFolder(long folder) {
John Reck903a0722011-11-09 17:53:10 -0800157 BookmarkAccount account =
158 (BookmarkAccount) mAccountSpinner.getSelectedItem();
159 if (folder == mRootFolder && account != null) {
160 return BookmarksLoader.addAccount(
161 BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER,
162 account.accountType, account.accountName);
163 }
John Reck2eec4c32011-05-11 15:55:32 -0700164 return BrowserContract.Bookmarks.buildFolderUri(folder);
Leon Scroggins8baaa632010-12-08 19:46:53 -0500165 }
166
Leon Scroggins III052ce662010-09-13 14:44:16 -0400167 @Override
John Reck71efc2b2011-05-09 16:54:28 -0700168 public void onTop(BreadCrumbView view, int level, Object data) {
Leon Scroggins74dbe012010-10-15 10:54:27 -0400169 if (null == data) return;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400170 Folder folderData = (Folder) data;
171 long folder = folderData.Id;
Leon Scroggins74dbe012010-10-15 10:54:27 -0400172 LoaderManager manager = getLoaderManager();
John Reck2eec4c32011-05-11 15:55:32 -0700173 CursorLoader loader = (CursorLoader) ((Loader<?>) manager.getLoader(
Leon Scroggins74dbe012010-10-15 10:54:27 -0400174 LOADER_ID_FOLDER_CONTENTS));
Leon Scroggins8baaa632010-12-08 19:46:53 -0500175 loader.setUri(getUriForFolder(folder));
Leon Scroggins74dbe012010-10-15 10:54:27 -0400176 loader.forceLoad();
Leon Scroggins162f8352010-10-18 15:02:44 -0400177 if (mIsFolderNamerShowing) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400178 completeOrCancelFolderNaming(true);
179 }
Leon Scroggins905250c2010-12-17 15:25:33 -0500180 setShowBookmarkIcon(level == 1);
181 }
182
183 /**
184 * Show or hide the icon for bookmarks next to "Bookmarks" in the crumb view.
185 * @param show True if the icon should visible, false otherwise.
186 */
187 private void setShowBookmarkIcon(boolean show) {
188 Drawable drawable = show ? mHeaderIcon: null;
189 mTopLevelLabel.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
Leon Scroggins74dbe012010-10-15 10:54:27 -0400190 }
191
Leon Scroggins74dbe012010-10-15 10:54:27 -0400192 @Override
Leon Scroggins III052ce662010-09-13 14:44:16 -0400193 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
194 if (v == mFolderNamer) {
195 if (v.getText().length() > 0) {
196 if (actionId == EditorInfo.IME_NULL) {
197 // Only want to do this once.
198 if (event.getAction() == KeyEvent.ACTION_UP) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400199 completeOrCancelFolderNaming(false);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400200 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400201 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800202 }
Michael Kolb31829b92010-10-01 11:50:21 -0700203 // Steal the key press; otherwise a newline will be added
204 return true;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800205 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400206 return false;
207 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800208
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400209 private void switchToDefaultView(boolean changedFolder) {
210 mFolderSelector.setVisibility(View.GONE);
211 mDefaultView.setVisibility(View.VISIBLE);
212 mCrumbHolder.setVisibility(View.GONE);
Leon Scroggins75630672011-01-13 17:56:15 -0500213 mFakeTitleHolder.setVisibility(View.VISIBLE);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400214 if (changedFolder) {
215 Object data = mCrumbs.getTopData();
216 if (data != null) {
217 Folder folder = (Folder) data;
218 mCurrentFolder = folder.Id;
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500219 if (mCurrentFolder == mRootFolder) {
220 // The Spinner changed to show "Other folder ..." Change
221 // it back to "Bookmarks", which is position 0 if we are
222 // editing a folder, 1 otherwise.
Leon Scroggins504433a2011-01-13 12:26:52 -0500223 mFolder.setSelectionIgnoringSelectionChange(mEditingFolder ? 0 : 1);
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500224 } else {
John Reck2eec4c32011-05-11 15:55:32 -0700225 mFolderAdapter.setOtherFolderDisplayText(folder.Name);
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500226 }
227 }
228 } else {
229 // The user canceled selecting a folder. Revert back to the earlier
230 // selection.
231 if (mSaveToHomeScreen) {
Leon Scroggins504433a2011-01-13 12:26:52 -0500232 mFolder.setSelectionIgnoringSelectionChange(0);
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500233 } else {
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500234 if (mCurrentFolder == mRootFolder) {
235 mFolder.setSelectionIgnoringSelectionChange(mEditingFolder ? 0 : 1);
236 } else {
237 Object data = mCrumbs.getTopData();
238 if (data != null && ((Folder) data).Id == mCurrentFolder) {
John Reck2eec4c32011-05-11 15:55:32 -0700239 // We are showing the correct folder hierarchy. The
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500240 // folder selector will say "Other folder..." Change it
241 // to say the name of the folder once again.
John Reck2eec4c32011-05-11 15:55:32 -0700242 mFolderAdapter.setOtherFolderDisplayText(((Folder) data).Name);
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500243 } else {
John Reck2eec4c32011-05-11 15:55:32 -0700244 // We are not showing the correct folder hierarchy.
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500245 // Clear the Crumbs and find the proper folder
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500246 setupTopCrumb();
247 LoaderManager manager = getLoaderManager();
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500248 manager.restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
249
250 }
251 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400252 }
253 }
254 }
255
Leon Scroggins III052ce662010-09-13 14:44:16 -0400256 @Override
257 public void onClick(View v) {
258 if (v == mButton) {
259 if (mFolderSelector.getVisibility() == View.VISIBLE) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400260 // We are showing the folder selector.
Leon Scroggins162f8352010-10-18 15:02:44 -0400261 if (mIsFolderNamerShowing) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400262 completeOrCancelFolderNaming(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700263 } else {
264 // User has selected a folder. Go back to the opening page
Leon Scroggins88d08032010-10-21 15:17:10 -0400265 mSaveToHomeScreen = false;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400266 switchToDefaultView(true);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700267 }
luxiaoldbe4a622013-07-19 17:14:06 +0800268 } else {
269 // add for carrier which requires same title or address can not
270 // exist.
271 if (mSaveToHomeScreen) {
272 if (save()) {
273 return;
274 }
275 } else {
276 onSaveWithConfirm();
277 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400278 }
279 } else if (v == mCancelButton) {
Leon Scroggins162f8352010-10-18 15:02:44 -0400280 if (mIsFolderNamerShowing) {
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400281 completeOrCancelFolderNaming(true);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400282 } else if (mFolderSelector.getVisibility() == View.VISIBLE) {
283 switchToDefaultView(false);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700284 } else {
285 finish();
286 }
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500287 } else if (v == mFolderCancel) {
288 completeOrCancelFolderNaming(true);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400289 } else if (v == mAddNewFolder) {
Leon Scroggins162f8352010-10-18 15:02:44 -0400290 setShowFolderNamer(true);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400291 mFolderNamer.setText(R.string.new_folder);
292 mFolderNamer.requestFocus();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700293 mAddNewFolder.setVisibility(View.GONE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400294 mAddSeparator.setVisibility(View.GONE);
Leon Scroggins162f8352010-10-18 15:02:44 -0400295 InputMethodManager imm = getInputMethodManager();
296 // Set the InputMethodManager to focus on the ListView so that it
297 // can transfer the focus to mFolderNamer.
Bijan Amirzada9b1e9882014-02-26 17:15:46 -0800298 //imm.focusIn(mListView);
299 Object[] params = {mListView};
300 Class[] type = new Class[] {View.class};
301 ReflectHelper.invokeMethod(imm, "focusIn", type, params);
Leon Scroggins162f8352010-10-18 15:02:44 -0400302 imm.showSoftInput(mFolderNamer, InputMethodManager.SHOW_IMPLICIT);
Leon Scroggins75630672011-01-13 17:56:15 -0500303 } else if (v == mRemoveLink) {
304 if (!mEditingExisting) {
305 throw new AssertionError("Remove button should not be shown for"
306 + " new bookmarks");
307 }
308 long id = mMap.getLong(BrowserContract.Bookmarks._ID);
309 createHandler();
310 Message msg = Message.obtain(mHandler, BOOKMARK_DELETED);
311 BookmarkUtils.displayRemoveBookmarkDialog(id,
312 mTitle.getText().toString(), this, msg);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800313 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400314 }
315
Leon Scroggins504433a2011-01-13 12:26:52 -0500316 // FolderSpinner.OnSetSelectionListener
317
Leon Scroggins88d08032010-10-21 15:17:10 -0400318 @Override
Leon Scroggins504433a2011-01-13 12:26:52 -0500319 public void onSetSelection(long id) {
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500320 int intId = (int) id;
321 switch (intId) {
322 case FolderSpinnerAdapter.ROOT_FOLDER:
Leon Scroggins02081942010-11-01 17:52:42 -0400323 mCurrentFolder = mRootFolder;
Leon Scroggins88d08032010-10-21 15:17:10 -0400324 mSaveToHomeScreen = false;
325 break;
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500326 case FolderSpinnerAdapter.HOME_SCREEN:
Leon Scroggins88d08032010-10-21 15:17:10 -0400327 // Create a short cut to the home screen
328 mSaveToHomeScreen = true;
Leon Scroggins88d08032010-10-21 15:17:10 -0400329 break;
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500330 case FolderSpinnerAdapter.OTHER_FOLDER:
Leon Scroggins88d08032010-10-21 15:17:10 -0400331 switchToFolderSelector();
332 break;
Leon Scroggins2f24e992011-02-11 14:02:10 -0500333 case FolderSpinnerAdapter.RECENT_FOLDER:
334 mCurrentFolder = mFolderAdapter.recentFolderId();
335 mSaveToHomeScreen = false;
336 // In case the user decides to select OTHER_FOLDER
337 // and choose a different one, so that we will start from
338 // the correct place.
339 LoaderManager manager = getLoaderManager();
Leon Scroggins2f24e992011-02-11 14:02:10 -0500340 manager.restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
Leon Scroggins0b95ad42011-02-23 15:23:48 -0500341 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400342 default:
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500343 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400344 }
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500345 }
346
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500347 /**
348 * Finish naming a folder, and close the IME
349 * @param cancel If true, the new folder is not created. If false, the new
350 * folder is created and the user is taken inside it.
351 */
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400352 private void completeOrCancelFolderNaming(boolean cancel) {
353 if (!cancel && !TextUtils.isEmpty(mFolderNamer.getText())) {
Michael Kolb31829b92010-10-01 11:50:21 -0700354 String name = mFolderNamer.getText().toString();
355 long id = addFolderToCurrent(mFolderNamer.getText().toString());
356 descendInto(name, id);
Michael Kolb31829b92010-10-01 11:50:21 -0700357 }
Leon Scroggins162f8352010-10-18 15:02:44 -0400358 setShowFolderNamer(false);
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400359 mAddNewFolder.setVisibility(View.VISIBLE);
360 mAddSeparator.setVisibility(View.VISIBLE);
361 getInputMethodManager().hideSoftInputFromWindow(
Leon Scroggins162f8352010-10-18 15:02:44 -0400362 mListView.getWindowToken(), 0);
Michael Kolb31829b92010-10-01 11:50:21 -0700363 }
364
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700365 private long addFolderToCurrent(String name) {
366 // Add the folder to the database
367 ContentValues values = new ContentValues();
368 values.put(BrowserContract.Bookmarks.TITLE,
369 name);
370 values.put(BrowserContract.Bookmarks.IS_FOLDER, 1);
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400371 long currentFolder;
372 Object data = mCrumbs.getTopData();
373 if (data != null) {
374 currentFolder = ((Folder) data).Id;
375 } else {
Leon Scroggins02081942010-11-01 17:52:42 -0400376 currentFolder = mRootFolder;
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400377 }
378 values.put(BrowserContract.Bookmarks.PARENT, currentFolder);
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700379 Uri uri = getContentResolver().insert(
380 BrowserContract.Bookmarks.CONTENT_URI, values);
381 if (uri != null) {
382 return ContentUris.parseId(uri);
383 } else {
384 return -1;
385 }
386 }
387
Leon Scroggins III052ce662010-09-13 14:44:16 -0400388 private void switchToFolderSelector() {
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500389 // Set the list to the top in case it is scrolled.
390 mListView.setSelection(0);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400391 mDefaultView.setVisibility(View.GONE);
392 mFolderSelector.setVisibility(View.VISIBLE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400393 mCrumbHolder.setVisibility(View.VISIBLE);
Leon Scroggins75630672011-01-13 17:56:15 -0500394 mFakeTitleHolder.setVisibility(View.GONE);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400395 mAddNewFolder.setVisibility(View.VISIBLE);
396 mAddSeparator.setVisibility(View.VISIBLE);
John Reck95f88e42011-09-26 09:25:43 -0700397 getInputMethodManager().hideSoftInputFromWindow(
398 mListView.getWindowToken(), 0);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400399 }
400
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700401 private void descendInto(String foldername, long id) {
Michael Kolb370a4f32010-10-06 10:45:32 -0700402 if (id != DEFAULT_FOLDER_ID) {
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400403 mCrumbs.pushView(foldername, new Folder(foldername, id));
Leon Scroggins74dbe012010-10-15 10:54:27 -0400404 mCrumbs.notifyController();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700405 }
406 }
407
John Reck2eec4c32011-05-11 15:55:32 -0700408 private LoaderCallbacks<EditBookmarkInfo> mEditInfoLoaderCallbacks =
409 new LoaderCallbacks<EditBookmarkInfo>() {
410
411 @Override
412 public void onLoaderReset(Loader<EditBookmarkInfo> loader) {
413 // Don't care
414 }
415
416 @Override
417 public void onLoadFinished(Loader<EditBookmarkInfo> loader,
418 EditBookmarkInfo info) {
419 boolean setAccount = false;
420 if (info.id != -1) {
421 mEditingExisting = true;
422 showRemoveButton();
423 mFakeTitle.setText(R.string.edit_bookmark);
424 mTitle.setText(info.title);
425 mFolderAdapter.setOtherFolderDisplayText(info.parentTitle);
426 mMap.putLong(BrowserContract.Bookmarks._ID, info.id);
427 setAccount = true;
428 setAccount(info.accountName, info.accountType);
429 mCurrentFolder = info.parentId;
430 onCurrentFolderFound();
431 }
John Reck37894a92011-05-13 12:47:53 -0700432 // TODO: Detect if lastUsedId is a subfolder of info.id in the
433 // editing folder case. For now, just don't show the last used
434 // folder at all to prevent any chance of the user adding a parent
435 // folder to a child folder
436 if (info.lastUsedId != -1 && info.lastUsedId != info.id
437 && !mEditingFolder) {
John Reck2eec4c32011-05-11 15:55:32 -0700438 if (setAccount && info.lastUsedId != mRootFolder
439 && TextUtils.equals(info.lastUsedAccountName, info.accountName)
440 && TextUtils.equals(info.lastUsedAccountType, info.accountType)) {
441 mFolderAdapter.addRecentFolder(info.lastUsedId, info.lastUsedTitle);
442 } else if (!setAccount) {
443 setAccount = true;
444 setAccount(info.lastUsedAccountName, info.lastUsedAccountType);
445 if (info.lastUsedId != mRootFolder) {
446 mFolderAdapter.addRecentFolder(info.lastUsedId,
447 info.lastUsedTitle);
448 }
449 }
450 }
451 if (!setAccount) {
452 mAccountSpinner.setSelection(0);
453 }
454 }
455
456 @Override
457 public Loader<EditBookmarkInfo> onCreateLoader(int id, Bundle args) {
458 return new EditBookmarkInfoLoader(AddBookmarkPage.this, mMap);
459 }
460 };
461
462 void setAccount(String accountName, String accountType) {
463 for (int i = 0; i < mAccountAdapter.getCount(); i++) {
464 BookmarkAccount account = mAccountAdapter.getItem(i);
465 if (TextUtils.equals(account.accountName, accountName)
466 && TextUtils.equals(account.accountType, accountType)) {
John Reck2eec4c32011-05-11 15:55:32 -0700467 mAccountSpinner.setSelection(i);
John Reck903a0722011-11-09 17:53:10 -0800468 onRootFolderFound(account.rootFolderId);
John Reck2eec4c32011-05-11 15:55:32 -0700469 return;
470 }
471 }
472 }
473
Leon Scroggins III052ce662010-09-13 14:44:16 -0400474 @Override
475 public Loader<Cursor> onCreateLoader(int id, Bundle args) {
476 String[] projection;
477 switch (id) {
John Reck2eec4c32011-05-11 15:55:32 -0700478 case LOADER_ID_ACCOUNTS:
479 return new AccountsLoader(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400480 case LOADER_ID_FOLDER_CONTENTS:
481 projection = new String[] {
482 BrowserContract.Bookmarks._ID,
483 BrowserContract.Bookmarks.TITLE,
484 BrowserContract.Bookmarks.IS_FOLDER
485 };
Leon Scrogginsc1129902010-12-08 15:28:33 -0500486 String where = BrowserContract.Bookmarks.IS_FOLDER + " != 0";
John Reck1dd8cd42011-05-13 11:22:09 -0700487 String whereArgs[] = null;
Leon Scrogginsc1129902010-12-08 15:28:33 -0500488 if (mEditingFolder) {
John Reck1dd8cd42011-05-13 11:22:09 -0700489 where += " AND " + BrowserContract.Bookmarks._ID + " != ?";
490 whereArgs = new String[] { Long.toString(mMap.getLong(
491 BrowserContract.Bookmarks._ID)) };
492 }
493 long currentFolder;
494 Object data = mCrumbs.getTopData();
495 if (data != null) {
496 currentFolder = ((Folder) data).Id;
497 } else {
498 currentFolder = mRootFolder;
Leon Scrogginsc1129902010-12-08 15:28:33 -0500499 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400500 return new CursorLoader(this,
John Reck1dd8cd42011-05-13 11:22:09 -0700501 getUriForFolder(currentFolder),
Leon Scroggins III052ce662010-09-13 14:44:16 -0400502 projection,
Leon Scrogginsc1129902010-12-08 15:28:33 -0500503 where,
John Reck1dd8cd42011-05-13 11:22:09 -0700504 whereArgs,
Leon Scroggins8baaa632010-12-08 19:46:53 -0500505 BrowserContract.Bookmarks._ID + " ASC");
Leon Scroggins III052ce662010-09-13 14:44:16 -0400506 default:
507 throw new AssertionError("Asking for nonexistant loader!");
508 }
509 }
510
511 @Override
512 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
513 switch (loader.getId()) {
John Reck2eec4c32011-05-11 15:55:32 -0700514 case LOADER_ID_ACCOUNTS:
515 mAccountAdapter.clear();
516 while (cursor.moveToNext()) {
517 mAccountAdapter.add(new BookmarkAccount(this, cursor));
Leon Scroggins504433a2011-01-13 12:26:52 -0500518 }
John Reck2eec4c32011-05-11 15:55:32 -0700519 getLoaderManager().destroyLoader(LOADER_ID_ACCOUNTS);
520 getLoaderManager().restartLoader(LOADER_ID_EDIT_INFO, null,
521 mEditInfoLoaderCallbacks);
Leon Scroggins504433a2011-01-13 12:26:52 -0500522 break;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400523 case LOADER_ID_FOLDER_CONTENTS:
524 mAdapter.changeCursor(cursor);
525 break;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400526 }
527 }
528
Dianne Hackborn39772c82010-12-16 00:43:54 -0800529 public void onLoaderReset(Loader<Cursor> loader) {
530 switch (loader.getId()) {
531 case LOADER_ID_FOLDER_CONTENTS:
532 mAdapter.changeCursor(null);
533 break;
534 }
535 }
536
Leon Scroggins02081942010-11-01 17:52:42 -0400537 /**
Leon Scroggins8baaa632010-12-08 19:46:53 -0500538 * Move cursor to the position that has folderToFind as its "_id".
539 * @param cursor Cursor containing folders in the bookmarks database
540 * @param folderToFind "_id" of the folder to move to.
541 * @param idIndex Index in cursor of "_id"
542 * @throws AssertionError if cursor is empty or there is no row with folderToFind
543 * as its "_id".
544 */
545 void moveCursorToFolder(Cursor cursor, long folderToFind, int idIndex)
546 throws AssertionError {
547 if (!cursor.moveToFirst()) {
548 throw new AssertionError("No folders in the database!");
549 }
550 long folder;
551 do {
552 folder = cursor.getLong(idIndex);
553 } while (folder != folderToFind && cursor.moveToNext());
554 if (cursor.isAfterLast()) {
555 throw new AssertionError("Folder(id=" + folderToFind
556 + ") holding this bookmark does not exist!");
557 }
558 }
559
Leon Scroggins III052ce662010-09-13 14:44:16 -0400560 @Override
561 public void onItemClick(AdapterView<?> parent, View view, int position,
562 long id) {
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400563 TextView tv = (TextView) view.findViewById(android.R.id.text1);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400564 // Switch to the folder that was clicked on.
Leon Scrogginsd14cb122010-09-29 16:01:48 -0400565 descendInto(tv.getText().toString(), id);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400566 }
567
Leon Scroggins162f8352010-10-18 15:02:44 -0400568 private void setShowFolderNamer(boolean show) {
569 if (show != mIsFolderNamerShowing) {
570 mIsFolderNamerShowing = show;
571 if (show) {
572 // Set the selection to the folder namer so it will be in
573 // view.
574 mListView.addFooterView(mFolderNamerHolder);
575 } else {
576 mListView.removeFooterView(mFolderNamerHolder);
577 }
578 // Refresh the list.
579 mListView.setAdapter(mAdapter);
580 if (show) {
581 mListView.setSelection(mListView.getCount() - 1);
582 }
583 }
584 }
585
Leon Scroggins III052ce662010-09-13 14:44:16 -0400586 /**
587 * Shows a list of names of folders.
588 */
589 private class FolderAdapter extends CursorAdapter {
590 public FolderAdapter(Context context) {
591 super(context, null);
592 }
593
594 @Override
595 public void bindView(View view, Context context, Cursor cursor) {
596 ((TextView) view.findViewById(android.R.id.text1)).setText(
597 cursor.getString(cursor.getColumnIndexOrThrow(
598 BrowserContract.Bookmarks.TITLE)));
599 }
600
601 @Override
602 public View newView(Context context, Cursor cursor, ViewGroup parent) {
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700603 View view = LayoutInflater.from(context).inflate(
604 R.layout.folder_list_item, null);
605 view.setBackgroundDrawable(context.getResources().
606 getDrawable(android.R.drawable.list_selector_background));
607 return view;
Leon Scroggins III052ce662010-09-13 14:44:16 -0400608 }
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400609
610 @Override
611 public boolean isEmpty() {
612 // Do not show the empty view if the user is creating a new folder.
Leon Scroggins162f8352010-10-18 15:02:44 -0400613 return super.isEmpty() && !mIsFolderNamerShowing;
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400614 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400615 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800616
Leon Scrogginsc1129902010-12-08 15:28:33 -0500617 @Override
The Android Open Source Project0c908882009-03-03 19:32:16 -0800618 protected void onCreate(Bundle icicle) {
619 super.onCreate(icicle);
Leon Scroggins7453ff22010-12-15 16:03:59 -0500620 requestWindowFeature(Window.FEATURE_NO_TITLE);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100621
622 mMap = getIntent().getExtras();
Ben Murdocheecb4e62010-07-06 16:30:38 +0100623
Leon Scroggins III052ce662010-09-13 14:44:16 -0400624 setContentView(R.layout.browser_add_bookmark);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100625
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400626 Window window = getWindow();
Michael Kolbd40ac1a2010-09-29 00:23:46 -0700627
The Android Open Source Project0c908882009-03-03 19:32:16 -0800628 String title = null;
629 String url = null;
Ben Murdocheecb4e62010-07-06 16:30:38 +0100630
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400631 mFakeTitle = (TextView) findViewById(R.id.fake_title);
632
The Android Open Source Project0c908882009-03-03 19:32:16 -0800633 if (mMap != null) {
John Reckc8490812010-11-22 14:15:36 -0800634 Bundle b = mMap.getBundle(EXTRA_EDIT_BOOKMARK);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800635 if (b != null) {
John Reckc8490812010-11-22 14:15:36 -0800636 mEditingFolder = mMap.getBoolean(EXTRA_IS_FOLDER, false);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800637 mMap = b;
638 mEditingExisting = true;
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400639 mFakeTitle.setText(R.string.edit_bookmark);
John Reckc8490812010-11-22 14:15:36 -0800640 if (mEditingFolder) {
641 findViewById(R.id.row_address).setVisibility(View.GONE);
Leon Scroggins75630672011-01-13 17:56:15 -0500642 } else {
643 showRemoveButton();
John Reckc8490812010-11-22 14:15:36 -0800644 }
Leon Scroggins III76a0e9c2010-10-05 16:10:01 -0400645 } else {
646 int gravity = mMap.getInt("gravity", -1);
647 if (gravity != -1) {
648 WindowManager.LayoutParams l = window.getAttributes();
649 l.gravity = gravity;
650 window.setAttributes(l);
651 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800652 }
Leon Scrogginsbc922852010-10-22 12:15:27 -0400653 title = mMap.getString(BrowserContract.Bookmarks.TITLE);
654 url = mOriginalUrl = mMap.getString(BrowserContract.Bookmarks.URL);
655 mTouchIconUrl = mMap.getString(TOUCH_ICON_URL);
Michael Kolb370a4f32010-10-06 10:45:32 -0700656 mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID);
Leon Scroggins25230d72010-09-28 20:09:25 -0400657 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800658
659 mTitle = (EditText) findViewById(R.id.title);
660 mTitle.setText(title);
luxiaoldbe4a622013-07-19 17:14:06 +0800661 BrowserUtils.maxLengthFilter(AddBookmarkPage.this, mTitle, BrowserUtils.FILENAME_MAX_LENGTH);
Ben Murdocheecb4e62010-07-06 16:30:38 +0100662
Leon Scroggins III052ce662010-09-13 14:44:16 -0400663 mAddress = (EditText) findViewById(R.id.address);
664 mAddress.setText(url);
luxiaoldbe4a622013-07-19 17:14:06 +0800665 BrowserUtils.maxLengthFilter(AddBookmarkPage.this, mAddress, BrowserUtils.ADDRESS_MAX_LENGTH);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800666
The Android Open Source Project0c908882009-03-03 19:32:16 -0800667 mButton = (TextView) findViewById(R.id.OK);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400668 mButton.setOnClickListener(this);
The Android Open Source Project0c908882009-03-03 19:32:16 -0800669
670 mCancelButton = findViewById(R.id.cancel);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400671 mCancelButton.setOnClickListener(this);
672
Leon Scroggins504433a2011-01-13 12:26:52 -0500673 mFolder = (FolderSpinner) findViewById(R.id.folder);
John Reck2eec4c32011-05-11 15:55:32 -0700674 mFolderAdapter = new FolderSpinnerAdapter(this, !mEditingFolder);
Leon Scroggins2f24e992011-02-11 14:02:10 -0500675 mFolder.setAdapter(mFolderAdapter);
Leon Scroggins504433a2011-01-13 12:26:52 -0500676 mFolder.setOnSetSelectionListener(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400677
678 mDefaultView = findViewById(R.id.default_view);
679 mFolderSelector = findViewById(R.id.folder_selector);
680
Leon Scroggins162f8352010-10-18 15:02:44 -0400681 mFolderNamerHolder = getLayoutInflater().inflate(R.layout.new_folder_layout, null);
682 mFolderNamer = (EditText) mFolderNamerHolder.findViewById(R.id.folder_namer);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400683 mFolderNamer.setOnEditorActionListener(this);
luxiaoldbe4a622013-07-19 17:14:06 +0800684
685 // add for carrier test about warning limit of edit text
686 BrowserUtils.maxLengthFilter(AddBookmarkPage.this, mFolderNamer,
687 BrowserUtils.FILENAME_MAX_LENGTH);
688
Leon Scroggins0e3a7b82011-01-11 19:08:03 -0500689 mFolderCancel = mFolderNamerHolder.findViewById(R.id.close);
690 mFolderCancel.setOnClickListener(this);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400691
692 mAddNewFolder = findViewById(R.id.add_new_folder);
693 mAddNewFolder.setOnClickListener(this);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400694 mAddSeparator = findViewById(R.id.add_divider);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400695
Leon Scroggins74dbe012010-10-15 10:54:27 -0400696 mCrumbs = (BreadCrumbView) findViewById(R.id.crumbs);
697 mCrumbs.setUseBackButton(true);
698 mCrumbs.setController(this);
Michael Kolb5a72f182011-01-13 20:35:06 -0800699 mHeaderIcon = getResources().getDrawable(R.drawable.ic_folder_holo_dark);
Leon Scroggins7e5f7352010-10-18 13:25:31 -0400700 mCrumbHolder = findViewById(R.id.crumb_holder);
John Reck89f73c12010-12-01 10:10:14 -0800701 mCrumbs.setMaxVisible(MAX_CRUMBS_SHOWN);
Leon Scroggins III052ce662010-09-13 14:44:16 -0400702
Leon Scroggins III052ce662010-09-13 14:44:16 -0400703 mAdapter = new FolderAdapter(this);
Leon Scroggins162f8352010-10-18 15:02:44 -0400704 mListView = (CustomListView) findViewById(R.id.list);
Leon Scroggins6573f9e2010-10-18 17:22:35 -0400705 View empty = findViewById(R.id.empty);
706 mListView.setEmptyView(empty);
707 mListView.setAdapter(mAdapter);
708 mListView.setOnItemClickListener(this);
Leon Scroggins162f8352010-10-18 15:02:44 -0400709 mListView.addEditText(mFolderNamer);
Leon Scroggins504433a2011-01-13 12:26:52 -0500710
John Reck2eec4c32011-05-11 15:55:32 -0700711 mAccountAdapter = new ArrayAdapter<BookmarkAccount>(this,
712 android.R.layout.simple_spinner_item);
713 mAccountAdapter.setDropDownViewResource(
714 android.R.layout.simple_spinner_dropdown_item);
715 mAccountSpinner = (Spinner) findViewById(R.id.accounts);
716 mAccountSpinner.setAdapter(mAccountAdapter);
717 mAccountSpinner.setOnItemSelectedListener(this);
718
719
Leon Scroggins75630672011-01-13 17:56:15 -0500720 mFakeTitleHolder = findViewById(R.id.title_holder);
721
Leon Scroggins504433a2011-01-13 12:26:52 -0500722 if (!window.getDecorView().isInTouchMode()) {
723 mButton.requestFocus();
724 }
725
John Reck2eec4c32011-05-11 15:55:32 -0700726 getLoaderManager().restartLoader(LOADER_ID_ACCOUNTS, null, this);
Leon Scroggins504433a2011-01-13 12:26:52 -0500727 }
728
Leon Scroggins75630672011-01-13 17:56:15 -0500729 private void showRemoveButton() {
730 findViewById(R.id.remove_divider).setVisibility(View.VISIBLE);
731 mRemoveLink = findViewById(R.id.remove);
732 mRemoveLink.setVisibility(View.VISIBLE);
733 mRemoveLink.setOnClickListener(this);
734 }
735
Leon Scroggins504433a2011-01-13 12:26:52 -0500736 // Called once we have determined which folder is the root folder
737 private void onRootFolderFound(long root) {
738 mRootFolder = root;
John Reck2eec4c32011-05-11 15:55:32 -0700739 mCurrentFolder = mRootFolder;
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500740 setupTopCrumb();
John Reck2eec4c32011-05-11 15:55:32 -0700741 onCurrentFolderFound();
Leon Scroggins504433a2011-01-13 12:26:52 -0500742 }
743
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500744 private void setupTopCrumb() {
John Reck2eec4c32011-05-11 15:55:32 -0700745 mCrumbs.clear();
Leon Scrogginsb3ae8802011-01-18 11:55:27 -0500746 String name = getString(R.string.bookmarks);
747 mTopLevelLabel = (TextView) mCrumbs.pushView(name, false,
748 new Folder(name, mRootFolder));
749 // To better match the other folders.
750 mTopLevelLabel.setCompoundDrawablePadding(6);
751 }
752
Leon Scroggins504433a2011-01-13 12:26:52 -0500753 private void onCurrentFolderFound() {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400754 LoaderManager manager = getLoaderManager();
Leon Scroggins8baaa632010-12-08 19:46:53 -0500755 if (mCurrentFolder != mRootFolder) {
Leon Scrogginsdd13bad2011-01-06 20:25:54 -0500756 // Since we're not in the root folder, change the selection to other
757 // folder now. The text will get changed once we select the correct
758 // folder.
Leon Scroggins504433a2011-01-13 12:26:52 -0500759 mFolder.setSelectionIgnoringSelectionChange(mEditingFolder ? 1 : 2);
Leon Scroggins905250c2010-12-17 15:25:33 -0500760 } else {
761 setShowBookmarkIcon(true);
Leon Scroggins504433a2011-01-13 12:26:52 -0500762 if (!mEditingFolder) {
763 // Initially the "Bookmarks" folder should be showing, rather than
764 // the home screen. In the editing folder case, home screen is not
765 // an option, so "Bookmarks" folder is already at the top.
766 mFolder.setSelectionIgnoringSelectionChange(FolderSpinnerAdapter.ROOT_FOLDER);
767 }
Leon Scroggins III052ce662010-09-13 14:44:16 -0400768 }
Leon Scroggins52f7daa2010-10-18 16:57:46 -0400769 // Find the contents of the current folder
John Reck2eec4c32011-05-11 15:55:32 -0700770 manager.restartLoader(LOADER_ID_FOLDER_CONTENTS, null, this);
Leon Scroggins8baaa632010-12-08 19:46:53 -0500771 }
772
Leon Scroggins02065b02010-01-04 14:30:13 -0500773 /**
774 * Runnable to save a bookmark, so it can be performed in its own thread.
775 */
776 private class SaveBookmarkRunnable implements Runnable {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400777 // FIXME: This should be an async task.
Leon Scroggins02065b02010-01-04 14:30:13 -0500778 private Message mMessage;
Henrik Baard980e9952010-09-06 18:13:23 +0200779 private Context mContext;
780 public SaveBookmarkRunnable(Context ctx, Message msg) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100781 mContext = ctx.getApplicationContext();
Leon Scroggins02065b02010-01-04 14:30:13 -0500782 mMessage = msg;
783 }
784 public void run() {
785 // Unbundle bookmark data.
786 Bundle bundle = mMessage.getData();
Leon Scrogginsbc922852010-10-22 12:15:27 -0400787 String title = bundle.getString(BrowserContract.Bookmarks.TITLE);
788 String url = bundle.getString(BrowserContract.Bookmarks.URL);
789 boolean invalidateThumbnail = bundle.getBoolean(REMOVE_THUMBNAIL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500790 Bitmap thumbnail = invalidateThumbnail ? null
Leon Scrogginsbc922852010-10-22 12:15:27 -0400791 : (Bitmap) bundle.getParcelable(BrowserContract.Bookmarks.THUMBNAIL);
792 String touchIconUrl = bundle.getString(TOUCH_ICON_URL);
Leon Scroggins02065b02010-01-04 14:30:13 -0500793
794 // Save to the bookmarks DB.
795 try {
796 final ContentResolver cr = getContentResolver();
Leon Scroggins III052ce662010-09-13 14:44:16 -0400797 Bookmarks.addBookmark(AddBookmarkPage.this, false, url,
John Reckaf262e72011-07-25 13:55:44 -0700798 title, thumbnail, mCurrentFolder);
Leon Scroggins02065b02010-01-04 14:30:13 -0500799 if (touchIconUrl != null) {
Henrik Baard980e9952010-09-06 18:13:23 +0200800 new DownloadTouchIcon(mContext, cr, url).execute(mTouchIconUrl);
Leon Scroggins02065b02010-01-04 14:30:13 -0500801 }
802 mMessage.arg1 = 1;
803 } catch (IllegalStateException e) {
804 mMessage.arg1 = 0;
805 }
806 mMessage.sendToTarget();
807 }
808 }
809
John Reckc8490812010-11-22 14:15:36 -0800810 private static class UpdateBookmarkTask extends AsyncTask<ContentValues, Void, Void> {
811 Context mContext;
812 Long mId;
813
814 public UpdateBookmarkTask(Context context, long id) {
Ben Murdoch914c5592011-08-01 13:58:47 +0100815 mContext = context.getApplicationContext();
John Reckc8490812010-11-22 14:15:36 -0800816 mId = id;
817 }
818
819 @Override
820 protected Void doInBackground(ContentValues... params) {
821 if (params.length != 1) {
822 throw new IllegalArgumentException("No ContentValues provided!");
823 }
824 Uri uri = ContentUris.withAppendedId(BookmarkUtils.getBookmarksUri(mContext), mId);
825 mContext.getContentResolver().update(
826 uri,
827 params[0], null, null);
828 return null;
829 }
830 }
831
Ben Murdoch1794fe22009-09-29 18:14:30 +0100832 private void createHandler() {
833 if (mHandler == null) {
834 mHandler = new Handler() {
835 @Override
836 public void handleMessage(Message msg) {
837 switch (msg.what) {
838 case SAVE_BOOKMARK:
Leon Scroggins02065b02010-01-04 14:30:13 -0500839 if (1 == msg.arg1) {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100840 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_saved,
841 Toast.LENGTH_LONG).show();
842 } else {
843 Toast.makeText(AddBookmarkPage.this, R.string.bookmark_not_saved,
844 Toast.LENGTH_LONG).show();
845 }
846 break;
Leon Scroggins88d08032010-10-21 15:17:10 -0400847 case TOUCH_ICON_DOWNLOADED:
848 Bundle b = msg.getData();
849 sendBroadcast(BookmarkUtils.createAddToHomeIntent(
Leon Scrogginsbc922852010-10-22 12:15:27 -0400850 AddBookmarkPage.this,
851 b.getString(BrowserContract.Bookmarks.URL),
852 b.getString(BrowserContract.Bookmarks.TITLE),
853 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.TOUCH_ICON),
854 (Bitmap) b.getParcelable(BrowserContract.Bookmarks.FAVICON)));
Leon Scroggins88d08032010-10-21 15:17:10 -0400855 break;
Leon Scroggins75630672011-01-13 17:56:15 -0500856 case BOOKMARK_DELETED:
857 finish();
858 break;
Ben Murdoch1794fe22009-09-29 18:14:30 +0100859 }
860 }
861 };
862 }
863 }
864
luxiaoldbe4a622013-07-19 17:14:06 +0800865 static void deleteDuplicateBookmark(final Context context, final long id) {
866 Uri uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI, id);
867 context.getContentResolver().delete(uri, null, null);
868 }
869
870 private void onSaveWithConfirm() {
871 String title = mTitle.getText().toString().trim();
872 String unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString());
873 String url = unfilteredUrl.trim();
874 Long id = mMap.getLong(BrowserContract.Bookmarks._ID);
875 int duplicateCount;
876 final ContentResolver cr = getContentResolver();
877
878 Cursor cursor = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
879 BookmarksLoader.PROJECTION,
880 "( title = ? OR url = ? ) AND parent = ?",
881 new String[] {
882 title, url, Long.toString(mCurrentFolder)
883 },
884 null);
885
886 if (cursor == null) {
887 save();
888 return;
889 }
890
891 duplicateCount = cursor.getCount();
892 if (duplicateCount <= 0) {
893 cursor.close();
894 save();
895 return;
896 } else {
897 try {
898 while (cursor.moveToNext()) {
899 mDuplicateId = cursor.getLong(BookmarksLoader.COLUMN_INDEX_ID);
900 mDuplicateContext = AddBookmarkPage.this;
901 }
902 } catch (IllegalStateException e) {
903 e.printStackTrace();
904 } finally {
905 if (cursor != null)
906 cursor.close();
907 }
908 }
909
910 if (mEditingExisting && duplicateCount == 1 && mDuplicateId == id) {
911 save();
912 return;
913 }
914
915 new AlertDialog.Builder(this)
916 .setTitle(getString(R.string.save_to_bookmarks_title))
917 .setMessage(getString(R.string.overwrite_bookmark_msg))
918 .setNegativeButton(android.R.string.cancel, null)
919 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
920 public void onClick(DialogInterface dialog, int which) {
921 if (mDuplicateContext == null) {
922 return;
923 }
924 deleteDuplicateBookmark(mDuplicateContext, mDuplicateId);
925 save();
926 }
927 })
928 .show();
929 }
930
The Android Open Source Project0c908882009-03-03 19:32:16 -0800931 /**
Ben Murdoch1794fe22009-09-29 18:14:30 +0100932 * 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 -0800933 */
934 boolean save() {
Ben Murdoch1794fe22009-09-29 18:14:30 +0100935 createHandler();
936
The Android Open Source Project0c908882009-03-03 19:32:16 -0800937 String title = mTitle.getText().toString().trim();
luxiaoldbe4a622013-07-19 17:14:06 +0800938 String unfilteredUrl = UrlUtils.fixUrl(mAddress.getText().toString());
Ben Murdocheecb4e62010-07-06 16:30:38 +0100939
The Android Open Source Project0c908882009-03-03 19:32:16 -0800940 boolean emptyTitle = title.length() == 0;
941 boolean emptyUrl = unfilteredUrl.trim().length() == 0;
942 Resources r = getResources();
John Reckc8490812010-11-22 14:15:36 -0800943 if (emptyTitle || (emptyUrl && !mEditingFolder)) {
The Android Open Source Project0c908882009-03-03 19:32:16 -0800944 if (emptyTitle) {
945 mTitle.setError(r.getText(R.string.bookmark_needs_title));
946 }
947 if (emptyUrl) {
Leon Scroggins III052ce662010-09-13 14:44:16 -0400948 mAddress.setError(r.getText(R.string.bookmark_needs_url));
The Android Open Source Project0c908882009-03-03 19:32:16 -0800949 }
Leon Scroggins III6e3faea2010-09-07 15:22:14 -0400950 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800951 }
Ben Murdochca12cfa2009-11-17 13:57:44 +0000952 String url = unfilteredUrl.trim();
John Reckc8490812010-11-22 14:15:36 -0800953 if (!mEditingFolder) {
954 try {
955 // We allow bookmarks with a javascript: scheme, but these will in most cases
956 // fail URI parsing, so don't try it if that's the kind of bookmark we have.
Ben Murdochca12cfa2009-11-17 13:57:44 +0000957
John Reckc8490812010-11-22 14:15:36 -0800958 if (!url.toLowerCase().startsWith("javascript:")) {
959 URI uriObj = new URI(url);
960 String scheme = uriObj.getScheme();
961 if (!Bookmarks.urlHasAcceptableScheme(url)) {
962 // If the scheme was non-null, let the user know that we
963 // can't save their bookmark. If it was null, we'll assume
964 // they meant http when we parse it in the WebAddress class.
965 if (scheme != null) {
966 mAddress.setError(r.getText(R.string.bookmark_cannot_save_url));
967 return false;
968 }
969 WebAddress address;
970 try {
971 address = new WebAddress(unfilteredUrl);
972 } catch (ParseException e) {
973 throw new URISyntaxException("", "");
974 }
975 if (address.getHost().length() == 0) {
976 throw new URISyntaxException("", "");
977 }
978 url = address.toString();
Ben Murdochca12cfa2009-11-17 13:57:44 +0000979 }
Ben Murdochde353622009-10-12 10:29:00 +0100980 }
John Reckc8490812010-11-22 14:15:36 -0800981 } catch (URISyntaxException e) {
982 mAddress.setError(r.getText(R.string.bookmark_url_not_valid));
983 return false;
The Android Open Source Project0c908882009-03-03 19:32:16 -0800984 }
The Android Open Source Project0c908882009-03-03 19:32:16 -0800985 }
Ben Murdochaac7aa62009-09-17 16:57:40 +0100986
Leon Scroggins88d08032010-10-21 15:17:10 -0400987 if (mSaveToHomeScreen) {
988 mEditingExisting = false;
989 }
990
991 boolean urlUnmodified = url.equals(mOriginalUrl);
992
Ben Murdoch1794fe22009-09-29 18:14:30 +0100993 if (mEditingExisting) {
John Reckc8490812010-11-22 14:15:36 -0800994 Long id = mMap.getLong(BrowserContract.Bookmarks._ID);
995 ContentValues values = new ContentValues();
996 values.put(BrowserContract.Bookmarks.TITLE, title);
997 values.put(BrowserContract.Bookmarks.PARENT, mCurrentFolder);
998 if (!mEditingFolder) {
999 values.put(BrowserContract.Bookmarks.URL, url);
1000 if (!urlUnmodified) {
1001 values.putNull(BrowserContract.Bookmarks.THUMBNAIL);
1002 }
1003 }
1004 if (values.size() > 0) {
1005 new UpdateBookmarkTask(getApplicationContext(), id).execute(values);
1006 }
1007 setResult(RESULT_OK);
Ben Murdoch1794fe22009-09-29 18:14:30 +01001008 } else {
Leon Scroggins88d08032010-10-21 15:17:10 -04001009 Bitmap thumbnail;
1010 Bitmap favicon;
1011 if (urlUnmodified) {
Leon Scrogginsbc922852010-10-22 12:15:27 -04001012 thumbnail = (Bitmap) mMap.getParcelable(
1013 BrowserContract.Bookmarks.THUMBNAIL);
1014 favicon = (Bitmap) mMap.getParcelable(
1015 BrowserContract.Bookmarks.FAVICON);
Leon Scroggins88d08032010-10-21 15:17:10 -04001016 } else {
1017 thumbnail = null;
1018 favicon = null;
1019 }
1020
Ben Murdoch1794fe22009-09-29 18:14:30 +01001021 Bundle bundle = new Bundle();
Leon Scrogginsbc922852010-10-22 12:15:27 -04001022 bundle.putString(BrowserContract.Bookmarks.TITLE, title);
1023 bundle.putString(BrowserContract.Bookmarks.URL, url);
1024 bundle.putParcelable(BrowserContract.Bookmarks.FAVICON, favicon);
Leon Scroggins88d08032010-10-21 15:17:10 -04001025
1026 if (mSaveToHomeScreen) {
1027 if (mTouchIconUrl != null && urlUnmodified) {
1028 Message msg = Message.obtain(mHandler,
1029 TOUCH_ICON_DOWNLOADED);
1030 msg.setData(bundle);
1031 DownloadTouchIcon icon = new DownloadTouchIcon(this, msg,
Leon Scrogginsbc922852010-10-22 12:15:27 -04001032 mMap.getString(USER_AGENT));
Leon Scroggins88d08032010-10-21 15:17:10 -04001033 icon.execute(mTouchIconUrl);
1034 } else {
1035 sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url,
1036 title, null /*touchIcon*/, favicon));
1037 }
1038 } else {
Leon Scrogginsbc922852010-10-22 12:15:27 -04001039 bundle.putParcelable(BrowserContract.Bookmarks.THUMBNAIL, thumbnail);
1040 bundle.putBoolean(REMOVE_THUMBNAIL, !urlUnmodified);
1041 bundle.putString(TOUCH_ICON_URL, mTouchIconUrl);
Leon Scroggins88d08032010-10-21 15:17:10 -04001042 // Post a message to write to the DB.
1043 Message msg = Message.obtain(mHandler, SAVE_BOOKMARK);
1044 msg.setData(bundle);
1045 // Start a new thread so as to not slow down the UI
1046 Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg));
1047 t.start();
1048 }
Ben Murdoch1794fe22009-09-29 18:14:30 +01001049 setResult(RESULT_OK);
Kristian Monsen0a1d8382010-02-01 18:41:07 +00001050 LogTag.logBookmarkAdded(url, "bookmarkview");
The Android Open Source Project0c908882009-03-03 19:32:16 -08001051 }
luxiaoldbe4a622013-07-19 17:14:06 +08001052 finish();
The Android Open Source Project0c908882009-03-03 19:32:16 -08001053 return true;
1054 }
Leon Scroggins162f8352010-10-18 15:02:44 -04001055
John Reck2eec4c32011-05-11 15:55:32 -07001056 @Override
1057 public void onItemSelected(AdapterView<?> parent, View view, int position,
1058 long id) {
1059 if (mAccountSpinner == parent) {
1060 long root = mAccountAdapter.getItem(position).rootFolderId;
1061 if (root != mRootFolder) {
1062 onRootFolderFound(root);
John Recke890c902011-07-11 17:44:43 -07001063 mFolderAdapter.clearRecentFolder();
John Reck2eec4c32011-05-11 15:55:32 -07001064 }
1065 }
1066 }
1067
1068 @Override
1069 public void onNothingSelected(AdapterView<?> parent) {
1070 // Don't care
1071 }
1072
Leon Scroggins162f8352010-10-18 15:02:44 -04001073 /*
1074 * Class used as a proxy for the InputMethodManager to get to mFolderNamer
1075 */
1076 public static class CustomListView extends ListView {
1077 private EditText mEditText;
1078
1079 public void addEditText(EditText editText) {
1080 mEditText = editText;
1081 }
1082
1083 public CustomListView(Context context) {
1084 super(context);
1085 }
1086
1087 public CustomListView(Context context, AttributeSet attrs) {
1088 super(context, attrs);
1089 }
1090
1091 public CustomListView(Context context, AttributeSet attrs, int defStyle) {
1092 super(context, attrs, defStyle);
1093 }
1094
1095 @Override
1096 public boolean checkInputConnectionProxy(View view) {
1097 return view == mEditText;
1098 }
1099 }
John Reck2eec4c32011-05-11 15:55:32 -07001100
John Reck3bf3cfb2011-10-17 18:00:05 -07001101 static class AccountsLoader extends CursorLoader {
John Reck2eec4c32011-05-11 15:55:32 -07001102
1103 static final String[] PROJECTION = new String[] {
1104 Accounts.ACCOUNT_NAME,
1105 Accounts.ACCOUNT_TYPE,
1106 Accounts.ROOT_ID,
1107 };
1108
1109 static final int COLUMN_INDEX_ACCOUNT_NAME = 0;
1110 static final int COLUMN_INDEX_ACCOUNT_TYPE = 1;
1111 static final int COLUMN_INDEX_ROOT_ID = 2;
1112
1113 public AccountsLoader(Context context) {
John Reck1e9815d2011-08-08 17:45:05 -07001114 super(context, Accounts.CONTENT_URI, PROJECTION, null, null, null);
John Reck2eec4c32011-05-11 15:55:32 -07001115 }
1116
1117 }
1118
John Reck9b8cd1e2011-05-25 18:14:01 -07001119 public static class BookmarkAccount {
John Reck2eec4c32011-05-11 15:55:32 -07001120
1121 private String mLabel;
1122 String accountName, accountType;
John Reck9b8cd1e2011-05-25 18:14:01 -07001123 public long rootFolderId;
John Reck2eec4c32011-05-11 15:55:32 -07001124
1125 public BookmarkAccount(Context context, Cursor cursor) {
1126 accountName = cursor.getString(
1127 AccountsLoader.COLUMN_INDEX_ACCOUNT_NAME);
1128 accountType = cursor.getString(
1129 AccountsLoader.COLUMN_INDEX_ACCOUNT_TYPE);
1130 rootFolderId = cursor.getLong(
1131 AccountsLoader.COLUMN_INDEX_ROOT_ID);
1132 mLabel = accountName;
1133 if (TextUtils.isEmpty(mLabel)) {
1134 mLabel = context.getString(R.string.local_bookmarks);
1135 }
1136 }
1137
1138 @Override
1139 public String toString() {
1140 return mLabel;
1141 }
1142 }
1143
1144 static class EditBookmarkInfo {
1145 long id = -1;
1146 long parentId = -1;
1147 String parentTitle;
1148 String title;
1149 String accountName;
1150 String accountType;
1151
1152 long lastUsedId = -1;
1153 String lastUsedTitle;
1154 String lastUsedAccountName;
1155 String lastUsedAccountType;
1156 }
1157
1158 static class EditBookmarkInfoLoader extends AsyncTaskLoader<EditBookmarkInfo> {
1159
1160 private Context mContext;
1161 private Bundle mMap;
1162
1163 public EditBookmarkInfoLoader(Context context, Bundle bundle) {
1164 super(context);
Ben Murdoch914c5592011-08-01 13:58:47 +01001165 mContext = context.getApplicationContext();
John Reck2eec4c32011-05-11 15:55:32 -07001166 mMap = bundle;
1167 }
1168
1169 @Override
1170 public EditBookmarkInfo loadInBackground() {
1171 final ContentResolver cr = mContext.getContentResolver();
1172 EditBookmarkInfo info = new EditBookmarkInfo();
1173 Cursor c = null;
1174
1175 try {
1176 // First, let's lookup the bookmark (check for dupes, get needed info)
1177 String url = mMap.getString(BrowserContract.Bookmarks.URL);
1178 info.id = mMap.getLong(BrowserContract.Bookmarks._ID, -1);
1179 boolean checkForDupe = mMap.getBoolean(CHECK_FOR_DUPE);
1180 if (checkForDupe && info.id == -1 && !TextUtils.isEmpty(url)) {
1181 c = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
1182 new String[] { BrowserContract.Bookmarks._ID},
1183 BrowserContract.Bookmarks.URL + "=?",
1184 new String[] { url }, null);
1185 if (c.getCount() == 1 && c.moveToFirst()) {
1186 info.id = c.getLong(0);
1187 }
1188 c.close();
1189 }
1190 if (info.id != -1) {
1191 c = cr.query(ContentUris.withAppendedId(
1192 BrowserContract.Bookmarks.CONTENT_URI, info.id),
1193 new String[] {
1194 BrowserContract.Bookmarks.PARENT,
1195 BrowserContract.Bookmarks.ACCOUNT_NAME,
1196 BrowserContract.Bookmarks.ACCOUNT_TYPE,
1197 BrowserContract.Bookmarks.TITLE},
1198 null, null, null);
1199 if (c.moveToFirst()) {
1200 info.parentId = c.getLong(0);
1201 info.accountName = c.getString(1);
1202 info.accountType = c.getString(2);
1203 info.title = c.getString(3);
1204 }
1205 c.close();
1206 c = cr.query(ContentUris.withAppendedId(
1207 BrowserContract.Bookmarks.CONTENT_URI, info.parentId),
1208 new String[] {
1209 BrowserContract.Bookmarks.TITLE,},
1210 null, null, null);
1211 if (c.moveToFirst()) {
1212 info.parentTitle = c.getString(0);
1213 }
1214 c.close();
1215 }
1216
1217 // Figure out the last used folder/account
1218 c = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
1219 new String[] {
1220 BrowserContract.Bookmarks.PARENT,
1221 }, null, null,
1222 BrowserContract.Bookmarks.DATE_MODIFIED + " DESC LIMIT 1");
1223 if (c.moveToFirst()) {
1224 long parent = c.getLong(0);
1225 c.close();
1226 c = cr.query(BrowserContract.Bookmarks.CONTENT_URI,
1227 new String[] {
1228 BrowserContract.Bookmarks.TITLE,
1229 BrowserContract.Bookmarks.ACCOUNT_NAME,
1230 BrowserContract.Bookmarks.ACCOUNT_TYPE},
1231 BrowserContract.Bookmarks._ID + "=?", new String[] {
1232 Long.toString(parent)}, null);
1233 if (c.moveToFirst()) {
1234 info.lastUsedId = parent;
1235 info.lastUsedTitle = c.getString(0);
1236 info.lastUsedAccountName = c.getString(1);
1237 info.lastUsedAccountType = c.getString(2);
1238 }
1239 c.close();
1240 }
1241 } finally {
1242 if (c != null) {
1243 c.close();
1244 }
1245 }
1246
1247 return info;
1248 }
1249
1250 @Override
1251 protected void onStartLoading() {
1252 forceLoad();
1253 }
1254
1255 }
1256
The Android Open Source Project0c908882009-03-03 19:32:16 -08001257}