Example usage for android.view MotionEvent getActionMasked

List of usage examples for android.view MotionEvent getActionMasked

Introduction

In this page you can find the example usage for android.view MotionEvent getActionMasked.

Prototype

public final int getActionMasked() 

Source Link

Document

Return the masked action being performed, without pointer index information.

Usage

From source file:com.inmobi.ultrapush.AnalyzeActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (isInGraphView(event.getX(0), event.getY(0))) {
        this.mDetector.onTouchEvent(event);
        if (isMeasure) {
            measureEvent(event);/*w w  w.  j  av a2s .  c o  m*/
        } else {
            scaleEvent(event);
        }
        invalidateGraphView();
        // Go to scaling mode when user release finger in measure mode.
        if (event.getActionMasked() == MotionEvent.ACTION_UP) {
            if (isMeasure) {
                switchMeasureAndScaleMode();
            }
        }
    } else {
        // When finger is outside the plot, hide the cursor and go to scaling mode.
        if (isMeasure) {
            graphView.hideCursor();
            switchMeasureAndScaleMode();
        }
    }
    return super.onTouchEvent(event);
}

From source file:com.github.crvv.wubinput.wubi.dictionary.suggestions.SuggestionStripView.java

@Override
public boolean onTouchEvent(final MotionEvent me) {
    // In the sliding input mode. {@link MotionEvent} should be forwarded to
    // {@link MoreSuggestionsView}.
    final int index = me.getActionIndex();
    final int x = mMoreSuggestionsView.translateX((int) me.getX(index));
    final int y = mMoreSuggestionsView.translateY((int) me.getY(index));
    me.setLocation(x, y);/*from   ww w .  java 2  s  .  c o  m*/
    if (!mNeedsToTransformTouchEventToHoverEvent) {
        mMoreSuggestionsView.onTouchEvent(me);
        return true;
    }
    // In sliding suggestion mode with accessibility mode on, a touch event should be
    // transformed to a hover event.
    final int width = mMoreSuggestionsView.getWidth();
    final int height = mMoreSuggestionsView.getHeight();
    final boolean onMoreSuggestions = (x >= 0 && x < width && y >= 0 && y < height);
    if (!onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Just drop this touch event because dispatching hover event isn't started yet and
        // the touch event isn't on {@link MoreSuggestionsView}.
        return true;
    }
    final int hoverAction;
    if (onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Transform this touch event to a hover enter event and start dispatching a hover
        // event to {@link MoreSuggestionsView}.
        mIsDispatchingHoverEventToMoreSuggestions = true;
        hoverAction = MotionEvent.ACTION_HOVER_ENTER;
    } else if (me.getActionMasked() == MotionEvent.ACTION_UP) {
        // Transform this touch event to a hover exit event and stop dispatching a hover event
        // after this.
        mIsDispatchingHoverEventToMoreSuggestions = false;
        mNeedsToTransformTouchEventToHoverEvent = false;
        hoverAction = MotionEvent.ACTION_HOVER_EXIT;
    } else {
        // Transform this touch event to a hover move event.
        hoverAction = MotionEvent.ACTION_HOVER_MOVE;
    }
    me.setAction(hoverAction);
    mMoreSuggestionsView.onHoverEvent(me);
    return true;
}

