Bug 884075 - Make button toast listeners per toast. r=margaret

This commit is contained in:
Wes Johnston 2013-07-16 01:33:05 -07:00
parent 77c101e0ed
commit ced383f6b0
2 changed files with 21 additions and 22 deletions

View File

@ -395,14 +395,7 @@ abstract public class BrowserApp extends GeckoApp
mBrowserToolbar = (BrowserToolbar) findViewById(R.id.browser_toolbar);
mToast = new ButtonToast(findViewById(R.id.toast), new ButtonToast.ToastListener() {
@Override
public void onButtonClicked(CharSequence token) {
if (ADD_SHORTCUT_TOAST.equals(token)) {
showBookmarkDialog();
}
}
});
mToast = new ButtonToast(findViewById(R.id.toast));
((GeckoApp.MainLayout) mMainLayout).setTouchEventInterceptor(new HideTabsTouchListener());
((GeckoApp.MainLayout) mMainLayout).setMotionEventInterceptor(new MotionEventInterceptor() {
@ -1699,10 +1692,15 @@ abstract public class BrowserApp extends GeckoApp
} else {
tab.addBookmark();
mToast.show(false,
getResources().getString(R.string.bookmark_added),
getResources().getString(R.string.bookmark_options),
0,
ADD_SHORTCUT_TOAST);
getResources().getString(R.string.bookmark_added),
getResources().getString(R.string.bookmark_options),
0,
new ButtonToast.ToastListener() {
@Override
public void onButtonClicked() {
showBookmarkDialog();
}
});
item.setIcon(R.drawable.ic_menu_bookmark_remove);
}
}

View File

@ -50,23 +50,24 @@ public class ButtonToast {
public final CharSequence buttonMessage;
public final int buttonIcon;
public final CharSequence message;
public ToastListener listener;
public Toast(CharSequence aMessage, CharSequence aButtonMessage, int aIcon, CharSequence aToken) {
public Toast(CharSequence aMessage, CharSequence aButtonMessage, int aIcon, ToastListener aListener) {
message = aMessage;
buttonMessage = aButtonMessage;
buttonIcon = aIcon;
token = aToken;
listener = aListener;
token = "";
}
}
public interface ToastListener {
void onButtonClicked(CharSequence token);
void onButtonClicked();
}
public ButtonToast(View view, ToastListener listener) {
public ButtonToast(View view) {
mView = view;
mListener = listener;
mListener = null;
mMessageView = (TextView) mView.findViewById(R.id.toast_message);
mButton = (Button) mView.findViewById(R.id.toast_button);
mButton.setOnClickListener(new View.OnClickListener() {
@ -77,8 +78,8 @@ public class ButtonToast {
return;
hide(false);
if (mListener != null) {
mListener.onButtonClicked(t.token);
if (t.listener != null) {
t.listener.onButtonClicked();
}
}
});
@ -88,8 +89,8 @@ public class ButtonToast {
public void show(boolean immediate, CharSequence message,
CharSequence buttonMessage, int buttonIcon,
CharSequence token) {
Toast t = new Toast(message, buttonMessage, buttonIcon, token);
ToastListener listener) {
Toast t = new Toast(message, buttonMessage, buttonIcon, listener);
show(t, immediate);
}