Example usage for android.view HapticFeedbackConstants LONG_PRESS

List of usage examples for android.view HapticFeedbackConstants LONG_PRESS

Introduction

In this page you can find the example usage for android.view HapticFeedbackConstants LONG_PRESS.

Prototype

int LONG_PRESS

To view the source code for android.view HapticFeedbackConstants LONG_PRESS.

Click Source Link

Document

The user has performed a long press on an object that is resulting in an action being performed.

Usage

From source file:com.nineducks.hereader.ui.NewsItemsFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    getListView().performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    clickedPosition = position;//ww  w . j a  v a2  s. co m
    getActivity().showDialog(R.id.open_dialog);
    return true;
}

From source file:android.support.v7.app.MediaRouteButton.java

@Override
public boolean performLongClick() {
    if (super.performLongClick()) {
        return true;
    }/*www .  jav a2s  .  c om*/

    if (!mCheatSheetEnabled) {
        return false;
    }

    final CharSequence contentDesc = getContentDescription();
    if (TextUtils.isEmpty(contentDesc)) {
        // Don't show the cheat sheet if we have no description
        return false;
    }

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

    Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    return true;
}

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

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    LayoutInflater li = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    viewLoading = li.inflate(R.layout.listitem_loading, null);
    if (!messagesSource.canNext()) {
        viewLoading.findViewById(R.id.loadingg).setVisibility(View.GONE);
        viewLoading.findViewById(R.id.end_of_messages).setVisibility(View.VISIBLE);
        viewLoading.findViewById(R.id.progress_bar).setVisibility(View.GONE);
        viewLoading.findViewById(R.id.progress_loading_more).setVisibility(View.GONE);
    }/*from   w w  w  . ja va2s .  c  o m*/

    mRefreshView = (RelativeLayout) li.inflate(R.layout.pull_to_refresh_header, null);
    mRefreshViewText = (TextView) mRefreshView.findViewById(R.id.pull_to_refresh_text);
    mRefreshViewImage = (ImageView) mRefreshView.findViewById(R.id.pull_to_refresh_image);
    mRefreshViewProgress = (ProgressBar) mRefreshView.findViewById(R.id.pull_to_refresh_progress);
    mRefreshViewImage.setMinimumHeight(50);
    mRefreshView.setOnClickListener(this);
    mRefreshOriginalTopPadding = mRefreshView.getPaddingTop();
    mRefreshState = TAP_TO_REFRESH;

    final ListView listView = getListView();
    listView.setBackgroundDrawable(null);
    listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
    installDividerColor(listView);
    MainActivity.restyleChildrenOrWidget(listView);

    listAdapter = new JuickMessagesAdapter(getActivity(), this, JuickMessagesAdapter.TYPE_MESSAGES,
            allMessages ? JuickMessagesAdapter.SUBTYPE_ALL : JuickMessagesAdapter.SUBTYPE_OTHER);

    listAdapter.setOnForgetListener(new Utils.Function<Void, JuickMessage>() {
        @Override
        public Void apply(final JuickMessage jm) {
            Network.executeJAHTTPS(
                    getActivity(), null, JA_API_URL + "/pending?command=ignore&mid="
                            + ((JuickMessageID) jm.getMID()).getMid() + "&rid=" + jm.getRID(),
                    new Utils.Function<Void, RESTResponse>() {
                        @Override
                        public Void apply(final RESTResponse response) {
                            final Activity activity = getActivity();
                            if (activity == null)
                                return null; // gone.
                            if (response.getErrorText() != null) {
                                activity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(activity, response.getErrorText(), Toast.LENGTH_SHORT)
                                                .show();
                                    }
                                });
                            } else {
                                activity.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        listAdapter.remove(jm);
                                        //To change body of implemented methods use File | Settings | File Templates.
                                        if (listAdapter.getCount() == 0) {
                                            if ((activity instanceof MainActivity)) {
                                                ((MainActivity) activity).doReload();
                                            }
                                        }
                                    }
                                });
                            }
                            return null;
                        }
                    });
            return null;
        }
    });
    listView.setOnTouchListener(this);
    listView.setOnScrollListener(this);
    listView.setOnItemClickListener(this);

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            if (view instanceof ImageGallery) {
                return false; // no need that! (possibly, make this condition work only if not scrolled meanwhile)
            }
            final Object itemAtPosition = parent.getItemAtPosition(position);
            if (itemAtPosition instanceof JuickMessage) {
                doOnClickActualTime = System.currentTimeMillis();
                doOnClick = new Runnable() {
                    @Override
                    public void run() {
                        JuickMessage msg = (JuickMessage) itemAtPosition;
                        MessageMenu messageMenu = MainActivity.getMicroBlog(msg).getMessageMenu(getActivity(),
                                messagesSource, listView, listAdapter);
                        if (messageMenu != null) {
                            messageMenu.onItemLongClick(parent, view, position, id);
                        } else {
                            Toast.makeText(getActivity(), "Not implemented ;-(", Toast.LENGTH_LONG).show();
                        }
                    }
                };
                if (alternativeLongClick) {
                    listView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                } else {
                    doOnClick.run();
                    doOnClick = null;
                    return true;
                }
            }
            return false;
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            System.out.println();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            System.out.println();
        }
    });
    init(false);
    if (parent != null) {
        parent.onFragmentCreated();
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment.java

public boolean openPopupMenu(View view, int position) {
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
    Menu menu = popupMenu.getMenu();
    final GBDeviceApp selectedApp = appList.get(position);

    if (!selectedApp.isInCache()) {
        menu.removeItem(R.id.appmanager_app_reinstall);
        menu.removeItem(R.id.appmanager_app_delete_cache);
    }/*from  www .  j a v  a2s  .  c o m*/
    if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_health_activate);
        menu.removeItem(R.id.appmanager_health_deactivate);
    }
    if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_hrm_activate);
        menu.removeItem(R.id.appmanager_hrm_deactivate);
    }
    if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_weather_activate);
        menu.removeItem(R.id.appmanager_weather_deactivate);
        menu.removeItem(R.id.appmanager_weather_install_provider);
    }
    if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM
            || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
        menu.removeItem(R.id.appmanager_app_delete);
    }
    if (!selectedApp.isConfigurable()) {
        menu.removeItem(R.id.appmanager_app_configure);
    }

    if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        PackageManager pm = getActivity().getPackageManager();
        try {
            pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES);
            menu.removeItem(R.id.appmanager_weather_install_provider);
        } catch (PackageManager.NameNotFoundException e) {
            menu.removeItem(R.id.appmanager_weather_activate);
            menu.removeItem(R.id.appmanager_weather_deactivate);
        }
    }

    switch (selectedApp.getType()) {
    case WATCHFACE:
    case APP_GENERIC:
    case APP_ACTIVITYTRACKER:
        break;
    default:
        menu.removeItem(R.id.appmanager_app_openinstore);
    }
    //menu.setHeaderTitle(selectedApp.getName());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            return onContextItemSelected(item, selectedApp);
        }
    });

    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    popupMenu.show();
    return true;
}

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

