0

I have custom scrollview written which is working fine without stylus from Tablets. When using Tablet stylus this customScrollview is allowing stylus to perform scrolling even when Scrolling is disabled.

public class CustomScrollView extends ScrollView {

    private boolean enabled = false;

    public CustomScrollView(Context context) {
        super(context);
    }

    public CustomScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public boolean getEnabled() {
        return this.enabled;
    }
}
HourGlass
  • 1,805
  • 1
  • 15
  • 29

3 Answers3

0

you could give this a try.

 if (MotionEvent.getToolType(TOOL_TYPE_STYLUS))
 { 
 // disable scrollview 
 }
Rick
  • 23
  • 8
  • Nope not a good solution @Rick. My problem is not the scrollview. I hope you used stylus in a tablet. So when you point your stylus to end of the home screen it move to the next screen. The same happens in scrollview as well. If something is scrollable on screen , pointing the stylus at the end will make it scroll. I want to stop this from happening. Because the scrollview is disabled 100% sure. But when I point the stylus to the end it starts scrolling. – HourGlass Feb 28 '17 at 11:30
0

Try this:

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (ev.getToolType(TOOL_TYPE_STYLUS)) { 
        // also, here you should check if it should be disabled at this point
        return !enabled;
    } else {
        return enabled;
    }
}
0

Overriding onInterceptHoverListener Did the trick. Now the Stylus onhover scroll is handled if scrollview is enabled,the same is not handled once the scrollview enabled = false.

    public class CustomScrollView extends ScrollView {

        private boolean enabled = false;

        public CustomScrollView(Context context) {
            super(context);
        }

        public CustomScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }

        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return enabled;
        }

        public void setEnabled(boolean enabled) {
            this.enabled = enabled;
        }

      @Override
        public boolean onInterceptHoverEvent(MotionEvent event) {
   if (this.enabled)
        {
            return false;
        }
        else
        {
          return true;
        }

}

       public boolean getEnabled() {
            return this.enabled;
        }
    }
HourGlass
  • 1,805
  • 1
  • 15
  • 29