@Override
  public boolean onTouch(View v, MotionEvent ev) {
    if (!mDslv.isDragEnabled() || mDslv.listViewIntercepted()) {
      return false;
    }

    mDetector.onTouchEvent(ev);
    if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE) {
      mFlingRemoveDetector.onTouchEvent(ev);
    }

    int action = ev.getAction() & MotionEvent.ACTION_MASK;
    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mCurrX = (int) ev.getX();
        mCurrY = (int) ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (mRemoveEnabled && mIsRemoving) {
          int x = mPositionX >= 0 ? mPositionX : -mPositionX;
          int removePoint = mDslv.getWidth() / 2;
          if (x > removePoint) {
            mDslv.stopDragWithVelocity(true, 0);
          }
        }
      case MotionEvent.ACTION_CANCEL:
        mIsRemoving = false;
        mDragging = false;
        break;
    }

    return false;
  }
Example #2
0
  /** Overrides to provide fading when slide removal is enabled. */
  @Override
  public void onDragFloatView(View floatView, Point position, Point touch) {

    if (mRemoveEnabled) {
      int x = touch.x;

      if (mRemoveMode == SLIDE_RIGHT_REMOVE) {
        int width = mDslv.getWidth();
        int thirdWidth = width / 3;

        float alpha;
        if (x < thirdWidth) {
          alpha = 1.0f;
        } else if (x < width - thirdWidth) {
          alpha = ((float) (width - thirdWidth - x)) / ((float) thirdWidth);
        } else {
          alpha = 0.0f;
        }
        mDslv.setFloatAlpha(mOrigFloatAlpha * alpha);
      } else if (mRemoveMode == SLIDE_LEFT_REMOVE) {
        int width = mDslv.getWidth();
        int thirdWidth = width / 3;

        float alpha;
        if (x < thirdWidth) {
          alpha = 0.0f;
        } else if (x < width - thirdWidth) {
          alpha = ((float) (x - thirdWidth)) / ((float) thirdWidth);
        } else {
          alpha = 1.0f;
        }
        mDslv.setFloatAlpha(mOrigFloatAlpha * alpha);
      }
    }
  }
Example #3
0
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    mDetector.onTouchEvent(ev);
    if (mRemoveEnabled
        && mDragging
        && (mRemoveMode == FLING_RIGHT_REMOVE || mRemoveMode == FLING_LEFT_REMOVE)) {
      mFlingRemoveDetector.onTouchEvent(ev);
    }

    int action = ev.getAction() & MotionEvent.ACTION_MASK;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        mCurrX = (int) ev.getX();
        mCurrY = (int) ev.getY();
        break;
      case MotionEvent.ACTION_UP:
        if (mRemoveEnabled) {
          final int x = (int) ev.getX();
          int thirdW = mDslv.getWidth() / 3;
          int twoThirdW = mDslv.getWidth() - thirdW;
          if ((mRemoveMode == SLIDE_RIGHT_REMOVE && x > twoThirdW)
              || (mRemoveMode == SLIDE_LEFT_REMOVE && x < thirdW)) {
            mDslv.stopDrag(true);
          }
        }
      case MotionEvent.ACTION_CANCEL:
        mDragging = false;
        break;
    }

    return false;
  }
 // complete the OnGestureListener interface
 @Override
 public boolean onSingleTapUp(MotionEvent ev) {
   if (mRemoveEnabled && mRemoveMode == CLICK_REMOVE) {
     if (mClickRemoveHitPos != MISS) {
       mDslv.removeItem(mClickRemoveHitPos - mDslv.getHeaderViewsCount());
     }
   }
   return true;
 }