From source file:io.apptik.widget.MultiSlider.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!mIsUserSeekable || !isEnabled()) {
        return false;
    }/*  w w  w .ja v  a2s  .  c  o  m*/

    int pointerIdx = event.getActionIndex();

    Thumb currThumb = null;
    if (mDraggingThumbs.size() > pointerIdx) {
        currThumb = mDraggingThumbs.get(pointerIdx);
    } else {

        LinkedList<Thumb> closestOnes = getClosestThumb((int) event.getX(event.getActionIndex()));
        if (closestOnes != null && !closestOnes.isEmpty()) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN
                    || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
                if (closestOnes.size() == 1) {
                    currThumb = closestOnes.getFirst();
                    onStartTrackingTouch(currThumb);
                    drawableStateChanged();
                } else {
                    //we have more than one thumb at the same place and we touched there
                    exactTouched = closestOnes;
                }
            } else if (exactTouched != null && !exactTouched.isEmpty()
                    && event.getActionMasked() == MotionEvent.ACTION_MOVE) {
                //we have thumbs waiting to be selected to move
                currThumb = getMostMovable(exactTouched, event);
                //check if move actually changed value
                if (currThumb == null)
                    return false;
                exactTouched = null;
                onStartTrackingTouch(currThumb);
                drawableStateChanged();
            } else {
                currThumb = closestOnes.getFirst();
                onStartTrackingTouch(currThumb);
                drawableStateChanged();
            }
        }

    }

    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        if (isInScrollingContainer()) {
            mTouchDownX = event.getX();
        } else {
            //currThumb = getClosestThumb(newValue);
            //onStartTrackingTouch(currThumb);
            setPressed(true);
            if (currThumb != null && currThumb.getThumb() != null) {
                invalidate(currThumb.getThumb().getBounds()); // This may be within the padding region
            }

            int value = getValue(event, currThumb);
            setThumbValue(currThumb, value, true);
            attemptClaimDrag();
        }
        break;

    case MotionEvent.ACTION_POINTER_DOWN:
        if (isInScrollingContainer()) {
            mTouchDownX = event.getX();
        } else {
            //currThumb = getClosestThumb(newValue);
            //onStartTrackingTouch(currThumb);
            setPressed(true);
            if (currThumb != null && currThumb.getThumb() != null) {
                invalidate(currThumb.getThumb().getBounds()); // This may be within the padding region
            }

            setThumbValue(currThumb, getValue(event, currThumb), true);
            attemptClaimDrag();
        }
        invalidate();
        break;

    //with move we dont have pointer action so set them all
    case MotionEvent.ACTION_MOVE:
        if (!mDraggingThumbs.isEmpty()) {

            //need the index
            for (int i = 0; i < mDraggingThumbs.size(); i++) {
                setPressed(true);
                if (mDraggingThumbs.get(i) != null && mDraggingThumbs.get(i).getThumb() != null) {
                    invalidate(mDraggingThumbs.get(i).getThumb().getBounds()); // This may be within the padding region
                }
                setThumbValue(mDraggingThumbs.get(i), getValue(event, i, mDraggingThumbs.get(i)), true);
                attemptClaimDrag();
            }

        } else {
            final float x = event.getX();
            if (Math.abs(x - mTouchDownX) > mScaledTouchSlop) {
                //currThumb = getClosestThumb(newValue);
                //onStartTrackingTouch(currThumb);
                setPressed(true);
                if (currThumb != null && currThumb.getThumb() != null) {
                    invalidate(currThumb.getThumb().getBounds()); // This may be within the padding region
                }

                setThumbValue(currThumb, getValue(event, currThumb), true);
                attemptClaimDrag();
            }
        }

        break;

    //there are other pointers left
    case MotionEvent.ACTION_POINTER_UP:
        if (currThumb != null) {
            setThumbValue(currThumb, getValue(event, currThumb), true);
            onStopTrackingTouch(currThumb);
        } else {
            //                    currThumb = getClosestThumb(newValue);
            //                    // Touch up when we never crossed the touch slop threshold should
            //                    // be interpreted as a tap-seek to that location.
            //                    onStartTrackingTouch(currThumb);
            //                    setThumbValue(currThumb, newValue, true);
            //                    onStopTrackingTouch(currThumb);
        }

        // ProgressBar doesn't know to repaint the thumb drawable
        // in its inactive state when the touch stops (because the
        // value has not apparently changed)
        invalidate();
        break;

    //we normally have one single pointer here and its gone now
    case MotionEvent.ACTION_UP:
        if (currThumb != null) {
            int value = getValue(event, currThumb);
            setThumbValue(currThumb, value, true);
            onStopTrackingTouch(currThumb);
        } else {
            //                    currThumb = getClosestThumb(newValue);
            //                    // Touch up when we never crossed the touch slop threshold should
            //                    // be interpreted as a tap-seek to that location.
            //                    onStartTrackingTouch(currThumb);
            //                    setThumbValue(currThumb, newValue, true);
            //                    onStopTrackingTouch();
        }
        setPressed(false);
        // ProgressBar doesn't know to repaint the thumb drawable
        // in its inactive state when the touch stops (because the
        // value has not apparently changed)
        invalidate();
        break;

    case MotionEvent.ACTION_CANCEL:
        if (mDraggingThumbs != null) {
            onStopTrackingTouch();
            setPressed(false);
        }
        invalidate(); // see above explanation
        break;
    }
    return true;
}

From source file:com.nextgis.mobile.fragment.MapFragment.java

protected void checkCompass(boolean showCompass) {
    int compassContainer = R.id.fl_compass;
    final FrameLayout compass = (FrameLayout) mMapRelativeLayout.findViewById(compassContainer);

    if (!showCompass) {
        compass.setVisibility(View.GONE);
        return;/*from w ww  .  j  ava  2s  .  c  o m*/
    }

    FragmentManager fragmentManager = mActivity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    //get or create fragment
    CompassFragment compassFragment = (CompassFragment) fragmentManager.findFragmentByTag("NEEDLE_COMPASS");
    if (null == compassFragment)
        compassFragment = new CompassFragment();

    compass.setClickable(false);
    compassFragment.setStyle(true);
    if (!compassFragment.isAdded())
        fragmentTransaction.add(compassContainer, compassFragment, "NEEDLE_COMPASS")
                .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

    if (!compassFragment.isVisible()) {
        fragmentTransaction.show(compassFragment);
    }

    fragmentTransaction.commit();

    compass.setVisibility(View.VISIBLE);
    compass.setOnClickListener(this);
    compass.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            mIsCompassDragging = true;
            mVibrator.vibrate(5);
            return true;
        }
    });
    // Thanks to http://javatechig.com/android/how-to-drag-a-view-in-android
    compass.setOnTouchListener(new View.OnTouchListener() {
        private int _xDelta;
        private int _yDelta;

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int X = (int) event.getRawX();
            final int Y = (int) event.getRawY();
            switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
                _xDelta = X - lParams.leftMargin;
                _yDelta = Y - lParams.topMargin;
                return false;
            case MotionEvent.ACTION_UP:
                mIsCompassDragging = false;
                return false;
            case MotionEvent.ACTION_MOVE:
                if (!mIsCompassDragging)
                    return false;

                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) v.getLayoutParams();
                int width = v.getWidth();
                int height = v.getHeight();
                int toolbarHeight = 0;
                if (mActivity.getSupportActionBar() != null)
                    toolbarHeight = mActivity.getSupportActionBar().getHeight();
                if (X > width / 3 && X < v.getRootView().getWidth() - width / 3)
                    layoutParams.leftMargin = X - _xDelta;
                if (Y > height / 2 + toolbarHeight && Y < v.getRootView().getHeight() - height / 2)
                    layoutParams.topMargin = Y - _yDelta;

                v.setLayoutParams(layoutParams);
                break;
            }
            mMapRelativeLayout.invalidate();
            return true;
        }
    });
}

From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

@Override
public void onPressedView(MotionEvent event, int activePointerId, View view) {
    mTouchHandler.removeCallbacksAndMessages(null);
    mPressedIconView = view;//  w  w  w . j  a  va  2s  .co  m

    if (view == null) {
        return;
    }

    final Widget widget = findWidgetByIcon(view);
    if (isCurrentWidget(widget)) {
        // We need to reset this, cause current widget may be
        // pinned.
        mHandler.removeMessages(MSG_SHOW_HOME_WIDGET);
        return;
    } else if (widget == null && mSelectedWidget.isHomeWidget()) {
        return;
    }

    int action = event.getActionMasked();
    int delay = action != MotionEvent.ACTION_DOWN ? mConfigWidgetSelectDelay : 0;
    mTouchHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            if (widget == null) {
                showHomeWidget();
            } else {
                showWidget(widget);
            }
        }
    }, delay);
}

