From 3155170e069e8a064b8b7d3dfd57f831772c9184 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 7 May 2019 12:51:10 -0700 Subject: [PATCH] Disable swiping in the ViewPager. https://redmine.stoutner.com/issues/415 --- .../views/NoSwipeViewPager.java | 67 +++++++++++++++++++ .../res/layout/about_coordinatorlayout.xml | 6 +- .../res/layout/guide_coordinatorlayout.xml | 6 +- .../import_export_coordinatorlayout.xml | 4 +- app/src/main/res/layout/main_framelayout.xml | 22 +++--- .../layout/pinned_mismatch_linearlayout.xml | 4 +- 6 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 app/src/main/java/com/stoutner/privacybrowser/views/NoSwipeViewPager.java diff --git a/app/src/main/java/com/stoutner/privacybrowser/views/NoSwipeViewPager.java b/app/src/main/java/com/stoutner/privacybrowser/views/NoSwipeViewPager.java new file mode 100644 index 00000000..cb6e0656 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/views/NoSwipeViewPager.java @@ -0,0 +1,67 @@ +/* + * Copyright © 2019 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser. If not, see . + */ + +package com.stoutner.privacybrowser.views; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.MotionEvent; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.viewpager.widget.ViewPager; + +public class NoSwipeViewPager extends ViewPager { + // The basic constructor + public NoSwipeViewPager(@NonNull Context context) { + // Roll up to the full constructor. + this(context, null); + } + + // The full constructor. + public NoSwipeViewPager(@NonNull Context context, @Nullable AttributeSet attributeSet) { + // Run the default commands. + super(context, attributeSet); + } + + // It is necessary to override `performClick()` when overriding `onTouchEvent()` + @Override + public boolean performClick() { + // Run the default commands. + super.performClick(); + + // Do not consume the events. + return false; + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + // `onTouchEvent()` requires calling `performClick()`. + performClick(); + + // Do not allow swiping. + return false; + } + + @Override + public boolean onInterceptTouchEvent(MotionEvent event) { + // Do not allow swiping. + return false; + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/about_coordinatorlayout.xml b/app/src/main/res/layout/about_coordinatorlayout.xml index bc365d6b..c9062d9e 100644 --- a/app/src/main/res/layout/about_coordinatorlayout.xml +++ b/app/src/main/res/layout/about_coordinatorlayout.xml @@ -23,7 +23,7 @@ @@ -54,8 +54,8 @@ android:id="@+id/about_tablayout" android:layout_height="wrap_content" android:layout_width="match_parent" - android.support.design:tabMode="scrollable" - android.support.design:tabIndicatorColor="?attr/tabIndicatorColor" + app:tabMode="scrollable" + app:tabIndicatorColor="?attr/tabIndicatorColor" android:theme="?attr/tabLayoutTheme" /> diff --git a/app/src/main/res/layout/guide_coordinatorlayout.xml b/app/src/main/res/layout/guide_coordinatorlayout.xml index b47501c9..a95e6a0c 100644 --- a/app/src/main/res/layout/guide_coordinatorlayout.xml +++ b/app/src/main/res/layout/guide_coordinatorlayout.xml @@ -23,7 +23,7 @@ When it is specified the theme should include @@ -54,8 +54,8 @@ When it is specified the theme should include diff --git a/app/src/main/res/layout/import_export_coordinatorlayout.xml b/app/src/main/res/layout/import_export_coordinatorlayout.xml index a38850aa..29b6fe89 100644 --- a/app/src/main/res/layout/import_export_coordinatorlayout.xml +++ b/app/src/main/res/layout/import_export_coordinatorlayout.xml @@ -184,7 +184,7 @@ android:onClick="onClickRadioButton" /> - + - + + app:layout_scrollFlags="scroll|enterAlways|snap" /> + app:layout_scrollFlags="scroll|enterAlways|snap" > + app:layout_scrollFlags="scroll|enterAlways|snap" > + app:tabIndicatorGravity="top" + app:tabMode="scrollable" /> + app:layout_behavior="@string/appbar_scrolling_view_behavior" > - @@ -181,9 +181,9 @@ android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="start" - android.support.design:headerLayout="@layout/navigation_header" - android.support.design:menu="@menu/webview_navigation_menu" - android.support.design:itemIconTint="?attr/navigationIconTintColor" /> + app:headerLayout="@layout/navigation_header" + app:menu="@menu/webview_navigation_menu" + app:itemIconTint="?attr/navigationIconTintColor" /> diff --git a/app/src/main/res/layout/pinned_mismatch_linearlayout.xml b/app/src/main/res/layout/pinned_mismatch_linearlayout.xml index be8db4c2..4154874e 100644 --- a/app/src/main/res/layout/pinned_mismatch_linearlayout.xml +++ b/app/src/main/res/layout/pinned_mismatch_linearlayout.xml @@ -20,7 +20,7 @@ @@ -29,7 +29,7 @@ android:id="@+id/pinned_ssl_certificate_mismatch_tablayout" android:layout_height="wrap_content" android:layout_width="wrap_content" - android.support.design:tabMode="scrollable" + app:tabMode="scrollable" android:theme="?attr/dialogTabLayoutTheme" />