Improve the visibility and discoverability of the "add shortcut
to home" functionality in the Browser.
When the user selects the bookmark button adjacent to the URL bar
they will be prompted to either add a new bookmark for the current
page or add a shortcut to the current page to their homescreen,
rather than being taken to the bookmark management activity. The
bookmarks button on the options menu will still take the user
directly to the bookmark management activity.
Bug: b/2794945
Change-Id: I07190250379f1d6e2fe6b8ea280317949cd58b15
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java
index c7abad1..aeb8c46 100644
--- a/src/com/android/browser/BrowserActivity.java
+++ b/src/com/android/browser/BrowserActivity.java
@@ -1487,6 +1487,7 @@
i.putExtra("touch_icon_url", w.getTouchIconUrl());
i.putExtra("thumbnail", createScreenshot(w, getDesiredThumbnailWidth(this),
getDesiredThumbnailHeight(this)));
+ i.putExtra("url_editable", false);
startActivity(i);
}
@@ -2287,6 +2288,8 @@
static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
+ private static final int TOUCH_ICON_DOWNLOADED = 109;
+
// Private handler for handling javascript and saving passwords
private Handler mHandler = new Handler() {
@@ -2357,6 +2360,14 @@
updateScreenshot(view);
}
break;
+
+ case TOUCH_ICON_DOWNLOADED:
+ Bundle b = msg.getData();
+ showSaveToHomescreenDialog(b.getString("url"),
+ b.getString("title"),
+ (Bitmap) b.getParcelable("touchIcon"),
+ (Bitmap) b.getParcelable("favicon"));
+ break;
}
}
};
@@ -3728,6 +3739,47 @@
}
+ /* package*/ void promptAddOrInstallBookmark() {
+ final Tab current = mTabControl.getCurrentTab();
+ Resources resources = getResources();
+ CharSequence[] choices = {
+ resources.getString(R.string.save_to_bookmarks),
+ resources.getString(R.string.create_shortcut_bookmark)
+ };
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.add_new_bookmark);
+ builder.setItems(choices, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int item) {
+ if (item == 0) {
+ bookmarkCurrentPage();
+ } else if (item == 1) {
+ current.populatePickerData();
+ String touchIconUrl = mTabControl.getCurrentWebView().getTouchIconUrl();
+ if (touchIconUrl != null) {
+ // Download the touch icon for this site then save it to the
+ // homescreen.
+ Bundle b = new Bundle();
+ b.putString("url", current.getUrl());
+ b.putString("title", current.getTitle());
+ b.putParcelable("favicon", current.getFavicon());
+ Message msg = mHandler.obtainMessage(TOUCH_ICON_DOWNLOADED);
+ msg.setData(b);
+ new DownloadTouchIcon(msg,
+ mTabControl.getCurrentWebView().getSettings()
+ .getUserAgentString()).execute(touchIconUrl);
+ } else {
+ // add to homescreen, can do it immediately as there is no touch
+ // icon.
+ showSaveToHomescreenDialog(current.getUrl(), current.getTitle(),
+ null, current.getFavicon());
+ }
+ }
+ }
+ });
+ builder.create().show();
+ }
+
/**
* Open the Go page.
* @param startWithHistory If true, open starting on the history tab.
@@ -3771,6 +3823,33 @@
startActivityForResult(intent, COMBO_PAGE);
}
+ private void showSaveToHomescreenDialog(String url, String title, Bitmap touchIcon,
+ Bitmap favicon) {
+ Intent intent = new Intent(this, SaveToHomescreenDialog.class);
+
+ // Just in case the user tries to save 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;
+ }
+
+ intent.putExtra("title", title);
+ intent.putExtra("url", url);
+ intent.putExtra("favicon", favicon);
+ intent.putExtra("touchIcon", touchIcon);
+ startActivity(intent);
+ }
+
+
// Called when loading from context menu or LOAD_URL message
private void loadUrlFromContext(WebView view, String url) {
// In case the user enters nothing.