/**
 * Send any events and feedback that the long press action has taken place.
 *
 * @param handled True if the long press has taken place.
 * @param view    The view the long press was on.
 * @return Pass through of 'handled' parameter.
 *//*from  w w  w. ja  v  a2  s  .c om*/
private boolean doLongPressFeedback(final boolean handled, final View view) {
    if (handled) {
        if (view != null) {
            view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED);
        }
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }
    return handled;
}

From source file:com.waz.zclient.views.images.CircularSeekBar.java

/**
 * Initialize the CircularSeekBar with the attributes from the XML style.
 * Uses the defaults defined at the top of this file when an attribute is not specified by the user.
 *
 * @param attrArray TypedArray containing the attributes.
 *//*from  w w  w . ja v  a  2  s  .  c om*/
protected void initAttributes(TypedArray attrArray) {
    circleXRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_x_radius,
            DEFAULT_CIRCLE_X_RADIUS * dpToPxScale);
    circleYRadius = attrArray.getDimension(R.styleable.CircularSeekBar_circle_y_radius,
            DEFAULT_CIRCLE_Y_RADIUS * dpToPxScale);
    pointerRadius = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_radius,
            DEFAULT_POINTER_RADIUS * dpToPxScale);
    pointerHaloWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_width,
            DEFAULT_POINTER_HALO_WIDTH * dpToPxScale);
    pointerHaloBorderWidth = attrArray.getDimension(R.styleable.CircularSeekBar_pointer_halo_border_width,
            DEFAULT_POINTER_HALO_BORDER_WIDTH * dpToPxScale);
    circleStrokeWidth = attrArray.getDimension(R.styleable.CircularSeekBar_circle_stroke_width,
            DEFAULT_CIRCLE_STROKE_WIDTH * dpToPxScale);

    String tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_color);
    if (tempColor != null) {
        try {
            pointerColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerColor = DEFAULT_POINTER_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color);
    if (tempColor != null) {
        try {
            pointerHaloColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerHaloColor = DEFAULT_POINTER_HALO_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_pointer_halo_color_ontouch);
    if (tempColor != null) {
        try {
            pointerHaloColorOnTouch = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            pointerHaloColorOnTouch = DEFAULT_POINTER_HALO_COLOR_ONTOUCH;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_color);
    if (tempColor != null) {
        try {
            circleColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleColor = DEFAULT_CIRCLE_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_progress_color);
    if (tempColor != null) {
        try {
            circleProgressColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleProgressColor = DEFAULT_CIRCLE_PROGRESS_COLOR;
        }
    }

    tempColor = attrArray.getString(R.styleable.CircularSeekBar_circle_fill);
    if (tempColor != null) {
        try {
            circleFillColor = Color.parseColor(tempColor);
        } catch (IllegalArgumentException e) {
            circleFillColor = DEFAULT_CIRCLE_FILL_COLOR;
        }
    }

    pointerAlpha = Color.alpha(pointerHaloColor);

    pointerAlphaOnTouch = attrArray.getInt(R.styleable.CircularSeekBar_pointer_alpha_ontouch,
            DEFAULT_POINTER_ALPHA_ONTOUCH);
    if (pointerAlphaOnTouch > 255 || pointerAlphaOnTouch < 0) {
        pointerAlphaOnTouch = DEFAULT_POINTER_ALPHA_ONTOUCH;
    }

    max = attrArray.getInt(R.styleable.CircularSeekBar_max, DEFAULT_MAX);
    progress = attrArray.getInt(R.styleable.CircularSeekBar_progress, DEFAULT_PROGRESS);
    customRadii = attrArray.getBoolean(R.styleable.CircularSeekBar_use_custom_radii, DEFAULT_USE_CUSTOM_RADII);
    maintainEqualCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_maintain_equal_circle,
            DEFAULT_MAINTAIN_EQUAL_CIRCLE);
    moveOutsideCircle = attrArray.getBoolean(R.styleable.CircularSeekBar_move_outside_circle,
            DEFAULT_MOVE_OUTSIDE_CIRCLE);

    // Modulo 360 right now to avoid constant conversion
    startAngle = ((360f
            + (attrArray.getFloat((R.styleable.CircularSeekBar_start_angle), DEFAULT_START_ANGLE) % 360f))
            % 360f);
    endAngle = ((360f + (attrArray.getFloat((R.styleable.CircularSeekBar_end_angle), DEFAULT_END_ANGLE) % 360f))
            % 360f);

    if (MathUtils.floatEqual(startAngle, endAngle)) {
        //startAngle = startAngle + 1f;
        endAngle = endAngle - .1f;
    }
    final GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (onArtClickListener != null) {
                onArtClickListener.onSingleClick();
                return true;
            }
            return false;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (onArtClickListener != null) {
                onArtClickListener.onDoubleClick();
            }
            return super.onDoubleTap(e);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            if (onArtLongClickListener != null) {
                onArtLongClickListener.onLongClick(CircularSeekBar.this);
            }
        }
    };
    gestureDetector = new GestureDetectorCompat(getContext(), gestureListener);
    gestureDetector.setOnDoubleTapListener(gestureListener);
}