From source file:com.example.SmartBoard.DrawingView.java

public boolean onTouchDragEvent(MotionEvent event) {

    boolean handled = false;

    JSONObject mObjectTouched;/*from   w w  w  .  j a  va2s .  c  o m*/
    int X;
    int Y;
    int pointerId;
    int actionIndex = event.getActionIndex();

    //get coordinates and make object transparent
    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        dragFinished = false;

        //it's the first pointer, so clear all existing pointers data
        mObjectPointers.clear();
        X = (int) event.getX(actionIndex);
        Y = (int) event.getY(actionIndex);
        dragX = X;
        dragY = Y;
        String objectType = "";
        //check if we've touched inside some object
        mObjectTouched = getTouchedObject(X, Y);

        if (mObjectTouched == null) {
            return true;
        } else {
            objectType = getObjectType(mObjectTouched);
        }

        if (objectType.compareTo("Circle") == 0) {
            try {
                mObjectTouched.put("x", X);
                mObjectTouched.put("y", Y);

            } catch (JSONException e) {
                e.printStackTrace();

            }
        } else if (objectType.compareTo("Rectangle") == 0) {
            Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens"));
            tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height());
            try {
                mObjectTouched.put("dimens", tempRect.flattenToString());
            } catch (JSONException e) {

            }

        } else if (objectType.compareTo("Line") == 0) {

            if (lengthOfLine(X, Y, mObjectTouched.optInt("startx"),
                    mObjectTouched.optInt("starty")) < lengthOfLine(X, Y, mObjectTouched.optInt("stopx"),
                            mObjectTouched.optInt("stopy"))) {

                try {
                    mObjectTouched.put("startx", X);
                    mObjectTouched.put("starty", Y);
                    mObjectTouched.put("length",
                            lengthOfLine(X, Y, mObjectTouched.optInt("stopx"), mObjectTouched.optInt("stopy")));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                dragLineStart = true;
            } else {
                try {
                    mObjectTouched.put("stopx", X);
                    mObjectTouched.put("stopy", Y);
                    mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"),
                            mObjectTouched.optInt("starty")));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                dragLineStart = false;
            }

        } else if (objectType.compareTo("Text") == 0) {
            try {
                mObjectTouched.put("x", X);
                mObjectTouched.put("y", Y);
                Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region"));
                tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y);
                mObjectTouched.put("region", tempRect.flattenToString());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        mObjectPointers.put(event.getPointerId(0), mObjectTouched);
        if (mObjectTouched != null) {
            mqtt.publishObject(mObjectTouched);
        }
        invalidate();
        handled = true;
        break;

    case MotionEvent.ACTION_POINTER_DOWN:
        break;
    case MotionEvent.ACTION_MOVE:
        dragFinished = false;

        final int pointerCount = event.getPointerCount();

        for (actionIndex = 0; actionIndex < pointerCount; actionIndex++) {
            //some pointer has moved, search it by pointer id
            pointerId = event.getPointerId(actionIndex);
            X = (int) event.getX(actionIndex);
            Y = (int) event.getY(actionIndex);

            dragX = X;
            dragY = Y;

            mObjectTouched = mObjectPointers.get(pointerId);
            if (mObjectTouched == null)
                continue; // if null no object was touched so skip

            if (mObjectTouched.optString("type").compareTo("Circle") == 0) {
                try {
                    mObjectTouched.put("x", X);
                    mObjectTouched.put("y", Y);
                } catch (JSONException e) {
                }
            } else if (mObjectTouched.optString("type").compareTo("Rectangle") == 0) {

                Rect tempRect = Rect.unflattenFromString(mObjectTouched.optString("dimens"));
                tempRect.set(X, Y, X + tempRect.width(), Y + tempRect.height());
                try {
                    mObjectTouched.put("dimens", tempRect.flattenToString());
                } catch (JSONException e) {

                }

            } else if (mObjectTouched.optString("type").compareTo("Text") == 0) {
                try {
                    mObjectTouched.put("x", X);
                    mObjectTouched.put("y", Y);
                    Rect tempRect = Rect.unflattenFromString(mObjectTouched.getString("region"));
                    tempRect.set(X, Y, tempRect.width() + X, tempRect.height() + Y);
                    mObjectTouched.put("region", tempRect.flattenToString());
                } catch (JSONException e) {

                    e.printStackTrace();
                }
            }

            else if (mObjectTouched.optString("type").compareTo("Line") == 0) {

                if (dragLineStart) {
                    try {
                        mObjectTouched.put("startx", X);
                        mObjectTouched.put("starty", Y);
                        mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("stopx"),
                                mObjectTouched.optInt("stopy")));

                        //mObjectTouched.put("stopx", tempStopX);
                        // mObjectTouched.put("stopy", tempStopY);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                } else {
                    try {
                        mObjectTouched.put("stopx", X);
                        mObjectTouched.put("stopy", Y);
                        mObjectTouched.put("length", lengthOfLine(X, Y, mObjectTouched.optInt("startx"),
                                mObjectTouched.optInt("starty")));

                        //mObjectTouched.put("stopx", tempStopX);
                        // mObjectTouched.put("stopy", tempStopY);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                }

            }

            if (mObjectTouched != null) {
                mqtt.publishObject(mObjectTouched);
            }
        }

        invalidate();
        handled = true;
        break;
    case MotionEvent.ACTION_UP:
        dragFinished = true;

        mObjectPointers.clear();
        invalidate();
        handled = true;
        break;
    case MotionEvent.ACTION_CANCEL:
        handled = true;
        break;

    default:
        // do nothing
        break;
    }

    return super.onTouchEvent(event) || handled;
}

