當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。