Bug 884075 - Include a reason when hiding a toast. r=margaret

This commit is contained in:
Wes Johnston 2013-07-16 01:33:06 -07:00
parent 065d61ecdc
commit afd90691f6
2 changed files with 18 additions and 5 deletions

View File

@ -1686,6 +1686,9 @@ abstract public class BrowserApp extends GeckoApp
public void onButtonClicked() {
showBookmarkDialog();
}
@Override
public void onToastHidden(ButtonToast.ReasonHidden reason) { }
});
item.setIcon(R.drawable.ic_menu_bookmark_remove);
}

View File

@ -47,6 +47,12 @@ public class ButtonToast {
private final LinkedList<Toast> mQueue = new LinkedList<Toast>();
private Toast mCurrentToast;
public enum ReasonHidden {
CLICKED,
TIMEOUT,
STARTUP
}
// State objects
private static class Toast {
public final CharSequence buttonMessage;
@ -65,6 +71,7 @@ public class ButtonToast {
public interface ToastListener {
void onButtonClicked();
void onToastHidden(ReasonHidden reason);
}
public ButtonToast(View view) {
@ -79,14 +86,14 @@ public class ButtonToast {
if (t == null)
return;
hide(false);
hide(false, ReasonHidden.CLICKED);
if (t.listener != null) {
t.listener.onButtonClicked();
}
}
});
hide(true);
hide(true, ReasonHidden.STARTUP);
}
public void show(boolean immediate, CharSequence message,
@ -123,12 +130,15 @@ public class ButtonToast {
mView.startAnimation(alpha);
}
public void hide(boolean immediate) {
if (mButton.isPressed()) {
public void hide(boolean immediate, ReasonHidden reason) {
if (mButton.isPressed() && reason != ReasonHidden.CLICKED) {
mHideHandler.postDelayed(mHideRunnable, TOAST_DURATION);
return;
}
if (mCurrentToast != null && mCurrentToast.listener != null) {
mCurrentToast.listener.onToastHidden(reason);
}
mCurrentToast = null;
mButton.setEnabled(false);
mHideHandler.removeCallbacks(mHideRunnable);
@ -173,7 +183,7 @@ public class ButtonToast {
private Runnable mHideRunnable = new Runnable() {
@Override
public void run() {
hide(false);
hide(false, ReasonHidden.TIMEOUT);
}
};
}