当前位置: 首页>>代码示例>>Java>>正文


Java MotionEventCompat.getSource方法代码示例

本文整理汇总了Java中android.support.v4.view.MotionEventCompat.getSource方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEventCompat.getSource方法的具体用法?Java MotionEventCompat.getSource怎么用?Java MotionEventCompat.getSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.view.MotionEventCompat的用法示例。


在下文中一共展示了MotionEventCompat.getSource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onTouchEvent

import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
	if (event.getAction() == MotionEvent.ACTION_DOWN) {
		// Selection may be beginning. Sync the TextView with the buffer.
		refreshTextFromBuffer();
	}

	// Mouse input is treated differently:
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
			MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) {
		if (onMouseEvent(event, terminalView.bridge)) {
			return true;
		}
		terminalView.viewPager.setPagingEnabled(true);
	} else {
		if (terminalView.onTouchEvent(event)) {
			return true;
		}
	}

	return super.onTouchEvent(event);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:TerminalTextViewOverlay.java

示例2: onGenericMotionEvent

import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onGenericMotionEvent(MotionEvent event) {
    if (!(this.mLayout == null || this.mLayoutFrozen || (MotionEventCompat.getSource(event) & 2) == 0 || event.getAction() != 8)) {
        float vScroll;
        float hScroll;
        if (this.mLayout.canScrollVertically()) {
            vScroll = -MotionEventCompat.getAxisValue(event, 9);
        } else {
            vScroll = 0.0f;
        }
        if (this.mLayout.canScrollHorizontally()) {
            hScroll = MotionEventCompat.getAxisValue(event, 10);
        } else {
            hScroll = 0.0f;
        }
        if (!(vScroll == 0.0f && hScroll == 0.0f)) {
            float scrollFactor = getScrollFactor();
            scrollByInternal((int) (hScroll * scrollFactor), (int) (vScroll * scrollFactor), event);
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:RecyclerView.java

示例3: onGenericMotionEvent

import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
@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);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:TerminalTextViewOverlay.java

示例4: mouseEventToJavaModifiers

import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
/**
 * Takes an android mouse event and produces a Java InputEvent modifiers int which can be
 * passed to vt320.
 * @param mouseEvent The {@link MotionEvent} which should be a mouse click or release.
 * @return A Java InputEvent modifier int. See
 * http://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html
 */
@TargetApi(14)
private static int mouseEventToJavaModifiers(MotionEvent mouseEvent) {
	if (MotionEventCompat.getSource(mouseEvent) != InputDevice.SOURCE_MOUSE) return 0;

	int mods = 0;

	// See http://docs.oracle.com/javase/7/docs/api/constant-values.html
	int buttonState = mouseEvent.getButtonState();
	if ((buttonState & MotionEvent.BUTTON_PRIMARY) != 0)
		mods |= 16;
	if ((buttonState & MotionEvent.BUTTON_SECONDARY) != 0)
		mods |= 8;
	if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0)
		mods |= 4;

	// Note: Meta and Ctrl are intentionally swapped here to keep logic in vt320 simple.
	int meta = mouseEvent.getMetaState();
	if ((meta & KeyEvent.META_META_ON) != 0)
		mods |= 2;
	if ((meta & KeyEvent.META_SHIFT_ON) != 0)
		mods |= 1;
	if ((meta & KeyEvent.META_CTRL_ON) != 0)
		mods |= 4;

	return mods;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:TerminalTextViewOverlay.java

示例5: onGenericMotionEvent

import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onGenericMotionEvent(MotionEvent event) {
    if (mLayout == null) {
        return false;
    }
    if (mLayoutFrozen) {
        return false;
    }
    if ((MotionEventCompat.getSource(event) & InputDeviceCompat.SOURCE_CLASS_POINTER) != 0) {
        if (event.getAction() == MotionEventCompat.ACTION_SCROLL) {
            final float vScroll, hScroll;
            if (mLayout.canScrollVertically()) {
                // Inverse the sign of the vertical scroll to align the scroll orientation
                // with AbsListView.
                vScroll = -MotionEventCompat
                        .getAxisValue(event, MotionEventCompat.AXIS_VSCROLL);
            } else {
                vScroll = 0f;
            }
            if (mLayout.canScrollHorizontally()) {
                hScroll = MotionEventCompat
                        .getAxisValue(event, MotionEventCompat.AXIS_HSCROLL);
            } else {
                hScroll = 0f;
            }

            if (vScroll != 0 || hScroll != 0) {
                final float scrollFactor = getScrollFactor();
                scrollByInternal((int) (hScroll * scrollFactor),
                        (int) (vScroll * scrollFactor), event);
            }
        }
    }
    return false;
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:35,代码来源:RecyclerView.java

示例6: onGenericMotionEvent

import android.support.v4.view.MotionEventCompat; //导入方法依赖的package包/类
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((MotionEventCompat.getSource(event) & 2) != 0) {
        switch (event.getAction()) {
            case 8:
                if (!this.mIsBeingDragged) {
                    float vscroll = MotionEventCompat.getAxisValue(event, 9);
                    if (vscroll != 0.0f) {
                        int delta = (int) (getVerticalScrollFactorCompat() * vscroll);
                        int range = getScrollRange();
                        int oldScrollY = getScrollY();
                        int newScrollY = oldScrollY - delta;
                        if (newScrollY < 0) {
                            newScrollY = 0;
                        } else if (newScrollY > range) {
                            newScrollY = range;
                        }
                        if (newScrollY != oldScrollY) {
                            super.scrollTo(getScrollX(), newScrollY);
                            return true;
                        }
                    }
                }
                break;
        }
    }
    return false;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:28,代码来源:NestedScrollView.java


注:本文中的android.support.v4.view.MotionEventCompat.getSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。