本文整理匯總了Java中android.view.MotionEvent.obtainNoHistory方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.obtainNoHistory方法的具體用法?Java MotionEvent.obtainNoHistory怎麽用?Java MotionEvent.obtainNoHistory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.obtainNoHistory方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: duplicateTouchEventForChildren
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Duplicate touch events to child views.
* We want to dispatch a down motion event and the move events to
* child views, but calling dispatchTouchEvent() causes StackOverflowError.
* Therefore we do it manually.
*
* @param ev motion event to be passed to children
* @param pendingEvents pending events like ACTION_DOWN. This will be passed to the children before ev
*/
private void duplicateTouchEventForChildren(MotionEvent ev, MotionEvent... pendingEvents) {
if (ev == null) {
return;
}
for (int i = getChildCount() - 1; 0 <= i; i--) {
View childView = getChildAt(i);
if (childView != null) {
Rect childRect = new Rect();
childView.getHitRect(childRect);
MotionEvent event = MotionEvent.obtainNoHistory(ev);
if (!childRect.contains((int) event.getX(), (int) event.getY())) {
continue;
}
float offsetX = -childView.getLeft();
float offsetY = -childView.getTop();
boolean consumed = false;
if (pendingEvents != null) {
for (MotionEvent pe : pendingEvents) {
if (pe != null) {
MotionEvent peAdjusted = MotionEvent.obtainNoHistory(pe);
peAdjusted.offsetLocation(offsetX, offsetY);
consumed |= childView.dispatchTouchEvent(peAdjusted);
}
}
}
event.offsetLocation(offsetX, offsetY);
consumed |= childView.dispatchTouchEvent(event);
if (consumed) {
break;
}
}
}
}
示例2: onTouchForwarded
import android.view.MotionEvent; //導入方法依賴的package包/類
private boolean onTouchForwarded(MotionEvent srcEvent) {
boolean z = true;
View src = this.mSrc;
ListPopupWindow popup = getPopup();
if (popup == null || !popup.isShowing()) {
return false;
}
DropDownListView dst = popup.mDropDownList;
if (dst == null || !dst.isShown()) {
return false;
}
MotionEvent dstEvent = MotionEvent.obtainNoHistory(srcEvent);
toGlobalMotionEvent(src, dstEvent);
toLocalMotionEvent(dst, dstEvent);
boolean handled = dst.onForwardedEvent(dstEvent, this.mActivePointerId);
dstEvent.recycle();
int action = MotionEventCompat.getActionMasked(srcEvent);
boolean keepForwarding;
if (action == 1 || action == 3) {
keepForwarding = false;
} else {
keepForwarding = true;
}
if (!(handled && keepForwarding)) {
z = false;
}
return z;
}
示例3: obtainMotionEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
private MotionEvent obtainMotionEvent(MotionEvent base, int action) {
MotionEvent ev = MotionEvent.obtainNoHistory(base);
ev.setAction(action);
return ev;
}