22
33import android .content .Context ;
44import android .content .Intent ;
5+ import android .content .res .Resources ;
56import android .support .annotation .NonNull ;
67import android .support .annotation .Nullable ;
78import android .support .design .widget .CoordinatorLayout ;
2829 */
2930public class NearbyNoificationCardView extends CardView {
3031
32+ private static final float MINIMUM_THRESHOLD_FOR_SWIPE = 100 ;
3133 private Context context ;
3234
3335 private Button permissionRequestButton ;
@@ -98,13 +100,14 @@ private void setActionListeners() {
98100 this .setOnTouchListener (
99101 (v , event ) -> {
100102 boolean isSwipe = false ;
103+ float deltaX =0.0f ;
101104 switch (event .getAction ()) {
102105 case MotionEvent .ACTION_DOWN :
103106 x1 = event .getX ();
104107 break ;
105108 case MotionEvent .ACTION_UP :
106109 x2 = event .getX ();
107- float deltaX = x2 - x1 ;
110+ deltaX = x2 - x1 ;
108111 if (deltaX < 0 ) {
109112 //Right to left swipe
110113 isSwipe = true ;
@@ -114,7 +117,7 @@ private void setActionListeners() {
114117 }
115118 break ;
116119 }
117- if (isSwipe ) {
120+ if (isSwipe && ( pixelToDp ( Math . abs ( deltaX )) > MINIMUM_THRESHOLD_FOR_SWIPE ) ) {
118121 v .setVisibility (GONE );
119122 // Save shared preference for nearby card view accordingly
120123 ((MainActivity ) context ).prefs .edit ()
@@ -126,6 +129,10 @@ private void setActionListeners() {
126129 });
127130 }
128131
132+ private float pixelToDp (float pixels ) {
133+ return (pixels / Resources .getSystem ().getDisplayMetrics ().density );
134+ }
135+
129136 /**
130137 * Sets permission request button visible and content layout invisible, then adds correct
131138 * permission request actions to permission request button according to PermissionType enum
0 commit comments