Example usage for android.util StateSet NOTHING

List of usage examples for android.util StateSet NOTHING

Introduction

In this page you can find the example usage for android.util StateSet NOTHING.

Prototype

null NOTHING

To view the source code for android.util StateSet NOTHING.

Click Source Link

Document

A state set that does not contain any valid states.

Usage

From source file:Main.java

@SuppressLint("NewApi")
public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;/* w  w w  . j  ava 2s .  co  m*/
    }
    Drawable drawable;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}

From source file:Main.java

public static void clearDrawableAnimation(View view) {
    if (Build.VERSION.SDK_INT < 21 || view == null) {
        return;/*from   www .  j  av  a2 s.co m*/
    }
    Drawable drawable = null;
    if (view instanceof ListView) {
        drawable = ((ListView) view).getSelector();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
        }
    } else {
        drawable = view.getBackground();
        if (drawable != null) {
            drawable.setState(StateSet.NOTHING);
            drawable.jumpToCurrentState();
        }
    }
}

From source file:Main.java

/**
 * Returns a new state that will seem to have changed in {@link Drawable#setState(int[])}, allowing
 * {@link Drawable#onStateChange(int[])} to be called.
 * <p>/*  ww  w.j  ava 2  s .c o m*/
 * However, the returned state is the same state with 0 (nothing) as the last item, or the reverse of that.
 */
public static int[] getForceState(int[] state) {
    if (state.length == 0) {
        return StateSet.NOTHING;
    } else if (state[state.length - 1] == 0) {
        return removeFrom(state);
    } else {
        return addTo(state);
    }
}

From source file:com.hippo.widget.recyclerview.EasyRecyclerView.java

private void positionSelector(int position, View sel, boolean manageHotspot, float x, float y) {
    final boolean positionChanged = position != mSelectorPosition;
    if (position != INVALID_POSITION) {
        mSelectorPosition = position;//from   ww w.java 2  s  .co m
    }

    final Rect selectorRect = mSelectorRect;
    selectorRect.set(sel.getLeft(), sel.getTop(), sel.getRight(), sel.getBottom());

    // Adjust for selection padding.
    selectorRect.left -= mSelectionLeftPadding;
    selectorRect.top -= mSelectionTopPadding;
    selectorRect.right += mSelectionRightPadding;
    selectorRect.bottom += mSelectionBottomPadding;

    // Update the selector drawable.
    final Drawable selector = mSelector;
    if (selector != null) {
        if (positionChanged) {
            // Wipe out the current selector state so that we can start
            // over in the new position with a fresh state.
            selector.setVisible(false, false);
            selector.setState(StateSet.NOTHING);
        }
        selector.setBounds(selectorRect);
        if (positionChanged) {
            if (getVisibility() == VISIBLE) {
                selector.setVisible(true, false);
            }
            updateSelectorState();
        }
        if (manageHotspot) {
            DrawableUtils.setHotspot(selector, x, y);
        }
    }
}

