Convert DisableableViewPager to Kotlin

This commit is contained in:
Billy Brawner 2019-08-17 13:49:53 -05:00 committed by William Brawner
parent 860407e5d0
commit 927bdb9546
2 changed files with 28 additions and 37 deletions

View file

@ -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;
}
}

View file

@ -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
}
}