Example usage for android.view MotionEvent ACTION_MOVE

List of usage examples for android.view MotionEvent ACTION_MOVE

Introduction

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

Prototype

int ACTION_MOVE

To view the source code for android.view MotionEvent ACTION_MOVE.

Click Source Link

Document

Constant for #getActionMasked : A change has happened during a press gesture (between #ACTION_DOWN and #ACTION_UP ).

Usage

From source file:SwipeListView.java

/**
 * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent)
 */// w ww . ja v a2 s . c  om
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();

    if (isEnabled() && touchListener.isSwipeEnabled()) {

        if (touchState == TOUCH_STATE_SCROLLING_X) {
            return touchListener.onTouch(this, ev);
        }

        switch (action) {
        case MotionEvent.ACTION_MOVE:
            checkInMoving(x, y);
            return touchState == TOUCH_STATE_SCROLLING_Y;
        case MotionEvent.ACTION_DOWN:
            super.onInterceptTouchEvent(ev);
            touchListener.onTouch(this, ev);
            touchState = TOUCH_STATE_REST;
            lastMotionX = x;
            lastMotionY = y;
            return false;
        case MotionEvent.ACTION_CANCEL:
            touchState = TOUCH_STATE_REST;
            break;
        case MotionEvent.ACTION_UP:
            touchListener.onTouch(this, ev);
            return touchState == TOUCH_STATE_SCROLLING_Y;
        default:
            break;
        }
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:com.asiaonline.tobaccoassistant.widget.SwipeListView.java

/**
 * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent)
 *//*from   www .  ja va  2 s .c o m*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = MotionEventCompat.getActionMasked(ev);
    final float x = ev.getX();
    final float y = ev.getY();
    getParent().requestDisallowInterceptTouchEvent(true);
    if (isEnabled() && touchListener.isSwipeEnabled()) {

        if (touchState == TOUCH_STATE_SCROLLING_X) {
            return touchListener.onTouch(this, ev);
        }

        switch (action) {
        case MotionEvent.ACTION_MOVE:
            checkInMoving(x, y);
            return touchState == TOUCH_STATE_SCROLLING_Y;
        case MotionEvent.ACTION_DOWN:
            touchListener.onTouch(this, ev);
            touchState = TOUCH_STATE_REST;
            lastMotionX = x;
            lastMotionY = y;
            return false;
        case MotionEvent.ACTION_CANCEL:
            touchState = TOUCH_STATE_REST;
            break;
        case MotionEvent.ACTION_UP:
            touchListener.onTouch(this, ev);
            return touchState == TOUCH_STATE_SCROLLING_Y;
        default:
            break;
        }
    }

    return super.onInterceptTouchEvent(ev);
}

From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    // Return if animation is running
    if (mAnimator.isRunning())
        return true;
    // If is not idle state, return
    if (mScrollState != ViewPager.SCROLL_STATE_IDLE)
        return true;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // Action down touch
        mIsActionDown = true;/*from  www  . j a  va 2s.  c o m*/
        if (!mIsViewPagerMode)
            break;
        // Detect if we touch down on tab, later to move
        mIsTabActionDown = (int) (event.getX() / mTabSize) == mIndex;
        break;
    case MotionEvent.ACTION_MOVE:
        // If tab touched, so move
        if (mIsTabActionDown) {
            mViewPager.setCurrentItem((int) (event.getX() / mTabSize), true);
            break;
        }
        if (mIsActionDown)
            break;
    case MotionEvent.ACTION_UP:
        // Press up and set tab index relative to current coordinate
        if (mIsActionDown)
            setTabIndex((int) (event.getX() / mTabSize));
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
    default:
        // Reset action touch variables
        mIsTabActionDown = false;
        mIsActionDown = false;
        break;
    }

    return true;
}

From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java

