From 927bdb954664a887979aa2bd27ba894fecd33b7b Mon Sep 17 00:00:00 2001 From: Billy Brawner Date: Sat, 17 Aug 2019 13:49:53 -0500 Subject: [PATCH] Convert DisableableViewPager to Kotlin --- .../view/DisableableViewPager.java | 37 ------------------- .../view/DisableableViewPager.kt | 28 ++++++++++++++ 2 files changed, 28 insertions(+), 37 deletions(-) delete mode 100644 app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java create mode 100644 app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java b/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java deleted file mode 100644 index 8ecdc60..0000000 --- a/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.wbrawner.simplemarkdown.view; - -import android.annotation.SuppressLint; -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 DisableableViewPager extends ViewPager { - private boolean isSwipeLocked = false; - - public DisableableViewPager(@NonNull Context context) { - super(context); - } - - public DisableableViewPager(@NonNull Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - } - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - return !isSwipeLocked && super.onInterceptTouchEvent(ev); - } - - @SuppressLint("ClickableViewAccessibility") - @Override - public boolean onTouchEvent(MotionEvent ev) { - return !isSwipeLocked && super.onTouchEvent(ev); - } - - public void setSwipeLocked(boolean locked) { - this.isSwipeLocked = locked; - } -} diff --git a/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt b/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt new file mode 100644 index 0000000..229fd2a --- /dev/null +++ b/app/src/main/java/com/wbrawner/simplemarkdown/view/DisableableViewPager.kt @@ -0,0 +1,28 @@ +package com.wbrawner.simplemarkdown.view + +import android.annotation.SuppressLint +import android.content.Context +import android.util.AttributeSet +import android.view.MotionEvent +import androidx.viewpager.widget.ViewPager + +class DisableableViewPager : ViewPager { + private var isSwipeLocked = false + + constructor(context: Context) : super(context) + + constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + return !isSwipeLocked && super.onInterceptTouchEvent(ev) + } + + @SuppressLint("ClickableViewAccessibility") + override fun onTouchEvent(ev: MotionEvent): Boolean { + return !isSwipeLocked && super.onTouchEvent(ev) + } + + fun setSwipeLocked(locked: Boolean) { + this.isSwipeLocked = locked + } +}