From source file:android.support.v7.widget.helper.ItemTouchHelper.java

/**
 * Starts dragging or swiping the given View. Call with null if you want to clear it.
 *
 * @param selected    The ViewHolder to drag or swipe. Can be null if you want to cancel the
 *                    current action//  w  ww . j  a v a2  s  . co  m
 * @param actionState The type of action
 */
private void select(ViewHolder selected, int actionState) {
    if (selected == mSelected && actionState == mActionState) {
        return;
    }
    mDragScrollStartTimeInMs = Long.MIN_VALUE;
    final int prevActionState = mActionState;
    // prevent duplicate animations
    endRecoverAnimation(selected, true);
    mActionState = actionState;
    if (actionState == ACTION_STATE_DRAG) {
        // we remove after animation is complete. this means we only elevate the last drag
        // child but that should perform good enough as it is very hard to start dragging a
        // new child before the previous one settles.
        mOverdrawChild = selected.itemView;
        addChildDrawingOrderCallback();
    }
    int actionStateMask = (1 << (DIRECTION_FLAG_COUNT + DIRECTION_FLAG_COUNT * actionState)) - 1;
    boolean preventLayout = false;

    if (mSelected != null) {
        final ViewHolder prevSelected = mSelected;
        if (prevSelected.itemView.getParent() != null) {
            final int swipeDir = prevActionState == ACTION_STATE_DRAG ? 0 : swipeIfNecessary(prevSelected);
            releaseVelocityTracker();
            // find where we should animate to
            final float targetTranslateX, targetTranslateY;
            int animationType;
            switch (swipeDir) {
            case LEFT:
            case RIGHT:
            case START:
            case END:
                targetTranslateY = 0;
                targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth();
                break;
            case UP:
            case DOWN:
                targetTranslateX = 0;
                targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight();
                break;
            default:
                targetTranslateX = 0;
                targetTranslateY = 0;
            }
            if (prevActionState == ACTION_STATE_DRAG) {
                animationType = ANIMATION_TYPE_DRAG;
            } else if (swipeDir > 0) {
                animationType = ANIMATION_TYPE_SWIPE_SUCCESS;
            } else {
                animationType = ANIMATION_TYPE_SWIPE_CANCEL;
            }
            getSelectedDxDy(mTmpPosition);
            final float currentTranslateX = mTmpPosition[0];
            final float currentTranslateY = mTmpPosition[1];
            final RecoverAnimation rv = new RecoverAnimation(prevSelected, animationType, prevActionState,
                    currentTranslateX, currentTranslateY, targetTranslateX, targetTranslateY) {
                @Override
                public void onAnimationEnd(ValueAnimatorCompat animation) {
                    super.onAnimationEnd(animation);
                    if (this.mOverridden) {
                        return;
                    }
                    if (swipeDir <= 0) {
                        // this is a drag or failed swipe. recover immediately
                        mCallback.clearView(mRecyclerView, prevSelected);
                        // full cleanup will happen on onDrawOver
                    } else {
                        // wait until remove animation is complete.
                        mPendingCleanup.add(prevSelected.itemView);
                        mIsPendingCleanup = true;
                        if (swipeDir > 0) {
                            // Animation might be ended by other animators during a layout.
                            // We defer callback to avoid editing adapter during a layout.
                            postDispatchSwipe(this, swipeDir);
                        }
                    }
                    // removed from the list after it is drawn for the last time
                    if (mOverdrawChild == prevSelected.itemView) {
                        removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
                    }
                }
            };
            final long duration = mCallback.getAnimationDuration(mRecyclerView, animationType,
                    targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY);
            rv.setDuration(duration);
            mRecoverAnimations.add(rv);
            rv.start();
            preventLayout = true;
        } else {
            removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
            mCallback.clearView(mRecyclerView, prevSelected);
        }
        mSelected = null;
    }
    if (selected != null) {
        mSelectedFlags = (mCallback.getAbsoluteMovementFlags(mRecyclerView, selected)
                & actionStateMask) >> (mActionState * DIRECTION_FLAG_COUNT);
        mSelectedStartX = selected.itemView.getLeft();
        mSelectedStartY = selected.itemView.getTop();
        mSelected = selected;

        if (actionState == ACTION_STATE_DRAG) {
            mSelected.itemView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        }
    }
    final ViewParent rvParent = mRecyclerView.getParent();
    if (rvParent != null) {
        rvParent.requestDisallowInterceptTouchEvent(mSelected != null);
    }
    if (!preventLayout) {
        mRecyclerView.getLayoutManager().requestSimpleAnimationsInNextLayout();
    }
    mCallback.onSelectedChanged(mSelected, mActionState);
    mRecyclerView.invalidate();
}

