diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index ff0eec9b56a..992a7b7964c 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -643,42 +643,6 @@ abstract public class BrowserApp extends GeckoApp registerEventListener("Prompt:ShowTop"); } - private void showBookmarkDialog() { - final Tab tab = Tabs.getInstance().getSelectedTab(); - final Prompt ps = new Prompt(this, new Prompt.PromptCallback() { - @Override - public void onPromptFinished(String result) { - int itemId = -1; - try { - itemId = new JSONObject(result).getInt("button"); - } catch(JSONException ex) { - Log.e(LOGTAG, "Exception reading bookmark prompt result", ex); - } - - if (tab == null) - return; - - if (itemId == 0) { - new EditBookmarkDialog(BrowserApp.this).show(tab.getURL()); - } else if (itemId == 1) { - String url = tab.getURL(); - String title = tab.getDisplayTitle(); - Bitmap favicon = tab.getFavicon(); - if (url != null && title != null) { - GeckoAppShell.createShortcut(title, url, url, favicon, ""); - } - } - } - }); - - final Prompt.PromptListItem[] items = new Prompt.PromptListItem[2]; - Resources res = getResources(); - items[0] = new Prompt.PromptListItem(res.getString(R.string.contextmenu_edit_bookmark)); - items[1] = new Prompt.PromptListItem(res.getString(R.string.contextmenu_add_to_launcher)); - - ps.show("", "", items, false); - } - private void setDynamicToolbarEnabled(boolean enabled) { if (enabled) { if (mLayerView != null) { @@ -745,16 +709,7 @@ abstract public class BrowserApp extends GeckoApp } if (itemId == R.id.subscribe) { - Tab tab = Tabs.getInstance().getSelectedTab(); - if (tab != null && tab.hasFeeds()) { - JSONObject args = new JSONObject(); - try { - args.put("tabId", tab.getId()); - } catch (JSONException e) { - Log.e(LOGTAG, "error building json arguments"); - } - GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feeds:Subscribe", args.toString())); - } + subscribeToFeeds(Tabs.getInstance().getSelectedTab()); return true; } @@ -784,27 +739,6 @@ abstract public class BrowserApp extends GeckoApp return true; } - if (itemId == R.id.add_to_launcher) { - Tab tab = Tabs.getInstance().getSelectedTab(); - if (tab == null) { - return true; - } - - final String url = tab.getURL(); - final String title = tab.getDisplayTitle(); - if (url == null || title == null) { - return true; - } - - final OnFaviconLoadedListener listener = new GeckoAppShell.CreateShortcutFaviconLoadedListener(url, title); - Favicons.getSizedFavicon(url, - tab.getFaviconURL(), - Integer.MAX_VALUE, - LoadFaviconTask.FLAG_PERSIST, - listener); - return true; - } - return false; } @@ -2155,6 +2089,9 @@ abstract public class BrowserApp extends GeckoApp MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode); MenuItem enterGuestMode = aMenu.findItem(R.id.new_guest_session); MenuItem exitGuestMode = aMenu.findItem(R.id.exit_guest_session); + MenuItem subscribe = aMenu.findItem(R.id.subscribe); + MenuItem addToReadingList = aMenu.findItem(R.id.reading_list_add); + MenuItem save = aMenu.findItem(R.id.save); // Only show the "Quit" menu item on pre-ICS or television devices. // In ICS+, it's easy to kill an app through the task switcher. @@ -2179,11 +2116,10 @@ abstract public class BrowserApp extends GeckoApp return true; } + save.setVisible(!GeckoProfile.get(this).inGuestMode()); + bookmark.setEnabled(!AboutPages.isAboutReader(tab.getURL())); - bookmark.setVisible(!GeckoProfile.get(this).inGuestMode()); - bookmark.setCheckable(true); bookmark.setChecked(tab.isBookmark()); - bookmark.setIcon(tab.isBookmark() ? R.drawable.ic_menu_bookmark_remove : R.drawable.ic_menu_bookmark_add); back.setEnabled(tab.canDoBack()); forward.setEnabled(tab.canDoForward()); @@ -2273,18 +2209,22 @@ abstract public class BrowserApp extends GeckoApp else enterGuestMode.setVisible(true); + addToReadingList.setChecked(tab.isReadingListItem()); + addToReadingList.setEnabled(tab.getReaderEnabled()); + + subscribe.setEnabled(tab.hasFeeds()); + return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { - Tab tab = null; + final Tab tab = Tabs.getInstance().getSelectedTab(); Intent intent = null; final int itemId = item.getItemId(); if (itemId == R.id.bookmark) { - tab = Tabs.getInstance().getSelectedTab(); if (tab != null) { if (item.isChecked()) { tab.removeBookmark(); @@ -2294,12 +2234,12 @@ abstract public class BrowserApp extends GeckoApp tab.addBookmark(); getButtonToast().show(false, getResources().getString(R.string.bookmark_added), - getResources().getString(R.string.bookmark_options), + getResources().getString(R.string.contextmenu_edit_bookmark), null, new ButtonToast.ToastListener() { @Override public void onButtonClicked() { - showBookmarkDialog(); + new EditBookmarkDialog(BrowserApp.this).show(tab.getURL()); } @Override @@ -2317,21 +2257,18 @@ abstract public class BrowserApp extends GeckoApp } if (itemId == R.id.reload) { - tab = Tabs.getInstance().getSelectedTab(); if (tab != null) tab.doReload(); return true; } if (itemId == R.id.back) { - tab = Tabs.getInstance().getSelectedTab(); if (tab != null) tab.doBack(); return true; } if (itemId == R.id.forward) { - tab = Tabs.getInstance().getSelectedTab(); if (tab != null) tab.doForward(); return true; @@ -2374,13 +2311,12 @@ abstract public class BrowserApp extends GeckoApp } if (itemId == R.id.desktop_mode) { - Tab selectedTab = Tabs.getInstance().getSelectedTab(); - if (selectedTab == null) + if (tab == null) return true; JSONObject args = new JSONObject(); try { args.put("desktopMode", !item.isChecked()); - args.put("tabId", selectedTab.getId()); + args.put("tabId", tab.getId()); } catch (JSONException e) { Log.e(LOGTAG, "error building json arguments"); } @@ -2415,6 +2351,25 @@ abstract public class BrowserApp extends GeckoApp return true; } + if (itemId == R.id.launcher_add) { + addToLauncher(tab.getURL(), tab.getTitle(), tab.getFaviconURL()); + return true; + } + + if (itemId == R.id.reading_list_add) { + if (item.isChecked()) { + ReaderModeUtils.removeFromReadingList(tab.getURL()); + } else { + ReaderModeUtils.addToReadingList(tab); + } + return true; + } + + if (itemId == R.id.subscribe) { + subscribeToFeeds(tab); + return true; + } + return super.onOptionsItemSelected(item); } @@ -2459,6 +2414,33 @@ abstract public class BrowserApp extends GeckoApp ps.show(res.getString(titleString), res.getString(msgString), null, false); } + public void subscribeToFeeds(Tab tab) { + if (!tab.hasFeeds()) { + return; + } + + JSONObject args = new JSONObject(); + try { + args.put("tabId", tab.getId()); + } catch (JSONException e) { + Log.e(LOGTAG, "JSON error", e); + } + GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feeds:Subscribe", args.toString())); + } + + private void addToLauncher(String url, String title, String faviconUrl) { + if (url == null || title == null) { + return; + } + + final OnFaviconLoadedListener listener = new GeckoAppShell.CreateShortcutFaviconLoadedListener(url, title); + Favicons.getSizedFavicon(url, + faviconUrl, + Integer.MAX_VALUE, + LoadFaviconTask.FLAG_PERSIST, + listener); + } + /** * This will detect if the key pressed is back. If so, will show the history. */ diff --git a/mobile/android/base/ReaderModeUtils.java b/mobile/android/base/ReaderModeUtils.java index 5e4bcb460ab..bab2c532f1c 100644 --- a/mobile/android/base/ReaderModeUtils.java +++ b/mobile/android/base/ReaderModeUtils.java @@ -4,9 +4,12 @@ package org.mozilla.gecko; +import org.json.JSONException; +import org.json.JSONObject; import org.mozilla.gecko.util.StringUtils; import android.net.Uri; +import android.util.Log; public class ReaderModeUtils { private static final String LOGTAG = "ReaderModeUtils"; @@ -45,4 +48,30 @@ public class ReaderModeUtils { return aboutReaderUrl; } + + public static void addToReadingList(Tab tab) { + if (!tab.getReaderEnabled()) { + return; + } + + JSONObject json = new JSONObject(); + try { + json.put("tabID", String.valueOf(tab.getId())); + } catch (JSONException e) { + Log.e(LOGTAG, "JSON error - failing to add to reading list", e); + return; + } + + GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Add", json.toString()); + GeckoAppShell.sendEventToGecko(e); + } + + public static void removeFromReadingList(String url) { + if (url == null) { + return; + } + + GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", url); + GeckoAppShell.sendEventToGecko(e); + } } diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index f189550fad9..0c991a7e740 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -8,6 +8,9 @@ package org.mozilla.gecko; import org.mozilla.gecko.SiteIdentity.SecurityMode; import org.mozilla.gecko.db.BrowserContract.Bookmarks; import org.mozilla.gecko.db.BrowserDB; +import org.mozilla.gecko.favicons.Favicons; +import org.mozilla.gecko.favicons.LoadFaviconTask; +import org.mozilla.gecko.favicons.OnFaviconLoadedListener; import org.mozilla.gecko.gfx.Layer; import org.mozilla.gecko.util.ThreadUtils; @@ -453,22 +456,6 @@ public class Tab { }); } - public void addToReadingList() { - if (!mReaderEnabled) - return; - - JSONObject json = new JSONObject(); - try { - json.put("tabID", String.valueOf(getId())); - } catch (JSONException e) { - Log.e(LOGTAG, "JSON error - failing to add to reading list", e); - return; - } - - GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Add", json.toString()); - GeckoAppShell.sendEventToGecko(e); - } - public void toggleReaderMode() { if (AboutPages.isAboutReader(mUrl)) { Tabs.getInstance().loadUrl(ReaderModeUtils.getUrlFromAboutReader(mUrl)); diff --git a/mobile/android/base/locales/en-US/android_strings.dtd b/mobile/android/base/locales/en-US/android_strings.dtd index 1b85a4f7950..3d0bc4ca072 100644 --- a/mobile/android/base/locales/en-US/android_strings.dtd +++ b/mobile/android/base/locales/en-US/android_strings.dtd @@ -54,6 +54,7 @@ + @@ -276,6 +277,7 @@ size. --> + diff --git a/mobile/android/base/resources/menu-large-v11/browser_app_menu.xml b/mobile/android/base/resources/menu-large-v11/browser_app_menu.xml index 1736bb4cf0e..e324e4be047 100644 --- a/mobile/android/base/resources/menu-large-v11/browser_app_menu.xml +++ b/mobile/android/base/resources/menu-large-v11/browser_app_menu.xml @@ -20,10 +20,30 @@ android:title="@string/forward" android:visible="false"/> - + android:title="@string/save" + android:showAsAction="ifRoom"> + + + + + + + + + + + + + + - + android:title="@string/save" + android:showAsAction="ifRoom"> + + + + + + + + + + + + + + - + android:title="@string/save" + android:showAsAction="always"> + + + + + + + + + + + + + + - + android:title="@string/save"> + + + + + + + + + + + + + + &tabs_normal; &tabs_private; &tabs_synced; + &save; &site_settings_title3; &site_settings_cancel; &site_settings_clear; &site_settings_no_settings; + &reading_list_add; &reading_list_added; &reading_list_removed; &reading_list_failed; diff --git a/mobile/android/base/toolbar/BrowserToolbar.java b/mobile/android/base/toolbar/BrowserToolbar.java index ea66aba53e6..5dbfa0c4738 100644 --- a/mobile/android/base/toolbar/BrowserToolbar.java +++ b/mobile/android/base/toolbar/BrowserToolbar.java @@ -11,6 +11,7 @@ import org.mozilla.gecko.GeckoAppShell; import org.mozilla.gecko.GeckoProfile; import org.mozilla.gecko.LightweightTheme; import org.mozilla.gecko.R; +import org.mozilla.gecko.ReaderModeUtils; import org.mozilla.gecko.SiteIdentity.SecurityMode; import org.mozilla.gecko.Tab; import org.mozilla.gecko.Tabs; @@ -30,7 +31,6 @@ import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.widget.GeckoImageButton; import org.mozilla.gecko.widget.GeckoImageView; import org.mozilla.gecko.widget.GeckoRelativeLayout; - import org.json.JSONObject; import android.content.Context; @@ -1345,10 +1345,7 @@ public class BrowserToolbar extends GeckoRelativeLayout tab.toggleReaderMode(); } } else if (event.equals("Reader:LongClick")) { - Tab tab = Tabs.getInstance().getSelectedTab(); - if (tab != null) { - tab.addToReadingList(); - } + ReaderModeUtils.addToReadingList(Tabs.getInstance().getSelectedTab()); } }