Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. package by.flipdev.lib.view;
  2.  
  3. import android.content.Context;
  4. import android.util.AttributeSet;
  5. import android.view.MotionEvent;
  6.  
  7. /**
  8. * Created by egormoseevskiy on 14.10.14.
  9. */
  10. public class ScrollViewAcnUseHorizontalScrollOnScrollListenerImplented extends ScrollViewCanUseViewPager {
  11.  
  12. private Listener listener;
  13.  
  14. private int width, height;
  15. private boolean scrollable = true;
  16.  
  17. public ScrollViewAcnUseHorizontalScrollOnScrollListenerImplented(Context context) {
  18. super(context);
  19. }
  20.  
  21. public ScrollViewAcnUseHorizontalScrollOnScrollListenerImplented(Context context, AttributeSet attrs) {
  22. super(context, attrs);
  23. }
  24.  
  25. public ScrollViewAcnUseHorizontalScrollOnScrollListenerImplented(Context context, AttributeSet attrs, int defStyle) {
  26. super(context, attrs, defStyle);
  27. }
  28.  
  29. public ScrollViewAcnUseHorizontalScrollOnScrollListenerImplented setListener(Listener Listener) {
  30. this.listener = Listener;
  31. return this;
  32. }
  33.  
  34. @Override
  35. protected void onScrollChanged(int l, int t, int oldl, int oldt) {
  36. if (listener != null)
  37. listener.onScrollChanged(l, t, oldl, oldt);
  38. }
  39.  
  40. @Override
  41. protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  42. super.onMeasure(widthMeasureSpec, heightMeasureSpec);
  43.  
  44. int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
  45. int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
  46.  
  47. this.setMeasuredDimension(
  48. parentWidth, parentHeight);
  49. if (width != parentWidth || height != parentHeight) {
  50. width = parentWidth;
  51. height = parentHeight;
  52. if (listener != null) listener.sizeChanged(width, height);
  53. }
  54. }
  55.  
  56. @Override
  57. public boolean onTouchEvent(MotionEvent ev) {
  58. if (ev.getAction() == MotionEvent.ACTION_DOWN)
  59. if (listener != null) listener.onPointerDown();
  60. if (scrollable) return super.onTouchEvent(ev);
  61. return scrollable;
  62. }
  63.  
  64. public void setScrollingEnabled(boolean enabled) {
  65. scrollable = enabled;
  66. }
  67.  
  68. public boolean isScrollable() {
  69. return scrollable;
  70. }
  71.  
  72. public interface Listener {
  73. void sizeChanged(int w, int h);
  74.  
  75. void onScrollChanged(int l, int t, int oldl, int oldt);
  76.  
  77. void onPointerDown();
  78. }
  79.  
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement