showhidepasswordedittext icon indicating copy to clipboard operation
showhidepasswordedittext copied to clipboard

Strange behavior when using layout_centerHorizontal

Open Logerfo opened this issue 9 years ago • 5 comments

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.

Logerfo avatar Jul 03 '16 00:07 Logerfo

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 avatar Jul 14 '16 20:07 joshkendrick

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);
}

joshkendrick avatar Jul 15 '16 18:07 joshkendrick

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

Logerfo avatar Jul 15 '16 18:07 Logerfo

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)

joshkendrick avatar Jul 15 '16 18:07 joshkendrick

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?

Logerfo avatar Jul 15 '16 18:07 Logerfo