android.view.MotionEvent#ACTION_SCROLL源码实例Demo

下面列出了android.view.MotionEvent#ACTION_SCROLL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: FlyWoo   文件: CircularImageView.java
@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);
}
 
源代码2 项目: android_9.0.0_r45   文件: StackView.java
@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);
}
 
源代码3 项目: UltimateAndroid   文件: CircularImageView.java
@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);
}
 
源代码4 项目: ZrcListView   文件: ZrcAbsListView.java
@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);
}
 
源代码5 项目: UltimateAndroid   文件: CircularImageView.java
@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);
}
 
源代码6 项目: FirefoxReality   文件: ServoPanZoomController.java
@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;
    }
}
 
源代码7 项目: buddycloud-android   文件: CircularImageView.java
@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);
}
 
源代码8 项目: Klyph   文件: AbsHListView.java
@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 );
}
 
@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);
}
 
源代码10 项目: MaterialDrawer-Xamarin   文件: BezelImageView.java
@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);
}
 
源代码11 项目: GithubContributorsLib   文件: CircularImageView.java
@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);
}
 
源代码12 项目: wearmouse   文件: MouseFragment.java
public boolean onGenericMotionEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_SCROLL && RotaryEncoder.isFromRotaryEncoder(ev)) {
        controller.onRotaryInput(RotaryEncoder.getRotaryAxisValue(ev) * scrollFactor);
        return true;
    }
    return false;
}
 
源代码13 项目: android_9.0.0_r45   文件: BaseMovementMethod.java
@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;
}
 
源代码14 项目: android_9.0.0_r45   文件: ScrollView.java
@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);
}
 
源代码15 项目: JotaTextEditor   文件: BaseMovementMethod.java
@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;
}
 
源代码16 项目: Trebuchet   文件: PagedView.java
@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);
}
 
源代码17 项目: LaunchEnr   文件: PagedView.java
@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);
}
 
源代码18 项目: LB-Launcher   文件: PagedView.java
@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);
}
 
源代码19 项目: ankihelper   文件: AppUtil.java
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);
    }
}
 
/**
 * 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);
}