diff options
author | John Spurlock <jspurlock@google.com> | 2013-05-21 17:19:53 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2013-05-28 13:09:23 -0400 |
commit | dcf4f2146097eeae6991e6131e5ae96b33fbeda9 (patch) | |
tree | 65b4e52a12595dd7678a92ec91888ad52f70469e /core/java/android/widget | |
parent | dadfb9c9bfe17eb99a4891af0fe4eed7166f0b86 (diff) | |
download | frameworks_base-dcf4f2146097eeae6991e6131e5ae96b33fbeda9.zip frameworks_base-dcf4f2146097eeae6991e6131e5ae96b33fbeda9.tar.gz frameworks_base-dcf4f2146097eeae6991e6131e5ae96b33fbeda9.tar.bz2 |
Hideybars feature confirmation toast bar.
Enhance Toast to support new standard toast bar style, similar
to the undo bar in Gmail. Toast bars can be interactive,
and can have a single action. Add a new toast duration to
indicate persistent toasts (no auto-hide delay).
Use the new toast bar to implement a feature hint when hiding
the navigation bar in hideybars mode.
Per UX, the feature confirmation bar can also be dismissed on
any outside touch as long as the user confirmed it using the
OK button at least once globally.
Bug: 8754108
Change-Id: Iaa85d3b4da7ada1952a562f1e31de04380f5d587
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/Toast.java | 72 |
1 files changed, 69 insertions, 3 deletions
diff --git a/core/java/android/widget/Toast.java b/core/java/android/widget/Toast.java index 1d85126..aaa1adaa 100644 --- a/core/java/android/widget/Toast.java +++ b/core/java/android/widget/Toast.java @@ -29,6 +29,7 @@ import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnClickListener; import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; @@ -74,6 +75,9 @@ public class Toast { */ public static final int LENGTH_LONG = 1; + /** @hide */ + public static final int LENGTH_INFINITE = 2; + final Context mContext; final TN mTN; int mDuration; @@ -288,6 +292,61 @@ public class Toast { tv.setText(s); } + /** @hide */ + public static Toast makeBar(Context context, int resId, int duration) { + return makeBar(context, context.getResources().getText(resId), duration); + } + + /** @hide */ + public static Toast makeBar(Context context, CharSequence text, int duration) { + Toast result = new Toast(context); + + LayoutInflater inflate = (LayoutInflater) + context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); + View v = inflate.inflate(com.android.internal.R.layout.toast_bar, null); + ((TextView)v.findViewById(android.R.id.message)).setText(text); + v.findViewById(android.R.id.button1).setVisibility(View.GONE); + + result.mNextView = v; + result.mDuration = duration; + result.mTN.mParams.alpha = 0.9f; + result.mTN.mParams.windowAnimations = com.android.internal.R.style.Animation_ToastBar; + + return result; + } + + /** @hide */ + public Toast setAction(int resId, Runnable action) { + return setAction(mContext.getResources().getText(resId), action); + } + + /** @hide */ + public Toast setAction(CharSequence actionText, final Runnable action) { + if (mNextView != null) { + TextView text1 = (TextView)mNextView.findViewById(android.R.id.text1); + View button1 = mNextView.findViewById(android.R.id.button1); + if (text1 != null && button1 != null) { + text1.setText(actionText); + button1.setVisibility(View.VISIBLE); + button1.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (action != null) { + action.run(); + } + }}); + return setInteractive(true); + } + } + throw new RuntimeException("This Toast was not created with Toast.makeBar()"); + } + + /** @hide */ + public Toast setInteractive(boolean interactive) { + mTN.setInteractive(interactive); + return this; + } + // ======================================================================================= // All the gunk below is the interaction with the Notification Service, which handles // the proper ordering of these system-wide. @@ -340,13 +399,20 @@ public class Toast { final WindowManager.LayoutParams params = mParams; params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.width = WindowManager.LayoutParams.WRAP_CONTENT; - params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE - | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE - | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; params.format = PixelFormat.TRANSLUCENT; params.windowAnimations = com.android.internal.R.style.Animation_Toast; params.type = WindowManager.LayoutParams.TYPE_TOAST; params.setTitle("Toast"); + setInteractive(false); + } + + private void setInteractive(boolean interactive) { + mParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON + | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE + | (interactive + ? (WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL + | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH) + : WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); } /** |