From source file:com.juick.android.MessagesFragment.java

public Boolean maybeInterceptTouchEventFromActivity(MotionEvent event) {
    if (rightScrollBound == 0) {
        Log.w("JAGP", "rightScrollBound == 0");
        return null;
    }//from   w  ww .ja v a 2 s.  c  om
    if (getActivity() == null || true)
        return null;
    int action = event.getAction();
    int actionMasked = event.getActionMasked();
    if (fragInParent == null)
        fragInParent = getActivity().findViewById(R.id.messagesfragment);
    if (action == MotionEvent.ACTION_DOWN || actionMasked == MotionEvent.ACTION_POINTER_DOWN) {
        if (mScrollState == SCROLL_STATE_IDLE && fragInParent.getAnimation() == null) {
            if (!canStartScroll(event)) {
                mIsUnableToDrag = true;
                return null;
            }
            if (event.getPointerCount() == 1) {
                Log.w("JAGP", "action_down 1");
                navigationOpenMode = fragInParent.getLeft() > 0;
                mLastMotionX = mInitialMotionX = event.getX();
                mLastMotionY = event.getY();
                currentScrollX = 0;
                mActivePointerId = MotionEventCompat.getPointerId(event, 0);
                mIsBeingDragged = false;
                mIsUnableToDrag = false;
            } else {
                Log.w("JAGP", "action_down 2");
                if (mIsBeingDragged) {
                    if (!navigationOpenMode) {
                        Log.w("JAGP", "action_down 3");
                        setScrollState(SCROLL_STATE_IDLE);
                        scrollToX(0, 500);
                    }
                }
                mIsUnableToDrag = true;
            }
        } else {
            Log.w("JAGP", "!(mScrollState == SCROLL_STATE_IDLE && fragInParent.getAnimation() == null)");
        }
    }
    if (action == MotionEvent.ACTION_UP || actionMasked == MotionEvent.ACTION_POINTER_UP) {
        if (mIsUnableToDrag)
            return null;
        if (mIsBeingDragged) {
            final int activePointerId = mActivePointerId;
            if (activePointerId == INVALID_POINTER) {
                // If we don't have a valid id, the touch down wasn't on content.
                return null;
            }
            int pointerIndex = MotionEventCompat.findPointerIndex(event, activePointerId);
            if (pointerIndex == event.getActionIndex()) {
                if (!navigationOpenMode) {
                    // commenting needed.
                    if (lastToXDelta != null) {
                        if (Math.abs(lastToXDelta) < rightScrollBound / 2) {
                            Log.w("JAGP", "action_up 1");
                            setScrollState(SCROLL_STATE_SETTLING);
                            scrollToX(0, 500);
                        } else {
                            Log.w("JAGP", "action_up 2");
                            setScrollState(SCROLL_STATE_SETTLING);
                            scrollToX((int) -rightScrollBound, 200);
                            handler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    Log.w("JAGP", "action_up 3");
                                    ((MainActivity) getActivity()).openNavigationMenu(false);
                                    lastToXDelta = 0;
                                    fragInParent.clearAnimation();
                                }
                            }, 200);
                        }
                    }
                } else {
                    Log.w("JAGP", "action_up 4");
                    mIsBeingDragged = false;
                    setScrollState(SCROLL_STATE_SETTLING);
                    scrollToX((int) rightScrollBound, 200);
                    mActivePointerId = INVALID_POINTER;
                    handler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Log.w("JAGP", "action_up 5");
                            ((MainActivity) getActivity()).closeNavigationMenu(false, true);

                            lastToXDelta = 0;
                            fragInParent.clearAnimation();
                        }
                    }, 200);

                }
                return null;
            }
        }
    }
    if (action == MotionEvent.ACTION_MOVE) {
        if (mIsUnableToDrag)
            return null;
        if (mScrollState == SCROLL_STATE_SETTLING)
            return null;

        /*
         * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
         * whether the user has moved far enough from his original down touch.
         */

        /*
        * Locally do absolute value. mLastMotionY is set to the y value
        * of the down event.
        */
        MotionEvent ev = event;
        final int activePointerId = mActivePointerId;
        if (activePointerId == INVALID_POINTER) {
            // If we don't have a valid id, the touch down wasn't on content.
            return null;
        }

        int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
        float x = MotionEventCompat.getX(ev, pointerIndex);
        float dx = x - mLastMotionX;
        float xDiff = Math.abs(dx);
        float yDiff = Math.abs(MotionEventCompat.getY(ev, pointerIndex) - mLastMotionY);

        if (!mIsBeingDragged) {
            if (isListAnyPressed()) {
                //Log.w("JAGP","action_move 1");
                mIsUnableToDrag = true;
            } else if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsBeingDragged = true;
                setScrollState(SCROLL_STATE_DRAGGING);
                mLastMotionX = x;
                //Log.w("JAGP","action_move 2");
                return null;
            } else {
                if (yDiff > mTouchSlop) {
                    // The finger has moved enough in the vertical
                    // direction to be counted as a drag...  abort
                    // any attempt to drag horizontally, to work correctly
                    // with children that have scrolling containers.
                    //Log.w("JAGP","action_move 3");
                    mIsUnableToDrag = true;
                }
            }
        }

        if (mIsBeingDragged) {
            //Log.w("JAGP","action_move 4");
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            x = MotionEventCompat.getX(ev, activePointerIndex);
            final float deltaX = mLastMotionX - x;
            mLastMotionX = x;
            float oldScrollX = getScrollX();
            float scrollX = oldScrollX + deltaX;
            final int width = getListView().getWidth();
            final int widthWithMargin = width;

            final float leftBound = -widthWithMargin;
            if (navigationOpenMode) {
                if (scrollX < 0) {
                    scrollX = 0;
                } else if (scrollX > rightScrollBound) { // prevent too much to left
                    scrollX = rightScrollBound;
                }
            } else {
                if (scrollX > 0) {
                    scrollX = 0;
                } else if (scrollX > rightScrollBound) {
                    scrollX = rightScrollBound;
                }
            }
            // Don't lose the rounded component
            mLastMotionX += scrollX - (int) scrollX;
            scrollToX((int) scrollX, 1);
            return null;
        }

    }
    return null;
}

