Bug 880118 - Android resource IDs must be mutable for library projects. r=cpeterson

This commit is contained in:
Shane Tully 2013-08-13 16:44:00 -07:00
parent 7f9689956b
commit b1a90adbf1
6 changed files with 337 additions and 288 deletions

View File

@ -521,97 +521,100 @@ public class AwesomeBar extends GeckoActivity
final String keyword = mContextMenuSubject.keyword;
final int display = mContextMenuSubject.display;
switch (item.getItemId()) {
case R.id.open_private_tab:
case R.id.open_new_tab: {
if (url == null) {
Log.e(LOGTAG, "Can't open in new tab because URL is null");
break;
}
String newTabUrl = url;
if (display == Combined.DISPLAY_READER)
newTabUrl = ReaderModeUtils.getAboutReaderForUrl(url, true);
int flags = Tabs.LOADURL_NEW_TAB;
if (item.getItemId() == R.id.open_private_tab)
flags |= Tabs.LOADURL_PRIVATE;
Tabs.getInstance().loadUrl(newTabUrl, flags);
Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
break;
final int itemId = item.getItemId();
if (itemId == R.id.open_private_tab || itemId == R.id.open_new_tab) {
if (url == null) {
Log.e(LOGTAG, "Can't open in new tab because URL is null");
}
case R.id.open_in_reader: {
if (url == null) {
Log.e(LOGTAG, "Can't open in reader mode because URL is null");
break;
}
String newTabUrl = url;
if (display == Combined.DISPLAY_READER)
newTabUrl = ReaderModeUtils.getAboutReaderForUrl(url, true);
int flags = Tabs.LOADURL_NEW_TAB;
if (item.getItemId() == R.id.open_private_tab)
flags |= Tabs.LOADURL_PRIVATE;
Tabs.getInstance().loadUrl(newTabUrl, flags);
Toast.makeText(this, R.string.new_tab_opened, Toast.LENGTH_SHORT).show();
return true;
}
if (itemId == R.id.open_in_reader) {
if (url == null) {
Log.e(LOGTAG, "Can't open in reader mode because URL is null");
} else {
openUrlAndFinish(ReaderModeUtils.getAboutReaderForUrl(url, true));
break;
}
case R.id.edit_bookmark: {
new EditBookmarkDialog(this).show(id, title, url, keyword);
break;
}
case R.id.remove_bookmark: {
(new UiAsyncTask<Void, Void, Integer>(ThreadUtils.getBackgroundHandler()) {
private boolean mInReadingList;
return true;
}
@Override
public void onPreExecute() {
mInReadingList = mAwesomeTabs.isInReadingList();
}
if (itemId == R.id.edit_bookmark) {
new EditBookmarkDialog(this).show(id, title, url, keyword);
return true;
}
@Override
public Integer doInBackground(Void... params) {
BrowserDB.removeBookmark(getContentResolver(), id);
Integer count = mInReadingList ?
BrowserDB.getReadingListCount(getContentResolver()) : 0;
if (itemId == R.id.remove_bookmark) {
(new UiAsyncTask<Void, Void, Integer>(ThreadUtils.getBackgroundHandler()) {
private boolean mInReadingList;
return count;
}
@Override
public void onPostExecute(Integer aCount) {
int messageId = R.string.bookmark_removed;
if (mInReadingList) {
messageId = R.string.reading_list_removed;
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", url);
GeckoAppShell.sendEventToGecko(e);
// Delete from Awesomebar context menu can alter reading list bookmark count
e = GeckoEvent.createBroadcastEvent("Reader:ListCountUpdated", Integer.toString(aCount));
GeckoAppShell.sendEventToGecko(e);
}
Toast.makeText(AwesomeBar.this, messageId, Toast.LENGTH_SHORT).show();
}
}).execute();
break;
}
case R.id.remove_history: {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
BrowserDB.removeHistoryEntry(getContentResolver(), id);
return null;
}
@Override
public void onPostExecute(Void result) {
Toast.makeText(AwesomeBar.this, R.string.history_removed, Toast.LENGTH_SHORT).show();
}
}).execute();
break;
}
case R.id.add_to_launcher: {
if (url == null) {
Log.e(LOGTAG, "Can't add to home screen because URL is null");
break;
@Override
public void onPreExecute() {
mInReadingList = mAwesomeTabs.isInReadingList();
}
@Override
public Integer doInBackground(Void... params) {
BrowserDB.removeBookmark(getContentResolver(), id);
Integer count = mInReadingList ?
BrowserDB.getReadingListCount(getContentResolver()) : 0;
return count;
}
@Override
public void onPostExecute(Integer aCount) {
int messageId = R.string.bookmark_removed;
if (mInReadingList) {
messageId = R.string.reading_list_removed;
GeckoEvent e = GeckoEvent.createBroadcastEvent("Reader:Remove", url);
GeckoAppShell.sendEventToGecko(e);
// Delete from Awesomebar context menu can alter reading list bookmark count
e = GeckoEvent.createBroadcastEvent("Reader:ListCountUpdated", Integer.toString(aCount));
GeckoAppShell.sendEventToGecko(e);
}
Toast.makeText(AwesomeBar.this, messageId, Toast.LENGTH_SHORT).show();
}
}).execute();
return true;
}
if (itemId == R.id.remove_history) {
(new UiAsyncTask<Void, Void, Void>(ThreadUtils.getBackgroundHandler()) {
@Override
public Void doInBackground(Void... params) {
BrowserDB.removeHistoryEntry(getContentResolver(), id);
return null;
}
@Override
public void onPostExecute(Void result) {
Toast.makeText(AwesomeBar.this, R.string.history_removed, Toast.LENGTH_SHORT).show();
}
}).execute();
return true;
}
if (itemId == R.id.add_to_launcher) {
if (url == null) {
Log.e(LOGTAG, "Can't add to home screen because URL is null");
} else {
Bitmap bitmap = null;
if (b != null) {
bitmap = BitmapUtils.decodeByteArray(b);
@ -619,23 +622,23 @@ public class AwesomeBar extends GeckoActivity
String shortcutTitle = TextUtils.isEmpty(title) ? url.replaceAll("^([a-z]+://)?(www\\.)?", "") : title;
GeckoAppShell.createShortcut(shortcutTitle, url, bitmap, "");
break;
}
case R.id.share: {
if (url == null) {
Log.e(LOGTAG, "Can't share because URL is null");
break;
}
return true;
}
if (itemId == R.id.share) {
if (url == null) {
Log.e(LOGTAG, "Can't share because URL is null");
} else {
GeckoAppShell.openUriExternal(url, "text/plain", "", "",
Intent.ACTION_SEND, title);
break;
}
default: {
return super.onContextItemSelected(item);
}
return true;
}
return true;
return super.onContextItemSelected(item);
}
public static String getReaderForUrl(String url) {

View File

@ -614,73 +614,79 @@ abstract public class BrowserApp extends GeckoApp
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.pasteandgo: {
String text = Clipboard.getText();
if (!TextUtils.isEmpty(text)) {
Tabs.getInstance().loadUrl(text);
}
return true;
}
case R.id.site_settings: {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null));
return true;
}
case R.id.paste: {
String text = Clipboard.getText();
if (!TextUtils.isEmpty(text)) {
showAwesomebar(AwesomeBar.Target.CURRENT_TAB, text);
}
return true;
}
case R.id.share: {
shareCurrentUrl();
return true;
}
case R.id.subscribe: {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null && tab.getFeedsEnabled()) {
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;
}
case R.id.copyurl: {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
String url = tab.getURL();
if (url != null) {
Clipboard.setText(url);
}
}
return true;
}
case R.id.add_to_launcher: {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
final String url = tab.getURL();
final String title = tab.getDisplayTitle();
if (url == null || title == null) {
return true;
}
Favicons favicons = Favicons.getInstance();
favicons.loadFavicon(url, tab.getFaviconURL(), 0,
new Favicons.OnFaviconLoadedListener() {
@Override
public void onFaviconLoaded(String url, Bitmap favicon) {
GeckoAppShell.createShortcut(title, url, url, favicon == null ? null : favicon, "");
}
});
}
return true;
final int itemId = item.getItemId();
if (itemId == R.id.pasteandgo) {
String text = Clipboard.getText();
if (!TextUtils.isEmpty(text)) {
Tabs.getInstance().loadUrl(text);
}
return true;
}
if (itemId == R.id.site_settings) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null));
return true;
}
if (itemId == R.id.paste) {
String text = Clipboard.getText();
if (!TextUtils.isEmpty(text)) {
showAwesomebar(AwesomeBar.Target.CURRENT_TAB, text);
}
return true;
}
if (itemId == R.id.share) {
shareCurrentUrl();
return true;
}
if (itemId == R.id.subscribe) {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null && tab.getFeedsEnabled()) {
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;
}
if (itemId == R.id.copyurl) {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
String url = tab.getURL();
if (url != null) {
Clipboard.setText(url);
}
}
return true;
}
if (itemId == R.id.add_to_launcher) {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
final String url = tab.getURL();
final String title = tab.getDisplayTitle();
if (url == null || title == null) {
return true;
}
Favicons favicons = Favicons.getInstance();
favicons.loadFavicon(url, tab.getFaviconURL(), 0,
new Favicons.OnFaviconLoadedListener() {
@Override
public void onFaviconLoaded(String url, Bitmap favicon) {
GeckoAppShell.createShortcut(title, url, url, favicon == null ? null : favicon, "");
}
});
}
return true;
}
return false;
}
@ -1719,96 +1725,128 @@ abstract public class BrowserApp extends GeckoApp
public boolean onOptionsItemSelected(MenuItem item) {
Tab tab = null;
Intent intent = null;
switch (item.getItemId()) {
case R.id.bookmark:
tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
if (item.isChecked()) {
tab.removeBookmark();
Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
item.setIcon(R.drawable.ic_menu_bookmark_add);
} else {
tab.addBookmark();
mToast.show(false,
getResources().getString(R.string.bookmark_added),
getResources().getString(R.string.bookmark_options),
null,
new ButtonToast.ToastListener() {
@Override
public void onButtonClicked() {
showBookmarkDialog();
}
@Override
public void onToastHidden(ButtonToast.ReasonHidden reason) { }
});
item.setIcon(R.drawable.ic_menu_bookmark_remove);
}
final int itemId = item.getItemId();
if (itemId == R.id.bookmark) {
tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
if (item.isChecked()) {
tab.removeBookmark();
Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
item.setIcon(R.drawable.ic_menu_bookmark_add);
} else {
tab.addBookmark();
mToast.show(false,
getResources().getString(R.string.bookmark_added),
getResources().getString(R.string.bookmark_options),
null,
new ButtonToast.ToastListener() {
@Override
public void onButtonClicked() {
showBookmarkDialog();
}
@Override
public void onToastHidden(ButtonToast.ReasonHidden reason) { }
});
item.setIcon(R.drawable.ic_menu_bookmark_remove);
}
return true;
case R.id.share:
shareCurrentUrl();
return true;
case R.id.reload:
tab = Tabs.getInstance().getSelectedTab();
if (tab != null)
tab.doReload();
return true;
case R.id.forward:
tab = Tabs.getInstance().getSelectedTab();
if (tab != null)
tab.doForward();
return true;
case R.id.save_as_pdf:
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
return true;
case R.id.settings:
intent = new Intent(this, GeckoPreferences.class);
startActivity(intent);
return true;
case R.id.addons:
Tabs.getInstance().loadUrlInTab("about:addons");
return true;
case R.id.downloads:
Tabs.getInstance().loadUrlInTab("about:downloads");
return true;
case R.id.apps:
Tabs.getInstance().loadUrlInTab("about:apps");
return true;
case R.id.char_encoding:
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
return true;
case R.id.find_in_page:
mFindInPageBar.show();
return true;
case R.id.desktop_mode:
Tab selectedTab = Tabs.getInstance().getSelectedTab();
if (selectedTab == null)
return true;
JSONObject args = new JSONObject();
try {
args.put("desktopMode", !item.isChecked());
args.put("tabId", selectedTab.getId());
} catch (JSONException e) {
Log.e(LOGTAG, "error building json arguments");
}
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
return true;
case R.id.new_tab:
addTab();
return true;
case R.id.new_private_tab:
addPrivateTab();
return true;
case R.id.new_guest_session:
showGuestModeDialog(GuestModeDialog.ENTERING);
return true;
case R.id.exit_guest_session:
showGuestModeDialog(GuestModeDialog.LEAVING);
return true;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
if (itemId == R.id.share) {
shareCurrentUrl();
return true;
}
if (itemId == R.id.reload) {
tab = Tabs.getInstance().getSelectedTab();
if (tab != null)
tab.doReload();
return true;
}
if (itemId == R.id.forward) {
tab = Tabs.getInstance().getSelectedTab();
if (tab != null)
tab.doForward();
return true;
}
if (itemId == R.id.save_as_pdf) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
return true;
}
if (itemId == R.id.settings) {
intent = new Intent(this, GeckoPreferences.class);
startActivity(intent);
return true;
}
if (itemId == R.id.addons) {
Tabs.getInstance().loadUrlInTab("about:addons");
return true;
}
if (itemId == R.id.downloads) {
Tabs.getInstance().loadUrlInTab("about:downloads");
return true;
}
if (itemId == R.id.apps) {
Tabs.getInstance().loadUrlInTab("about:apps");
return true;
}
if (itemId == R.id.char_encoding) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
return true;
}
if (itemId == R.id.find_in_page) {
mFindInPageBar.show();
return true;
}
if (itemId == R.id.desktop_mode) {
Tab selectedTab = Tabs.getInstance().getSelectedTab();
if (selectedTab == null)
return true;
JSONObject args = new JSONObject();
try {
args.put("desktopMode", !item.isChecked());
args.put("tabId", selectedTab.getId());
} catch (JSONException e) {
Log.e(LOGTAG, "error building json arguments");
}
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
return true;
}
if (itemId == R.id.new_tab) {
addTab();
return true;
}
if (itemId == R.id.new_private_tab) {
addPrivateTab();
return true;
}
if (itemId == R.id.new_guest_session) {
showGuestModeDialog(GuestModeDialog.ENTERING);
return true;
}
if (itemId == R.id.exit_guest_session) {
showGuestModeDialog(GuestModeDialog.LEAVING);
return true;
}
return super.onOptionsItemSelected(item);
}
private void showGuestModeDialog(final GuestModeDialog type) {

View File

@ -109,18 +109,22 @@ public class FindInPageBar extends LinearLayout implements TextWatcher, View.OnC
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.find_prev:
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FindInPage:Prev", mFindText.getText().toString()));
getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
break;
case R.id.find_next:
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FindInPage:Next", mFindText.getText().toString()));
getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
break;
case R.id.find_close:
hide();
break;
final int viewId = v.getId();
if (viewId == R.id.find_prev) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FindInPage:Prev", mFindText.getText().toString()));
getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
return;
}
if (viewId == R.id.find_next) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FindInPage:Next", mFindText.getText().toString()));
getInputMethodManager(mFindText).hideSoftInputFromWindow(mFindText.getWindowToken(), 0);
return;
}
if (viewId == R.id.find_close) {
hide();
}
}