@Override
public boolean onTouchEvent(MotionEvent ev) {

    final int action = ev.getAction();

    if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX)
            && !allowSlidingFromHereY(ev, mInitialY)) {
        return false;
    }//from w w  w  .j a  va 2 s  .c o m

    if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL
            || action == MotionEvent.ACTION_OUTSIDE) {
        mLastTouchAllowed = false;
    } else {
        mLastTouchAllowed = true;
    }

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(ev);

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        completeScroll();

        // Remember where the motion event started
        mLastX = mInitialX = ev.getX();
        mLastY = mInitialY = ev.getY();
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    case MotionEvent.ACTION_MOVE:
        if (!mIsDragging) {
            final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (pointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, pointerIndex);
            final float xDiff = Math.abs(x - mLastX);
            final float y = MotionEventCompat.getY(ev, pointerIndex);
            final float yDiff = Math.abs(y - mLastY);
            if (xDiff > mTouchSlop && xDiff > yDiff) {
                mIsDragging = true;
                mLastX = x;
                setDrawingCacheEnabled(true);
            } else if (yDiff > mTouchSlop && yDiff > xDiff) {
                mIsDragging = true;
                mLastY = y;
                setDrawingCacheEnabled(true);
            }
        }
        if (mIsDragging) {
            // Scroll to follow the motion event
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            if (activePointerIndex == -1) {
                mActivePointerId = INVALID_POINTER;
                break;
            }
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            if (mOnInteractListener != null) {
                mOnInteractListener.onActionMove(x, y);
            }
            final float deltaX = mLastX - x;
            final float deltaY = mLastY - y;
            mLastX = x;
            mLastY = y;
            final float oldScrollX = getScrollX();
            final float oldScrollY = getScrollY();
            float scrollX = oldScrollX + deltaX;
            float scrollY = oldScrollY + deltaY;

            // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]",
            // scrollX, scrollY));
            final float leftBound, rightBound;
            final float bottomBound, topBound;
            switch (mScreenSide) {
            case STICK_TO_LEFT:
                topBound = bottomBound = rightBound = 0;
                leftBound = getWidth(); // How far left we can scroll
                break;
            case STICK_TO_MIDDLE:
                topBound = getHeight();
                bottomBound = -getHeight();
                leftBound = getWidth();
                rightBound = -getWidth();
                break;
            case STICK_TO_RIGHT:
                rightBound = -getWidth();
                topBound = bottomBound = leftBound = 0;
                break;
            case STICK_TO_TOP:
                topBound = getHeight();
                bottomBound = rightBound = leftBound = 0;
                break;
            case STICK_TO_BOTTOM:
                topBound = rightBound = leftBound = 0;
                bottomBound = -getHeight();
                break;
            default:
                topBound = bottomBound = rightBound = leftBound = 0;
                break;
            }
            if (scrollX > leftBound) {
                scrollX = leftBound;
            } else if (scrollX < rightBound) {
                scrollX = rightBound;
            }
            if (scrollY > topBound) {
                scrollY = topBound;
            } else if (scrollY < bottomBound) {
                scrollY = bottomBound;
            }

            // TODO top/bottom bounds
            // Keep the precision
            mLastX += scrollX - (int) scrollX;
            mLastY += scrollY - (int) scrollY;
            scrollTo((int) scrollX, (int) scrollY);
        }
        break;
    case MotionEvent.ACTION_UP:

        if (mIsDragging) {

            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker,
                    mActivePointerId);
            final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker,
                    mActivePointerId);
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
            final float x = MotionEventCompat.getX(ev, activePointerIndex);
            final float y = MotionEventCompat.getY(ev, activePointerIndex);
            final int totalDeltaX = (int) (x - mInitialX);
            final int totalDeltaY = (int) (y - mInitialY);

            boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX,
                    initialVelocityY, totalDeltaX, totalDeltaY);

            boolean isControlled = false;
            if (isControlled) {
                break;
            }

            switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY);

            mActivePointerId = INVALID_POINTER;
            Log.d("", "end drag from action up");
            endDrag();
        } else if (mIsOpen && closeOnTapEnabled) {
            closeLayer(true);
        } else if (!mIsOpen && openOnTapEnabled) {
            openLayer(true);
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        if (mIsDragging) {
            switchLayer(mIsOpen, true, true);
            mActivePointerId = INVALID_POINTER;
            Log.d(TAG, "end drag from action cancel");
            endDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastX = MotionEventCompat.getX(ev, index);
        mLastY = MotionEventCompat.getY(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        onSecondaryPointerUp(ev);
        mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    if (mActivePointerId == INVALID_POINTER) {
        mLastTouchAllowed = false;
    }
    return true;
}

From source file:chenyoufu.hciprojectes10.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent event) {

    int action = MotionEventCompat.getActionMasked(event);
    int index = MotionEventCompat.getActionIndex(event);

    if (event.getPointerCount() > 1) {
        if (action == MotionEvent.ACTION_POINTER_UP && event.getPointerCount() == 2) {
            xOri = MotionEventCompat.getX(event, 1 - index);
            yOri = MotionEventCompat.getY(event, 1 - index);
        }//ww w  .  jav  a 2  s . c  o  m
        mScaleDetector.onTouchEvent(event);
    } else {
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            xOri = MotionEventCompat.getX(event, index);
            yOri = MotionEventCompat.getY(event, index);

            break;
        case MotionEvent.ACTION_MOVE:
            float xNow = MotionEventCompat.getX(event, index);
            float yNow = MotionEventCompat.getY(event, index);

            float[] xMove = Global.fArrayMul(Global.getCamCrossProductNV(), (xOri - xNow) / Global.moveFactor);
            Global.cameraEye = Global.fArrayAdd(Global.cameraEye, xMove);
            Global.cameraCentre = Global.fArrayAdd(Global.cameraCentre, xMove);
            float[] yMove = Global.fArrayMul(Global.cameraUp, (yNow - yOri) / Global.moveFactor);
            Global.cameraEye = Global.fArrayAdd(Global.cameraEye, yMove);
            Global.cameraCentre = Global.fArrayAdd(Global.cameraCentre, yMove);
            xOri = xNow;
            yOri = yNow;
            break;
        default:
            break;
        }
    }
    requestRender();
    return true;
}

