Example usage for android.view MotionEvent getPointerCount

List of usage examples for android.view MotionEvent getPointerCount

Introduction

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

Prototype

public final int getPointerCount() 

Source Link

Document

The number of pointers of data contained in this event.

Usage

From source file:com.ywesee.amiko.MainActivity.java

/**
 * Gesture detector for expert-info webview
 * @param webView/*from  www  .ja v  a 2  s. c  o  m*/
 */
private void setupGestureDetector(WebView webView) {
    GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
            if (event1 == null || event2 == null)
                return false;
            if (event1.getPointerCount() > 1 || event2.getPointerCount() > 1)
                return false;
            else {
                try {
                    // right to left swipe... return to mSuggestView
                    // float diffX = event1.getX()-event2.getX();
                    // left to right swipe... return to mSuggestView
                    float diffX = event2.getX() - event1.getX();
                    if (diffX > 120 && Math.abs(velocityX) > 300) {
                        setSuggestView();
                        return true;
                    }
                } catch (Exception e) {
                    // Handle exceptions...
                }
                return false;
            }
        }
    };

    final GestureDetector detector = new GestureDetector(this, simpleOnGestureListener);

    webView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (detector.onTouchEvent(event))
                return true;
            hideSoftKeyboard(50);
            return false;
        }
    });
}

From source file:info.tellmetime.TellmetimeActivity.java

/**
 * Processes touch events for FrameLayout overlaying whole activity.
 *
 * If the touch was not on the panel then it changes background color according to the touch
 * position as long as the touch event was recognized as a movement,
 * or toggles panel visibility if it was a tap.
 *
 * @return true if the touch event was consumed.
 *//*  w  ww. j  av  a 2  s.co m*/
@Override
public boolean onTouch(View view, MotionEvent event) {
    // Coordinates of current touch point.
    final float rawX = event.getRawX();
    final float rawY = event.getRawY();

    switch (MotionEventCompat.getActionMasked(event)) {
    case (MotionEvent.ACTION_DOWN):
        // This action signals that a new touch gesture begins, so we cache its starting point.
        mStartX = rawX;
        mStartY = rawY;

        // Schedule a Runnable to run in 1 second.
        mLongPressHandler.postDelayed(mLongPressed, 1000);

        return true;
    case (MotionEvent.ACTION_MOVE):
        // Distance between starting point and current one.
        final double distance = Math.sqrt(Math.pow(rawX - mStartX, 2) + Math.pow(rawY - mStartY, 2));

        if (distance > mTouchSlop) {
            // If the user exceeded the slop value, then we start to track the movement.
            isSlopped = true;

            // Cancel scheduled Runnable.
            mLongPressHandler.removeCallbacks(mLongPressed);

            if (mHider.isVisible()) {
                // Hide panel to present only the clock.
                mHider.hide();
            } else {
                if (mBackgroundMode != MODE_BACKGROUND_SOLID)
                    return true;

                // Change the background color according to the touch position.

                if (event.getPointerCount() > 1) {
                    // If the user is using more than one finger, then we change saturation.

                    // Saturation depends on top <-> bottom movement of second finger.
                    mHSV[1] = MotionEventCompat.getY(event, 1) / mScreenHeight;
                } else {
                    // If it's a single finger gesture, then we change hue and value.

                    // Hue depends on left <-> right movement.
                    mHSV[0] = (float) Math.floor(rawX / mScreenWidth * 360);
                    // Value depends on up <-> down movement.
                    mHSV[2] = rawY / mScreenHeight;
                }

                mBackgroundColor = Color.HSVToColor(mHSV);
                mSurface.setBackgroundColor(mBackgroundColor);
            }
        } else {
            // If required distance is not exceeded, we only unset the slop flag.
            isSlopped = false;
        }

        return true;
    case (MotionEvent.ACTION_UP):
        mLongPressHandler.removeCallbacks(mLongPressed);

        // This action ends every touch interaction, so if the event was just a tap,
        // i.e. distance hasn't exceed the slop value, then it concerns panel.

        if (!isSlopped && !wasModeToggled) {
            // If the touch gesture was just a tap then toggle panel visibility.
            mHider.toggle();
        }

        // As the gesture ended, we need to unset the slop and toggle flag.
        isSlopped = false;
        wasModeToggled = false;

        return true;
    case (MotionEvent.ACTION_POINTER_UP):
        // Action occurs when second or farther finger goes up.

        isSlopped = true;

        return true;
    default:
        return super.onTouchEvent(event);
    }
}

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  w  w.  ja va 2 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:com.juick.android.MessagesFragment.java

