本文整理匯總了Java中android.view.MotionEvent.ACTION_SCROLL屬性的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.ACTION_SCROLL屬性的具體用法?Java MotionEvent.ACTION_SCROLL怎麽用?Java MotionEvent.ACTION_SCROLL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.ACTION_SCROLL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
if(PreferenceManager.getDefaultSharedPreferences(getContext()).getBoolean("widgetScroll", false)) {
if (ev.getAction() == MotionEvent.ACTION_MOVE || ev.getAction() == MotionEvent.ACTION_SCROLL) {
if(Math.abs(ev.getX()-lastX)<Math.abs(ev.getY()-lastY)) {
for (int i = 0; i < getChildCount(); i++) {
View v = getChildAt(i);
if (v.getTag() instanceof Card.Apps) {
Card.Apps c = (Card.Apps) v.getTag();
float x = v.getX() + c.getCardContainer().getX();
float y = v.getY() + c.getCardContainer().getY();
float w = c.getCardContainer().getWidth();
float h = c.getCardContainer().getHeight();
if (ev.getX() >= x && ev.getX() < x + w && ev.getY() >= y && ev.getY() < y + h) {
return true;
} else break;
}
}
}
}
}
lastX = ev.getX();
lastY = ev.getY();
return super.onInterceptTouchEvent(ev);
}
示例2: dispatchTouchEvent
@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);
}
示例3: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!this.isClickable()) {
this.setSelected(false);
return super.onTouchEvent(event);
}
if (!mIsTouchSelectModeEnabled) {
return super.onTouchEvent(event);
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
this.setSelected(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_SCROLL:
case MotionEvent.ACTION_OUTSIDE:
case MotionEvent.ACTION_CANCEL:
this.setSelected(false);
break;
}
return super.onTouchEvent(event);
}
示例4: onGenericMotionEvent
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@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);
}
示例5: dispatchTouchEvent
@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: onGenericMotionEvent
@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(DBG) Log.d(TAG,"onGenericMotionEvent ACTION_SCROLL vscroll="+vscroll);
if (vscroll != 0) {
final int index = mLayout.getFrontCoverIndex();
int targetIndex;
if (index+vscroll<0) {
targetIndex=0;
} else if (index+vscroll >= mCovers.size()-1) {
targetIndex = mCovers.size()-1;
} else {
targetIndex = (int)(index+vscroll+0.5);
}
float targetScroll = mLayout.getScrollingPositionToCenterThisCover(targetIndex);
mAnimHandler.startScrollingAnimPosition(targetScroll, AnimHandler.SPEED_FAST);
}
}
}
}
return super.onGenericMotionEvent(event);
}
示例7: processGenericEvent
public void processGenericEvent(final MotionEvent event)
{
// Joysticks are supported since Honeycomb, but I don't care about it, because very few devices have it
if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
{
// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, on Nvidia Shield and some other joysticks
DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
event.getAxisValue(MotionEvent.AXIS_LTRIGGER), event.getAxisValue(MotionEvent.AXIS_RTRIGGER),
event.getAxisValue(MotionEvent.AXIS_HAT_X), event.getAxisValue(MotionEvent.AXIS_HAT_Y),
processGamepadDeviceId(event.getDevice()) );
return;
}
// Process mousewheel
if( event.getAction() == MotionEvent.ACTION_SCROLL )
{
int scrollX = Math.round(event.getAxisValue(MotionEvent.AXIS_HSCROLL));
int scrollY = Math.round(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
DemoGLSurfaceView.nativeMouseWheel(scrollX, scrollY);
return;
}
super.processGenericEvent(event);
}
示例8: onGenericMotionEvent
@Override
@TargetApi(12)
public boolean onGenericMotionEvent(MotionEvent event) {
if ((MotionEventCompat.getSource(event) & InputDevice.SOURCE_CLASS_POINTER) != 0) {
switch (event.getAction()) {
case MotionEvent.ACTION_SCROLL:
// Process scroll wheel movement:
float yDistance = MotionEventCompat.getAxisValue(event, MotionEvent.AXIS_VSCROLL);
vt320 vtBuffer = (vt320) terminalView.bridge.buffer;
boolean mouseReport = vtBuffer.isMouseReportEnabled();
if (mouseReport) {
int row = (int) Math.floor(event.getY() / terminalView.bridge.charHeight);
int col = (int) Math.floor(event.getX() / terminalView.bridge.charWidth);
vtBuffer.mouseWheel(
yDistance > 0,
col,
row,
(event.getMetaState() & KeyEvent.META_CTRL_ON) != 0,
(event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0,
(event.getMetaState() & KeyEvent.META_META_ON) != 0);
return true;
}
}
}
return super.onGenericMotionEvent(event);
}
示例9: onGenericMotionEvent
@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);
}
示例10: friendlyMotionEvent
private String friendlyMotionEvent(MotionEvent ev) {
String action;
if (ev != null) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
action = "ACTION_DOWN";
break;
case MotionEvent.ACTION_UP:
action = "ACTION_UP";
break;
case MotionEvent.ACTION_MOVE:
action = "ACTION_MOVE";
break;
case MotionEvent.ACTION_CANCEL:
action = "ACTION_CANCEL";
break;
case MotionEvent.ACTION_SCROLL:
action = "ACTION_SCROLL";
break;
default:
action = String.valueOf(ev.getAction());
}
} else {
action = "MotionEvent is null (action cannot be taken from it)";
}
return action;
}
示例11: onGenericMotion
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
float x, y;
int action;
switch ( event.getSource() ) {
case InputDevice.SOURCE_JOYSTICK:
case InputDevice.SOURCE_GAMEPAD:
case InputDevice.SOURCE_DPAD:
return SDLActivity.handleJoystickMotionEvent(event);
case InputDevice.SOURCE_MOUSE:
action = event.getActionMasked();
switch (action) {
case MotionEvent.ACTION_SCROLL:
x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
SDLActivity.onNativeMouse(0, action, x, y);
return true;
case MotionEvent.ACTION_HOVER_MOVE:
x = event.getX(0);
y = event.getY(0);
SDLActivity.onNativeMouse(0, action, x, y);
return true;
default:
break;
}
break;
default:
break;
}
// Event was not managed
return false;
}
示例12: actionToString
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";
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);
}
}
示例13: dispatchTouchEventForDialog
public boolean dispatchTouchEventForDialog(MotionEvent ev, Dialog dialog, final boolean consumed,
Activity activity, boolean needClearFocus) {
if (ev.getAction() == MotionEvent.ACTION_UP
&& ev.getAction() != MotionEvent.ACTION_SCROLL) {
final View view = dialog.getWindow().getCurrentFocus();
if (view != null) {
final View viewTmp;
viewTmp = dialog.getWindow().getCurrentFocus();
final View viewNew = viewTmp != null ? viewTmp : view;
if (viewNew.equals(view)) {
final Rect rect = new Rect();
final int[] coordinates = new int[2];
view.getLocationOnScreen(coordinates);
rect.set(coordinates[0], coordinates[1], coordinates[0] + view.getWidth(), coordinates[1] + view.getHeight());
final int x = (int) ev.getRawX();
final int y = (int) ev.getRawY();
if (rect.contains(x, y)) {
return consumed;
}
} else if (viewNew instanceof EditText) {
return consumed;
}
hideKeyboard(view, activity);
if (needClearFocus) {
viewNew.clearFocus();
}
return consumed;
}
}
return consumed;
}
示例14: dispatchTouchEventForActivity
public boolean dispatchTouchEventForActivity(MotionEvent ev, final boolean consumed,
Activity activity, boolean needClearFocus) {
if (ev.getAction() == MotionEvent.ACTION_UP
&& ev.getAction() != MotionEvent.ACTION_SCROLL) {
final View view = activity.getCurrentFocus();
if (view != null) {
final View viewTmp = activity.getCurrentFocus();
final View viewNew = viewTmp != null ? viewTmp : view;
if (viewNew.equals(view)) {
final Rect rect = new Rect();
final int[] coordinates = new int[2];
view.getLocationOnScreen(coordinates);
rect.set(coordinates[0], coordinates[1], coordinates[0] + view.getWidth(), coordinates[1] + view.getHeight());
final int x = (int) ev.getX();
final int y = (int) ev.getY();
if (rect.contains(x, y)) {
return consumed;
}
} else if (viewNew instanceof EditText) {
return consumed;
}
hideKeyboard(view, activity);
if (needClearFocus) {
viewNew.clearFocus();
}
return consumed;
}
}
return consumed;
}
示例15: onGenericMotionEvent
/**
* Overriding {@link View#onGenericMotionEvent(MotionEvent)}.
*/
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
if (mEmulator != null && event.isFromSource(InputDevice.SOURCE_MOUSE) && event.getAction() == MotionEvent.ACTION_SCROLL) {
// Handle mouse wheel scrolling.
boolean up = event.getAxisValue(MotionEvent.AXIS_VSCROLL) > 0.0f;
doScroll(event, up ? -3 : 3);
return true;
}
return false;
}