Skip to content

Commit

Permalink
Bug fix issue #1999 (#2000)
Browse files Browse the repository at this point in the history
* Added a threshold on swipe, ie. if a swipe is considered a swipe only if it covers a distance of 100dp
  • Loading branch information
ashishkumar468 authored and maskaravivek committed Nov 19, 2018
1 parent 8eac08f commit 4930a82
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.CoordinatorLayout;
Expand All @@ -28,6 +29,7 @@
*/
public class NearbyNoificationCardView extends CardView{

private static final float MINIMUM_THRESHOLD_FOR_SWIPE = 100;
private Context context;

private Button permissionRequestButton;
Expand Down Expand Up @@ -98,13 +100,14 @@ private void setActionListeners() {
this.setOnTouchListener(
(v, event) -> {
boolean isSwipe = false;
float deltaX=0.0f;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
break;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float deltaX = x2 - x1;
deltaX = x2 - x1;
if (deltaX < 0) {
//Right to left swipe
isSwipe = true;
Expand All @@ -114,7 +117,7 @@ private void setActionListeners() {
}
break;
}
if (isSwipe) {
if (isSwipe && (pixelToDp(Math.abs(deltaX)) > MINIMUM_THRESHOLD_FOR_SWIPE)) {
v.setVisibility(GONE);
// Save shared preference for nearby card view accordingly
((MainActivity) context).prefs.edit()
Expand All @@ -126,6 +129,10 @@ private void setActionListeners() {
});
}

private float pixelToDp(float pixels) {
return (pixels / Resources.getSystem().getDisplayMetrics().density);
}

/**
* Sets permission request button visible and content layout invisible, then adds correct
* permission request actions to permission request button according to PermissionType enum
Expand Down

0 comments on commit 4930a82

Please sign in to comment.