From source file:pl.edu.agh.mindmapex.gui.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    progressDialog = ProgressDialog.show(this, "Drawing", "Please wait...", true, false);
    if (WelcomeScreen.workbook != null) {
        workbook = WelcomeScreen.workbook;
    }/*w ww. j  a  va2  s  .c  om*/
    res = getResources();
    if (handler == null) {
        handler = WorkbookHandler.createNewWorkbook();
    }

    if (workbook == null) {
        workbook = handler.getWorkbook();
        styleSheet = workbook.getStyleSheet();
        style1 = styleSheet.createStyle(IStyle.TOPIC);
        styleSheet.addStyle(style1, IStyleSheet.NORMAL_STYLES);
    }
    styleSheet = workbook.getStyleSheet();
    sheet1 = workbook.getPrimarySheet();
    res = getResources();
    if (style == null) {
        Intent intent = getIntent();
        style = intent.getStringExtra(WelcomeScreen.STYLE);
    }
    if (root == null) {

        //            Display display = getWindowManager().getDefaultDisplay();
        setContentView(R.layout.main_content_view);
        lay = (DrawView) findViewById(R.id.main_draw_view);
        lay.post(new Runnable() {
            @Override
            public void run() {
                rootTopic = sheet1.getRootTopic();
                root = new Box();

                //            Point size = new Point(lay.getWidth(), lay.getHeight());
                //            width = size.x / 2;
                //            height = size.y / 2;
                root.setPoint(new pl.edu.agh.mindmapex.common.Point(
                        lay.getWidth() / 2 - getResources().getDimensionPixelSize(R.dimen.init_box_size),
                        lay.getHeight() / 2
                                - getResources().getDimensionPixelSize(R.dimen.init_box_size_height)));
                lay.setZOrderOnTop(true);

                if (style.equals("ReadyMap")) {

                    if (sheet1.getTheme() == null) {
                        root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height));
                        final HashMap<String, Box> boxes = new HashMap<>();
                        root.topic = rootTopic;
                        if (root.topic.getStyleId() != null) {
                            checkStyle(root);
                        } else {
                            root.setDrawableShape(res.getDrawable(R.drawable.round_rect));
                        }

                        root.topic.setFolded(false);

                        boxes.put(root.topic.getId(), root);
                        for (ITopic t : root.topic.getAllChildren()) {
                            Box b = new Box();
                            b.topic = t;
                            boxes.put(root.topic.getId(), root);
                            b.point = new pl.edu.agh.mindmapex.common.Point();
                            if (b.topic.getStyleId() != null) {
                                checkStyle(b);
                            } else {
                                b.setDrawableShape(res.getDrawable(R.drawable.round_rect));
                            }
                            b.parent = root;
                            root.addChild(b);
                            rootTopic.add(b.topic, 0, ITopic.ATTACHED);
                            Utils.fireAddSubtopic(b, boxes);
                            boxes.put(t.getId(), b);
                        }
                        Utils.findRelationships(boxes);
                    } else {
                        if (sheet1.getTheme().getName().equals("%classic")
                                || sheet1.getTheme().getName().equals("%comic")) {
                            root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height));
                            root.topic = rootTopic;
                            final HashMap<String, Box> boxes = new HashMap<>();
                            if (root.topic.getStyleId() != null) {
                                checkStyle(root);
                            } else {
                                root.setDrawableShape(res.getDrawable(R.drawable.elipse));
                            }
                            root.topic.setFolded(false);
                            boxes.put(root.topic.getId(), root);

                            for (ITopic t : root.topic.getAllChildren()) {
                                Box b = new Box();
                                b.topic = t;
                                b.point = new pl.edu.agh.mindmapex.common.Point();
                                boxes.put(root.topic.getId(), root);
                                if (b.topic.getStyleId() != null) {
                                    checkStyle(b);
                                } else {
                                    b.setDrawableShape(res.getDrawable(R.drawable.round_rect));
                                }
                                b.parent = root;
                                root.addChild(b);
                                Utils.fireAddSubtopic(b, boxes);
                                rootTopic.add(b.topic, 0, ITopic.ATTACHED);
                                boxes.put(t.getId(), b);
                            }
                            Utils.findRelationships(boxes);
                        } else if (sheet1.getTheme().getName().equals("%simple")) {
                            root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height));
                            final HashMap<String, Box> boxes = new HashMap<>();
                            root.topic = rootTopic;
                            if (root.topic.getStyleId() != null) {
                                checkStyle(root);
                            } else {
                                root.setDrawableShape(res.getDrawable(R.drawable.elipse));
                            }
                            root.topic.setFolded(false);
                            boxes.put(root.topic.getId(), root);

                            for (ITopic t : root.topic.getAllChildren()) {
                                Box b = new Box();
                                b.topic = t;
                                b.point = new pl.edu.agh.mindmapex.common.Point();
                                boxes.put(root.topic.getId(), root);

                                if (b.topic.getStyleId() != null) {
                                    checkStyle(b);
                                } else {
                                    b.setDrawableShape(res.getDrawable(R.drawable.no_border));
                                }
                                b.parent = root;
                                root.addChild(b);
                                rootTopic.add(b.topic, 0, ITopic.ATTACHED);
                                Utils.fireAddSubtopic(b, boxes);
                                boxes.put(t.getId(), b);
                            }
                            Utils.findRelationships(boxes);
                        } else if (sheet1.getTheme().getName().equals("%bussiness")) {
                            root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height));
                            final HashMap<String, Box> boxes = new HashMap<>();
                            root.topic = rootTopic;
                            if (root.topic.getStyleId() != null) {
                                checkStyle(root);
                            } else {
                                root.setDrawableShape(res.getDrawable(R.drawable.round_rect));
                            }
                            root.topic.setFolded(false);

                            boxes.put(root.topic.getId(), root);

                            for (ITopic t : root.topic.getAllChildren()) {
                                Box b = new Box();
                                b.topic = t;
                                b.point = new pl.edu.agh.mindmapex.common.Point();
                                boxes.put(root.topic.getId(), root);
                                if (b.topic.getStyleId() != null) {
                                    checkStyle(b);
                                } else {
                                    b.setDrawableShape(res.getDrawable(R.drawable.rect));
                                }

                                b.parent = root;
                                root.addChild(b);
                                rootTopic.add(b.topic, 0, ITopic.ATTACHED);
                                Utils.fireAddSubtopic(b, boxes);
                                boxes.put(t.getId(), b);
                            }
                            Utils.findRelationships(boxes);
                        } else if (sheet1.getTheme().getName().equals("%academese")) {
                            root.setPoint(new pl.edu.agh.mindmapex.common.Point(width, height));
                            final HashMap<String, Box> boxes = new HashMap<>();
                            root.topic = rootTopic;
                            if (root.topic.getStyleId() != null) {
                                checkStyle(root);
                            } else {
                                root.setDrawableShape(res.getDrawable(R.drawable.rect));
                            }
                            root.topic.setFolded(false);
                            Style s = (Style) workbook.getStyleSheet().createStyle(IStyle.MAP);
                            s.setProperty(Styles.FillColor,
                                    Integer.toString(res.getColor(R.color.dark_gray), 16));
                            styleSheet.addStyle(s, IStyleSheet.NORMAL_STYLES);
                            sheet1.setStyleId(s.getId());
                            lay.setBackgroundColor(res.getColor(R.color.dark_gray));

                            boxes.put(root.topic.getId(), root);

                            for (ITopic t : root.topic.getAllChildren()) {
                                Box b = new Box();
                                b.topic = t;
                                b.point = new pl.edu.agh.mindmapex.common.Point();
                                boxes.put(root.topic.getId(), root);

                                if (b.topic.getStyleId() != null) {
                                    checkStyle(b);
                                } else {
                                    b.setDrawableShape(res.getDrawable(R.drawable.elipse));
                                }
                                b.parent = root;
                                root.addChild(b);
                                Utils.fireAddSubtopic(b, boxes);
                                rootTopic.add(b.topic, 0, ITopic.ATTACHED);
                                boxes.put(t.getId(), b);
                            }
                            Utils.findRelationships(boxes);
                        }
                    }
                } else if (style.equals("Default")) {

                    rootTopic.setTitleText("Central Topic");
                    root.topic = rootTopic;
                    root.topic.setFolded(false);
                    root.setDrawableShape(res.getDrawable(R.drawable.round_rect));
                    IStyle style3 = styleSheet.createStyle(IStyle.TOPIC);
                    style3.setProperty(Styles.FillColor, "#CCE5FF");
                    style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ROUNDEDRECT);
                    style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_STRAIGHT);
                    styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES);
                    rootTopic.setStyleId(style3.getId());
                } else if (style.equals("Classic")) {
                    rootTopic.setTitleText("Central Topic");
                    root.topic = rootTopic;
                    root.topic.setFolded(false);
                    root.setDrawableShape(res.getDrawable(R.drawable.elipse));
                    IStyle style2 = styleSheet.createStyle(IStyle.THEME);
                    style2.setName("%classic");
                    style2.setProperty(Styles.FillColor, String.valueOf(res.getColor(R.color.light_yellow)));
                    styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES);
                    sheet1.setThemeId(style2.getId());
                    IStyle style3 = styleSheet.createStyle(IStyle.TOPIC);
                    style3.setProperty(Styles.FillColor, "#9ACD32");
                    style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ELLIPSE);
                    style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_CURVE);
                    styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES);
                    style2.setProperty(Style.TOPIC, style3.getId());
                    rootTopic.setStyleId(style3.getId());
                } else if (style.equals("Simple")) {
                    rootTopic.setTitleText("Central Topic");
                    root.topic = rootTopic;
                    root.topic.setFolded(false);
                    root.setDrawableShape(res.getDrawable(R.drawable.elipse));
                    IStyle style2 = styleSheet.createStyle(IStyle.THEME);
                    style2.setName("%simple");
                    style2.setProperty(Styles.FillColor, String.valueOf(res.getColor(R.color.white)));
                    styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES);
                    sheet1.setThemeId(style2.getId());
                    IStyle style3 = styleSheet.createStyle(IStyle.TOPIC);
                    style3.setProperty(Styles.FillColor, "#FFFFFF");
                    style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ELLIPSE);
                    style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_CURVE);
                    styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES);
                    style2.setProperty(Style.TOPIC, style3.getId());
                    rootTopic.setStyleId(style3.getId());
                } else if (style.equals("Business")) {
                    rootTopic.setTitleText("Central Topic");
                    root.topic = rootTopic;
                    root.topic.setFolded(false);
                    root.setDrawableShape(res.getDrawable(R.drawable.round_rect));
                    IStyle style2 = styleSheet.createStyle(IStyle.THEME);
                    style2.setName("%business");
                    style2.setProperty(Styles.FillColor, String.valueOf(res.getColor(R.color.white)));
                    styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES);
                    sheet1.setThemeId(style2.getId());
                    IStyle style3 = styleSheet.createStyle(IStyle.TOPIC);
                    style3.setProperty(Styles.FillColor, "#B87333");
                    style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_ROUNDEDRECT);
                    style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_CURVE);
                    styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES);
                    style2.setProperty(Style.TOPIC, style3.getId());
                    rootTopic.setStyleId(style3.getId());
                } else if (style.equals("Academese")) {
                    rootTopic.setTitleText("Central Topic");
                    root.topic = rootTopic;
                    root.topic.setFolded(false);
                    root.setDrawableShape(res.getDrawable(R.drawable.rect));
                    IStyle style2 = styleSheet.createStyle(IStyle.THEME);
                    style2.setProperty(Styles.FillColor, "#404040");
                    styleSheet.addStyle(style2, IStyleSheet.NORMAL_STYLES);
                    sheet1.setStyleId(style2.getId());
                    lay.setBackgroundColor(res.getColor(R.color.dark_gray));
                    IStyle style3 = styleSheet.createStyle(IStyle.TOPIC);
                    style3.setProperty(Styles.FillColor, "#404040");
                    style3.setProperty(Styles.ShapeClass, Styles.TOPIC_SHAPE_RECT);
                    style3.setProperty(Styles.LineClass, Styles.BRANCH_CONN_STRAIGHT);
                    style3.setProperty(Styles.LineColor, "#FFFFFF");
                    styleSheet.addStyle(style3, IStyleSheet.NORMAL_STYLES);
                    style2.setProperty(Style.TOPIC, style3.getId());
                    rootTopic.setStyleId(style3.getId());
                }

            }
        });

    } else {
        setContentView(R.layout.main_content_view);
        lay = (DrawView) findViewById(R.id.main_draw_view);
        lay.setZOrderOnTop(true);
    }
    gestureDetector = new GestureDetector(this, gestList);
    Utils.lay = lay;
    if (lay != null) {
        lay.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {

                detector.onTouchEvent(event);

                switch (event.getActionMasked()) {
                case (MotionEvent.ACTION_OUTSIDE):
                    return true;
                case (MotionEvent.ACTION_UP):
                    break;
                case MotionEvent.ACTION_POINTER_UP:

                    if (!detector.isInProgress()) {
                        int count = event.getPointerCount(); // Number of 'fingers' in this time

                        Utils.getCoordsInView(lay, event, 1);
                        boxEdited = Utils.whichBox(lay, event);
                        float[] tab1 = Utils.getCoordsInView(lay, event, 0);
                        float[] tab = Utils.getCoordsInView(lay, event, 1);
                        if (count == 2 && boxEdited != null) {

                            if (tab.length == 2) {
                                if (mTourGuide != null)
                                    mTourGuide.cleanUp();
                                Box box1 = new Box();
                                box1.setPoint(new pl.edu.agh.mindmapex.common.Point(
                                        (int) tab[0] - (box1.getWidth() / 2),
                                        (int) tab[1] - (box1.getHeight() / 2)));
                                AddBox addBox = new AddBox();
                                Properties properties = new Properties();
                                properties.put("box", MainActivity.boxEdited);
                                properties.put("new_box", box1);
                                properties.put("root", root);
                                properties.put("res", res);
                                properties.put("style", style);
                                addBox.execute(properties);
                                MainActivity.addCommendUndo(addBox);
                                editContent(box1, addBox);
                                lay.updateBoxWithText(box1);

                            }
                        }

                        break;
                    }
                default:
                    break;
                }

                boolean response = gestureDetector.onTouchEvent(event);
                lay.requestFocus();
                InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                in.hideSoftInputFromWindow(lay.getApplicationWindowToken(), 0);
                return response;
            }
        });
        lay.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
    Utils.context = this;
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(
            ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.show();

    detector = new ScaleGestureDetector(this, new SimpleOnScaleGestureListener() {
        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            mScaling = true;
            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            //                float focusX = detector.getFocusX();
            //                float focusY = detector.getFocusY();
            ////                lay.setPivotX(mid.x);
            ////                lay.setPivotY(mid.y);
            ////                               lay.pivotx = (int) (lastFocusX  + detector.getFocusX())/2;
            ////               lay.pivoty = (int) (lastFocusY+ detector.getFocusY())/2;
            //          //     lay.pivotx = (int) mid.x;
            //          //     lay.pivoty = (int) mid.y;
            //            //    lay.canvas.translate(-focusX,-focusY);
            lay.pivotx = detector.getFocusX();
            lay.pivoty = detector.getFocusY();
            //                lay.transx = (lay.pivotx);
            //                lay.transy = (lay.pivoty);
            //                lay.pivotx = (int) mid.x;
            //                lay.pivoty = (int) mid.y;
            //                lay.setPivotX(lastFocusX);
            //                lay.setPivotY(lastFocusY);
            float SF = detector.getScaleFactor();
            lay.zoomx *= SF;
            lay.zoomy *= SF;
            //    lay.canvas.scale(SF, SF, mid.x, mid.y);
            //                float focusShiftX = focusX - lastFocusX;
            //                float focusShiftY = focusY - lastFocusY;
            //lay.canvas.translate(focusX + focusShiftX, focusY + focusShiftY);
            //  lastFocusX = focusX;
            // lastFocusY = focusY;
            //  lay.transy = detector.getFocusY();
            // lay.zoomx = Math.max(0.1f, Math.min(lay.zoomx, 5.0f));
            // lay.zoomy = Math.max(0.1f, Math.min(lay.zoomy, 5.0f));
            return true;

        }
    });
    progressDialog.dismiss();
    lay.setId(View.generateViewId());
    lay.setSaveEnabled(true);

    if (savedInstanceState != null) {
        lay.transx = savedInstanceState.getFloat(TRANSX_KEY);
        lay.transy = savedInstanceState.getFloat(TRANSY_KEY);
        lay.zoomx = savedInstanceState.getFloat(ZOOMX_KEY);
        lay.zoomy = savedInstanceState.getFloat(ZOOMY_KEY);
        lay.pivotx = savedInstanceState.getFloat(PIVOTX_KEY);
        lay.pivoty = savedInstanceState.getFloat(PIVOTY_KEY);

    }

}

