1
1
package com .mobeta .android .dslv ;
2
2
3
- import android .util . Log ;
3
+ import android .graphics . Point ;
4
4
import android .view .GestureDetector ;
5
5
import android .view .HapticFeedbackConstants ;
6
6
import android .view .MotionEvent ;
7
7
import android .view .View ;
8
8
import android .view .ViewConfiguration ;
9
- import android .graphics .Point ;
10
9
import android .widget .AdapterView ;
11
10
12
11
/**
@@ -37,11 +36,7 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
37
36
* Remove mode enum.
38
37
*/
39
38
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 ;
45
40
46
41
/**
47
42
* The current remove mode.
@@ -76,8 +71,6 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
76
71
77
72
private float mFlingSpeed = 500f ;
78
73
79
- private float mOrigFloatAlpha = 1.0f ;
80
-
81
74
private int mDragHandleId ;
82
75
83
76
private int mClickRemoveId ;
@@ -98,7 +91,7 @@ public class DragSortController extends SimpleFloatViewManager implements View.O
98
91
* @param dslv The DSLV instance
99
92
*/
100
93
public DragSortController (DragSortListView dslv ) {
101
- this (dslv , 0 , ON_DOWN , FLING_RIGHT_REMOVE );
94
+ this (dslv , 0 , ON_DOWN , FLING_REMOVE );
102
95
}
103
96
104
97
public DragSortController (DragSortListView dslv , int dragHandleId , int dragInitMode , int removeMode ) {
@@ -129,7 +122,6 @@ public DragSortController(DragSortListView dslv, int dragHandleId, int dragInitM
129
122
mFlingHandleId = flingHandleId ;
130
123
setRemoveMode (removeMode );
131
124
setDragInitMode (dragInitMode );
132
- mOrigFloatAlpha = dslv .getFloatAlpha ();
133
125
}
134
126
135
127
@@ -234,16 +226,9 @@ public boolean startDrag(int position, int deltaX, int deltaY) {
234
226
if (mSortEnabled && !mIsRemoving ) {
235
227
dragFlags |= DragSortListView .DRAG_POS_Y | DragSortListView .DRAG_NEG_Y ;
236
228
}
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 ;
247
232
}
248
233
249
234
mDragging = mDslv .startDrag (position - mDslv .getHeaderViewsCount (), dragFlags , deltaX , deltaY );
@@ -257,7 +242,7 @@ public boolean onTouch(View v, MotionEvent ev) {
257
242
}
258
243
259
244
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 ) {
261
246
mFlingRemoveDetector .onTouchEvent (ev );
262
247
}
263
248
@@ -269,23 +254,11 @@ public boolean onTouch(View v, MotionEvent ev) {
269
254
mCurrY = (int ) ev .getY ();
270
255
break ;
271
256
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 );
289
262
}
290
263
}
291
264
case MotionEvent .ACTION_CANCEL :
@@ -303,40 +276,8 @@ public boolean onTouch(View v, MotionEvent ev) {
303
276
@ Override
304
277
public void onDragFloatView (View floatView , Point position , Point touch ) {
305
278
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 ;
340
281
}
341
282
}
342
283
@@ -357,7 +298,7 @@ public int startDragPosition(MotionEvent ev) {
357
298
return dragHandleHitPosition (ev );
358
299
}
359
300
public int startFlingPosition (MotionEvent ev ) {
360
- return mRemoveMode == FLING_OR_SLIDE_REMOVE ? flingHandleHitPosition (ev ) : MISS ;
301
+ return mRemoveMode == FLING_REMOVE ? flingHandleHitPosition (ev ) : MISS ;
361
302
}
362
303
363
304
/**
@@ -395,9 +336,7 @@ public int viewIdHitPosition(MotionEvent ev, int id) {
395
336
final int rawX = (int ) ev .getRawX ();
396
337
final int rawY = (int ) ev .getRawY ();
397
338
398
- //View dragBox = (View) item.getTag();
399
339
View dragBox = id == 0 ? item : (View ) item .findViewById (id );
400
- boolean dragHit = false ;
401
340
if (dragBox != null ) {
402
341
dragBox .getLocationOnScreen (mTempLoc );
403
342
@@ -445,7 +384,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
445
384
final int deltaX = x2 -mItemX ;
446
385
final int deltaY = y2 -mItemY ;
447
386
448
- if ( mRemoveMode == FLING_OR_SLIDE_REMOVE && mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos !=MISS )) {
387
+ if ( mCanDrag && !mDragging && (mHitPos != MISS || mFlingHitPos !=MISS )) {
449
388
450
389
if ( mHitPos != MISS )
451
390
{
@@ -476,21 +415,6 @@ else if( Math.abs(y2-y1) > mTouchSlop)
476
415
}
477
416
}
478
417
}
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
- }
494
418
// return whatever
495
419
return false ;
496
420
}
@@ -532,41 +456,25 @@ public void onShowPress(MotionEvent ev) {
532
456
@ Override
533
457
public final boolean onFling (MotionEvent e1 , MotionEvent e2 , float velocityX , float velocityY ) {
534
458
//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
+ }
567
475
}
476
+ mIsRemoving = false ;
568
477
}
569
- mIsRemoving = false ;
570
478
return false ;
571
479
}
572
480
};
0 commit comments