From source file:com.code44.finance.views.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);//from   www.  java 2 s.com
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

    int motionPosition = pointToPosition((int) ev.getX(), (int) ev.getY());

    switch (action) {
    case MotionEvent.ACTION_DOWN:

        mVelocityTracker.clear();
        mScroller.abortAnimation();
        mLastTouchY = ev.getY();
        mLastTouchX = ev.getX();
        motionPosition = pointToPosition((int) mLastTouchX, (int) mLastTouchY);
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mTouchRemainderY = 0;

        if (mTouchMode != TOUCH_MODE_FLINGING && !mDataChanged && motionPosition >= 0
                && getAdapter().isEnabled(motionPosition)) {
            mTouchMode = TOUCH_MODE_DOWN;

            mBeginClick = true;

            if (mPendingCheckForTap == null) {
                mPendingCheckForTap = new CheckForTap();
            }

            postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
        }

        mMotionPosition = motionPosition;
        invalidate();
        break;

    case MotionEvent.ACTION_MOVE: {

        final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "onInterceptTouchEvent could not find pointer with id " + mActivePointerId
                    + " - did StaggeredGridView receive an inconsistent " + "event stream?");
            return false;
        }
        final float y = MotionEventCompat.getY(ev, index);
        final float dy = y - mLastTouchY + mTouchRemainderY;
        final int deltaY = (int) dy;
        mTouchRemainderY = dy - deltaY;

        if (Math.abs(dy) > mTouchSlop) {
            mTouchMode = TOUCH_MODE_DRAGGING;
        }

        if (mTouchMode == TOUCH_MODE_DRAGGING) {
            mLastTouchY = y;

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

        updateSelectorState();
    }
        break;

    case MotionEvent.ACTION_CANCEL:
        mTouchMode = TOUCH_MODE_IDLE;
        updateSelectorState();
        setPressed(false);
        View motionView = this.getChildAt(mMotionPosition - mFirstPosition);
        if (motionView != null) {
            motionView.setPressed(false);
        }
        final Handler handler = getHandler();
        if (handler != null) {
            handler.removeCallbacks(mPendingCheckForLongPress);
        }

        if (mTopEdge != null) {
            mTopEdge.onRelease();
            mBottomEdge.onRelease();
        }

        mTouchMode = TOUCH_MODE_IDLE;
        break;

    case MotionEvent.ACTION_UP: {
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
        final float velocity = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        final int prevTouchMode = mTouchMode;

        if (Math.abs(velocity) > mFlingVelocity) { // TODO
            mTouchMode = TOUCH_MODE_FLINGING;
            mScroller.fling(0, 0, 0, (int) velocity, 0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE);
            mLastTouchY = 0;
            invalidate();
        } else {
            mTouchMode = TOUCH_MODE_IDLE;
        }

        if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
            // TODO : handle
            mTouchMode = TOUCH_MODE_TAP;
        } else {
            mTouchMode = TOUCH_MODE_REST;
        }

        switch (prevTouchMode) {
        case TOUCH_MODE_DOWN:
        case TOUCH_MODE_TAP:
        case TOUCH_MODE_DONE_WAITING:
            final View child = getChildAt(motionPosition - mFirstPosition);
            final float x = ev.getX();
            final boolean inList = x > getPaddingLeft() && x < getWidth() - getPaddingRight();
            if (child != null && !child.hasFocusable() && inList) {
                if (mTouchMode != TOUCH_MODE_DOWN) {
                    child.setPressed(false);
                }

                if (mPerformClick == null) {
                    invalidate();
                    mPerformClick = new PerformClick();
                }

                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();

                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    final Handler handlerTouch = getHandler();
                    if (handlerTouch != null) {
                        handlerTouch.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ? mPendingCheckForTap
                                : mPendingCheckForLongPress);
                    }

                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;

                        layoutChildren(mDataChanged);
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchMode = TOUCH_MODE_REST;
                                child.setPressed(false);
                                setPressed(false);
                                if (!mDataChanged) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset, ViewConfiguration.getPressedStateDuration());

                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                    }
                    return true;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }

            mTouchMode = TOUCH_MODE_REST;
        }

        mBeginClick = false;

        updateSelectorState();
    }
        break;
    }
    return true;
}