From source file:cnedu.ustcjd.widget.MultiSlider.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!mIsUserSeekable || !isEnabled()) {
        return false;
    }//  w  w  w. j a  v a 2  s  .  c o  m
    final int xx = Math.round(event.getX());
    final int yy = Math.round(event.getY());

    int pointerIdx = event.getActionIndex();

    Thumb currThumb = null;
    if (event.getActionMasked() == MotionEvent.ACTION_DOWN
            || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
        LinkedList<Thumb> closestOnes = getClosestThumb((int) event.getX(pointerIdx));

        if (isInScrollingContainer() && mDraggingThumbs.size() == 0 && exactTouched != null && pointerIdx > 0) {
            //we have been here before => we want to use the bar
            Thumb prevThumb = exactTouched.getFirst();
            onStartTrackingTouch(prevThumb);
            exactTouched = null;
        }

        if (closestOnes != null && !closestOnes.isEmpty()) {
            if (closestOnes.size() == 1) {
                currThumb = closestOnes.getFirst();
                if (isInScrollingContainer() && mDraggingThumbs.size() == 0) {
                    exactTouched = closestOnes;
                }
            } else {
                //we have more than one thumb at the same place and we touched there
                exactTouched = closestOnes;
            }
        }
    } else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        if (exactTouched != null && !exactTouched.isEmpty()) {
            currThumb = getMostMovableThumb(event);
            //check if move actually changed value
            // if (currThumb == null) return false;
        } else if (mDraggingThumbs.size() > pointerIdx) {
            currThumb = mDraggingThumbs.get(pointerIdx);
        }
    } else if (event.getActionMasked() == MotionEvent.ACTION_UP
            || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
        if (mDraggingThumbs.size() > pointerIdx) {
            currThumb = mDraggingThumbs.get(pointerIdx);
        } //else we had a candidate but was never tracked
        else if (exactTouched != null && exactTouched.size() > 0) {
            currThumb = getMostMovableThumb(event);
            exactTouched = null;
        }
    }
    //        else {
    //            LinkedList<Thumb> closestOnes = getClosestThumb((int) event.getX());
    //            currThumb = closestOnes.getFirst();
    //        }

    switch (event.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        if (isInScrollingContainer() && mDraggingThumbs.size() == 0) {
            mTouchDownX = event.getX(pointerIdx);
        } else {
            onStartTrackingTouch(currThumb);
            setThumbValue(currThumb, getValue(event, currThumb), true);
            setHotspot(xx, yy, currThumb);
        }
        break;
    //with move we dont have pointer action so set them all
    case MotionEvent.ACTION_MOVE:
        if (mDraggingThumbs.contains(currThumb)) {
            //need the index
            for (int i = 0; i < mDraggingThumbs.size(); i++) {
                if (mDraggingThumbs.get(i) != null && mDraggingThumbs.get(i).getThumb() != null) {
                    invalidate(mDraggingThumbs.get(i).getThumb().getBounds());
                }
                setThumbValue(mDraggingThumbs.get(i), getValue(event, i, mDraggingThumbs.get(i)), true);

            }
            setHotspot(xx, yy, currThumb);
        } else {
            final float x = event.getX(pointerIdx);
            if (Math.abs(x - mTouchDownX) > mScaledTouchSlop) {
                onStartTrackingTouch(currThumb);
                exactTouched = null;
                setThumbValue(currThumb, getValue(event, currThumb), true);
                setHotspot(xx, yy, currThumb);
            }
        }

        break;

    case MotionEvent.ACTION_UP:
        setPressed(false);
        //there are other pointers left
    case MotionEvent.ACTION_POINTER_UP:
        if (currThumb != null) {
            boolean toUnPress = false;
            if (!isPressed()) {
                setPressed(true);
                toUnPress = true;
            }
            setThumbValue(currThumb, getValue(event, currThumb), true);
            setHotspot(xx, yy, currThumb);
            onStopTrackingTouch(currThumb);
            if (toUnPress) {
                setPressed(false);
            }
        } else {
            //                    currThumb = getClosestThumb(newValue);
            //                    // Touch up when we never crossed the touch slop threshold should
            //                    // be interpreted as a tap-seek to that location.
            //                    onStartTrackingTouch(currThumb);
            //                    setThumbValue(currThumb, newValue, true);
            //                    onStopTrackingTouch(currThumb);
        }
        // ProgressBar doesn't know to repaint the thumb drawable
        // in its inactive state when the touch stops (because the
        // value has not apparently changed)
        invalidate();
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mDraggingThumbs != null) {
            onStopTrackingTouch();
            setPressed(false);
        }
        invalidate(); // see above explanation
        break;
    }
    return true;
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
        mDownEvent = event;/*  www . j  a va2 s. c  o  m*/
        mElfAccelY = mThrustAccelY;
        if (!mElfIsHit) {
            updateElfThrust(1);
        }
        mJetThrustStream = mSoundPool.play(mJetThrustSound, 1.0f, 1.0f, 1, -1, 1.0f);
    } else if ((event.getActionMasked() == MotionEvent.ACTION_UP)
            || (event.getActionMasked() == MotionEvent.ACTION_CANCEL)) {
        mDownEvent = null;
        mElfAccelY = 0.0f;
        if (!mElfIsHit) {
            updateElfThrust(0);
        }
        if (mJetThrustStream > 0) {
            mSoundPool.stop(mJetThrustStream);
            mJetThrustStream = 0;
        }
    }

    //      return mGestureDetector.onTouchEvent(event);
    return true;
}