Bug 984677 - Back out bookmark submenu. r=mfinkle

--HG--
extra : rebase_source : 7ff1fa41da1fe32e63f57141040cf172486996b7
This commit is contained in:
Brian Nicholson 2014-03-24 15:38:57 -07:00
parent cfb8e0372c
commit a8d5ed6af7
10 changed files with 112 additions and 193 deletions

View File

@ -45,6 +45,7 @@ import org.mozilla.gecko.home.SearchEngine;
import org.mozilla.gecko.menu.GeckoMenu;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.prompts.Prompt;
import org.mozilla.gecko.prompts.PromptListItem;
import org.mozilla.gecko.sync.setup.SyncAccounts;
import org.mozilla.gecko.toolbar.AutocompleteHandler;
import org.mozilla.gecko.toolbar.BrowserToolbar;
@ -636,6 +637,42 @@ 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 PromptListItem[] items = new PromptListItem[2];
Resources res = getResources();
items[0] = new PromptListItem(res.getString(R.string.contextmenu_edit_bookmark));
items[1] = new PromptListItem(res.getString(R.string.contextmenu_add_to_launcher));
ps.show("", "", items, ListView.CHOICE_MODE_NONE);
}
private void setDynamicToolbarEnabled(boolean enabled) {
ThreadUtils.assertOnUiThread();
@ -700,7 +737,16 @@ abstract public class BrowserApp extends GeckoApp
}
if (itemId == R.id.subscribe) {
subscribeToFeeds(Tabs.getInstance().getSelectedTab());
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()));
}
return true;
}
@ -730,6 +776,27 @@ 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;
}
@ -2084,9 +2151,6 @@ 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.save_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.
@ -2111,15 +2175,11 @@ abstract public class BrowserApp extends GeckoApp
return true;
}
save.setVisible(!GeckoProfile.get(this).inGuestMode());
if (tab.isBookmark() || tab.isReadingListItem()) {
save.setIcon(R.drawable.ic_menu_bookmark_remove);
} else {
save.setIcon(R.drawable.ic_menu_bookmark_add);
}
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());
@ -2209,22 +2269,18 @@ 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) {
final Tab tab = Tabs.getInstance().getSelectedTab();
Tab tab = null;
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();
@ -2234,12 +2290,12 @@ abstract public class BrowserApp extends GeckoApp
tab.addBookmark();
getButtonToast().show(false,
getResources().getString(R.string.bookmark_added),
getResources().getString(R.string.contextmenu_edit_bookmark),
getResources().getString(R.string.bookmark_options),
null,
new ButtonToast.ToastListener() {
@Override
public void onButtonClicked() {
new EditBookmarkDialog(BrowserApp.this).show(tab.getURL());
showBookmarkDialog();
}
@Override
@ -2257,18 +2313,21 @@ 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;
@ -2311,12 +2370,13 @@ abstract public class BrowserApp extends GeckoApp
}
if (itemId == R.id.desktop_mode) {
if (tab == null)
Tab selectedTab = Tabs.getInstance().getSelectedTab();
if (selectedTab == null)
return true;
JSONObject args = new JSONObject();
try {
args.put("desktopMode", !item.isChecked());
args.put("tabId", tab.getId());
args.put("tabId", selectedTab.getId());
} catch (JSONException e) {
Log.e(LOGTAG, "error building json arguments");
}
@ -2351,25 +2411,6 @@ 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 || itemId == R.id.save_subscribe) {
subscribeToFeeds(tab);
return true;
}
return super.onOptionsItemSelected(item);
}
@ -2414,33 +2455,6 @@ abstract public class BrowserApp extends GeckoApp
ps.show(res.getString(titleString), res.getString(msgString), null, ListView.CHOICE_MODE_NONE);
}
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.
*/

View File

@ -4,12 +4,9 @@
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";
@ -48,30 +45,4 @@ 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);
}
}

View File

@ -457,6 +457,22 @@ 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));

View File

@ -54,7 +54,6 @@
<!ENTITY back "Back">
<!ENTITY stop "Stop">
<!ENTITY site_security "Site Security">
<!ENTITY save "Save">
<!ENTITY close_tab "Close Tab">
<!ENTITY one_tab "1 tab">
@ -290,7 +289,6 @@ size. -->
<!ENTITY site_settings_clear "Clear">
<!ENTITY site_settings_no_settings "There are no settings to clear.">
<!ENTITY reading_list_add "Add to Reading List">
<!ENTITY reading_list_added "Page added to your Reading List">
<!ENTITY reading_list_removed "Page removed from your Reading List">
<!ENTITY reading_list_failed "Failed to add page to your Reading List">

View File