From source file:com.ritesh.sevilla.EditDeliverAddressPhoneFields.VerifyPhoneFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.activity_edit_delivery_address, container, false);
    ButterKnife.bind(this, rootView);

    Appconstant.sh = getActivity().getSharedPreferences(Appconstant.MyPREFERENCES, Context.MODE_PRIVATE);
    User_ID = Appconstant.sh.getString("id", null);
    Log.e("User_ID from SharedPref :", "" + User_ID);

    /*textDotLoaderCountry = (DotLoader) rootView.findViewById(R.id.text_dot_loader_country);
    for (int i = 1; i < 4; i++) {/*from  w  ww  .j a  v a2 s.c o m*/
    textDotLoaderCountry.postDelayed(new DotIncrementRunnable(3 + i, textDotLoaderCountry), i * 3000);
    }
            
            
            
    textDotLoaderState = (DotLoader) rootView.findViewById(R.id.text_dot_loader_state);
    for (int i = 1; i < 4; i++) {
    textDotLoaderState.postDelayed(new DotIncrementRunnable(3 + i, textDotLoaderState), i * 3000);
    }
            
            
            
    textDotLoaderCity = (DotLoader) rootView.findViewById(R.id.text_dot_loader_city);
    for (int i = 1; i < 4; i++) {
    textDotLoaderCity.postDelayed(new DotIncrementRunnable(3 + i, textDotLoaderCity), i * 3000);
    }*/

    if (Utils.isConnected(getActivity())) {
        UserGetAddressJsontask task = new UserGetAddressJsontask();
        task.execute();
    } else {

        SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP).margin(15, 15)
                .backgroundDrawable(R.drawable.snackbar_custom_layout)
                .text("Please Your Internet Connectivity..!!"));

    }

    CPB_address_progressbar_circular = (CircularProgressBar) rootView
            .findViewById(R.id.cpb_address_progressbar_circular);
    //        signupProgress.setVisibility(View.GONE);
    ((CircularProgressDrawable) CPB_address_progressbar_circular.getIndeterminateDrawable()).start();
    updateValues();

    /*%%%%%%%%%%%%%%      Spinner Country (Start)        %%%%%%%%%%%%%%*/

    /*spinner click method and not clicked method for country (Start)*/
    SP_user_country.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {

        @Override
        public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
            SP_user_country.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            /*Toast.makeText(getActivity(), "Position :" + "  " + position + "  Clicked " + "" + item,
                Toast.LENGTH_SHORT).show();*/

            Log.e("Country Detail :",
                    "Position :" + "" + position + "\t" + "ID :" + "" + id + "\t" + "Name :" + "" + item);

            /*android.support.design.widget.Snackbar.make(view, "Clicked " + item,
                android.support.design.widget.Snackbar.LENGTH_SHORT).show();*/
            Get_user_country_SelectedValue = item;
            Str_get_user_country = item;
            Str_set_user_country = Str_get_user_country;
            long pos = id;
            int posi = position;
            Log.e("pos :", "" + pos);
            Log.e("posi ID:", "" + posi);
            GetSet_user_country_ID = String.valueOf(posi);
            Log.e("GetSet_user_country_ID :", "" + GetSet_user_country_ID);
            Log.e("Str_get_user_country :", "" + Str_get_user_country);
            Log.e("Str_set_user_country :", "" + Str_set_user_country);
            Log.e("Get_user_country_SelectedValue :", "" + Get_user_country_SelectedValue);

            if (Utils.isConnected(getActivity())) {
                UserStateListJsontask task = new UserStateListJsontask();
                task.execute();
            } else {

                SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                        .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                        .text("Please Your Internet Connectivity..!!"));

            }

        }
    });
    SP_user_country.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() {

        @Override
        public void onNothingSelected(MaterialSpinner spinner) {
            /*Toast.makeText(getActivity(), "Please select Country First..!!",
                Toast.LENGTH_SHORT).show();*/

            android.support.design.widget.Snackbar.make(spinner, "Please select Country First..!!",
                    android.support.design.widget.Snackbar.LENGTH_SHORT).show();

        }
    });
    /*%%%%%%%%%%%%%%      Spinner Country (End)        %%%%%%%%%%%%%%*/

    /*%%%%%%%%%%%%%%      Spinner State (Start)        %%%%%%%%%%%%%%*/
    SP_user_state.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {

        @Override
        public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
            SP_user_state.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            /*Toast.makeText(getActivity(), "Position :" + "  " + position + "  Clicked " + "" + item,
                Toast.LENGTH_SHORT).show();*/

            Log.e("State Detail :",
                    "Position :" + "" + position + "\t" + "ID :" + "" + id + "\t" + "Name :" + "" + item);

            /*android.support.design.widget.Snackbar.make(view, "Clicked " + item,
                android.support.design.widget.Snackbar.LENGTH_SHORT).show();*/
            Get_user_state_SelectedValue = item;
            Str_get_user_state = item;
            Str_set_user_state = Str_get_user_state;
            long pos = id;
            int posi = position;
            Log.e("pos :", "" + pos);
            Log.e("posi ID:", "" + posi);
            GetSet_user_state_ID = String.valueOf(posi);
            Log.e("GetSet_user_state_ID :", "" + GetSet_user_state_ID);
            Log.e("Str_get_user_state :", "" + Str_get_user_state);
            Log.e("Str_set_user_state :", "" + Str_set_user_state);

            if (Utils.isConnected(getActivity())) {
                UserCityListJsontask task = new UserCityListJsontask();
                task.execute();
            } else {

                SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                        .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                        .text("Please Your Internet Connectivity..!!"));

            }

        }
    });
    SP_user_state.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() {

        @Override
        public void onNothingSelected(MaterialSpinner spinner) {
            /*Toast.makeText(getActivity(), "Please select Country First..!!",
                Toast.LENGTH_SHORT).show();*/

            android.support.design.widget.Snackbar.make(spinner, "Please select State First..!!",
                    android.support.design.widget.Snackbar.LENGTH_SHORT).show();

        }
    });
    /*%%%%%%%%%%%%%%      Spinner State (End)        %%%%%%%%%%%%%%*/

    /*%%%%%%%%%%%%%%      Spinner City (Start)        %%%%%%%%%%%%%%*/
    SP_user_city.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener<String>() {

        @Override
        public void onItemSelected(MaterialSpinner view, int position, long id, String item) {
            SP_user_city.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
            /*Toast.makeText(getActivity(), "Position :" + "  " + position + "  Clicked " + "" + item,
                Toast.LENGTH_SHORT).show();*/

            Log.e("City Detail :",
                    "Position :" + "" + position + "\t" + "ID :" + "" + id + "\t" + "Name :" + "" + item);

            /*android.support.design.widget.Snackbar.make(view, "Clicked " + item,
                android.support.design.widget.Snackbar.LENGTH_SHORT).show();*/

            Get_user_city_SelectedValue = item;
            Str_get_user_city = item;
            Str_set_user_city = Str_get_user_city;
            Log.e("Get_user_city_SelectedValue :", "" + Get_user_city_SelectedValue);
            Log.e("Str_get_user_city :", "" + Str_get_user_city);
            Log.e("Str_set_user_city :", "" + Str_set_user_city);

        }
    });
    SP_user_city.setOnNothingSelectedListener(new MaterialSpinner.OnNothingSelectedListener() {

        @Override
        public void onNothingSelected(MaterialSpinner spinner) {
            /*Toast.makeText(getActivity(), "Please select Country First..!!",
                Toast.LENGTH_SHORT).show();*/

            android.support.design.widget.Snackbar.make(spinner, "Please select City First..!!",
                    android.support.design.widget.Snackbar.LENGTH_SHORT).show();

        }
    });
    /*%%%%%%%%%%%%%%      Spinner City (End)        %%%%%%%%%%%%%%*/

    CV_et_address_continue_payment.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            Str_set_user_f_name = ET_address_user_first_name.getText().toString().trim();
            Str_set_user_l_name = ET_address_user_last_name.getText().toString().trim();
            Str_set_user_street_address = ET_address_user_address.getText().toString().trim();
            Str_set_user_phone = ET_address_phone.getText().toString().trim();
            Str_set_user_phone_replace = Str_set_user_phone.replace(" ", "");
            Str_set_user_zip_code = ET_address_user_zip_code.getText().toString().trim();

            Log.e("Address Data :",
                    "\n" + "Str_set_user_f_name :" + "" + Str_set_user_f_name + "\n" + "Str_set_user_l_name :"
                            + "" + Str_set_user_l_name + "\n" + "Str_set_user_street_address :" + ""
                            + Str_set_user_street_address + "\n" + "Str_set_user_phone :" + ""
                            + Str_set_user_phone + "\n" + "Str_set_user_phone_replace :" + ""
                            + Str_set_user_phone_replace + "\n" + "Str_set_user_zip_code :" + ""
                            + Str_set_user_zip_code + "\n" + "Str_set_user_country :" + ""
                            + Str_set_user_country + "\n" + "Str_set_user_state :" + "" + Str_set_user_state
                            + "\n" + "Str_set_user_city :" + "" + Str_set_user_city + "\n");

            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                Log.e("Action ", "Down");
                CV_et_address_continue_payment_click.setVisibility(View.VISIBLE);
                CV_et_address_continue_payment.setVisibility(View.GONE);
                v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);

                //                    Toast.makeText(getApplicationContext(), "Add to cart Clicked", Toast.LENGTH_SHORT).show();
                return true;
            }

            if (event.getAction() == MotionEvent.ACTION_MOVE) {

                Log.e("Action ", "Move");
                CV_et_address_continue_payment_click.setVisibility(View.VISIBLE);
                CV_et_address_continue_payment.setVisibility(View.GONE);
                return true;

            }
            if (event.getAction() == MotionEvent.ACTION_UP) {

                Log.e("Action ", "Up");

                CV_et_address_continue_payment_click.setVisibility(View.GONE);
                CV_et_address_continue_payment.setVisibility(View.VISIBLE);
                /*Intent MyCartPage = new Intent(GetDeliveryAddress.this, MyCartActivity.class);
                startActivity(MyCartPage);*/

                if (Str_set_user_f_name.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_first_name);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please enter your First Name"));

                } else if (Str_set_user_l_name.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_last_name);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please enter your Last Name"));

                } else if (Str_set_user_street_address.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_address);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please enter your Street Address"));

                } else if (Str_set_user_phone_replace.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_phone);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please enter your Phone Number"));

                } else if (Str_set_user_country.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(SP_user_country);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please select your Country"));

                } else if (Str_set_user_state.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(SP_user_state);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please select your State"));

                } else if (Str_set_user_city.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);

                    /**************** Start Animation ***************/
                    YoYo.with(Techniques.Tada).duration(700).playOn(SP_user_city);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please select your City"));

                } else if (Str_set_user_zip_code.isEmpty()) {
                    ISerror = true;
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    //                    v.playSoundEffect(SoundEffectConstants.CLICK);
                    /**************** Start Animation **************  **/
                    YoYo.with(Techniques.Tada).duration(700).playOn(ET_address_user_zip_code);
                    /**************** End Animation ****************/

                    /*Toast.makeText(getApplicationContext(),
                    "Please enter your Email Id", Toast.LENGTH_SHORT).show();*/

                    SnackbarManager.show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Please enter your area code"));

                } else if (!ISerror) {

                    //                        v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                    /*Toast.makeText(getApplicationContext(),
                    "Good", Toast.LENGTH_SHORT).show();*/

                    if (Utils.isConnected(getActivity())) {
                        UserUpdateAddressJsontask task = new UserUpdateAddressJsontask();
                        task.execute();
                    } else {

                        SnackbarManager
                                .show(Snackbar.with(getActivity()).position(Snackbar.SnackbarPosition.TOP)
                                        .margin(15, 15).backgroundDrawable(R.drawable.snackbar_custom_layout)
                                        .text("Please Your Internet Connectivity..!!"));

                    }
                    /*
                    SnackbarManager.show(
                        Snackbar.with(getActivity())
                                .position(Snackbar.SnackbarPosition.TOP)
                                .margin(15, 15)
                                .backgroundDrawable(R.drawable.snackbar_custom_layout)
                                .text("Good All Value Correct"));*/

                    //                    v.playSoundEffect(android.view.SoundEffectConstants.CLICK);

                }

                /*SnackbarManager.show(
                    Snackbar.with(getActivity())
                            .position(Snackbar.SnackbarPosition.TOP)
                            .margin(15, 15)
                            .backgroundDrawable(R.drawable.snackbar_custom_layout)
                            .text("Confirm Clicked"));
                */
                return true;
            }

            return false;
        }
    });

    initUI(rootView);
    return rootView;
}

