gt:             dragFlags |= DragSortListView.DRAG_POS_X;
context: package com.zsx.widget.drag;
  
  import android.graphics.Point;
  import android.view.GestureDetector;
  import android.view.HapticFeedbackConstants;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewConfiguration;
  import android.widget.AdapterView;
  
  /**
   * Class that starts and stops item drags on a {@link DragSortListView}
   * based on touch gestures. This class also inherits from
   * {@link SimpleFloatViewManager}, which provides basic float View
   * creation.
   *
   * An instance of this class is meant to be passed to the methods
   * {@link DragSortListView#setTouchListener()} and
   * {@link DragSortListView#setFloatViewManager()} of your
   * {@link DragSortListView} instance.
   */
  public class DragSortController extends SimpleFloatViewManager implements View.OnTouchListener, GestureDetector.OnGestureListener {
  
      /**
       * Drag init mode enum.
       */
      public static final int ON_DOWN = 0;
      public static final int ON_DRAG = 1;
      public static final int ON_LONG_PRESS = 2;
  
      private int mDragInitMode = ON_DOWN;
  
      private boolean mSortEnabled = true;
  
      /**
       * Remove mode enum.
       */
      public static final int CLICK_REMOVE = 0;
      public static final int FLING_REMOVE = 1;
  
      /**
       * The current remove mode.
       */
      private int mRemoveMode;
  
      private boolean mRemoveEnabled = false;
      private boolean mIsRemoving = false;
  
      private GestureDetector mDetector;
  
      private GestureDetector mFlingRemoveDetector;
  
      private int mTouchSlop;
  
      public static final int MISS = -1;
  
      private int mHitPos = MISS;
      private int mFlingHitPos = MISS;
  
      private int mClickRemoveHitPos = MISS;
  
      private int[] mTempLoc = new int[2];
  
      private int mItemX;
      private int mItemY;
  
      private int mCurrX;
      private int mCurrY;
  
      private boolean mDragging = false;
  
      private float mFlingSpeed = 500f;
  
      private int mDragHandleId;
  
      private int mClickRemoveId;
  
      private int mFlingHandleId;
      private boolean mCanDrag;
  
      private DragSortListView mDslv;
      private int mPositionX;
  
      /**
       * Calls {@link #DragSortController(DragSortListView, int)} with a
       * 0 drag handle id, FLING_RIGHT_REMOVE remove mode,
       * and ON_DOWN drag init. By default, sorting is enabled, and
       * removal is disabled.
       *
       * @param dslv The DSLV instance
       */
      public DragSortController(DragSortListView dslv) {
          this(dslv, 0, ON_DOWN, FLING_REMOVE);
      }
  
      public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode) {
          this(dslv, dragHandleId, dragInitMode, removeMode, 0);
      }
  
      public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode, int clickRemoveId) {
          this(dslv, dragHandleId, dragInitMode, removeMode, clickRemoveId, 0);
      }
  
      /**
       * By default, sorting is enabled, and removal is disabled.
       *
       * @param dslv The DSLV instance
       * @param dragHandleId The resource id of the View that represents
       * the drag handle in a list item.
       */
      public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode,
              int removeMode, int clickRemoveId, int flingHandleId) {
          super(dslv);
          mDslv = dslv;
          mDetector = new GestureDetector(dslv.getContext(), this);
          mFlingRemoveDetector = new GestureDetector(dslv.getContext(), mFlingRemoveListener);
          mFlingRemoveDetector.setIsLongpressEnabled(false);
          mTouchSlop = ViewConfiguration.get(dslv.getContext()).getScaledTouchSlop();
          mDragHandleId = dragHandleId;
          mClickRemoveId = clickRemoveId;
          mFlingHandleId = flingHandleId;
          setRemoveMode(removeMode);
          setDragInitMode(dragInitMode);
      }
  
  
      public int getDragInitMode() {
          return mDragInitMode;
      }
  
      /**
       * Set how a drag is initiated. Needs to be one of
       * {@link ON_DOWN}, {@link ON_DRAG}, or {@link ON_LONG_PRESS}.
       *
       * @param mode The drag init mode.
       */
      public void setDragInitMode(int mode) {
          mDragInitMode = mode;
      }
  
      /**
       * Enable/Disable list item sorting. Disabling is useful if only item
       * removal is desired. Prevents drags in the vertical direction.
       *
       * @param enabled Set <code>true</code> to enable list
       * item sorting.
       */
      public void setSortEnabled(boolean enabled) {
          mSortEnabled = enabled;
      }
  
      public boolean isSortEnabled() {
          return mSortEnabled;
      }
  
      /**
       * One of {@link CLICK_REMOVE}, {@link FLING_RIGHT_REMOVE},
       * {@link FLING_LEFT_REMOVE},
       * {@link SLIDE_RIGHT_REMOVE}, or {@link SLIDE_LEFT_REMOVE}.
       */
      public void setRemoveMode(int mode) {
          mRemoveMode = mode;
      }
  
      public int getRemoveMode() {
          return mRemoveMode;
      }
  
      /**
       * Enable/Disable item removal without affecting remove mode.
       */
      public void setRemoveEnabled(boolean enabled) {
          mRemoveEnabled = enabled;
      }
  
      public boolean isRemoveEnabled() {
          return mRemoveEnabled;
      }
  
      /**
       * Set the resource id for the View that represents the drag
       * handle in a list item.
       *
       * @param id An android resource id.
       */
      public void setDragHandleId(int id) {
          mDragHandleId = id;
      }
  
      /**
       * Set the resource id for the View that represents the fling
       * handle in a list item.
       *
       * @param id An android resource id.
       */
      public void setFlingHandleId(int id) {
          mFlingHandleId = id;
      }
  
      /**
       * Set the resource id for the View that represents click
       * removal button.
       *
       * @param id An android resource id.
       */
      public void setClickRemoveId(int id) {
          mClickRemoveId = id;
      }
  
      /**
       * Sets flags to restrict certain motions of the floating View
       * based on DragSortController settings (such as remove mode).
       * Starts the drag on the DragSortListView.
       *
       * @param position The list item position (includes headers).
       * @param deltaX Touch x-coord minus left edge of floating View.
       * @param deltaY Touch y-coord minus top edge of floating View.
       *
       * @return True if drag started, false otherwise.
       */
      public boolean startDrag(int position, int deltaX, int deltaY) {
  
          int dragFlags = 0;
          if (mSortEnabled && !mIsRemoving) {
              dragFlags |= DragSortListView.DRAG_POS_Y | DragSortListView.DRAG_NEG_Y;
          }
          if (mRemoveEnabled && mIsRemoving) {
  