diff options
author | Leon Scroggins <scroggo@google.com> | 2010-10-21 15:17:10 -0400 |
---|---|---|
committer | Leon Scroggins <scroggo@google.com> | 2010-10-22 11:04:39 -0400 |
commit | 88d080394ca18120e05c6926b178fd6843ff9cec (patch) | |
tree | 0720a96b8658d58dec59581b7876c0f74b88b586 /src/com/android/browser/AddBookmarkPage.java | |
parent | fa6401f9759594b206e3b2effe2c3198a8b2449f (diff) | |
download | packages_apps_Browser-88d080394ca18120e05c6926b178fd6843ff9cec.zip packages_apps_Browser-88d080394ca18120e05c6926b178fd6843ff9cec.tar.gz packages_apps_Browser-88d080394ca18120e05c6926b178fd6843ff9cec.tar.bz2 |
Incorporate save to home screen with add bookmark dialog.
Bug:2953515
Remove the initial popup menu when pressing the star that
selects between saving to home screen and saving to bookmarks.
Instead, once the add bookmark dialog is open, the user can
select between bookmarks and saving to home screen.
Change-Id: I35e8590ff6a2a7c2058e45e4f77ec6b5d209b0f9
Diffstat (limited to 'src/com/android/browser/AddBookmarkPage.java')
-rw-r--r-- | src/com/android/browser/AddBookmarkPage.java | 100 |
1 files changed, 86 insertions, 14 deletions
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index 9e5b349..fc480ee 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -42,6 +42,7 @@ import android.provider.BrowserContract; import android.text.TextUtils; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -52,6 +53,7 @@ import android.widget.AdapterView; import android.widget.CursorAdapter; import android.widget.EditText; import android.widget.ListView; +import android.widget.PopupMenu; import android.widget.TextView; import android.widget.Toast; @@ -63,7 +65,7 @@ import java.util.Stack; public class AddBookmarkPage extends Activity implements View.OnClickListener, TextView.OnEditorActionListener, AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor>, - BreadCrumbView.Controller { + BreadCrumbView.Controller, PopupMenu.OnMenuItemClickListener { public static final long DEFAULT_FOLDER_ID = -1; @@ -84,7 +86,6 @@ public class AddBookmarkPage extends Activity private boolean mEditingExisting; private Bundle mMap; private String mTouchIconUrl; - private Bitmap mThumbnail; private String mOriginalUrl; private TextView mFolder; private View mDefaultView; @@ -98,6 +99,7 @@ public class AddBookmarkPage extends Activity private TextView mFakeTitle; private View mCrumbHolder; private ListView mListView; + private boolean mSaveToHomeScreen; private static class Folder { String Name; @@ -110,6 +112,7 @@ public class AddBookmarkPage extends Activity // Message IDs private static final int SAVE_BOOKMARK = 100; + private static final int TOUCH_ICON_DOWNLOADED = 101; private Handler mHandler; @@ -207,6 +210,7 @@ public class AddBookmarkPage extends Activity completeOrCancelFolderNaming(false); } else { // User has selected a folder. Go back to the opening page + mSaveToHomeScreen = false; switchToDefaultView(true); } } else if (save()) { @@ -221,7 +225,14 @@ public class AddBookmarkPage extends Activity finish(); } } else if (v == mFolder) { - switchToFolderSelector(); + // FIXME: We want to use mFolder as an anchor, but cannot until we + // fix the issue that the PopupMenu will not extend past the edge of + // the dialog. + PopupMenu popup = new PopupMenu(this, mFakeTitle); + popup.getMenuInflater().inflate(R.menu.folder_choice, + popup.getMenu()); + popup.setOnMenuItemClickListener(this); + popup.show(); } else if (v == mAddNewFolder) { mFolderNamer.setVisibility(View.VISIBLE); mFolderNamer.setText(R.string.new_folder); @@ -234,6 +245,28 @@ public class AddBookmarkPage extends Activity } } + @Override + public boolean onMenuItemClick(MenuItem item) { + switch(item.getItemId()) { + case R.id.bookmarks: + mCurrentFolder = getBookmarksBarId(this); + mFolder.setText(item.getTitle()); + mSaveToHomeScreen = false; + break; + case R.id.home_screen: + // Create a short cut to the home screen + mSaveToHomeScreen = true; + mFolder.setText(item.getTitle()); + break; + case R.id.other: + switchToFolderSelector(); + break; + default: + return false; + } + return true; + } + // Refresh the ListView to hide or show the empty view, as necessary. // Should be called after mFolderNamer is shown or hidden. private void updateList() { @@ -462,7 +495,6 @@ public class AddBookmarkPage extends Activity title = mMap.getString("title"); url = mOriginalUrl = mMap.getString("url"); mTouchIconUrl = mMap.getString("touch_icon_url"); - mThumbnail = (Bitmap) mMap.getParcelable("thumbnail"); mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID); } if (mCurrentFolder == DEFAULT_FOLDER_ID) { @@ -609,6 +641,14 @@ public class AddBookmarkPage extends Activity Toast.LENGTH_LONG).show(); } break; + case TOUCH_ICON_DOWNLOADED: + Bundle b = msg.getData(); + sendBroadcast(BookmarkUtils.createAddToHomeIntent( + AddBookmarkPage.this, b.getString("url"), + b.getString("title"), + (Bitmap) b.getParcelable("touchIcon"), + (Bitmap) b.getParcelable("favicon"))); + break; } } }; @@ -671,27 +711,59 @@ public class AddBookmarkPage extends Activity return false; } + if (mSaveToHomeScreen) { + mEditingExisting = false; + } + + boolean urlUnmodified = url.equals(mOriginalUrl); + if (mEditingExisting) { mMap.putString("title", title); mMap.putString("url", url); - mMap.putBoolean("invalidateThumbnail", !url.equals(mOriginalUrl)); + mMap.putBoolean("invalidateThumbnail", !urlUnmodified); // FIXME: This does not work yet mMap.putLong(BrowserContract.Bookmarks.PARENT, mCurrentFolder); setResult(RESULT_OK, (new Intent()).setAction( getIntent().toString()).putExtras(mMap)); } else { - // Post a message to write to the DB. + Bitmap thumbnail; + Bitmap favicon; + if (urlUnmodified) { + thumbnail = (Bitmap) mMap.getParcelable("thumbnail"); + favicon = (Bitmap) mMap.getParcelable("favicon"); + } else { + thumbnail = null; + favicon = null; + } + Bundle bundle = new Bundle(); bundle.putString("title", title); bundle.putString("url", url); - bundle.putParcelable("thumbnail", mThumbnail); - bundle.putBoolean("invalidateThumbnail", !url.equals(mOriginalUrl)); - bundle.putString("touchIconUrl", mTouchIconUrl); - Message msg = Message.obtain(mHandler, SAVE_BOOKMARK); - msg.setData(bundle); - // Start a new thread so as to not slow down the UI - Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg)); - t.start(); + bundle.putParcelable("favicon", favicon); + + if (mSaveToHomeScreen) { + if (mTouchIconUrl != null && urlUnmodified) { + Message msg = Message.obtain(mHandler, + TOUCH_ICON_DOWNLOADED); + msg.setData(bundle); + DownloadTouchIcon icon = new DownloadTouchIcon(this, msg, + mMap.getString("user_agent")); + icon.execute(mTouchIconUrl); + } else { + sendBroadcast(BookmarkUtils.createAddToHomeIntent(this, url, + title, null /*touchIcon*/, favicon)); + } + } else { + bundle.putParcelable("thumbnail", thumbnail); + bundle.putBoolean("invalidateThumbnail", !urlUnmodified); + bundle.putString("touchIconUrl", mTouchIconUrl); + // Post a message to write to the DB. + Message msg = Message.obtain(mHandler, SAVE_BOOKMARK); + msg.setData(bundle); + // Start a new thread so as to not slow down the UI + Thread t = new Thread(new SaveBookmarkRunnable(getApplicationContext(), msg)); + t.start(); + } setResult(RESULT_OK); LogTag.logBookmarkAdded(url, "bookmarkview"); } |