diff options
-rw-r--r-- | src/com/android/browser/AddBookmarkPage.java | 56 | ||||
-rw-r--r-- | src/com/android/browser/BrowserActivity.java | 47 | ||||
-rw-r--r-- | src/com/android/browser/BrowserBookmarksPage.java | 10 | ||||
-rw-r--r-- | src/com/android/browser/BrowserHistoryPage.java | 2 | ||||
-rw-r--r-- | src/com/android/browser/DownloadTouchIcon.java | 7 |
5 files changed, 55 insertions, 67 deletions
diff --git a/src/com/android/browser/AddBookmarkPage.java b/src/com/android/browser/AddBookmarkPage.java index fc480ee..1292bf6 100644 --- a/src/com/android/browser/AddBookmarkPage.java +++ b/src/com/android/browser/AddBookmarkPage.java @@ -68,6 +68,10 @@ public class AddBookmarkPage extends Activity BreadCrumbView.Controller, PopupMenu.OnMenuItemClickListener { public static final long DEFAULT_FOLDER_ID = -1; + public static final String TOUCH_ICON_URL = "touch_icon_url"; + // Place on an edited bookmark to remove the saved thumbnail + public static final String REMOVE_THUMBNAIL = "remove_thumbnail"; + public static final String USER_AGENT = "user_agent"; private static final int MAX_CRUMBS_SHOWN = 2; @@ -492,9 +496,9 @@ public class AddBookmarkPage extends Activity window.setAttributes(l); } } - title = mMap.getString("title"); - url = mOriginalUrl = mMap.getString("url"); - mTouchIconUrl = mMap.getString("touch_icon_url"); + title = mMap.getString(BrowserContract.Bookmarks.TITLE); + url = mOriginalUrl = mMap.getString(BrowserContract.Bookmarks.URL); + mTouchIconUrl = mMap.getString(TOUCH_ICON_URL); mCurrentFolder = mMap.getLong(BrowserContract.Bookmarks.PARENT, DEFAULT_FOLDER_ID); } if (mCurrentFolder == DEFAULT_FOLDER_ID) { @@ -602,13 +606,12 @@ public class AddBookmarkPage extends Activity public void run() { // Unbundle bookmark data. Bundle bundle = mMessage.getData(); - String title = bundle.getString("title"); - String url = bundle.getString("url"); - boolean invalidateThumbnail = bundle.getBoolean( - "invalidateThumbnail"); + String title = bundle.getString(BrowserContract.Bookmarks.TITLE); + String url = bundle.getString(BrowserContract.Bookmarks.URL); + boolean invalidateThumbnail = bundle.getBoolean(REMOVE_THUMBNAIL); Bitmap thumbnail = invalidateThumbnail ? null - : (Bitmap) bundle.getParcelable("thumbnail"); - String touchIconUrl = bundle.getString("touchIconUrl"); + : (Bitmap) bundle.getParcelable(BrowserContract.Bookmarks.THUMBNAIL); + String touchIconUrl = bundle.getString(TOUCH_ICON_URL); // Save to the bookmarks DB. try { @@ -644,10 +647,11 @@ public class AddBookmarkPage extends Activity 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"))); + AddBookmarkPage.this, + b.getString(BrowserContract.Bookmarks.URL), + b.getString(BrowserContract.Bookmarks.TITLE), + (Bitmap) b.getParcelable(BrowserContract.Bookmarks.TOUCH_ICON), + (Bitmap) b.getParcelable(BrowserContract.Bookmarks.FAVICON))); break; } } @@ -718,9 +722,9 @@ public class AddBookmarkPage extends Activity boolean urlUnmodified = url.equals(mOriginalUrl); if (mEditingExisting) { - mMap.putString("title", title); - mMap.putString("url", url); - mMap.putBoolean("invalidateThumbnail", !urlUnmodified); + mMap.putString(BrowserContract.Bookmarks.TITLE, title); + mMap.putString(BrowserContract.Bookmarks.URL, url); + mMap.putBoolean(REMOVE_THUMBNAIL, !urlUnmodified); // FIXME: This does not work yet mMap.putLong(BrowserContract.Bookmarks.PARENT, mCurrentFolder); setResult(RESULT_OK, (new Intent()).setAction( @@ -729,17 +733,19 @@ public class AddBookmarkPage extends Activity Bitmap thumbnail; Bitmap favicon; if (urlUnmodified) { - thumbnail = (Bitmap) mMap.getParcelable("thumbnail"); - favicon = (Bitmap) mMap.getParcelable("favicon"); + thumbnail = (Bitmap) mMap.getParcelable( + BrowserContract.Bookmarks.THUMBNAIL); + favicon = (Bitmap) mMap.getParcelable( + BrowserContract.Bookmarks.FAVICON); } else { thumbnail = null; favicon = null; } Bundle bundle = new Bundle(); - bundle.putString("title", title); - bundle.putString("url", url); - bundle.putParcelable("favicon", favicon); + bundle.putString(BrowserContract.Bookmarks.TITLE, title); + bundle.putString(BrowserContract.Bookmarks.URL, url); + bundle.putParcelable(BrowserContract.Bookmarks.FAVICON, favicon); if (mSaveToHomeScreen) { if (mTouchIconUrl != null && urlUnmodified) { @@ -747,16 +753,16 @@ public class AddBookmarkPage extends Activity TOUCH_ICON_DOWNLOADED); msg.setData(bundle); DownloadTouchIcon icon = new DownloadTouchIcon(this, msg, - mMap.getString("user_agent")); + 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); + bundle.putParcelable(BrowserContract.Bookmarks.THUMBNAIL, thumbnail); + bundle.putBoolean(REMOVE_THUMBNAIL, !urlUnmodified); + bundle.putString(TOUCH_ICON_URL, mTouchIconUrl); // Post a message to write to the DB. Message msg = Message.obtain(mHandler, SAVE_BOOKMARK); msg.setData(bundle); diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index bd50a77..ce85f61 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -1488,19 +1488,21 @@ public class BrowserActivity extends Activity Intent i = new Intent(BrowserActivity.this, AddBookmarkPage.class); WebView w = getTopWindow(); - i.putExtra("url", w.getUrl()); - i.putExtra("title", w.getTitle()); + i.putExtra(BrowserContract.Bookmarks.URL, w.getUrl()); + i.putExtra(BrowserContract.Bookmarks.TITLE, w.getTitle()); String touchIconUrl = w.getTouchIconUrl(); if (touchIconUrl != null) { - i.putExtra("touch_icon_url", touchIconUrl); + i.putExtra(AddBookmarkPage.TOUCH_ICON_URL, touchIconUrl); WebSettings settings = w.getSettings(); if (settings != null) { - i.putExtra("user_agent", settings.getUserAgentString()); + i.putExtra(AddBookmarkPage.USER_AGENT, + settings.getUserAgentString()); } } - i.putExtra("thumbnail", createScreenshot(w, getDesiredThumbnailWidth(this), + i.putExtra(BrowserContract.Bookmarks.THUMBNAIL, + createScreenshot(w, getDesiredThumbnailWidth(this), getDesiredThumbnailHeight(this))); - i.putExtra("favicon", w.getFavicon()); + i.putExtra(BrowserContract.Bookmarks.FAVICON, w.getFavicon()); i.putExtra(BrowserContract.Bookmarks.PARENT, folderId); // Put the dialog at the upper right of the screen, covering the @@ -2336,8 +2338,9 @@ public class BrowserActivity extends Activity case R.id.bookmark_context_menu_id: Intent intent = new Intent(BrowserActivity.this, AddBookmarkPage.class); - intent.putExtra("url", url); - intent.putExtra("title", title); + intent.putExtra(BrowserContract.Bookmarks.URL, url); + intent.putExtra(BrowserContract.Bookmarks.TITLE, + title); startActivity(intent); break; case R.id.share_link_context_menu_id: @@ -3830,35 +3833,13 @@ public class BrowserActivity extends Activity * Otherwise, start with the bookmarks tab. */ /* package */ void bookmarksOrHistoryPicker(boolean startWithHistory) { - WebView current = mTabControl.getCurrentWebView(); - if (current == null) { + if (mTabControl.getCurrentWebView() == null) { return; } - String title = current.getTitle(); - String url = current.getUrl(); - Bitmap thumbnail = createScreenshot(current, getDesiredThumbnailWidth(this), - getDesiredThumbnailHeight(this)); - - // Just in case the user opens bookmarks before a page finishes loading - // so the current history item, and therefore the page, is null. - if (null == url) { - url = mLastEnteredUrl; - // This can happen. - if (null == url) { - url = mSettings.getHomePage(); - } - } - // In case the web page has not yet received its associated title. - if (title == null) { - title = url; - } Bundle extras = new Bundle(); - extras.putString("title", title); - extras.putString("url", url); - extras.putParcelable("thumbnail", thumbnail); // Disable opening in a new window if we have maxed out the windows - extras.putBoolean("disable_new_window", !mTabControl.canCreateNewTab()); - extras.putString("touch_icon_url", current.getTouchIconUrl()); + extras.putBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW, + !mTabControl.canCreateNewTab()); mComboView = new CombinedBookmarkHistoryView(this, startWithHistory ? CombinedBookmarkHistoryView.FRAGMENT_ID_HISTORY diff --git a/src/com/android/browser/BrowserBookmarksPage.java b/src/com/android/browser/BrowserBookmarksPage.java index 522d37e..4a3ae1f 100644 --- a/src/com/android/browser/BrowserBookmarksPage.java +++ b/src/com/android/browser/BrowserBookmarksPage.java @@ -354,8 +354,8 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte super.onCreate(icicle); Bundle args = getArguments(); - mCreateShortcut = args == null ? false : args.getBoolean("create_shortcut", false); - mDisableNewWindow = args == null ? false : args.getBoolean("disable_new_window", false); + mCreateShortcut = args == null ? false : args.getBoolean(EXTRA_SHORTCUT, false); + mDisableNewWindow = args == null ? false : args.getBoolean(EXTRA_DISABLE_WINDOW, false); } @Override @@ -520,8 +520,8 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte if (data != null && (extras = data.getExtras()) != null) { // If there are extras, then we need to save // the edited bookmark. This is done in updateRow() - String title = extras.getString("title"); - String url = extras.getString("url"); + String title = extras.getString(BrowserContract.Bookmarks.TITLE); + String url = extras.getString(BrowserContract.Bookmarks.URL); if (title != null && url != null) { updateRow(extras); } @@ -562,7 +562,7 @@ public class BrowserBookmarksPage extends Fragment implements View.OnCreateConte values.put(BrowserContract.Bookmarks.URL, url); } - if (map.getBoolean("invalidateThumbnail") == true) { + if (map.getBoolean(AddBookmarkPage.REMOVE_THUMBNAIL)) { values.putNull(BrowserContract.Bookmarks.THUMBNAIL); } diff --git a/src/com/android/browser/BrowserHistoryPage.java b/src/com/android/browser/BrowserHistoryPage.java index e565696..61af0ce 100644 --- a/src/com/android/browser/BrowserHistoryPage.java +++ b/src/com/android/browser/BrowserHistoryPage.java @@ -159,7 +159,7 @@ public class BrowserHistoryPage extends Fragment setHasOptionsMenu(true); Bundle args = getArguments(); - mDisableNewWindow = args.getBoolean("disable_new_window", false); + mDisableNewWindow = args.getBoolean(BrowserBookmarksPage.EXTRA_DISABLE_WINDOW, false); } @Override diff --git a/src/com/android/browser/DownloadTouchIcon.java b/src/com/android/browser/DownloadTouchIcon.java index 992284f..768eab5 100644 --- a/src/com/android/browser/DownloadTouchIcon.java +++ b/src/com/android/browser/DownloadTouchIcon.java @@ -34,6 +34,7 @@ import android.net.http.AndroidHttpClient; import android.os.AsyncTask; import android.os.Bundle; import android.os.Message; +import android.provider.BrowserContract; import android.provider.BrowserContract.Images; import android.webkit.WebView; @@ -85,8 +86,8 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> { /** * Use this ctor to not store the touch icon in a database, rather add it to - * the passed Message's data bundle with the key "touchIcon" and then send - * the message. + * the passed Message's data bundle with the key + * {@link BrowserContract.Bookmarks#TOUCH_ICON} and then send the message. */ public DownloadTouchIcon(Context context, Message msg, String userAgent) { mMessage = msg; @@ -133,7 +134,7 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> { storeIcon(icon); } else if (mMessage != null) { Bundle b = mMessage.getData(); - b.putParcelable("touchIcon", icon); + b.putParcelable(BrowserContract.Bookmarks.TOUCH_ICON, icon); } } } |