From source file:at.ac.uniklu.mobile.sportal.ui.viewpagerindicator.TitlePageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }//from   w w w.ja v a  2  s. c  om

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            if (!mViewPager.isFakeDragging()) {
                mViewPager.beginFakeDrag();
            }

            mLastMotionX = x;

            mViewPager.fakeDragBy(deltaX);
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            final float leftThird = halfWidth - sixthWidth;
            final float rightThird = halfWidth + sixthWidth;
            final float eventX = ev.getX();

            if (eventX < leftThird) {
                if (mCurrentPage > 0) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                    return true;
                }
            } else if (eventX > rightThird) {
                if (mCurrentPage < count - 1) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                    return true;
                }
            } else {
                //Middle third
                if (mCenterItemClickListener != null) {
                    mCenterItemClickListener.onCenterItemClick(mCurrentPage);
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastMotionX = x;
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.orbar.pxdemo.ImageView.FivePXImageFragment.java

private void setupMap(String latitude, String longitude, String imageName, String imageDescription) {

    map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();

    // get references to transparent image and ScrollView
    final ScrollView mainScrollView = (ScrollView) rootView.findViewById(R.id.image_details_scrollView);
    ImageView transparentImageView = (ImageView) rootView.findViewById(R.id.transparent_image);

    // allows scrolling on the map independently of the scrollView
    transparentImageView.setOnTouchListener(new View.OnTouchListener() {

        @Override/* w  ww. java 2s. c o m*/
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();

            switch (action) {
            case MotionEvent.ACTION_DOWN:
                // Disallow ScrollView to intercept touch events.
                mainScrollView.requestDisallowInterceptTouchEvent(true);
                // Disable touch on transparent view
                return false;

            case MotionEvent.ACTION_UP:
                // Allow ScrollView to intercept touch events.
                mainScrollView.requestDisallowInterceptTouchEvent(false);
                return true;

            case MotionEvent.ACTION_MOVE:
                mainScrollView.requestDisallowInterceptTouchEvent(true);
                return false;

            default:
                return true;
            }
        }

    });

    LatLng imageLocation = new LatLng(Double.valueOf(latitude), Double.valueOf(longitude));
    LatLng mapCenter = new LatLng(Double.valueOf(latitude) - 1, Double.valueOf(longitude));

    map.addMarker(new MarkerOptions().position(imageLocation).snippet(imageDescription).title(imageName));

    // Move the camera instantly to position with a zoom of 6.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapCenter, 6));

}

From source file:com.alibaba.akita.widget.TitlePageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from ww  w .  j  av a2s  .c  o  m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction();

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            if (!mViewPager.isFakeDragging()) {
                mViewPager.beginFakeDrag();
            }

            mLastMotionX = x;
            try {
                mViewPager.fakeDragBy(deltaX);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            final float leftThird = halfWidth - sixthWidth;
            final float rightThird = halfWidth + sixthWidth;
            final float eventX = ev.getX();

            if (eventX < leftThird) {
                if (mCurrentPage > 0) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                    return true;
                }
            } else if (eventX > rightThird) {
                if (mCurrentPage < count - 1) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                    return true;
                }
            } else {
                //Middle third
                if (mCenterItemClickListener != null) {
                    mCenterItemClickListener.onCenterItemClick(mCurrentPage);
                }
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging()) {
            try {
                mViewPager.endFakeDrag();
            } catch (NullPointerException npe) {
                npe.printStackTrace(); // fix a crash report.
            }
        }
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        final float x = MotionEventCompat.getX(ev, index);
        mLastMotionX = x;
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}