Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 36c84403 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Fix issue #3362484: Can't dismiss activity picker by tapping outside dialog" into honeycomb

parents f4368c95 cfaf8878
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -10894,6 +10894,17 @@
 visibility="public"
>
</field>
<field name="windowCloseOnTouchOutside"
 type="int"
 transient="false"
 volatile="false"
 value="16843611"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="windowContentOverlay"
 type="int"
 transient="false"
@@ -24300,6 +24311,19 @@
<parameter name="uri" type="android.net.Uri">
</parameter>
</method>
<method name="setFinishOnTouchOutside"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="finish" type="boolean">
</parameter>
</method>
<method name="setIntent"
 return="void"
 abstract="false"
+13 −0
Original line number Diff line number Diff line
@@ -1807,6 +1807,14 @@ public class Activity extends ContextThemeWrapper
        initActionBar();
    }

    /**
     * Sets whether this activity is finished when touched outside its window's
     * bounds.
     */
    public void setFinishOnTouchOutside(boolean finish) {
        mWindow.setCloseOnTouchOutside(finish);
    }
    
    /**
     * Use with {@link #setDefaultKeyMode} to turn off default handling of
     * keys.
@@ -2063,6 +2071,11 @@ public class Activity extends ContextThemeWrapper
     * The default implementation always returns false.
     */
    public boolean onTouchEvent(MotionEvent event) {
        if (mWindow.shouldCloseOnTouch(this, event)) {
            finish();
            return true;
        }
        
        return false;
    }
    
+2 −19
Original line number Diff line number Diff line
@@ -64,11 +64,13 @@ public class AlertDialog extends Dialog implements DialogInterface {

    protected AlertDialog(Context context, int theme) {
        super(context, theme == 0 ? getDefaultDialogTheme(context) : theme);
        mWindow.alwaysReadCloseOnTouchAttr();
        mAlert = new AlertController(context, this, getWindow());
    }

    protected AlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, getDefaultDialogTheme(context));
        mWindow.alwaysReadCloseOnTouchAttr();
        setCancelable(cancelable);
        setOnCancelListener(cancelListener);
        mAlert = new AlertController(context, this, getWindow());
@@ -81,25 +83,6 @@ public class AlertDialog extends Dialog implements DialogInterface {
        return outValue.resourceId;
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (mCancelable) {
            final View decor = mWindow.getDecorView();
            final int width = decor.getWidth();
            final int height = decor.getHeight();
            final float x = ev.getX();
            final float y = ev.getY();

            if (mCancelable && (x < 0 || x > width || y < 0 || y > height)
                    &&  mDecor != null && isShowing()) {
                cancel();
                return true;
            }
        }

        return super.onTouchEvent(ev);
    }

    /**
     * Gets one of the buttons used in the dialog.
     * <p>
+2 −20
Original line number Diff line number Diff line
@@ -41,7 +41,6 @@ import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnCreateContextMenuListener;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
@@ -90,12 +89,6 @@ public class Dialog implements DialogInterface, Window.Callback,
    private Message mDismissMessage;
    private Message mShowMessage;

    /**
     * Whether to cancel the dialog when a touch is received outside of the
     * window's bounds.
     */
    private boolean mCanceledOnTouchOutside = false;
    
    private OnKeyListener mOnKeyListener;

    private boolean mCreated = false;
@@ -597,8 +590,7 @@ public class Dialog implements DialogInterface, Window.Callback,
     *         happens outside of the window bounds.
     */
    public boolean onTouchEvent(MotionEvent event) {
        if (mCancelable && mCanceledOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
                && isOutOfBounds(event) && mDecor != null && mShowing) {
        if (mCancelable && mShowing && mWindow.shouldCloseOnTouch(mContext, event)) {
            cancel();
            return true;
        }
@@ -606,16 +598,6 @@ public class Dialog implements DialogInterface, Window.Callback,
        return false;
    }

    private boolean isOutOfBounds(MotionEvent event) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        final int slop = ViewConfiguration.get(mContext).getScaledWindowTouchSlop();
        final View decorView = getWindow().getDecorView();
        return (x < -slop) || (y < -slop)
                || (x > (decorView.getWidth()+slop))
                || (y > (decorView.getHeight()+slop));
    }
    
    /**
     * Called when the trackball was moved and not handled by any of the
     * views inside of the activity.  So, for example, if the trackball moves
@@ -1021,7 +1003,7 @@ public class Dialog implements DialogInterface, Window.Callback,
            mCancelable = true;
        }
        
        mCanceledOnTouchOutside = cancel;
        mWindow.setCloseOnTouchOutside(cancel);
    }
    
    /**
+35 −0
Original line number Diff line number Diff line
@@ -116,6 +116,8 @@ public abstract class Window {
    private Window mActiveChild;
    private boolean mIsActive = false;
    private boolean mHasChildren = false;
    private boolean mCloseOnTouchOutside = false;
    private boolean mSetCloseOnTouchOutside = false;
    private int mForcedWindowFlags = 0;

    private int mFeatures = DEFAULT_FEATURES;
@@ -786,6 +788,39 @@ public abstract class Window {
        return mHasSoftInputMode;
    }
    
    /** @hide */
    public void setCloseOnTouchOutside(boolean close) {
        mCloseOnTouchOutside = close;
        mSetCloseOnTouchOutside = true;
    }
    
    /** @hide */
    public boolean hasSetCloseOnTouchOutside() {
        return mSetCloseOnTouchOutside;
    }
    
    /** @hide */
    public abstract void alwaysReadCloseOnTouchAttr();
    
    /** @hide */
    public boolean shouldCloseOnTouch(Context context, MotionEvent event) {
        if (mCloseOnTouchOutside && event.getAction() == MotionEvent.ACTION_DOWN
                && isOutOfBounds(context, event) && peekDecorView() != null) {
            return true;
        }
        return false;
    }
    
    private boolean isOutOfBounds(Context context, MotionEvent event) {
        final int x = (int) event.getX();
        final int y = (int) event.getY();
        final int slop = ViewConfiguration.get(context).getScaledWindowTouchSlop();
        final View decorView = getDecorView();
        return (x < -slop) || (y < -slop)
                || (x > (decorView.getWidth()+slop))
                || (y > (decorView.getHeight()+slop));
    }
    
    /**
     * Enable extended screen features.  This must be called before
     * setContentView().  May be called as many times as desired as long as it
Loading