@ -20,30 +20,10 @@
android:title="@string/forward"
android:visible="false"/>
<item android:id="@+id/save"
<item android:id="@+id/bookmark"
android:icon="@drawable/ic_menu_bookmark_add"
android:title="@string/save"
android:showAsAction="ifRoom">
<menu>
<item android:id="@+id/bookmark"
android:title="@string/bookmark"
android:checkable="true" />
<item android:id="@+id/reading_list_add"
android:title="@string/reading_list_add"
android:checkable="true" />
<item android:id="@+id/launcher_add"
android:title="@string/contextmenu_add_to_launcher" />
<item android:id="@+id/save_subscribe"
android:title="@string/contextmenu_subscribe" />
</menu>
</item>
android:title="@string/bookmark"
android:showAsAction="ifRoom"/>
<item android:id="@+id/share"
android:icon="@drawable/ic_menu_share"

View File

@ -20,30 +20,10 @@
android:title="@string/reload"
android:showAsAction="always"/>
<item android:id="@+id/save"
<item android:id="@+id/bookmark"
android:icon="@drawable/ic_menu_bookmark_add"
android:title="@string/save"
android:showAsAction="ifRoom">
<menu>
<item android:id="@+id/bookmark"
android:title="@string/bookmark"
android:checkable="true" />
<item android:id="@+id/reading_list_add"
android:title="@string/reading_list_add"
android:checkable="true" />
<item android:id="@+id/launcher_add"
android:title="@string/contextmenu_add_to_launcher" />
<item android:id="@+id/save_subscribe"
android:title="@string/contextmenu_subscribe" />
</menu>
</item>
android:title="@string/bookmark"
android:showAsAction="ifRoom"/>
<item android:id="@+id/share"
android:icon="@drawable/ic_menu_share"

View File

@ -20,30 +20,10 @@
android:title="@string/forward"
android:visible="false"/>
<item android:id="@+id/save"
<item android:id="@+id/bookmark"
android:icon="@drawable/ic_menu_bookmark_add"
android:title="@string/save"
android:showAsAction="always">
<menu>
<item android:id="@+id/bookmark"
android:title="@string/bookmark"
android:checkable="true" />
<item android:id="@+id/reading_list_add"
android:title="@string/reading_list_add"
android:checkable="true" />
<item android:id="@+id/launcher_add"
android:title="@string/contextmenu_add_to_launcher" />
<item android:id="@+id/save_subscribe"
android:title="@string/contextmenu_subscribe" />
</menu>
</item>
android:title="@string/bookmark"
android:showAsAction="always"/>
<item android:id="@+id/share"
android:icon="@drawable/ic_menu_share"

View File

@ -18,29 +18,9 @@
android:icon="@drawable/ic_menu_forward"
android:title="@string/forward"/>
<item android:id="@+id/save"
<item android:id="@+id/bookmark"
android:icon="@drawable/ic_menu_bookmark_add"
android:title="@string/save">
<menu>
<item android:id="@+id/bookmark"
android:title="@string/bookmark"
android:checkable="true" />
<item android:id="@+id/reading_list_add"
android:title="@string/reading_list_add"
android:checkable="true" />
<item android:id="@+id/launcher_add"
android:title="@string/contextmenu_add_to_launcher" />
<item android:id="@+id/save_subscribe"
android:title="@string/contextmenu_subscribe" />
</menu>
</item>
android:title="@string/bookmark"/>
<item android:id="@+id/new_tab"
android:icon="@drawable/ic_menu_new_tab"

View File

@ -233,14 +233,12 @@
<string name="tabs_normal">&tabs_normal;</string>
<string name="tabs_private">&tabs_private;</string>
<string name="tabs_synced">&tabs_synced;</string>
<string name="save">&save;</string>
<string name="site_settings_title">&site_settings_title3;</string>
<string name="site_settings_cancel">&site_settings_cancel;</string>
<string name="site_settings_clear">&site_settings_clear;</string>
<string name="site_settings_no_settings">&site_settings_no_settings;</string>
<string name="reading_list_add">&reading_list_add;</string>
<string name="reading_list_added">&reading_list_added;</string>
<string name="reading_list_removed">&reading_list_removed;</string>
<string name="reading_list_failed">&reading_list_failed;</string>

View File

@ -17,7 +17,6 @@ import org.mozilla.gecko.GeckoApplication;
import org.mozilla.gecko.GeckoProfile;
import org.mozilla.gecko.LightweightTheme;
import org.mozilla.gecko.R;
import org.mozilla.gecko.ReaderModeUtils;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.animation.PropertyAnimator;
@ -1352,7 +1351,10 @@ public class BrowserToolbar extends GeckoRelativeLayout
tab.toggleReaderMode();
}
} else if (event.equals("Reader:LongClick")) {
ReaderModeUtils.addToReadingList(Tabs.getInstance().getSelectedTab());
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
tab.addToReadingList();
}
}
}