Skip to content
This repository has been archived by the owner on Nov 18, 2017. It is now read-only.

Strange behavior when using layout_centerHorizontal #23

Open
Logerfo opened this issue Jul 3, 2016 · 5 comments
Open

Strange behavior when using layout_centerHorizontal #23

Logerfo opened this issue Jul 3, 2016 · 5 comments

Comments

@Logerfo
Copy link

Logerfo commented Jul 3, 2016

I've noticed the icon would not work if I set android:layout_centerHorizontal=true in the ShowHidePasswordEditText view, but I also observed that it would work (and apparently that's only way) if I swipe the icon from left to right.

PS: I'm using RelativeLayout, I don't know if this makes any difference.

Edit: I forgot to mention that I'm also using api 24.

@joshkendrick
Copy link

ive noticed the same thing. same issue described and same behavior with the swipe described. i can get it to work if i set the app:additionalTouchTargetSize sufficiently large (like 100dp), but im hesitant to do that because it seems hacky.

@joshkendrick
Copy link

i think something like this should fix it -- i think the problem stems from using getLeft() and getRight()

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ( event.getAction() == MotionEvent.ACTION_UP && mVisibilityDrawable != null ) {
        Rect bounds = mVisibilityDrawable.getBounds();

        float clickX = event.getX();
        float iconXStart = mIsRightToLeft ? getWidth() - getTotalPaddingLeft() : getWidth() - getTotalPaddingRight();

        //check if the touch is within bounds of mVisibilityDrawable icon
        if ( iconXStart <= clickX && clickX < iconXStart + bounds.width() ) {
            togglePasswordVisibility();

            //use this to prevent the keyboard from coming up
            event.setAction(MotionEvent.ACTION_CANCEL);
        }
    }

    return super.onTouchEvent(event);
}

@Logerfo
Copy link
Author

Logerfo commented Jul 15, 2016

@joshkendrick I don't understand how this would explain the swipe behavior

@joshkendrick
Copy link

my issue was that the icon wouldnt work at all if my layout was android:layout_centerHorizontal=true -- that's what the above seems to have fixed for me.

swipe doesnt seem to be fixed, but im betting the swipe behavior is due to to this being checked on MotionEvent.ACTION_UP, (and not entirely related to any centerHorizontal stuff)

@Logerfo
Copy link
Author

Logerfo commented Jul 15, 2016

I see. So this is probably two (semi) separated issues. I cannot test it at the moment, but I guess the perfect pull request for that would get rid of both issues, since they are probably in the same piece of code. Does swiping actually trigger MotionEvent.ACTION_UP?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants