@Nullable Message cancelCallback) {
this(context);
mCancelable = cancelable;
+ updateWindowForCancelable();
mCancelMessage = cancelCallback;
}
@Nullable OnCancelListener cancelListener) {
this(context);
mCancelable = cancelable;
+ updateWindowForCancelable();
setOnCancelListener(cancelListener);
}
*/
public void setCancelable(boolean flag) {
mCancelable = flag;
+ updateWindowForCancelable();
}
/**
public void setCanceledOnTouchOutside(boolean cancel) {
if (cancel && !mCancelable) {
mCancelable = true;
+ updateWindowForCancelable();
}
mWindow.setCloseOnTouchOutside(cancel);
}
}
}
+
+ private void updateWindowForCancelable() {
+ mWindow.setCloseOnSwipeEnabled(mCancelable);
+ }
}
private boolean mDestroyed;
private boolean mOverlayWithDecorCaptionEnabled = false;
+ private boolean mCloseOnSwipeEnabled = false;
// The current window attributes.
private final WindowManager.LayoutParams mWindowAttributes =
* @hide
*/
public abstract void reportActivityRelaunched();
+
+ /**
+ * Called to set flag to check if the close on swipe is enabled. This will only function if
+ * FEATURE_SWIPE_TO_DISMISS has been set.
+ * @hide
+ */
+ public void setCloseOnSwipeEnabled(boolean closeOnSwipeEnabled) {
+ mCloseOnSwipeEnabled = closeOnSwipeEnabled;
+ }
+
+ /**
+ * @return {@code true} if the close on swipe is enabled.
+ * @hide
+ */
+ public boolean isCloseOnSwipeEnabled() {
+ return mCloseOnSwipeEnabled;
+ }
}
// System.out.println("Features: 0x" + Integer.toHexString(features));
if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) {
layoutResource = R.layout.screen_swipe_dismiss;
+ setCloseOnSwipeEnabled(true);
} else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) {
if (mIsFloating) {
TypedValue res = new TypedValue();
}
if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) {
- registerSwipeCallbacks();
+ registerSwipeCallbacks(contentParent);
}
// Remaining setup -- of background and title -- that only applies
return (mRightIconView = (ImageView)findViewById(R.id.right_icon));
}
- private void registerSwipeCallbacks() {
- SwipeDismissLayout swipeDismiss =
- (SwipeDismissLayout) findViewById(R.id.content);
+ private void registerSwipeCallbacks(ViewGroup contentParent) {
+ if (!(contentParent instanceof SwipeDismissLayout)) {
+ Log.w(TAG, "contentParent is not a SwipeDismissLayout: " + contentParent);
+ return;
+ }
+ SwipeDismissLayout swipeDismiss = (SwipeDismissLayout) contentParent;
swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() {
@Override
public void onDismissed(SwipeDismissLayout layout) {
});
}
+ /** @hide */
+ @Override
+ public void setCloseOnSwipeEnabled(boolean closeOnSwipeEnabled) {
+ if (hasFeature(Window.FEATURE_SWIPE_TO_DISMISS) // swipe-to-dismiss feature is requested
+ && mContentParent instanceof SwipeDismissLayout) { // check casting mContentParent
+ ((SwipeDismissLayout) mContentParent).setDismissable(closeOnSwipeEnabled);
+ }
+ super.setCloseOnSwipeEnabled(closeOnSwipeEnabled);
+ }
+
/**
* Helper method for calling the {@link Callback#onPanelClosed(int, Menu)}
* callback. This method will grab whatever extra state is needed for the
private float mLastX;
+ private boolean mDismissable = true;
+
public SwipeDismissLayout(Context context) {
super(context);
init(context);
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
+ if (!mDismissable) {
+ return super.onInterceptTouchEvent(ev);
+ }
+
// offset because the view is translated during swipe
ev.offsetLocation(mTranslationX, 0);
@Override
public boolean onTouchEvent(MotionEvent ev) {
- if (mVelocityTracker == null) {
+ if (mVelocityTracker == null || !mDismissable) {
return super.onTouchEvent(ev);
}
// offset because the view is translated during swipe
return checkV && v.canScrollHorizontally((int) -dx);
}
+
+ public void setDismissable(boolean dismissable) {
+ if (!dismissable && mDismissable) {
+ cancel();
+ resetMembers();
+ }
+
+ mDismissable = dismissable;
+ }
}