From source file:com.panahit.telegramma.support.widget.helper.ItemTouchHelper.java

/**
 * Starts dragging or swiping the given View. Call with null if you want to clear it.
 *
 * @param selected    The ViewHolder to drag or swipe. Can be null if you want to cancel the
 *                    current action/*from w w w . j a  va 2 s . c o  m*/
 * @param actionState The type of action
 */
private void select(RecyclerView.ViewHolder selected, int actionState) {
    if (selected == mSelected && actionState == mActionState) {
        return;
    }
    mDragScrollStartTimeInMs = Long.MIN_VALUE;
    final int prevActionState = mActionState;
    // prevent duplicate animations
    endRecoverAnimation(selected, true);
    mActionState = actionState;
    if (actionState == ACTION_STATE_DRAG) {
        // we remove after animation is complete. this means we only elevate the last drag
        // child but that should perform good enough as it is very hard to start dragging a
        // new child before the previous one settles.
        mOverdrawChild = selected.itemView;
        addChildDrawingOrderCallback();
    }
    int actionStateMask = (1 << (DIRECTION_FLAG_COUNT + DIRECTION_FLAG_COUNT * actionState)) - 1;
    boolean preventLayout = false;

    if (mSelected != null) {
        final RecyclerView.ViewHolder prevSelected = mSelected;
        if (prevSelected.itemView.getParent() != null) {
            final int swipeDir = prevActionState == ACTION_STATE_DRAG ? 0 : swipeIfNecessary(prevSelected);
            releaseVelocityTracker();
            // find where we should animate to
            final float targetTranslateX, targetTranslateY;
            int animationType;
            switch (swipeDir) {
            case LEFT:
            case RIGHT:
            case START:
            case END:
                targetTranslateY = 0;
                targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth();
                break;
            case UP:
            case DOWN:
                targetTranslateX = 0;
                targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight();
                break;
            default:
                targetTranslateX = 0;
                targetTranslateY = 0;
            }
            if (prevActionState == ACTION_STATE_DRAG) {
                animationType = ANIMATION_TYPE_DRAG;
            } else if (swipeDir > 0) {
                animationType = ANIMATION_TYPE_SWIPE_SUCCESS;
            } else {
                animationType = ANIMATION_TYPE_SWIPE_CANCEL;
            }
            getSelectedDxDy(mTmpPosition);
            final float currentTranslateX = mTmpPosition[0];
            final float currentTranslateY = mTmpPosition[1];
            final RecoverAnimation rv = new RecoverAnimation(prevSelected, animationType, prevActionState,
                    currentTranslateX, currentTranslateY, targetTranslateX, targetTranslateY) {
                @Override
                public void onAnimationEnd(ValueAnimatorCompat animation) {
                    super.onAnimationEnd(animation);
                    if (this.mOverridden) {
                        return;
                    }
                    if (swipeDir <= 0) {
                        // this is a drag or failed swipe. recover immediately
                        mCallback.clearView(mRecyclerView, prevSelected);
                        // full cleanup will happen on onDrawOver
                    } else {
                        // wait until remove animation is complete.
                        mPendingCleanup.add(prevSelected.itemView);
                        mIsPendingCleanup = true;
                        if (swipeDir > 0) {
                            // Animation might be ended by other animators during a layout.
                            // We defer callback to avoid editing adapter during a layout.
                            postDispatchSwipe(this, swipeDir);
                        }
                    }
                    // removed from the list after it is drawn for the last time
                    if (mOverdrawChild == prevSelected.itemView) {
                        removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
                    }
                }
            };
            final long duration = mCallback.getAnimationDuration(mRecyclerView, animationType,
                    targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY);
            rv.setDuration(duration);
            mRecoverAnimations.add(rv);
            rv.start();
            preventLayout = true;
        } else {
            removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
            mCallback.clearView(mRecyclerView, prevSelected);
        }
        mSelected = null;
    }
    if (selected != null) {
        mSelectedFlags = (mCallback.getAbsoluteMovementFlags(mRecyclerView, selected)
                & actionStateMask) >> (mActionState * DIRECTION_FLAG_COUNT);
        mSelectedStartX = selected.itemView.getLeft();
        mSelectedStartY = selected.itemView.getTop();
        mSelected = selected;

        if (actionState == ACTION_STATE_DRAG) {
            mSelected.itemView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        }
    }
    final ViewParent rvParent = mRecyclerView.getParent();
    if (rvParent != null) {
        rvParent.requestDisallowInterceptTouchEvent(mSelected != null);
    }
    if (!preventLayout) {
        mRecyclerView.getLayoutManager().requestSimpleAnimationsInNextLayout();
    }
    mCallback.onSelectedChanged(mSelected, mActionState);
    mRecyclerView.invalidate();
}