public Boolean maybeInterceptTouchEventFromActivity(MotionEvent event) {
    if (rightScrollBound == 0) {
        Log.w("JAGP", "rightScrollBound == 0");
        return null;
    }//from w ww .  ja  va 2  s  .  co  m
    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:com.doubleTwist.drawerlib.ADrawerLayout.java

private int preProcessScrollMotionEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (DEBUG_TOUCH)
            Log.d(TAG, "DOWN: " + ev.getX(0) + "," + ev.getY(0));
        if (!mIsScrolling) {
            mVelocityTracker.clear();/*from   www .  jav  a2  s.  co  m*/
            mDownEvent.mCoords.x = ev.getX(0);
            mDownEvent.mCoords.y = ev.getY(0);
            mDownEvent.mPointerId = ev.getPointerId(0);
            if (DEBUG_TOUCH)
                Log.d(TAG, "SAVED: " + ev.getX(0) + "," + ev.getY(0));
        }
        break;
    case MotionEvent.ACTION_MOVE: {
        final int ptrIdx = ev.findPointerIndex(mDownEvent.mPointerId);
        if (ptrIdx < 0 || ptrIdx >= ev.getPointerCount())
            return -1;

        if (DEBUG_TOUCH)
            Log.d(TAG, "MOVE: " + ev.getX(ptrIdx) + "," + ev.getY(ptrIdx));
        if (mIsScrolling) {
            return mDrawerState.mActiveDrawer;
        }

        // If the user has dragged her finger horizontally more than
        // the touch slop, start the scroll

        final float xDiff = calculateDistanceX(ev, mDownEvent);
        final float yDiff = calculateDistanceY(ev, mDownEvent);
        final float dxAbs = Math.abs(xDiff);
        final float dyAbs = Math.abs(yDiff);

        if (DEBUG_TOUCH) {
            Log.d(TAG, "xDiff: " + xDiff + " -- " + ev.getX(ptrIdx) + " -- " + mDownEvent.mCoords.x);
            Log.d(TAG, "xDiff/yDiff/dxAbs/dyAbs: " + xDiff + "/" + yDiff + "/" + dxAbs + "/" + dyAbs);
            Log.d(TAG, "canScrollX/canScrollY: " + canScroll(MotionEvent.AXIS_X, xDiff) + "/"
                    + canScroll(MotionEvent.AXIS_Y, yDiff));
            Log.d(TAG, "activeDrawer/scrollState: " + mDrawerState.mActiveDrawer + "/"
                    + mDrawerState.mScrollState);
        }

        if (dxAbs > dyAbs && dxAbs > mTouchSlop && canScroll(MotionEvent.AXIS_X, xDiff)) {
            if (DEBUG_TOUCH)
                Log.d(TAG, "X axis branch");
            int drawer;
            if (mDrawerState.mActiveDrawer == NO_DRAWER)
                drawer = xDiff > 0 ? LEFT_DRAWER : RIGHT_DRAWER;
            else
                drawer = mDrawerState.mActiveDrawer;
            if (!isInitialPositionValidForDrawer(mDownEvent, drawer))
                drawer = -1;
            return drawer;
        }

        if (dyAbs > dxAbs && dyAbs > mTouchSlop && canScroll(MotionEvent.AXIS_Y, yDiff)) {
            if (DEBUG_TOUCH)
                Log.d(TAG, "Y axis branch");
            int drawer;
            if (mDrawerState.mActiveDrawer == NO_DRAWER)
                drawer = yDiff > 0 ? TOP_DRAWER : BOTTOM_DRAWER;
            else
                drawer = mDrawerState.mActiveDrawer;

            if (!isInitialPositionValidForDrawer(mDownEvent, drawer))
                drawer = -1;
            return drawer;
        }

        break;
    }
    }
    return -1;
}

