-
Notifications
You must be signed in to change notification settings - Fork 0
/
LockableViewPager.java
49 lines (37 loc) · 1.39 KB
/
LockableViewPager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package com.lorenzostanco.utils;
import android.annotation.SuppressLint;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.KeyEvent;
import android.view.MotionEvent;
// For AndroidX projects:
// import androidx.annotation.NonNull;
// import androidx.viewpager.widget.ViewPager;
/** Un ViewPager orizzontale, la cui paginazione col tocco può essere all'occorrenza bloccata
* http://stackoverflow.com/a/7814054/995958 */
@SuppressWarnings("unused") public class LockableViewPager extends ViewPager {
private boolean isPagingEnabled = true;
public LockableViewPager(final Context context) {
super(context);
}
public LockableViewPager(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(final MotionEvent event) {
return this.isPagingEnabled && super.onTouchEvent(event);
}
@Override public boolean onInterceptTouchEvent(final MotionEvent event) {
return this.isPagingEnabled && super.onInterceptTouchEvent(event);
}
@Override public boolean executeKeyEvent(@NonNull final KeyEvent event) {
return false;
}
public void setPagingEnabled(final boolean b) {
this.isPagingEnabled = b;
}
public boolean isPagingEnabled() {
return isPagingEnabled;
}
}