From source file:com.anarchy.classify.library.helper.ClassifyItemTouchHelper.java

/**
 * Starts dragging or swiping the given View. Call with null if you want to clear it.
 *
 * @param selected    The ViewHolder to drag or swipe. Can be null if you want to cancel the
 *                    current action//w w  w .  j  a  v  a2s . com
 * @param actionState The type of action
 */
private void select(RecyclerView.ViewHolder selected, int actionState) {
    if (selected == mSelected && actionState == mActionState) {
        return;
    }
    if (mCallback.getMergeStatus()) {
        if (mSelected != null) {
            mCallback.onMerged(mSelected);
            mSelected = null;
            return;
        }
    }
    mDragScrollStartTimeInMs = Long.MIN_VALUE;
    final int prevActionState = mActionState;
    // prevent duplicate animations
    endRecoverAnimation(selected, true);
    mActionState = actionState;
    if (actionState == ACTION_STATE_DRAG) {
        // we remove after animation is complete. this means we only elevate the last drag
        // child but that should perform good enough as it is very hard to start dragging a
        // new child before the previous one settles.
        mOverdrawChild = selected.itemView;
        addChildDrawingOrderCallback();
    }
    int actionStateMask = (1 << (DIRECTION_FLAG_COUNT + DIRECTION_FLAG_COUNT * actionState)) - 1;
    boolean preventLayout = false;

    if (mSelected != null) {
        final RecyclerView.ViewHolder prevSelected = mSelected;
        if (prevSelected.itemView.getParent() != null) {
            final int swipeDir = prevActionState == ACTION_STATE_DRAG ? 0 : swipeIfNecessary(prevSelected);
            releaseVelocityTracker();
            // find where we should animate to
            final float targetTranslateX, targetTranslateY;
            int animationType;
            switch (swipeDir) {
            case LEFT:
            case RIGHT:
            case START:
            case END:
                targetTranslateY = 0;
                targetTranslateX = Math.signum(mDx) * mRecyclerView.getWidth();
                break;
            case UP:
            case DOWN:
                targetTranslateX = 0;
                targetTranslateY = Math.signum(mDy) * mRecyclerView.getHeight();
                break;
            default:
                targetTranslateX = 0;
                targetTranslateY = 0;
            }
            if (prevActionState == ACTION_STATE_DRAG) {
                animationType = ANIMATION_TYPE_DRAG;
            } else if (swipeDir > 0) {
                animationType = ANIMATION_TYPE_SWIPE_SUCCESS;
            } else {
                animationType = ANIMATION_TYPE_SWIPE_CANCEL;
            }
            getSelectedDxDy(mTmpPosition);
            final float currentTranslateX = mTmpPosition[0];
            final float currentTranslateY = mTmpPosition[1];
            final RecoverAnimation rv = new RecoverAnimation(prevSelected, animationType, prevActionState,
                    currentTranslateX, currentTranslateY, targetTranslateX, targetTranslateY) {
                @Override
                public void onAnimationEnd(ValueAnimatorCompat animation) {
                    super.onAnimationEnd(animation);
                    if (this.mOverridden) {
                        return;
                    }
                    if (swipeDir <= 0) {
                        // this is a drag or failed swipe. recover immediately
                        mCallback.clearView(mRecyclerView, prevSelected);
                        // full cleanup will happen on onDrawOver
                    } else {
                        // wait until remove animation is complete.
                        mPendingCleanup.add(prevSelected.itemView);
                        mIsPendingCleanup = true;
                        if (swipeDir > 0) {
                            // Animation might be ended by other animators during a layout.
                            // We defer callback to avoid editing adapter during a layout.
                            postDispatchSwipe(this, swipeDir);
                        }
                    }
                    // removed from the list after it is drawn for the last time
                    if (mOverdrawChild == prevSelected.itemView) {
                        removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
                    }
                }
            };
            final long duration = mCallback.getAnimationDuration(mRecyclerView, animationType,
                    targetTranslateX - currentTranslateX, targetTranslateY - currentTranslateY);
            rv.setDuration(duration);
            mRecoverAnimations.add(rv);
            rv.start();
            preventLayout = true;
        } else {
            removeChildDrawingOrderCallbackIfNecessary(prevSelected.itemView);
            mCallback.clearView(mRecyclerView, prevSelected);
        }
        mSelected = null;
    }
    if (selected != null) {
        mSelectedFlags = (mCallback.getAbsoluteMovementFlags(mRecyclerView, selected)
                & actionStateMask) >> (mActionState * DIRECTION_FLAG_COUNT);
        mSelectedStartX = selected.itemView.getLeft();
        mSelectedStartY = selected.itemView.getTop();
        mSelected = selected;

        if (actionState == ACTION_STATE_DRAG) {
            mSelected.itemView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        }
    }
    final ViewParent rvParent = mRecyclerView.getParent();
    if (rvParent != null) {
        rvParent.requestDisallowInterceptTouchEvent(mSelected != null);
    }
    if (!preventLayout) {
        mRecyclerView.getLayoutManager().requestSimpleAnimationsInNextLayout();
    }
    mCallback.onSelectedChanged(mSelected, mActionState);
    mRecyclerView.invalidate();
}