Java Code Examples for android.view.MotionEvent#ACTION_SCROLL

The following examples show how to use android.view.MotionEvent#ACTION_SCROLL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircularImageView.java    From FlyWoo with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Check for clickable state and do nothing if disabled
    if (!this.isClickable()) {
        this.isSelected = false;
        return super.onTouchEvent(event);
    }

    // Set selected state based on Motion Event
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            this.isSelected = true;
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_SCROLL:
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
            this.isSelected = false;
            break;
    }

    // Redraw image and return super type
    this.invalidate();
    return super.dispatchTouchEvent(event);
}
 
Example 2
Source File: CircularImageView.java    From GithubContributorsLib with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
	// Check for clickable state and do nothing if disabled
	if (!this.isClickable()) {
		this.isSelected = false;
		return super.onTouchEvent(event);
	}

	// Set selected state based on Motion Event
	switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			this.isSelected = true;
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_SCROLL:
		case MotionEvent.ACTION_OUTSIDE:
		case MotionEvent.ACTION_CANCEL:
			this.isSelected = false;
			break;
	}

	// Redraw image and return super type
	this.invalidate();
	return super.dispatchTouchEvent(event);
}
 
Example 3
Source File: BezelImageView.java    From MaterialDrawer-Xamarin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Check for clickable state and do nothing if disabled
    if (!this.isClickable()) {
        this.isSelected = false;
        return super.onTouchEvent(event);
    }

    // Set selected state based on Motion Event
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            this.isSelected = true;
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_SCROLL:
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
            this.isSelected = false;
            break;
    }

    // Redraw image and return super type
    this.invalidate();
    return super.dispatchTouchEvent(event);
}
 
Example 4
Source File: CircleImageView.java    From CollapsingToolbar-With-Webview with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    // Check for clickable state and do nothing if disabled
    if (!this.isClickable()) {
        this.isSelected = false;
        return super.onTouchEvent(event);
    }

    // Set selected state based on Motion Event
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            this.isSelected = true;
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_SCROLL:
        case MotionEvent.ACTION_OUTSIDE:
        case MotionEvent.ACTION_CANCEL:
            this.isSelected = false;
            break;
    }

    // Redraw image and return super type
    this.invalidate();
    return super.dispatchTouchEvent(event);
}
 
Example 5
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
@TargetApi(12)
@Override
public boolean onGenericMotionEvent( MotionEvent event ) {
	if ( ( event.getSource() & InputDevice.SOURCE_CLASS_POINTER ) != 0 ) {
		switch ( event.getAction() ) {
			case MotionEvent.ACTION_SCROLL: {
				if ( mTouchMode == TOUCH_MODE_REST ) {
					final float hscroll = event.getAxisValue( MotionEvent.AXIS_HSCROLL );
					if ( hscroll != 0 ) {
						final int delta = (int) ( hscroll * getHorizontalScrollFactor() );
						if ( !trackMotionScroll( delta, delta ) ) {
							return true;
						}
					}
				}
			}
		}
	}
	return super.onGenericMotionEvent( event );
}
 
Example 6
Source File: CircularImageView.java    From buddycloud-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
	// Check for clickable state and do nothing if disabled
	if (!this.isClickable()) {
		this.isSelected = false;
		return super.onTouchEvent(event);
	}

	// Set selected state based on Motion Event
	switch (event.getAction()) {
	case MotionEvent.ACTION_DOWN:
		this.isSelected = true;
		break;
	case MotionEvent.ACTION_UP:
	case MotionEvent.ACTION_SCROLL:
	case MotionEvent.ACTION_OUTSIDE:
	case MotionEvent.ACTION_CANCEL:
		this.isSelected = false;
		break;
	}

	// Redraw image and return super type
	this.invalidate();
	return super.dispatchTouchEvent(event);
}
 