From source file:xiaofan.llongimageview.view.SubsamplingScaleImageView.java

/**
 * Handle touch events. One finger pans, and two finger pinch and zoom plus panning.
 *///from w ww .  ja  va  2  s.co m
@Override
public boolean onTouchEvent(MotionEvent event) {
    PointF vCenterEnd;
    float vDistEnd;
    // During non-interruptible anims, ignore all touch events
    if (anim != null && !anim.interruptible) {
        getParent().requestDisallowInterceptTouchEvent(true);
        return true;
    } else {
        anim = null;
    }

    // Abort if not ready
    if (vTranslate == null) {
        return true;
    }
    // Detect flings, taps and double taps
    if (detector == null || detector.onTouchEvent(event)) {
        return true;
    }

    int touchCount = event.getPointerCount();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_1_DOWN:
    case MotionEvent.ACTION_POINTER_2_DOWN:
        anim = null;
        getParent().requestDisallowInterceptTouchEvent(true);
        maxTouchCount = Math.max(maxTouchCount, touchCount);
        if (touchCount >= 2) {
            if (zoomEnabled) {
                // Start pinch to zoom. Calculate distance between touch points and center point of the pinch.
                float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                scaleStart = scale;
                vDistStart = distance;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                vCenterStart = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);
            } else {
                // Abort all gestures on second touch
                maxTouchCount = 0;
            }
            // Cancel long click timer
            handler.removeMessages(MESSAGE_LONG_CLICK);
        } else {
            // Start one-finger pan
            vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
            vCenterStart = new PointF(event.getX(), event.getY());

            // Start long click timer
            handler.sendEmptyMessageDelayed(MESSAGE_LONG_CLICK, 600);
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        boolean consumed = false;
        if (maxTouchCount > 0) {
            if (touchCount >= 2) {
                // Calculate new distance between touch points, to scale and pan relative to start values.
                vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                vCenterEnd = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);

                if (zoomEnabled && (distance(vCenterStart.x, vCenterEnd.x, vCenterStart.y, vCenterEnd.y) > 5
                        || Math.abs(vDistEnd - vDistStart) > 5 || isPanning)) {
                    isZooming = true;
                    isPanning = true;
                    consumed = true;

                    scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart);

                    if (scale <= minScale()) {
                        // Minimum scale reached so don't pan. Adjust start settings so any expand will zoom in.
                        vDistStart = vDistEnd;
                        scaleStart = minScale();
                        vCenterStart = vCenterEnd;
                        vTranslateStart = vTranslate;
                    } else if (panEnabled) {
                        // Translate to place the source image coordinate that was at the center of the pinch at the start
                        // at the center of the pinch now, to give simultaneous pan + zoom.
                        float vLeftStart = vCenterStart.x - vTranslateStart.x;
                        float vTopStart = vCenterStart.y - vTranslateStart.y;
                        float vLeftNow = vLeftStart * (scale / scaleStart);
                        float vTopNow = vTopStart * (scale / scaleStart);
                        vTranslate.x = vCenterEnd.x - vLeftNow;
                        vTranslate.y = vCenterEnd.y - vTopNow;
                    } else if (sRequestedCenter != null) {
                        // With a center specified from code, zoom around that point.
                        vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x);
                        vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y);
                    } else {
                        // With no requested center, scale around the image center.
                        vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2));
                        vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2));
                    }

                    fitToBounds(true);
                    refreshRequiredTiles(false);
                }
            } else if (!isZooming) {
                // One finger pan - translate the image. We do this calculation even with pan disabled so click
                // and long click behaviour is preserved.
                float dx = Math.abs(event.getX() - vCenterStart.x);
                float dy = Math.abs(event.getY() - vCenterStart.y);
                if (dx > 5 || dy > 5 || isPanning) {
                    consumed = true;
                    vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x);
                    vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y);

                    float lastX = vTranslate.x;
                    float lastY = vTranslate.y;
                    fitToBounds(true);
                    if (lastX == vTranslate.x || (lastY == vTranslate.y && dy > 10) || isPanning) {
                        isPanning = true;
                    } else if (dx > 5) {
                        // Haven't panned the image, and we're at the left or right edge. Switch to page swipe.
                        maxTouchCount = 0;
                        handler.removeMessages(MESSAGE_LONG_CLICK);
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    if (!panEnabled) {
                        vTranslate.x = vTranslateStart.x;
                        vTranslate.y = vTranslateStart.y;
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    refreshRequiredTiles(false);
                }
            }
        }
        if (consumed) {
            handler.removeMessages(MESSAGE_LONG_CLICK);
            invalidate();
            return true;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_POINTER_2_UP:
        handler.removeMessages(MESSAGE_LONG_CLICK);
        if (maxTouchCount > 0 && (isZooming || isPanning)) {
            if (isZooming && touchCount == 2) {
                // Convert from zoom to pan with remaining touch
                isPanning = true;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                if (event.getActionIndex() == 1) {
                    vCenterStart = new PointF(event.getX(0), event.getY(0));
                } else {
                    vCenterStart = new PointF(event.getX(1), event.getY(1));
                }
            }
            if (touchCount < 3) {
                // End zooming when only one touch point
                isZooming = false;
            }
            if (touchCount < 2) {
                // End panning when no touch points
                isPanning = false;
                maxTouchCount = 0;
            }
            // Trigger load of tiles now required
            refreshRequiredTiles(true);
            return true;
        }
        if (touchCount == 1) {
            isZooming = false;
            isPanning = false;
            maxTouchCount = 0;
        }
        return true;
    }
    return super.onTouchEvent(event);
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