From source file:net.simonvt.staggeredgridview.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    velocityTracker.addMovement(ev);/*  w ww.jav a2  s  . c  o m*/
    final int action = ev.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        if (tapReset != null) {
            removeCallbacks(tapReset);
            tapReset = null;
        }
        if (pendingTapCheck != null) {
            removeCallbacks(pendingTapCheck);
            pendingTapCheck = null;
        }

        velocityTracker.clear();
        scroller.abortAnimation();
        lastTouchY = ev.getY();
        lastTouchX = ev.getX();
        final int x = (int) ev.getX();
        activePointerId = ev.getPointerId(0);
        touchRemainderY = 0;
        motionPosition = getPositionAt(x, (int) lastTouchY);
        if (motionPosition != INVALID_POSITION && adapter != null && adapter.isEnabled(motionPosition)) {
            pendingTapCheck = new TapCheck();
            postDelayed(pendingTapCheck, ViewConfiguration.getTapTimeout());
            if (hasStableIds) {
                motionId = ((LayoutParams) getChildAt(motionPosition - firstPosition).getLayoutParams()).id;
            }
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        final int index = ev.findPointerIndex(activePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + activePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = ev.getY(index);
        final float x = ev.getX(index);
        final float dy = y - lastTouchY + touchRemainderY;
        final int deltaY = (int) dy;
        touchRemainderY = dy - deltaY;

        if (Math.abs(dy) > touchSlop) {
            touchMode = TOUCH_MODE_DRAGGING;
        }

        if (touchMode == TOUCH_MODE_DRAGGING) {
            if (pendingTapCheck != null) {
                removeCallbacks(pendingTapCheck);
            }
            if (!selectorRect.isEmpty()) {
                selectorRect.setEmpty();
            }
            if (motionPosition != INVALID_POSITION) {
                final View child = getChildAt(motionPosition - firstPosition);
                if (child != null) {
                    child.setPressed(false);
                }
                setPressed(false);
                selector.setState(StateSet.NOTHING);
                motionPosition = INVALID_POSITION;
                motionId = -1L;
            }

            lastTouchY = y;
            lastTouchX = x;

            if (!trackMotionScroll(deltaY, true)) {
                // Break fling velocity if we impacted an edge.
                velocityTracker.clear();
            }
        }
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        touchMode = TOUCH_MODE_IDLE;

        if (motionPosition != INVALID_POSITION) {
            View child = getChildAt(motionPosition - firstPosition);
            child.setPressed(false);

            setPressed(false);
        }

        motionPosition = INVALID_POSITION;
        motionId = -1L;
        selectorRect.setEmpty();

        if (pendingTapCheck != null) {
            removeCallbacks(pendingTapCheck);
            pendingTapCheck = null;
        }
        if (tapReset != null) {
            removeCallbacks(tapReset);
            tapReset = null;
        }
        break;

    case MotionEvent.ACTION_UP: {
        velocityTracker.computeCurrentVelocity(1000, maximumVelocity);
        final float velocity = velocityTracker.getYVelocity(activePointerId);

        if (pendingTapCheck != null) {
            removeCallbacks(pendingTapCheck);
            pendingTapCheck = null;
        }

        if (Math.abs(velocity) > flingVelocity) { // TODO
            touchMode = TOUCH_MODE_FLINGING;
            scroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            lastTouchY = 0;
            postInvalidateOnAnimation();

            if (motionPosition != INVALID_POSITION) {
                View child = getChildAt(motionPosition - firstPosition);
                if (child != null) {
                    child.setPressed(false);
                }

                setPressed(false);

                motionPosition = INVALID_POSITION;
                motionId = -1L;
                selectorRect.setEmpty();

                if (pendingTapCheck != null) {
                    removeCallbacks(pendingTapCheck);
                    pendingTapCheck = null;
                }
            }
        } else {
            if (touchMode != TOUCH_MODE_DRAGGING && motionPosition != INVALID_POSITION) {
                if (adapter != null && adapter.isEnabled(motionPosition)) {
                    new TapCheck().run();
                    tapReset = new TapReset();
                    postDelayed(tapReset, ViewConfiguration.getPressedStateDuration());
                } else {
                    motionPosition = INVALID_POSITION;
                    motionId = -1L;
                }
            }
            touchMode = TOUCH_MODE_IDLE;
        }
    }
        break;
    }
    return true;
}

From source file:nz.ac.otago.psyanlab.common.designer.program.stage.StageView.java

private void updateSelectorState() {
    for (int i = 0; i < mSelectors.size(); i++) {
        Drawable d = mSelectors.valueAt(i);
        if (d != null) {
            if (shouldShowSelector()) {
                d.setState(getDrawableState());
            } else {
                d.setState(StateSet.NOTHING);
            }/* w w w  .  j a v  a  2  s.  com*/
        }
    }
}

From source file:com.example.libwidgettv.bak.AbsListView.java

void updateSelectorState() {
    if (mSelector != null) {
        if (shouldShowSelector()) {
            mSelector.setState(getDrawableState());
        } else {//from w w w  .j ava 2s . c o  m
            mSelector.setState(StateSet.NOTHING);
        }
    }
}