Example 7
Source File: ServoPanZoomController.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean onMotionEvent(MotionEvent event) {
    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_SCROLL) {
        if (event.getDownTime() >= mLastDownTime) {
            mLastDownTime = event.getDownTime();
        } else if ((InputDevice.getDevice(event.getDeviceId()).getSources() &
                InputDevice.SOURCE_TOUCHPAD) == InputDevice.SOURCE_TOUCHPAD) {
            return false;
        }
        return handleScrollEvent(event);
    } else if ((action == MotionEvent.ACTION_HOVER_MOVE) ||
        (action == MotionEvent.ACTION_HOVER_ENTER) ||
        (action == MotionEvent.ACTION_HOVER_EXIT)) {
      return onMouseEvent(event);
    } else {
        return false;
    }
}
 
Example 8
Source File: CircularImageView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
	// Check for clickable state and do nothing if disabled
	if(!this.isClickable()) {
		this.isSelected = false;
		return super.onTouchEvent(event);
	}

	// Set selected state based on Motion Event
	switch(event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			this.isSelected = true;
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_SCROLL:
		case MotionEvent.ACTION_OUTSIDE:
		case MotionEvent.ACTION_CANCEL:
			this.isSelected = false;
			break;
	}

	// Redraw image and return super type
	this.invalidate();
	return super.dispatchTouchEvent(event);
}
 
Example 9
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
	if (APIUtil.isSupport(12)) {
		if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
			switch (event.getAction()) {
			case MotionEvent.ACTION_SCROLL: {
				if (mTouchMode == TOUCH_MODE_REST) {
					final float vscroll = event
							.getAxisValue(MotionEvent.AXIS_VSCROLL);
					if (vscroll != 0) {
						final int delta = (int) (vscroll * getVerticalScrollFactor());
						if (!trackMotionScroll(delta, delta)) {
							return true;
						}
					}
				}
			}
			}
		}
	}
	return super.onGenericMotionEvent(event);
}
 
Example 10
Source File: CircularImageView.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
	// Check for clickable state and do nothing if disabled
	if(!this.isClickable()) {
		this.isSelected = false;
		return super.onTouchEvent(event);
	}

	// Set selected state based on Motion Event
	switch(event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			this.isSelected = true;
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_SCROLL:
		case MotionEvent.ACTION_OUTSIDE:
		case MotionEvent.ACTION_CANCEL:
			this.isSelected = false;
			break;
	}

	// Redraw image and return super type
	this.invalidate();
	return super.dispatchTouchEvent(event);
}
 
Example 11
Source File: StackView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                if (vscroll < 0) {
                    pacedScroll(false);
                    return true;
                } else if (vscroll > 0) {
                    pacedScroll(true);
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 12
Source File: BaseMovementMethod.java    From JotaTextEditor with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
    if ((ApiWrapper.getSourceOfEvent(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = ApiWrapper.getAxisValue(event,MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -ApiWrapper.getAxisValue(event,MotionEvent.AXIS_VSCROLL);
                    hscroll = ApiWrapper.getAxisValue(event,MotionEvent.AXIS_HSCROLL);
                }

                boolean handled = false;
                if (hscroll < 0) {
                    handled |= scrollLeft(widget, text, (int)Math.ceil(-hscroll));
                } else if (hscroll > 0) {
                    handled |= scrollRight(widget, text, (int)Math.ceil(hscroll));
                }
                if (vscroll < 0) {
                    handled |= scrollUp(widget, text, (int)Math.ceil(-vscroll));
                    if ( handled ){
                    	widget.moveCursorToVisibleOffset();
                    }
                } else if (vscroll > 0) {
                    handled |= scrollDown(widget, text, (int)Math.ceil(vscroll));
                    if ( handled ){
                    	widget.moveCursorToVisibleOffset();
                    }
                }
                return handled;
            }
        }
    }
    return false;
}
 
