Example usage for android.view MotionEvent ACTION_UP

List of usage examples for android.view MotionEvent ACTION_UP

Introduction

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

Prototype

int ACTION_UP

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

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.

Usage

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

/**
 * @see android.widget.ListView#onInterceptTouchEvent(android.view.MotionEvent)
 *///from w  ww  .  ja  v  a2  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.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 a  2 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:cn.iterlog.myapplication.widget.overscroll.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);/*from  w  w  w  . j a  v a 2  s.c om*/
    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 && mAdapter != null
                && mAdapter.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 != null && 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 != null && 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 != null && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }

            mTouchMode = TOUCH_MODE_REST;
        }

        mBeginClick = false;

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

From source file:com.albedinsky.android.ui.widget.ViewPagerWidget.java

/**
 *//*ww w  . ja  v a  2 s  .com*/
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    this.ensureDecorator();
    if (!mDecorator.hasPrivateFlag(PFLAG_PAGE_SWIPING_ENABLED)) {
        return false;
    }
    if (mDecorator.onTouchEvent(event)) {
        this.requestParentDisallowInterceptTouchEvent(true);
        return true;
    }
    if (mDecorator.hasPrivateFlag(PFLAG_PAGE_FLING_SWIPING_ENABLED)) {
        this.ensureVelocityTracker();
        mVelocityTracker.addMovement(event);
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            mVelocityTracker.computeCurrentVelocity(UiConfig.VELOCITY_UNITS);
            final float xVelocity = mVelocityTracker.getXVelocity();
            if (Math.abs(xVelocity) > mPageFlingSwipingSensitivity) {
                super.onTouchEvent(event);
                this.handleFling(xVelocity);
                return true;
            }
        }
    }
    return super.onTouchEvent(event);
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    mVelocityTracker.addMovement(ev);//from   ww  w . ja  va  2  s . c  o m
    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.achep.acdisplay.ui.fragments.AcDisplayFragment.java

@Override
public void onForwardedEvent(MotionEvent event, int activePointerId) {
    int action = event.getActionMasked();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        // Track the velocity of movement, so we
        // can do swipe-to-dismiss.
        mVelocityTracker = VelocityTracker.obtain();
        mTouchSticky = false;//from  ww  w  .ja  va 2s.  co  m
    case MotionEvent.ACTION_MOVE:
    case MotionEvent.ACTION_UP:
        populateStdMotion(event);

        if (action != MotionEvent.ACTION_UP) {
            return; // Don't fall down.
        }

        boolean dismissing = swipeToDismiss();
        if (!dismissing) {
            if (mTouchSticky) {
                // Disable the default timeout mechanism and let
                // the selected widget to stay for a while.
                onWidgetStick(mSelectedWidget);
            } else if (mPressedIconView == null || !isPinnable()) {
                showHomeWidget();
            } else {
                onWidgetPin(mSelectedWidget);
            }
        }
    case MotionEvent.ACTION_CANCEL:
        mTouchHandler.removeCallbacksAndMessages(null);
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mTouchSticky = false;

        if (action == MotionEvent.ACTION_CANCEL) {
            showHomeWidget();
        }
        break;
    }
}

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;
    }/*  ww  w  .j a  va2s  .c o m*/

    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.android.BluetoothManager.UI.viewpager.TitlePageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from   w  w  w  . ja  v a 2s  .  com*/
    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;

            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.alibaba.akita.widget.TitlePageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from   www .j a va  2  s.  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;
}

From source file:it.mb.whatshare.Utils.java

/**
 * Returns a string that represents the symbolic name of the specified
 * action such as "ACTION_DOWN", "ACTION_POINTER_DOWN(3)" or an equivalent
 * numeric constant such as "35" if unknown. By Google.
 * /*from   w ww .  ja  v  a 2s . c  o  m*/
 * @param action
 *            The action.
 * @return The symbolic name of the specified action.
 */
public static String actionToString(int action) {
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        return "ACTION_DOWN";
    case MotionEvent.ACTION_UP:
        return "ACTION_UP";
    case MotionEvent.ACTION_CANCEL:
        return "ACTION_CANCEL";
    case MotionEvent.ACTION_OUTSIDE:
        return "ACTION_OUTSIDE";
    case MotionEvent.ACTION_MOVE:
        return "ACTION_MOVE";
    case MotionEvent.ACTION_HOVER_MOVE:
        return "ACTION_HOVER_MOVE";
    case MotionEvent.ACTION_SCROLL:
        return "ACTION_SCROLL";
    case MotionEvent.ACTION_HOVER_ENTER:
        return "ACTION_HOVER_ENTER";
    case MotionEvent.ACTION_HOVER_EXIT:
        return "ACTION_HOVER_EXIT";
    }
    int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        return "ACTION_POINTER_DOWN(" + index + ")";
    case MotionEvent.ACTION_POINTER_UP:
        return "ACTION_POINTER_UP(" + index + ")";
    default:
        return Integer.toString(action);
    }
}