Example #5
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) {
   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;
   setRemoveMode(removeMode);
   setDragInitMode(dragInitMode);
   mOrigFloatAlpha = dslv.getFloatAlpha();
 }
  /**
   * 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) {
      dragFlags |= DragSortListView.DRAG_POS_X;
      dragFlags |= DragSortListView.DRAG_NEG_X;
    }

    mDragging = mDslv.startDrag(position - mDslv.getHeaderViewsCount(), dragFlags, deltaX, deltaY);
    return mDragging;
  }
 @Override
 public void onLongPress(MotionEvent e) {
   // Log.d("mobeta", "lift listener long pressed");
   if (mHitPos != MISS && mDragInitMode == ON_LONG_PRESS) {
     mDslv.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
     startDrag(mHitPos, mCurrX - mItemX, mCurrY - mItemY);
   }
 }
Example #8
0
  /**
   * 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) {
      dragFlags |= DragSortListView.DRAG_POS_Y | DragSortListView.DRAG_NEG_Y;
      // dragFlags |= DRAG_POS_Y; //for fun
    }
    if (mRemoveEnabled) {
      if (mRemoveMode == FLING_RIGHT_REMOVE) {
        dragFlags |= DragSortListView.DRAG_POS_X;
      } else if (mRemoveMode == FLING_LEFT_REMOVE) {
        dragFlags |= DragSortListView.DRAG_NEG_X;
      }
    }

    mDragging = mDslv.startDrag(position - mDslv.getHeaderViewsCount(), dragFlags, deltaX, deltaY);
    return mDragging;
  }
 @Override
 public final boolean onFling(
     MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   // Log.d("mobeta", "on fling remove called");
   if (mRemoveEnabled && mIsRemoving) {
     int w = mDslv.getWidth();
     int minPos = w / 5;
     if (velocityX > mFlingSpeed) {
       if (mPositionX > -minPos) {
         mDslv.stopDragWithVelocity(true, velocityX);
       }
     } else if (velocityX < -mFlingSpeed) {
       if (mPositionX < minPos) {
         mDslv.stopDragWithVelocity(true, velocityX);
       }
     }
     mIsRemoving = false;
   }
   return false;
 }
Example #10
0
 @Override
 public final boolean onFling(
     MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   // Log.d("mobeta", "on fling remove called");
   if (mRemoveEnabled) {
     switch (mRemoveMode) {
       case FLING_RIGHT_REMOVE:
         if (velocityX > mFlingSpeed) {
           mDslv.stopDrag(true);
         }
         break;
       case FLING_LEFT_REMOVE:
         if (velocityX < -mFlingSpeed) {
           mDslv.stopDrag(true);
         }
         break;
     }
   }
   return false;
 }
 public void a(int i1)
 {
     if (!m)
     {
         e = false;
         m = true;
         j = SystemClock.uptimeMillis();
         f = j;
         k = i1;
         d.post(this);
     }
 }
 public void a(boolean flag)
 {
     if (flag)
     {
         d.removeCallbacks(this);
         m = false;
         return;
     } else
     {
         e = true;
         return;
     }
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_workout);

    Bundle bundle = this.getIntent().getExtras();
    position = bundle.getInt("position");

    editNameField = (EditText) findViewById(R.id.workoutNameField);
    addExerciseButton = (Button) findViewById(R.id.addExerciseButton);

    if (position >= 0) {
      workout = WorkoutList.getInstance().getWorkout(position);
      editNameField.setText(workout.getName());
    } else {
      workout = new Workout();
    }

    dslv = (DragSortListView) findViewById(R.id.exerciseList);

    String[] cols = {"name"};
    int[] ids = {R.id.text};
    adapter = new MyAdapter(this, R.layout.list_item_click_remove, null, cols, ids, 0);
    dslv.setAdapter(adapter);

    if (workout != null) {
      // populate the list of exercises
      cursor = new MatrixCursor(new String[] {"_id", "name"});
      int size = workout.getExercises().size();
      for (int i = 0; i < size; i++) {
        cursor.newRow().add(i).add(workout.getExercises().get(i).getName());
      }
      adapter.changeCursor(cursor);
    }

    setUpButtonListeners();
    setUpTextWatcher();
  }
Example #14
0
  /**
   * Checks for the touch of an item's drag handle (specified by {@link #setDragHandleId(int)}), and
   * returns that item's position if a drag handle touch was detected.
   *
   * @param ev The ACTION_DOWN MotionEvent.
   * @return The list position of the item whose drag handle was touched; MISS if unsuccessful.
   */
  public int dragHandleHitPosition(MotionEvent ev) {
    final int x = (int) ev.getX();
    final int y = (int) ev.getY();

    int touchPos = mDslv.pointToPosition(x, y); // includes headers/footers

    final int numHeaders = mDslv.getHeaderViewsCount();
    final int numFooters = mDslv.getFooterViewsCount();
    final int count = mDslv.getCount();

    // Log.d("mobeta", "touch down on position " + itemnum);
    // We're only interested if the touch was on an
    // item that's not a header or footer.
    if (touchPos != AdapterView.INVALID_POSITION
        && touchPos >= numHeaders
        && touchPos < (count - numFooters)) {
      final View item = mDslv.getChildAt(touchPos - mDslv.getFirstVisiblePosition());
      final int rawX = (int) ev.getRawX();
      final int rawY = (int) ev.getRawY();

      // View dragBox = (View) item.getTag();
      View dragBox = (View) item.findViewById(mDragHandleId);
      if (dragBox != null) {
        dragBox.getLocationOnScreen(mTempLoc);

        if (rawX > mTempLoc[0]
            && rawY > mTempLoc[1]
            && rawX < mTempLoc[0] + dragBox.getWidth()
            && rawY < mTempLoc[1] + dragBox.getHeight()) {

          mItemX = item.getLeft();
          mItemY = item.getTop();

          return touchPos;
        }
      }
    }

    return MISS;
  }
 public void run()
 {
     if (e)
     {
         m = false;
         return;
     }
     int j1 = d.getFirstVisiblePosition();
     int i1 = d.getLastVisiblePosition();
     int l1 = d.getCount();
     int k1 = d.getPaddingTop();
     int i2 = d.getHeight() - k1 - d.getPaddingBottom();
     int j2 = Math.min(DragSortListView.f(d), DragSortListView.r(d) + DragSortListView.d(d));
     int k2 = Math.max(DragSortListView.f(d), DragSortListView.r(d) - DragSortListView.d(d));
     View view1;
     if (k == 0)
     {
         View view = d.getChildAt(0);
         if (view == null)
         {
             m = false;
             return;
         }
         if (j1 == 0 && view.getTop() == k1)
         {
             m = false;
             return;
         }
         l = DragSortListView.u(d).a((DragSortListView.s(d) - (float)k2) / DragSortListView.t(d), f);
     } else
     {
         View view2 = d.getChildAt(i1 - j1);
         if (view2 == null)
         {
             m = false;
             return;
         }
         if (i1 == l1 - 1 && view2.getBottom() <= i2 + k1)
         {
             m = false;
             return;
         }
         l = -DragSortListView.u(d).a(((float)j2 - DragSortListView.v(d)) / DragSortListView.w(d), f);
     }
     g = SystemClock.uptimeMillis();
     i = g - f;
     h = Math.round(l * i);
     if (h >= 0)
     {
         h = Math.min(i2, h);
         i1 = j1;
     } else
     {
         h = Math.max(-i2, h);
     }
     view1 = d.getChildAt(i1 - j1);
     l1 = view1.getTop() + h;
     j1 = l1;
     if (i1 == 0)
     {
         j1 = l1;
         if (l1 > k1)
         {
             j1 = k1;
         }
     }
     DragSortListView.b(d, true);
     d.setSelectionFromTop(i1, j1 - k1);
     d.layoutChildren();
     d.invalidate();
     DragSortListView.b(d, false);
     DragSortListView.c(d, i1, view1, false);
     f = g;
     d.post(this);
 }