Example 13
Source File: PagedView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 14
Source File: PagedView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 15
Source File: ScrollView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL:
            final float axisValue;
            if (event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
                axisValue = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
            } else if (event.isFromSource(InputDevice.SOURCE_ROTARY_ENCODER)) {
                axisValue = event.getAxisValue(MotionEvent.AXIS_SCROLL);
            } else {
                axisValue = 0;
            }

            final int delta = Math.round(axisValue * mVerticalScrollFactor);
            if (delta != 0) {
                final int range = getScrollRange();
                int oldScrollY = mScrollY;
                int newScrollY = oldScrollY - delta;
                if (newScrollY < 0) {
                    newScrollY = 0;
                } else if (newScrollY > range) {
                    newScrollY = range;
                }
                if (newScrollY != oldScrollY) {
                    super.scrollTo(mScrollX, newScrollY);
                    return true;
                }
            }
            break;
    }

    return super.onGenericMotionEvent(event);
}
 
Example 16
Source File: PagedView.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = isLayoutRtl() ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
Example 17
Source File: BaseMovementMethod.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGenericMotionEvent(TextView widget, Spannable text, MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }

                boolean handled = false;
                if (hscroll < 0) {
                    handled |= scrollLeft(widget, text, (int)Math.ceil(-hscroll));
                } else if (hscroll > 0) {
                    handled |= scrollRight(widget, text, (int)Math.ceil(hscroll));
                }
                if (vscroll < 0) {
                    handled |= scrollUp(widget, text, (int)Math.ceil(-vscroll));
                } else if (vscroll > 0) {
                    handled |= scrollDown(widget, text, (int)Math.ceil(vscroll));
                }
                return handled;
            }
        }
    }
    return false;
}
 
Example 18
Source File: MouseFragment.java    From wearmouse with Apache License 2.0 5 votes vote down vote up
public boolean onGenericMotionEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_SCROLL && RotaryEncoder.isFromRotaryEncoder(ev)) {
        controller.onRotaryInput(RotaryEncoder.getRotaryAxisValue(ev) * scrollFactor);
        return true;
    }
    return false;
}
 
Example 19
Source File: AppUtil.java    From ankihelper with GNU General Public License v3.0 4 votes vote down vote up
public static String actionToString(int action) {
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            return "ACTION_DOWN";
        case MotionEvent.ACTION_UP:
            return "ACTION_UP";
        case MotionEvent.ACTION_CANCEL:
            return "ACTION_CANCEL";
        case MotionEvent.ACTION_OUTSIDE:
            return "ACTION_OUTSIDE";
        case MotionEvent.ACTION_MOVE:
            return "ACTION_MOVE";
        case MotionEvent.ACTION_HOVER_MOVE:
            return "ACTION_HOVER_MOVE";
        case MotionEvent.ACTION_SCROLL:
            return "ACTION_SCROLL";
        case MotionEvent.ACTION_HOVER_ENTER:
            return "ACTION_HOVER_ENTER";
        case MotionEvent.ACTION_HOVER_EXIT:
            return "ACTION_HOVER_EXIT";
    }

    if (Build.VERSION.SDK_INT >= 23) {
        switch (action) {
            case MotionEvent.ACTION_BUTTON_PRESS:
                return "ACTION_BUTTON_PRESS";
            case MotionEvent.ACTION_BUTTON_RELEASE:
                return "ACTION_BUTTON_RELEASE";
        }
    }

    int index = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_DOWN:
            return "ACTION_POINTER_DOWN(" + index + ")";
        case MotionEvent.ACTION_POINTER_UP:
            return "ACTION_POINTER_UP(" + index + ")";
        default:
            return Integer.toString(action);
    }
}
 
Example 20
Source File: BottomSheetRecyclerView.java    From arcgis-runtime-samples-android with Apache License 2.0 3 votes vote down vote up
/**
 * Intercept touch events and determine if {@link RecyclerView} should grab touch event to allow scrolling of RecyclerView
 * within Bottom Sheet
 *
 * @param e event intercepted
 * @return return true to consume the event, false otherwise
 */
@Override public boolean onInterceptTouchEvent(MotionEvent e) {
  if (e.getAction() == MotionEvent.ACTION_SCROLL && canScrollVertically(1)) {
    return true;
  }
  return super.onInterceptTouchEvent(e);
}