Skip to content

Commit d736daa

Browse files
committed
remove methods consolidation
1 parent 1ccc218 commit d736daa

File tree

8 files changed

+43
-142
lines changed

8 files changed

+43
-142
lines changed

demo/res/layout/hetero_main.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@
2222
dslv:sort_enabled="true"
2323
dslv:remove_enabled="true"
2424
dslv:drag_start_mode="onDown"
25-
dslv:remove_mode="flingLeft" />
25+
dslv:remove_mode="flingRemove" />

demo/res/values/strings.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,7 @@
5757
<string name="add_footer">Add footer</string>
5858
<string-array name="remove_mode_labels">
5959
<item>Click remove</item>
60-
<item>Fling right</item>
61-
<item>Fling left</item>
62-
<item>Slide right</item>
63-
<item>Slide left</item>
64-
<item>Fling or Slide</item>
60+
<item>Fling remove</item>
6561
</string-array>
6662
<string-array name="drag_init_mode_labels">
6763
<item>On down</item>

demo/src/com/mobeta/android/demodslv/DSLVFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ protected int getLayout() {
5353
* Return list item layout resource passed to the ArrayAdapter.
5454
*/
5555
protected int getItemLayout() {
56-
if (removeMode == DragSortController.FLING_LEFT_REMOVE || removeMode == DragSortController.SLIDE_LEFT_REMOVE) {
56+
/*if (removeMode == DragSortController.FLING_LEFT_REMOVE || removeMode == DragSortController.SLIDE_LEFT_REMOVE) {
5757
return R.layout.list_item_handle_right;
58-
} else if (removeMode == DragSortController.CLICK_REMOVE) {
58+
} else */
59+
if (removeMode == DragSortController.CLICK_REMOVE) {
5960
return R.layout.list_item_click_remove;
6061
} else {
6162
return R.layout.list_item_handle_left;
@@ -67,7 +68,7 @@ protected int getItemLayout() {
6768

6869
public int dragStartMode = DragSortController.ON_DOWN;
6970
public boolean removeEnabled = false;
70-
public int removeMode = DragSortController.FLING_RIGHT_REMOVE;
71+
public int removeMode = DragSortController.FLING_REMOVE;
7172
public boolean sortEnabled = true;
7273
public boolean dragEnabled = true;
7374

demo/src/com/mobeta/android/demodslv/RemoveModeDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class RemoveModeDialog extends DialogFragment {
2121

2222
public RemoveModeDialog() {
2323
super();
24-
mRemoveMode = DragSortController.FLING_RIGHT_REMOVE;
24+
mRemoveMode = DragSortController.FLING_REMOVE;
2525
}
2626

2727
public RemoveModeDialog(int inRemoveMode) {

demo/src/com/mobeta/android/demodslv/TestBedDSLV.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TestBedDSLV extends FragmentActivity implements
2929

3030
private int mDragStartMode = DragSortController.ON_DRAG;
3131
private boolean mRemoveEnabled = true;
32-
private int mRemoveMode = DragSortController.FLING_OR_SLIDE_REMOVE;
32+
private int mRemoveMode = DragSortController.FLING_REMOVE;
3333
private boolean mSortEnabled = true;
3434
private boolean mDragEnabled = true;
3535

library/res/values/dslv_attrs.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
<attr name="float_background_color" format="color" />
88
<attr name="remove_mode">
99
<enum name="clickRemove" value="0" />
10-
<enum name="flingRight" value="1" />
11-
<enum name="flingLeft" value="2" />
12-
<enum name="slideRight" value="3" />
13-
<enum name="slideLeft" value="4" />
14-
<enum name="flingOrSlide" value="5" />
10+
<enum name="flingRemove" value="1" />
1511
</attr>
1612
<attr name="track_drag_sort" format="boolean"/>
1713
<attr name="float_alpha" format="float"/>

library/src/com/mobeta/android/dslv/DragSortController.java

Lines changed: 33 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.mobeta.android.dslv;
22

3-
import android.util.Log;
3+
import android.graphics.Point;
44
import android.view.GestureDetector;
55
import android.view.HapticFeedbackConstants;
66
import android.view.MotionEvent;
77
import android.view.View;
88
import android.view.ViewConfiguration;
9-
import android.graphics.Point;
109
import android.widget.AdapterView;
1110

1211
/**
@@ -37,11 +36,7 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
3736
* Remove mode enum.
3837
*/
3938
public static final int CLICK_REMOVE = 0;
40-
public static final int FLING_RIGHT_REMOVE = 1;
41-
public static final int FLING_LEFT_REMOVE = 2;
42-
public static final int SLIDE_RIGHT_REMOVE = 3;
43-
public static final int SLIDE_LEFT_REMOVE = 4;
44-
public static final int FLING_OR_SLIDE_REMOVE = 5;
39+
public static final int FLING_REMOVE = 1;
4540

4641
/**
4742
* The current remove mode.
@@ -76,8 +71,6 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
7671

7772
private float mFlingSpeed = 500f;
7873

79-
private float mOrigFloatAlpha = 1.0f;
80-
8174
private int mDragHandleId;
8275

8376
private int mClickRemoveId;
@@ -98,7 +91,7 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
9891
* @param dslv The DSLV instance
9992
*/
10093
public DragSortController(DragSortListView dslv) {
101-
this(dslv, 0, ON_DOWN, FLING_RIGHT_REMOVE);
94+
this(dslv, 0, ON_DOWN, FLING_REMOVE);
10295
}
10396

10497
public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitMode, int removeMode) {
@@ -129,7 +122,6 @@ public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitM
129122
mFlingHandleId = flingHandleId;
130123
setRemoveMode(removeMode);
131124
setDragInitMode(dragInitMode);
132-
mOrigFloatAlpha = dslv.getFloatAlpha();
133125
}
134126

135127

@@ -234,16 +226,9 @@ public boolean startDrag(int position, int deltaX, int deltaY) {
234226
if (mSortEnabled && !mIsRemoving) {
235227
dragFlags |= DragSortListView.DRAG_POS_Y | DragSortListView.DRAG_NEG_Y;
236228
}
237-
if (mRemoveEnabled) {
238-
if (mRemoveMode == FLING_RIGHT_REMOVE) {
239-
dragFlags |= DragSortListView.DRAG_POS_X;
240-
} else if (mRemoveMode == FLING_LEFT_REMOVE) {
241-
dragFlags |= DragSortListView.DRAG_NEG_X;
242-
}
243-
else if( mRemoveMode == FLING_OR_SLIDE_REMOVE && mIsRemoving){
244-
dragFlags |= DragSortListView.DRAG_POS_X;
245-
dragFlags |= DragSortListView.DRAG_NEG_X;
246-
}
229+
if (mRemoveEnabled && mIsRemoving){
230+
dragFlags |= DragSortListView.DRAG_POS_X;
231+
dragFlags |= DragSortListView.DRAG_NEG_X;
247232
}
248233

249234
mDragging = mDslv.startDrag(position - mDslv.getHeaderViewsCount(), dragFlags, deltaX, deltaY);
@@ -257,7 +242,7 @@ public boolean onTouch(View v, MotionEvent ev) {
257242
}
258243

259244
mDetector.onTouchEvent(ev);
260-
if (mRemoveEnabled && mDragging && (mRemoveMode == FLING_RIGHT_REMOVE || mRemoveMode == FLING_LEFT_REMOVE || mRemoveMode == FLING_OR_SLIDE_REMOVE )) {
245+
if (mRemoveEnabled && mDragging && mRemoveMode == FLING_REMOVE ) {
261246
mFlingRemoveDetector.onTouchEvent(ev);
262247
}
263248

@@ -269,23 +254,11 @@ public boolean onTouch(View v, MotionEvent ev) {
269254
mCurrY = (int) ev.getY();
270255
break;
271256
case MotionEvent.ACTION_UP:
272-
if (mRemoveEnabled) {
273-
if ( mRemoveMode == FLING_OR_SLIDE_REMOVE && mIsRemoving ) {
274-
int x = mPositionX >= 0 ? mPositionX : -mPositionX;
275-
int removePoint = mDslv.getWidth() / 2;
276-
if( x > removePoint ){
277-
mDslv.stopDragWithVelocity(true,0);
278-
}
279-
}
280-
else
281-
{
282-
final int x = (int) ev.getX();
283-
int thirdW = mDslv.getWidth() / 3;
284-
int twoThirdW = mDslv.getWidth() - thirdW;
285-
if ((mRemoveMode == SLIDE_RIGHT_REMOVE && x > twoThirdW) ||
286-
(mRemoveMode == SLIDE_LEFT_REMOVE && x < thirdW)) {
287-
mDslv.stopDrag(true);
288-
}
257+
if (mRemoveEnabled && mIsRemoving ) {
258+
int x = mPositionX >= 0 ? mPositionX : -mPositionX;
259+
int removePoint = mDslv.getWidth() / 2;
260+
if( x > removePoint ){
261+
mDslv.stopDragWithVelocity(true,0);
289262
}
290263
}
291264
case MotionEvent.ACTION_CANCEL:
@@ -303,40 +276,8 @@ public boolean onTouch(View v, MotionEvent ev) {
303276
@Override
304277
public void onDragFloatView(View floatView, Point position, Point touch) {
305278

306-
if (mRemoveEnabled) {
307-
if( mIsRemoving ){
308-
mPositionX = position.x;
309-
}
310-
int x = touch.x;
311-
int y = touch.y;
312-
313-
if (mRemoveMode == SLIDE_RIGHT_REMOVE) {
314-
int width = mDslv.getWidth();
315-
int thirdWidth = width / 3;
316-
317-
float alpha;
318-
if (x < thirdWidth) {
319-
alpha = 1.0f;
320-
} else if (x < width - thirdWidth) {
321-
alpha = ((float) (width - thirdWidth - x)) / ((float) thirdWidth);
322-
} else {
323-
alpha = 0.0f;
324-
}
325-
mDslv.setFloatAlpha(mOrigFloatAlpha * alpha);
326-
} else if (mRemoveMode == SLIDE_LEFT_REMOVE) {
327-
int width = mDslv.getWidth();
328-
int thirdWidth = width / 3;
329-
330-
float alpha;
331-
if (x < thirdWidth) {
332-
alpha = 0.0f;
333-
} else if (x < width - thirdWidth) {
334-
alpha = ((float) (x - thirdWidth)) / ((float) thirdWidth);
335-
} else {
336-
alpha = 1.0f;
337-
}
338-
mDslv.setFloatAlpha(mOrigFloatAlpha * alpha);
339-
}
279+
if (mRemoveEnabled && mIsRemoving ){
280+
mPositionX = position.x;
340281
}
341282
}
342283

@@ -357,7 +298,7 @@ public int startDragPosition(MotionEvent ev) {
357298
return dragHandleHitPosition(ev);
358299
}
359300
public int startFlingPosition(MotionEvent ev) {
360-
return mRemoveMode == FLING_OR_SLIDE_REMOVE ? flingHandleHitPosition(ev) : MISS;
301+
return mRemoveMode == FLING_REMOVE ? flingHandleHitPosition(ev) : MISS;
361302
}
362303

363304
/**
@@ -395,9 +336,7 @@ public int viewIdHitPosition(MotionEvent ev, int id) {
395336
final int rawX = (int) ev.getRawX();
396337
final int rawY = (int) ev.getRawY();
397338

398-
//View dragBox = (View) item.getTag();
399339
View dragBox = id == 0 ? item : (View) item.findViewById(id);
400-
boolean dragHit = false;
401340
if (dragBox != null) {
402341
dragBox.getLocationOnScreen(mTempLoc);
403342

@@ -445,7 +384,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
445384
final int deltaX = x2-mItemX;
446385
final int deltaY = y2-mItemY;
447386

448-
if( mRemoveMode==FLING_OR_SLIDE_REMOVE && mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos !=MISS )) {
387+
if( mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos !=MISS )) {
449388

450389
if( mHitPos != MISS )
451390
{
@@ -476,21 +415,6 @@ else if( Math.abs(y2-y1) > mTouchSlop)
476415
}
477416
}
478417
}
479-
else if (mHitPos != MISS && mDragInitMode == ON_DRAG && !mDragging) {
480-
481-
boolean start = false;
482-
if (mRemoveEnabled && mSortEnabled) {
483-
start = true;
484-
} else if (mRemoveEnabled) {
485-
start = Math.abs(x2 - x1) > mTouchSlop;
486-
} else if (mSortEnabled) {
487-
start = Math.abs(y2 - y1) > mTouchSlop;
488-
}
489-
490-
if (start) {
491-
startDrag(mHitPos, deltaX, deltaY);
492-
}
493-
}
494418
// return whatever
495419
return false;
496420
}
@@ -532,41 +456,25 @@ public void onShowPress(MotionEvent ev) {
532456
@Override
533457
public final boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
534458
//Log.d("mobeta", "on fling remove called");
535-
if (mRemoveEnabled) {
536-
switch (mRemoveMode) {
537-
case FLING_OR_SLIDE_REMOVE:
538-
if( mIsRemoving ) {
539-
int w = mDslv.getWidth();
540-
int minPos = w/5;
541-
if (velocityX > mFlingSpeed )
542-
{
543-
if( mPositionX > -minPos )
544-
{
545-
mDslv.stopDragWithVelocity(true,velocityX);
546-
}
547-
}
548-
else if (velocityX < -mFlingSpeed )
549-
{
550-
if( mPositionX < minPos )
551-
{
552-
mDslv.stopDragWithVelocity(true,velocityX);
553-
}
554-
}
555-
}
556-
break;
557-
case FLING_RIGHT_REMOVE:
558-
if (velocityX > mFlingSpeed) {
559-
mDslv.stopDrag(true);
560-
}
561-
break;
562-
case FLING_LEFT_REMOVE:
563-
if (velocityX < -mFlingSpeed) {
564-
mDslv.stopDrag(true);
565-
}
566-
break;
459+
if (mRemoveEnabled && mIsRemoving ) {
460+
int w = mDslv.getWidth();
461+
int minPos = w/5;
462+
if (velocityX > mFlingSpeed )
463+
{
464+
if( mPositionX > -minPos )
465+
{
466+
mDslv.stopDragWithVelocity(true,velocityX);
467+
}
468+
}
469+
else if (velocityX < -mFlingSpeed )
470+
{
471+
if( mPositionX < minPos )
472+
{
473+
mDslv.stopDragWithVelocity(true,velocityX);
474+
}
567475
}
476+
mIsRemoving = false;
568477
}
569-
mIsRemoving = false;
570478
return false;
571479
}
572480
};

library/src/com/mobeta/android/dslv/DragSortListView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public DragSortListView(Context context, AttributeSet attrs) {
503503
false);
504504
int removeMode = a.getInt(
505505
R.styleable.DragSortListView_remove_mode,
506-
DragSortController.FLING_RIGHT_REMOVE);
506+
DragSortController.FLING_REMOVE);
507507
boolean sortEnabled = a.getBoolean(
508508
R.styleable.DragSortListView_sort_enabled,
509509
true);

0 commit comments

Comments
 (0)