2
2
3
3
import android .content .Context ;
4
4
import android .content .Intent ;
5
+ import android .content .res .Resources ;
5
6
import android .support .annotation .NonNull ;
6
7
import android .support .annotation .Nullable ;
7
8
import android .support .design .widget .CoordinatorLayout ;
28
29
*/
29
30
public class NearbyNoificationCardView extends CardView {
30
31
32
+ private static final float MINIMUM_THRESHOLD_FOR_SWIPE = 100 ;
31
33
private Context context ;
32
34
33
35
private Button permissionRequestButton ;
@@ -98,13 +100,14 @@ private void setActionListeners() {
98
100
this .setOnTouchListener (
99
101
(v , event ) -> {
100
102
boolean isSwipe = false ;
103
+ float deltaX =0.0f ;
101
104
switch (event .getAction ()) {
102
105
case MotionEvent .ACTION_DOWN :
103
106
x1 = event .getX ();
104
107
break ;
105
108
case MotionEvent .ACTION_UP :
106
109
x2 = event .getX ();
107
- float deltaX = x2 - x1 ;
110
+ deltaX = x2 - x1 ;
108
111
if (deltaX < 0 ) {
109
112
//Right to left swipe
110
113
isSwipe = true ;
@@ -114,7 +117,7 @@ private void setActionListeners() {
114
117
}
115
118
break ;
116
119
}
117
- if (isSwipe ) {
120
+ if (isSwipe && ( pixelToDp ( Math . abs ( deltaX )) > MINIMUM_THRESHOLD_FOR_SWIPE ) ) {
118
121
v .setVisibility (GONE );
119
122
// Save shared preference for nearby card view accordingly
120
123
((MainActivity ) context ).prefs .edit ()
@@ -126,6 +129,10 @@ private void setActionListeners() {
126
129
});
127
130
}
128
131
132
+ private float pixelToDp (float pixels ) {
133
+ return (pixels / Resources .getSystem ().getDisplayMetrics ().density );
134
+ }
135
+
129
136
/**
130
137
* Sets permission request button visible and content layout invisible, then adds correct
131
138
* permission request actions to permission request button according to PermissionType enum
0 commit comments