Loading core/java/android/app/Dialog.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -200,6 +200,7 @@ public class Dialog implements DialogInterface, Window.Callback, @Nullable Message cancelCallback) { @Nullable Message cancelCallback) { this(context); this(context); mCancelable = cancelable; mCancelable = cancelable; updateWindowForCancelable(); mCancelMessage = cancelCallback; mCancelMessage = cancelCallback; } } Loading @@ -207,6 +208,7 @@ public class Dialog implements DialogInterface, Window.Callback, @Nullable OnCancelListener cancelListener) { @Nullable OnCancelListener cancelListener) { this(context); this(context); mCancelable = cancelable; mCancelable = cancelable; updateWindowForCancelable(); setOnCancelListener(cancelListener); setOnCancelListener(cancelListener); } } Loading Loading @@ -1187,6 +1189,7 @@ public class Dialog implements DialogInterface, Window.Callback, */ */ public void setCancelable(boolean flag) { public void setCancelable(boolean flag) { mCancelable = flag; mCancelable = flag; updateWindowForCancelable(); } } /** /** Loading @@ -1200,6 +1203,7 @@ public class Dialog implements DialogInterface, Window.Callback, public void setCanceledOnTouchOutside(boolean cancel) { public void setCanceledOnTouchOutside(boolean cancel) { if (cancel && !mCancelable) { if (cancel && !mCancelable) { mCancelable = true; mCancelable = true; updateWindowForCancelable(); } } mWindow.setCloseOnTouchOutside(cancel); mWindow.setCloseOnTouchOutside(cancel); Loading Loading @@ -1351,4 +1355,8 @@ public class Dialog implements DialogInterface, Window.Callback, } } } } } } private void updateWindowForCancelable() { mWindow.setCloseOnSwipeEnabled(mCancelable); } } } core/java/android/view/Window.java +18 −0 Original line number Original line Diff line number Diff line Loading @@ -301,6 +301,7 @@ public abstract class Window { private boolean mDestroyed; private boolean mDestroyed; private boolean mOverlayWithDecorCaptionEnabled = false; private boolean mOverlayWithDecorCaptionEnabled = false; private boolean mCloseOnSwipeEnabled = false; // The current window attributes. // The current window attributes. private final WindowManager.LayoutParams mWindowAttributes = private final WindowManager.LayoutParams mWindowAttributes = Loading Loading @@ -2209,4 +2210,21 @@ public abstract class Window { * @hide * @hide */ */ public abstract void reportActivityRelaunched(); 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; } } } core/java/com/android/internal/policy/PhoneWindow.java +18 −4 Original line number Original line Diff line number Diff line Loading @@ -2502,6 +2502,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // System.out.println("Features: 0x" + Integer.toHexString(features)); // System.out.println("Features: 0x" + Integer.toHexString(features)); if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { layoutResource = R.layout.screen_swipe_dismiss; layoutResource = R.layout.screen_swipe_dismiss; setCloseOnSwipeEnabled(true); } else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) { } else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) { if (mIsFloating) { if (mIsFloating) { TypedValue res = new TypedValue(); TypedValue res = new TypedValue(); Loading Loading @@ -2573,7 +2574,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } } if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { registerSwipeCallbacks(); registerSwipeCallbacks(contentParent); } } // Remaining setup -- of background and title -- that only applies // Remaining setup -- of background and title -- that only applies Loading Loading @@ -2987,9 +2988,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { return (mRightIconView = (ImageView)findViewById(R.id.right_icon)); return (mRightIconView = (ImageView)findViewById(R.id.right_icon)); } } private void registerSwipeCallbacks() { private void registerSwipeCallbacks(ViewGroup contentParent) { SwipeDismissLayout swipeDismiss = if (!(contentParent instanceof SwipeDismissLayout)) { (SwipeDismissLayout) findViewById(R.id.content); Log.w(TAG, "contentParent is not a SwipeDismissLayout: " + contentParent); return; } SwipeDismissLayout swipeDismiss = (SwipeDismissLayout) contentParent; swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() { swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() { @Override @Override public void onDismissed(SwipeDismissLayout layout) { public void onDismissed(SwipeDismissLayout layout) { Loading Loading @@ -3028,6 +3032,16 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { }); }); } } /** @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)} * Helper method for calling the {@link Callback#onPanelClosed(int, Menu)} * callback. This method will grab whatever extra state is needed for the * callback. This method will grab whatever extra state is needed for the Loading core/java/com/android/internal/widget/SwipeDismissLayout.java +16 −1 Original line number Original line Diff line number Diff line Loading @@ -110,6 +110,8 @@ public class SwipeDismissLayout extends FrameLayout { private float mLastX; private float mLastX; private boolean mDismissable = true; public SwipeDismissLayout(Context context) { public SwipeDismissLayout(Context context) { super(context); super(context); init(context); init(context); Loading Loading @@ -166,6 +168,10 @@ public class SwipeDismissLayout extends FrameLayout { @Override @Override public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mDismissable) { return super.onInterceptTouchEvent(ev); } // offset because the view is translated during swipe // offset because the view is translated during swipe ev.offsetLocation(mTranslationX, 0); ev.offsetLocation(mTranslationX, 0); Loading Loading @@ -225,7 +231,7 @@ public class SwipeDismissLayout extends FrameLayout { @Override @Override public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) { if (mVelocityTracker == null) { if (mVelocityTracker == null || !mDismissable) { return super.onTouchEvent(ev); return super.onTouchEvent(ev); } } // offset because the view is translated during swipe // offset because the view is translated during swipe Loading Loading @@ -363,4 +369,13 @@ public class SwipeDismissLayout extends FrameLayout { return checkV && v.canScrollHorizontally((int) -dx); return checkV && v.canScrollHorizontally((int) -dx); } } public void setDismissable(boolean dismissable) { if (!dismissable && mDismissable) { cancel(); resetMembers(); } mDismissable = dismissable; } } } Loading
core/java/android/app/Dialog.java +8 −0 Original line number Original line Diff line number Diff line Loading @@ -200,6 +200,7 @@ public class Dialog implements DialogInterface, Window.Callback, @Nullable Message cancelCallback) { @Nullable Message cancelCallback) { this(context); this(context); mCancelable = cancelable; mCancelable = cancelable; updateWindowForCancelable(); mCancelMessage = cancelCallback; mCancelMessage = cancelCallback; } } Loading @@ -207,6 +208,7 @@ public class Dialog implements DialogInterface, Window.Callback, @Nullable OnCancelListener cancelListener) { @Nullable OnCancelListener cancelListener) { this(context); this(context); mCancelable = cancelable; mCancelable = cancelable; updateWindowForCancelable(); setOnCancelListener(cancelListener); setOnCancelListener(cancelListener); } } Loading Loading @@ -1187,6 +1189,7 @@ public class Dialog implements DialogInterface, Window.Callback, */ */ public void setCancelable(boolean flag) { public void setCancelable(boolean flag) { mCancelable = flag; mCancelable = flag; updateWindowForCancelable(); } } /** /** Loading @@ -1200,6 +1203,7 @@ public class Dialog implements DialogInterface, Window.Callback, public void setCanceledOnTouchOutside(boolean cancel) { public void setCanceledOnTouchOutside(boolean cancel) { if (cancel && !mCancelable) { if (cancel && !mCancelable) { mCancelable = true; mCancelable = true; updateWindowForCancelable(); } } mWindow.setCloseOnTouchOutside(cancel); mWindow.setCloseOnTouchOutside(cancel); Loading Loading @@ -1351,4 +1355,8 @@ public class Dialog implements DialogInterface, Window.Callback, } } } } } } private void updateWindowForCancelable() { mWindow.setCloseOnSwipeEnabled(mCancelable); } } }
core/java/android/view/Window.java +18 −0 Original line number Original line Diff line number Diff line Loading @@ -301,6 +301,7 @@ public abstract class Window { private boolean mDestroyed; private boolean mDestroyed; private boolean mOverlayWithDecorCaptionEnabled = false; private boolean mOverlayWithDecorCaptionEnabled = false; private boolean mCloseOnSwipeEnabled = false; // The current window attributes. // The current window attributes. private final WindowManager.LayoutParams mWindowAttributes = private final WindowManager.LayoutParams mWindowAttributes = Loading Loading @@ -2209,4 +2210,21 @@ public abstract class Window { * @hide * @hide */ */ public abstract void reportActivityRelaunched(); 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; } } }
core/java/com/android/internal/policy/PhoneWindow.java +18 −4 Original line number Original line Diff line number Diff line Loading @@ -2502,6 +2502,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { // System.out.println("Features: 0x" + Integer.toHexString(features)); // System.out.println("Features: 0x" + Integer.toHexString(features)); if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { layoutResource = R.layout.screen_swipe_dismiss; layoutResource = R.layout.screen_swipe_dismiss; setCloseOnSwipeEnabled(true); } else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) { } else if ((features & ((1 << FEATURE_LEFT_ICON) | (1 << FEATURE_RIGHT_ICON))) != 0) { if (mIsFloating) { if (mIsFloating) { TypedValue res = new TypedValue(); TypedValue res = new TypedValue(); Loading Loading @@ -2573,7 +2574,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { } } if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { if ((features & (1 << FEATURE_SWIPE_TO_DISMISS)) != 0) { registerSwipeCallbacks(); registerSwipeCallbacks(contentParent); } } // Remaining setup -- of background and title -- that only applies // Remaining setup -- of background and title -- that only applies Loading Loading @@ -2987,9 +2988,12 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { return (mRightIconView = (ImageView)findViewById(R.id.right_icon)); return (mRightIconView = (ImageView)findViewById(R.id.right_icon)); } } private void registerSwipeCallbacks() { private void registerSwipeCallbacks(ViewGroup contentParent) { SwipeDismissLayout swipeDismiss = if (!(contentParent instanceof SwipeDismissLayout)) { (SwipeDismissLayout) findViewById(R.id.content); Log.w(TAG, "contentParent is not a SwipeDismissLayout: " + contentParent); return; } SwipeDismissLayout swipeDismiss = (SwipeDismissLayout) contentParent; swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() { swipeDismiss.setOnDismissedListener(new SwipeDismissLayout.OnDismissedListener() { @Override @Override public void onDismissed(SwipeDismissLayout layout) { public void onDismissed(SwipeDismissLayout layout) { Loading Loading @@ -3028,6 +3032,16 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback { }); }); } } /** @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)} * Helper method for calling the {@link Callback#onPanelClosed(int, Menu)} * callback. This method will grab whatever extra state is needed for the * callback. This method will grab whatever extra state is needed for the Loading
core/java/com/android/internal/widget/SwipeDismissLayout.java +16 −1 Original line number Original line Diff line number Diff line Loading @@ -110,6 +110,8 @@ public class SwipeDismissLayout extends FrameLayout { private float mLastX; private float mLastX; private boolean mDismissable = true; public SwipeDismissLayout(Context context) { public SwipeDismissLayout(Context context) { super(context); super(context); init(context); init(context); Loading Loading @@ -166,6 +168,10 @@ public class SwipeDismissLayout extends FrameLayout { @Override @Override public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) { if (!mDismissable) { return super.onInterceptTouchEvent(ev); } // offset because the view is translated during swipe // offset because the view is translated during swipe ev.offsetLocation(mTranslationX, 0); ev.offsetLocation(mTranslationX, 0); Loading Loading @@ -225,7 +231,7 @@ public class SwipeDismissLayout extends FrameLayout { @Override @Override public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent ev) { if (mVelocityTracker == null) { if (mVelocityTracker == null || !mDismissable) { return super.onTouchEvent(ev); return super.onTouchEvent(ev); } } // offset because the view is translated during swipe // offset because the view is translated during swipe Loading Loading @@ -363,4 +369,13 @@ public class SwipeDismissLayout extends FrameLayout { return checkV && v.canScrollHorizontally((int) -dx); return checkV && v.canScrollHorizontally((int) -dx); } } public void setDismissable(boolean dismissable) { if (!dismissable && mDismissable) { cancel(); resetMembers(); } mDismissable = dismissable; } } }