View File

@ -452,17 +452,16 @@ abstract public class GeckoApp
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.quit:
if (GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.GeckoRunning, GeckoThread.LaunchState.GeckoExiting)) {
GeckoAppShell.notifyGeckoOfEvent(GeckoEvent.createBroadcastEvent("Browser:Quit", null));
} else {
System.exit(0);
}
return true;
default:
return super.onOptionsItemSelected(item);
if (item.getItemId() == R.id.quit) {
if (GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.GeckoRunning, GeckoThread.LaunchState.GeckoExiting)) {
GeckoAppShell.notifyGeckoOfEvent(GeckoEvent.createBroadcastEvent("Browser:Quit", null));
} else {
System.exit(0);
}
return true;
}
return super.onOptionsItemSelected(item);
}
@Override

View File

@ -1379,7 +1379,7 @@ all_resources = \
$(NULL)
R.java: $(all_resources)
$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -J . --custom-package org.mozilla.gecko
$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -J . --custom-package org.mozilla.gecko --non-constant-id
gecko.ap_: $(all_resources)
$(AAPT) package -f -M AndroidManifest.xml -I $(ANDROID_SDK)/android.jar -S res -F $@

View File

@ -189,28 +189,33 @@ public class AboutHome extends Fragment {
return true;
}
switch (item.getItemId()) {
case R.id.abouthome_open_new_tab:
mTopSitesView.openNewTab(info);
return true;
case R.id.abouthome_open_private_tab:
mTopSitesView.openNewPrivateTab(info);
return true;
case R.id.abouthome_topsites_edit:
mTopSitesView.editSite(info);
return true;
case R.id.abouthome_topsites_unpin:
mTopSitesView.unpinSite(info, TopSitesView.UnpinFlags.REMOVE_PIN);
return true;
case R.id.abouthome_topsites_pin:
mTopSitesView.pinSite(info);
return true;
final int itemId = item.getItemId();
if (itemId == R.id.abouthome_open_new_tab) {
mTopSitesView.openNewTab(info);
return true;
}
if (itemId == R.id.abouthome_open_private_tab) {
mTopSitesView.openNewPrivateTab(info);
return true;
}
if (itemId == R.id.abouthome_topsites_edit) {
mTopSitesView.editSite(info);
return true;
}
if (itemId == R.id.abouthome_topsites_unpin) {
mTopSitesView.unpinSite(info, TopSitesView.UnpinFlags.REMOVE_PIN);
return true;
}
if (itemId == R.id.abouthome_topsites_pin) {
mTopSitesView.pinSite(info);
return true;
}
return super.onContextItemSelected(item);
}