本文整理汇总了C++中MotionEvent类的典型用法代码示例。如果您正苦于以下问题:C++ MotionEvent类的具体用法?C++ MotionEvent怎么用?C++ MotionEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MotionEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: android_view_MotionEvent_nativeGetAxisValue
static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz,
jlong nativePtr, jint axis, jint pointerIndex, jint historyPos) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
//ActionsCode(authro:songzhining, comment: fix BUG00232351)
if (pointerIndex >= pointerCount) {
ALOGE("Error pointerIndex! count=%d, index=%d", pointerCount, pointerIndex);
pointerIndex = 0;
}
if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
return 0;
}
if (historyPos == HISTORY_CURRENT) {
return event->getAxisValue(axis, pointerIndex);
} else {
size_t historySize = event->getHistorySize();
if (!validateHistoryPos(env, historyPos, historySize)) {
return 0;
}
return event->getHistoricalAxisValue(axis, pointerIndex, historyPos);
}
}
示例2: TEST_F
TEST_F(MotionEventTest, OffsetLocation) {
MotionEvent event;
initializeEventWithHistory(&event);
event.offsetLocation(5.0f, -2.0f);
ASSERT_EQ(X_OFFSET + 5.0f, event.getXOffset());
ASSERT_EQ(Y_OFFSET - 2.0f, event.getYOffset());
}
示例3: android_view_MotionEvent_nativeGetToolType
static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz,
jint nativePtr, jint pointerIndex) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
return -1;
}
return event->getToolType(pointerIndex);
}
示例4: android_view_MotionEvent_nativeCopy
static jint android_view_MotionEvent_nativeCopy(JNIEnv* env, jclass clazz,
jint destNativePtr, jint sourceNativePtr, jboolean keepHistory) {
MotionEvent* destEvent = reinterpret_cast<MotionEvent*>(destNativePtr);
if (!destEvent) {
destEvent = new MotionEvent();
}
MotionEvent* sourceEvent = reinterpret_cast<MotionEvent*>(sourceNativePtr);
destEvent->copyFrom(sourceEvent, keepHistory);
return reinterpret_cast<jint>(destEvent);
}
示例5: android_view_MotionEvent_nativeWriteToParcel
static void android_view_MotionEvent_nativeWriteToParcel(JNIEnv* env, jclass clazz,
jint nativePtr, jobject parcelObj) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
Parcel* parcel = parcelForJavaObject(env, parcelObj);
status_t status = event->writeToParcel(parcel);
if (status) {
jniThrowRuntimeException(env, "Failed to write MotionEvent parcel.");
}
}
示例6: nativeSendMotionEvent
static jlong nativeSendMotionEvent(JNIEnv* env, jobject clazz, jlong ptr, jobject eventObj) {
sp<InputQueue> queue = reinterpret_cast<InputQueue*>(ptr);
MotionEvent* originalEvent = android_view_MotionEvent_getNativePtr(env, eventObj);
if (!originalEvent) {
jniThrowRuntimeException(env, "Could not obtain MotionEvent pointer.");
return -1;
}
MotionEvent* event = queue->createMotionEvent();
event->copyFrom(originalEvent, true /* keepHistory */);
queue->enqueueEvent(event);
return reinterpret_cast<jlong>(event);
}
示例7: android_view_MotionEvent_nativeGetPointerProperties
static void android_view_MotionEvent_nativeGetPointerProperties(JNIEnv* env, jclass clazz,
jint nativePtr, jint pointerIndex, jobject outPointerPropertiesObj) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
if (!validatePointerIndex(env, pointerIndex, pointerCount)
|| !validatePointerProperties(env, outPointerPropertiesObj)) {
return;
}
const PointerProperties* pointerProperties = event->getPointerProperties(pointerIndex);
pointerPropertiesFromNative(env, pointerProperties, outPointerPropertiesObj);
}
示例8: android_view_MotionEvent_nativeGetEventTimeNanos
static jlong android_view_MotionEvent_nativeGetEventTimeNanos(JNIEnv* env, jclass clazz,
jint nativePtr, jint historyPos) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
if (historyPos == HISTORY_CURRENT) {
return event->getEventTime();
} else {
size_t historySize = event->getHistorySize();
if (!validateHistoryPos(env, historyPos, historySize)) {
return 0;
}
return event->getHistoricalEventTime(historyPos);
}
}
示例9: android_view_MotionEvent_nativeInitialize
static jint android_view_MotionEvent_nativeInitialize(JNIEnv* env, jclass clazz,
jint nativePtr,
jint deviceId, jint source, jint action, jint flags, jint edgeFlags,
jint metaState, jint buttonState,
jfloat xOffset, jfloat yOffset, jfloat xPrecision, jfloat yPrecision,
jlong downTimeNanos, jlong eventTimeNanos,
jint pointerCount, jobjectArray pointerPropertiesObjArray,
jobjectArray pointerCoordsObjArray) {
if (!validatePointerCount(env, pointerCount)
|| !validatePointerPropertiesArray(env, pointerPropertiesObjArray, pointerCount)
|| !validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) {
return 0;
}
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
if (!event) {
event = new MotionEvent();
}
PointerProperties pointerProperties[pointerCount];
PointerCoords rawPointerCoords[pointerCount];
for (jint i = 0; i < pointerCount; i++) {
jobject pointerPropertiesObj = env->GetObjectArrayElement(pointerPropertiesObjArray, i);
if (!pointerPropertiesObj) {
goto Error;
}
pointerPropertiesToNative(env, pointerPropertiesObj, &pointerProperties[i]);
env->DeleteLocalRef(pointerPropertiesObj);
jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i);
if (!pointerCoordsObj) {
jniThrowNullPointerException(env, "pointerCoords");
goto Error;
}
pointerCoordsToNative(env, pointerCoordsObj, xOffset, yOffset, &rawPointerCoords[i]);
env->DeleteLocalRef(pointerCoordsObj);
}
event->initialize(deviceId, source, action, flags, edgeFlags, metaState, buttonState,
xOffset, yOffset, xPrecision, yPrecision,
downTimeNanos, eventTimeNanos, pointerCount, pointerProperties, rawPointerCoords);
return reinterpret_cast<jint>(event);
Error:
if (!nativePtr) {
delete event;
}
return 0;
}
示例10: android_view_MotionEvent_nativeGetToolType
static jint android_view_MotionEvent_nativeGetToolType(JNIEnv* env, jclass clazz,
jlong nativePtr, jint pointerIndex) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
//ActionsCode(authro:songzhining, comment: fix BUG00232351)
if (pointerIndex >= pointerCount) {
ALOGE("Error pointerIndex! count=%d, index=%d", pointerCount, pointerIndex);
pointerIndex = 0;
}
if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
return -1;
}
return event->getToolType(pointerIndex);
}
示例11: android_view_MotionEvent_nativeTransform
static void android_view_MotionEvent_nativeTransform(JNIEnv* env, jclass clazz,
jint nativePtr, jobject matrixObj) {
SkMatrix* matrix = android_graphics_Matrix_getSkMatrix(env, matrixObj);
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
float m[9];
m[0] = SkScalarToFloat(matrix->get(SkMatrix::kMScaleX));
m[1] = SkScalarToFloat(matrix->get(SkMatrix::kMSkewX));
m[2] = SkScalarToFloat(matrix->get(SkMatrix::kMTransX));
m[3] = SkScalarToFloat(matrix->get(SkMatrix::kMSkewY));
m[4] = SkScalarToFloat(matrix->get(SkMatrix::kMScaleY));
m[5] = SkScalarToFloat(matrix->get(SkMatrix::kMTransY));
m[6] = SkScalarToFloat(matrix->get(SkMatrix::kMPersp0));
m[7] = SkScalarToFloat(matrix->get(SkMatrix::kMPersp1));
m[8] = SkScalarToFloat(matrix->get(SkMatrix::kMPersp2));
event->transform(m);
}
示例12: android_view_MotionEvent_nativeGetPointerCoords
static void android_view_MotionEvent_nativeGetPointerCoords(JNIEnv* env, jclass clazz,
jlong nativePtr, jint pointerIndex, jint historyPos, jobject outPointerCoordsObj) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
//ActionsCode(authro:songzhining, comment: fix BUG00232351)
if (pointerIndex >= pointerCount) {
ALOGE("Error pointerIndex! count=%d, index=%d", pointerCount, pointerIndex);
pointerIndex = 0;
}
if (!validatePointerIndex(env, pointerIndex, pointerCount)
|| !validatePointerCoords(env, outPointerCoordsObj)) {
return;
}
const PointerCoords* rawPointerCoords;
if (historyPos == HISTORY_CURRENT) {
rawPointerCoords = event->getRawPointerCoords(pointerIndex);
} else {
size_t historySize = event->getHistorySize();
if (!validateHistoryPos(env, historyPos, historySize)) {
return;
}
rawPointerCoords = event->getHistoricalRawPointerCoords(pointerIndex, historyPos);
}
pointerCoordsFromNative(env, rawPointerCoords, event->getXOffset(), event->getYOffset(),
outPointerCoordsObj);
}
示例13: android_view_MotionEvent_nativeAddBatch
static void android_view_MotionEvent_nativeAddBatch(JNIEnv* env, jclass clazz,
jint nativePtr, jlong eventTimeNanos, jobjectArray pointerCoordsObjArray,
jint metaState) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
if (!validatePointerCoordsObjArray(env, pointerCoordsObjArray, pointerCount)) {
return;
}
PointerCoords rawPointerCoords[pointerCount];
for (size_t i = 0; i < pointerCount; i++) {
jobject pointerCoordsObj = env->GetObjectArrayElement(pointerCoordsObjArray, i);
if (!pointerCoordsObj) {
jniThrowNullPointerException(env, "pointerCoords");
return;
}
pointerCoordsToNative(env, pointerCoordsObj,
event->getXOffset(), event->getYOffset(), &rawPointerCoords[i]);
env->DeleteLocalRef(pointerCoordsObj);
}
event->addSample(eventTimeNanos, rawPointerCoords);
event->setMetaState(event->getMetaState() | metaState);
}
示例14: android_view_MotionEvent_nativeGetAxisValue
static jfloat android_view_MotionEvent_nativeGetAxisValue(JNIEnv* env, jclass clazz,
jint nativePtr, jint axis, jint pointerIndex, jint historyPos) {
MotionEvent* event = reinterpret_cast<MotionEvent*>(nativePtr);
size_t pointerCount = event->getPointerCount();
if (!validatePointerIndex(env, pointerIndex, pointerCount)) {
return 0;
}
if (historyPos == HISTORY_CURRENT) {
return event->getAxisValue(axis, pointerIndex);
} else {
size_t historySize = event->getHistorySize();
if (!validateHistoryPos(env, historyPos, historySize)) {
return 0;
}
return event->getHistoricalAxisValue(axis, pointerIndex, historyPos);
}
}
示例15: stopAutoScroll
bool AutoScrollWidgetPager::onTouchEvent(const MotionEvent& ev) {
if (mStopScrollWhenTouch) {
if (ev.getAction() == MotionEvent::ACTION_DOWN && mIsAutoScroll) {
mIsStopByTouch = true;
stopAutoScroll();
} else if (ev.getAction() == MotionEvent::ACTION_UP && mIsStopByTouch) {
startAutoScroll();
}
}
WidgetController* pParent = dynamic_cast<WidgetController*>(getParent());
if (mSlideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || mSlideBorderMode == SLIDE_BORDER_MODE_CYCLE) {
mTouchX = ev.getX();
if (ev.getAction() == MotionEvent::ACTION_DOWN) {
mDownX = mTouchX;
}
int32_t currentItem = getCurrentItem();
IPagerProvider* adapter = getProvider();
int32_t pageCount = adapter == NULL ? 0 : adapter->getCount();
/**
* current index is first one and slide to right or current index is last one and slide to left.<br/>
* if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.<br/>
* else scroll to last one when current item is first one, scroll to first one when current item is last
* one.
*/
if ((currentItem == 0 && mDownX <= mTouchX) || (currentItem == pageCount - 1 && mDownX >= mTouchX)) {
if (mSlideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) {
if (pParent)
pParent->requestDisallowInterceptTouchEvent(false);
} else {
if (pageCount > 1) {
setCurrentItem(pageCount - currentItem - 1, mIsBorderAnimation);
}
if (pParent)
pParent->requestDisallowInterceptTouchEvent(true);
}
return WidgetPager::onTouchEvent(ev);
}
}
if (pParent)
pParent->requestDisallowInterceptTouchEvent(true);
return WidgetPager::onTouchEvent(ev);
}