diff --git a/CHANGELOG.md b/CHANGELOG.md
index 561f4b50b..005a1e845 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
### Changelog
+#### Version NEXT
+* Charts: added preference to disable swiping charts left/right
+
#### Version 0.22.1
* Mi Band 2: Fix being detected as Amazfit Bip which lead to various problems especially on newly paired devices
diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java
index c28cc6d26..d857800a4 100644
--- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java
+++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ChartsActivity.java
@@ -29,8 +29,10 @@ import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.SwipeRefreshLayout;
+import android.util.AttributeSet;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
@@ -66,7 +68,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
private Date mStartDate;
private Date mEndDate;
private SwipeRefreshLayout swipeLayout;
- private ViewPager viewPager;
+ private NonSwipeableViewPager viewPager;
LimitedQueue mActivityAmountCache = new LimitedQueue(60);
@@ -153,7 +155,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
enableSwipeRefresh(true);
// Set up the ViewPager with the sections adapter.
- viewPager = (ViewPager) findViewById(R.id.charts_pager);
+ viewPager = (NonSwipeableViewPager) findViewById(R.id.charts_pager);
viewPager.setAdapter(getPagerAdapter());
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
@@ -365,3 +367,26 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
}
}
}
+
+class NonSwipeableViewPager extends ViewPager {
+
+ public NonSwipeableViewPager(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ if (GBApplication.getPrefs().getBoolean("charts_allow_swipe", true)) {
+ return super.onInterceptTouchEvent(ev);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent ev) {
+ if (GBApplication.getPrefs().getBoolean("charts_allow_swipe", true)) {
+ return super.onTouchEvent(ev);
+ }
+ return false;
+ }
+}
diff --git a/app/src/main/res/layout/activity_charts.xml b/app/src/main/res/layout/activity_charts.xml
index 6321f441e..3fe54825d 100644
--- a/app/src/main/res/layout/activity_charts.xml
+++ b/app/src/main/res/layout/activity_charts.xml
@@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
-
-
+
Reconnect automatically
Preferred Audioplayer
Default
+ Enable left/right swipe in the charts activity
Date and Time
Sync time
diff --git a/app/src/main/res/xml/changelog_master.xml b/app/src/main/res/xml/changelog_master.xml
index b4c6e1a92..8144295a5 100644
--- a/app/src/main/res/xml/changelog_master.xml
+++ b/app/src/main/res/xml/changelog_master.xml
@@ -1,5 +1,8 @@
+
+ Charts: added preference to disable swiping charts left/right
+
Mi Band 2: Fix being detected as Amazfit Bip which lead to various problems especially on newly paired devices
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 58b2b2597..d27e22388 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -92,6 +92,10 @@
android:maxLength="2"
android:title="@string/activity_prefs_sleep_duration" />
+