зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1018417 - Add duration parameter to ButtonToast. r=margaret
This commit is contained in:
Родитель
55e086d99c
Коммит
7c0f5a892a
|
@ -2545,6 +2545,7 @@ public class BrowserApp extends GeckoApp
|
|||
tab.addBookmark();
|
||||
getButtonToast().show(false,
|
||||
getResources().getString(R.string.bookmark_added),
|
||||
ButtonToast.LENGTH_SHORT,
|
||||
getResources().getString(R.string.bookmark_options),
|
||||
null,
|
||||
new ButtonToast.ToastListener() {
|
||||
|
|
|
@ -605,14 +605,14 @@ public abstract class GeckoApp
|
|||
|
||||
} else if ("Toast:Show".equals(event)) {
|
||||
final String msg = message.getString("message");
|
||||
final String duration = message.getString("duration");
|
||||
final NativeJSObject button = message.optObject("button", null);
|
||||
if (button != null) {
|
||||
final String label = button.optString("label", "");
|
||||
final String icon = button.optString("icon", "");
|
||||
final String id = button.optString("id", "");
|
||||
showButtonToast(msg, label, icon, id);
|
||||
showButtonToast(msg, duration, label, icon, id);
|
||||
} else {
|
||||
final String duration = message.getString("duration");
|
||||
showNormalToast(msg, duration);
|
||||
}
|
||||
|
||||
|
@ -788,12 +788,14 @@ public abstract class GeckoApp
|
|||
return mToast;
|
||||
}
|
||||
|
||||
void showButtonToast(final String message, final String buttonText,
|
||||
final String buttonIcon, final String buttonId) {
|
||||
void showButtonToast(final String message, final String duration,
|
||||
final String buttonText, final String buttonIcon,
|
||||
final String buttonId) {
|
||||
BitmapUtils.getDrawable(GeckoApp.this, buttonIcon, new BitmapUtils.BitmapLoader() {
|
||||
@Override
|
||||
public void onBitmapFound(final Drawable d) {
|
||||
getButtonToast().show(false, message, buttonText, d, new ButtonToast.ToastListener() {
|
||||
final int toastDuration = duration.equals("long") ? ButtonToast.LENGTH_LONG : ButtonToast.LENGTH_SHORT;
|
||||
getButtonToast().show(false, message, toastDuration ,buttonText, d, new ButtonToast.ToastListener() {
|
||||
@Override
|
||||
public void onButtonClicked() {
|
||||
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Toast:Click", buttonId));
|
||||
|
|
|
@ -203,6 +203,7 @@ abstract class HomeFragment extends Fragment {
|
|||
final GeckoApp geckoApp = (GeckoApp) context;
|
||||
geckoApp.getButtonToast().show(false,
|
||||
message,
|
||||
ButtonToast.LENGTH_SHORT,
|
||||
buttonMessage,
|
||||
R.drawable.switch_button_icon,
|
||||
new ButtonToast.ToastListener() {
|
||||
|
|
|
@ -32,7 +32,8 @@ public class ButtonToast {
|
|||
@SuppressWarnings("unused")
|
||||
private final static String LOGTAG = "GeckoButtonToast";
|
||||
|
||||
private final static int TOAST_DURATION = 5000;
|
||||
public static int LENGTH_SHORT = 3000;
|
||||
public static int LENGTH_LONG = 5000;
|
||||
|
||||
private final View mView;
|
||||
private final TextView mMessageView;
|
||||
|
@ -53,11 +54,14 @@ public class ButtonToast {
|
|||
public final CharSequence buttonMessage;
|
||||
public Drawable buttonDrawable;
|
||||
public final CharSequence message;
|
||||
public final int duration;
|
||||
public ToastListener listener;
|
||||
|
||||
public Toast(CharSequence aMessage, CharSequence aButtonMessage,
|
||||
Drawable aDrawable, ToastListener aListener) {
|
||||
public Toast(CharSequence aMessage, int aDuration,
|
||||
CharSequence aButtonMessage, Drawable aDrawable,
|
||||
ToastListener aListener) {
|
||||
message = aMessage;
|
||||
duration = aDuration;
|
||||
buttonMessage = aButtonMessage;
|
||||
buttonDrawable = aDrawable;
|
||||
listener = aListener;
|
||||
|
@ -91,16 +95,16 @@ public class ButtonToast {
|
|||
}
|
||||
|
||||
public void show(boolean immediate, CharSequence message,
|
||||
CharSequence buttonMessage, int buttonDrawableId,
|
||||
ToastListener listener) {
|
||||
int duration, CharSequence buttonMessage,
|
||||
int buttonDrawableId, ToastListener listener) {
|
||||
final Drawable d = mView.getContext().getResources().getDrawable(buttonDrawableId);
|
||||
show(false, message, buttonMessage, d, listener);
|
||||
show(false, message, duration, buttonMessage, d, listener);
|
||||
}
|
||||
|
||||
public void show(boolean immediate, CharSequence message,
|
||||
CharSequence buttonMessage, Drawable buttonDrawable,
|
||||
ToastListener listener) {
|
||||
show(new Toast(message, buttonMessage, buttonDrawable, listener), immediate);
|
||||
int duration, CharSequence buttonMessage,
|
||||
Drawable buttonDrawable, ToastListener listener) {
|
||||
show(new Toast(message, duration, buttonMessage, buttonDrawable, listener), immediate);
|
||||
}
|
||||
|
||||
private void show(Toast t, boolean immediate) {
|
||||
|
@ -119,7 +123,7 @@ public class ButtonToast {
|
|||
mButton.setCompoundDrawablesWithIntrinsicBounds(t.buttonDrawable, null, null, null);
|
||||
|
||||
mHideHandler.removeCallbacks(mHideRunnable);
|
||||
mHideHandler.postDelayed(mHideRunnable, TOAST_DURATION);
|
||||
mHideHandler.postDelayed(mHideRunnable, t.duration);
|
||||
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
int duration = immediate ? 0 : mView.getResources().getInteger(android.R.integer.config_longAnimTime);
|
||||
|
|
Загрузка…
Ссылка в новой задаче