private boolean isOpenQsEvent(MotionEvent event) {
    final int pointerCount = event.getPointerCount();
    final int action = event.getActionMasked();

    final boolean twoFingerDrag = action == MotionEvent.ACTION_POINTER_DOWN && pointerCount == 2;

    final boolean stylusButtonClickDrag = action == MotionEvent.ACTION_DOWN
            && (event.isButtonPressed(MotionEvent.BUTTON_STYLUS_PRIMARY)
                    || event.isButtonPressed(MotionEvent.BUTTON_STYLUS_SECONDARY));

    final boolean mouseButtonClickDrag = action == MotionEvent.ACTION_DOWN
            && (event.isButtonPressed(MotionEvent.BUTTON_SECONDARY)
                    || event.isButtonPressed(MotionEvent.BUTTON_TERTIARY));
    boolean isOverride = true;

    return twoFingerDrag || isOverride || stylusButtonClickDrag || mouseButtonClickDrag;
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

private float getAverageY(MotionEvent me) {
    int count = me.getPointerCount();
    float focusY = 0;
    for (int i = 0; i < count; i++) {
        focusY += me.getY(i);/*w w  w . j  a  va 2  s . c  o m*/
    }
    focusY /= count;
    return focusY;
}

From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java

/**
 * Handle touch events. One finger pans, and two finger pinch and zoom plus
 * panning./*w w  w .j  a  v  a2 s . c o m*/
 */
@Override
public boolean onTouchEvent(MotionEvent event) {
    PointF vCenterEnd;
    float vDistEnd;
    // During non-interruptible anims, ignore all touch events
    if (anim != null && !anim.interruptible) {
        getParent().requestDisallowInterceptTouchEvent(true);
        return true;
    } else {
        anim = null;
    }

    // Abort if not ready
    if (vTranslate == null) {
        return true;
    }
    // Detect flings, taps and double taps
    if (detector == null || detector.onTouchEvent(event)) {
        return true;
    }

    int touchCount = event.getPointerCount();
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_1_DOWN:
    case MotionEvent.ACTION_POINTER_2_DOWN:
        anim = null;
        getParent().requestDisallowInterceptTouchEvent(true);
        maxTouchCount = Math.max(maxTouchCount, touchCount);
        if (touchCount >= 2) {
            if (zoomEnabled) {
                // Start pinch to zoom. Calculate distance between touch
                // points and center point of the pinch.
                float distance = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                scaleStart = scale;
                vDistStart = distance;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                vCenterStart = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);
            } else {
                // Abort all gestures on second touch
                maxTouchCount = 0;
            }
            // Cancel long click timer
            handler.removeMessages(MESSAGE_LONG_CLICK);
        } else {
            // Start one-finger pan
            vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
            vCenterStart = new PointF(event.getX(), event.getY());

            // Start long click timer
            handler.sendEmptyMessageDelayed(MESSAGE_LONG_CLICK, 600);
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        boolean consumed = false;
        if (maxTouchCount > 0) {
            if (touchCount >= 2) {
                // Calculate new distance between touch points, to scale and
                // pan relative to start values.
                vDistEnd = distance(event.getX(0), event.getX(1), event.getY(0), event.getY(1));
                vCenterEnd = new PointF((event.getX(0) + event.getX(1)) / 2,
                        (event.getY(0) + event.getY(1)) / 2);

                if (zoomEnabled && (distance(vCenterStart.x, vCenterEnd.x, vCenterStart.y, vCenterEnd.y) > 5
                        || Math.abs(vDistEnd - vDistStart) > 5 || isPanning)) {
                    isZooming = true;
                    isPanning = true;
                    consumed = true;

                    scale = Math.min(maxScale, (vDistEnd / vDistStart) * scaleStart);

                    if (scale <= minScale()) {
                        // Minimum scale reached so don't pan. Adjust start
                        // settings so any expand will zoom in.
                        vDistStart = vDistEnd;
                        scaleStart = minScale();
                        vCenterStart = vCenterEnd;
                        vTranslateStart = vTranslate;
                    } else if (panEnabled) {
                        // Translate to place the source image coordinate
                        // that was at the center of the pinch at the start
                        // at the center of the pinch now, to give
                        // simultaneous pan + zoom.
                        float vLeftStart = vCenterStart.x - vTranslateStart.x;
                        float vTopStart = vCenterStart.y - vTranslateStart.y;
                        float vLeftNow = vLeftStart * (scale / scaleStart);
                        float vTopNow = vTopStart * (scale / scaleStart);
                        vTranslate.x = vCenterEnd.x - vLeftNow;
                        vTranslate.y = vCenterEnd.y - vTopNow;
                    } else if (sRequestedCenter != null) {
                        // With a center specified from code, zoom around
                        // that point.
                        vTranslate.x = (getWidth() / 2) - (scale * sRequestedCenter.x);
                        vTranslate.y = (getHeight() / 2) - (scale * sRequestedCenter.y);
                    } else {
                        // With no requested center, scale around the image
                        // center.
                        vTranslate.x = (getWidth() / 2) - (scale * (sWidth() / 2));
                        vTranslate.y = (getHeight() / 2) - (scale * (sHeight() / 2));
                    }

                    fitToBounds(true);
                    refreshRequiredTiles(false);
                }
            } else if (!isZooming) {
                // One finger pan - translate the image. We do this
                // calculation even with pan disabled so click
                // and long click behaviour is preserved.
                float dx = Math.abs(event.getX() - vCenterStart.x);
                float dy = Math.abs(event.getY() - vCenterStart.y);
                if (dx > 5 || dy > 5 || isPanning) {
                    consumed = true;
                    vTranslate.x = vTranslateStart.x + (event.getX() - vCenterStart.x);
                    vTranslate.y = vTranslateStart.y + (event.getY() - vCenterStart.y);

                    float lastX = vTranslate.x;
                    float lastY = vTranslate.y;
                    fitToBounds(true);
                    if (lastX == vTranslate.x || (lastY == vTranslate.y && dy > 10) || isPanning) {
                        isPanning = true;
                    } else if (dx > 5) {
                        // Haven't panned the image, and we're at the left
                        // or right edge. Switch to page swipe.
                        maxTouchCount = 0;
                        handler.removeMessages(MESSAGE_LONG_CLICK);
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    if (!panEnabled) {
                        vTranslate.x = vTranslateStart.x;
                        vTranslate.y = vTranslateStart.y;
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }

                    refreshRequiredTiles(false);
                }
            }
        }
        if (consumed) {
            handler.removeMessages(MESSAGE_LONG_CLICK);
            invalidate();
            return true;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_POINTER_2_UP:
        handler.removeMessages(MESSAGE_LONG_CLICK);
        if (maxTouchCount > 0 && (isZooming || isPanning)) {
            if (isZooming && touchCount == 2) {
                // Convert from zoom to pan with remaining touch
                isPanning = true;
                vTranslateStart = new PointF(vTranslate.x, vTranslate.y);
                if (event.getActionIndex() == 1) {
                    vCenterStart = new PointF(event.getX(0), event.getY(0));
                } else {
                    vCenterStart = new PointF(event.getX(1), event.getY(1));
                }
            }
            if (touchCount < 3) {
                // End zooming when only one touch point
                isZooming = false;
            }
            if (touchCount < 2) {
                // End panning when no touch points
                isPanning = false;
                maxTouchCount = 0;
            }
            // Trigger load of tiles now required
            refreshRequiredTiles(true);
            return true;
        }
        if (touchCount == 1) {
            isZooming = false;
            isPanning = false;
            maxTouchCount = 0;
        }
        return true;
    }
    return super.onTouchEvent(event);
}

From source file:xyz.zpayh.hdimage.HDImageView.java

@Override
@SuppressWarnings("deprecation")
public boolean onTouchEvent(MotionEvent event) {

    if (mValueAnimator != null && !mValueAnimator.isInterrupted()) {
        // ??,?//ww  w .  java 2s .  c  o  m
        getParent().requestDisallowInterceptTouchEvent(true);
        return true;
    }

    stopAnimator();

    // 
    if (mViewTranslate == null) {
        return true;
    }

    //?
    if (mFlingDetector.onTouchEvent(event)) {
        //??mDetector?
        mIsZooming = false;
        mIsPanning = false;
        mMaxTouchCount = 0;
        return true;
    }

    if (mClickDetector.onTouchEvent(event)) {
        mIsZooming = false;
        mIsPanning = false;
        mMaxTouchCount = 0;
        return true;
    }

    if (mLongPressDetector.onTouchEvent(event)) {
        mIsZooming = false;
        mIsPanning = false;
        mMaxTouchCount = 0;
        return true;
    }

    final int touchCount = event.getPointerCount();
    switch (event.getAction()) {
    case ACTION_DOWN:
    case ACTION_POINTER_1_DOWN:
    case ACTION_POINTER_2_DOWN:
        down(event, touchCount);
        return true;
    case ACTION_MOVE:
        boolean consumed = move(event, touchCount);
        if (consumed) {
            invalidate();
            return true;
        }
        break;
    case ACTION_UP:
    case ACTION_POINTER_UP:
    case ACTION_POINTER_2_UP:
        if (up(event, touchCount))
            return true;
        return true;
    }

    return super.onTouchEvent(event);
}