Java Code Examples for android.view.View#getDrawableState()

The following examples show how to use android.view.View#getDrawableState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UTilitiesActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            if (!buttonPressed) {
                buttonPressed = true;
                crossfade.startTransition(BUTTON_ANIMATION_DURATION);
            }
            break;
        case MotionEvent.ACTION_UP:
            if (buttonPressed) {
                buttonPressed = false;
                crossfade.reverseTransition(BUTTON_ANIMATION_DURATION);
            }
            break;
        case MotionEvent.ACTION_MOVE:
            final int[] states = v.getDrawableState();
            boolean pressedStateFound = false;
            for (int state : states) {
                if (state == android.R.attr.state_pressed) {
                    pressedStateFound = true;
                    if (!buttonPressed) {
                        buttonPressed = true;
                        crossfade.startTransition(BUTTON_ANIMATION_DURATION);
                    }
                    break;
                }
            }
            if (!pressedStateFound && buttonPressed) {
                buttonPressed = false;
                crossfade.reverseTransition(BUTTON_ANIMATION_DURATION);
            }
            break;
    }
    return false;
}