當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.obtain方法代碼示例

本文整理匯總了Java中android.view.MotionEvent.obtain方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.obtain方法的具體用法?Java MotionEvent.obtain怎麽用?Java MotionEvent.obtain使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.obtain方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleStartProgressEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
protected void handleStartProgressEvent(int actionCode, MotionEvent event){
    switch (actionCode) { 
        case MotionEvent.ACTION_DOWN: 
            resetState(); // In case we missed an UP/CANCEL event
            
            mPrevEvent = MotionEvent.obtain(event);
            mTimeDelta = 0;

            updateStateByEvent(event);
            break;
        
        case MotionEvent.ACTION_MOVE:
            mGestureInProgress = mListener.onMoveBegin(this);
            break;
    }
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:18,代碼來源:MoveGestureDetector.java

示例2: testSwipeRight_ShouldCallKeepOnListener

import android.view.MotionEvent; //導入方法依賴的package包/類
@Test
public void testSwipeRight_ShouldCallKeepOnListener() throws Exception {
    long downTime = 0;
    long moveTime = downTime + 500;
    long upTime = downTime + 1000;
    float xStart = 200;
    float yStart = 200;
    float xEnd = 500;
    float yEnd = 250;

    MotionEvent e1 = MotionEvent.obtain(downTime, moveTime, MotionEvent.ACTION_MOVE, xStart, yStart, 0);
    MotionEvent e2 = MotionEvent.obtain(downTime, upTime, MotionEvent.ACTION_UP, xEnd, yEnd, 0);
    float velocityX = 120;

    detector.onFling(e1, e2, velocityX, 0);
    verify(listener).onKeep();
}
 
開發者ID:micromasterandroid,項目名稱:androidadvanced,代碼行數:18,代碼來源:SwipeGestureDetectorTest.java

示例3: canScrollDown

import android.view.MotionEvent; //導入方法依賴的package包/類
private static boolean canScrollDown(View targetView, MotionEvent event) {
    if (canScrollDown(targetView)) {
        return true;
    }
    if (targetView instanceof ViewGroup && event != null) {
        ViewGroup viewGroup = (ViewGroup) targetView;
        final int childCount = viewGroup.getChildCount();
        PointF point = new PointF();
        for (int i = 0; i < childCount; i++) {
            View child = viewGroup.getChildAt(i);
            if (isTransformedTouchPointInView(viewGroup,child, event.getX(), event.getY() , point)) {
                event = MotionEvent.obtain(event);
                event.offsetLocation(point.x, point.y);
                return canScrollDown(child, event);
            }
        }
    }
    return false;
}
 
開發者ID:Brave-wan,項目名稱:SmartRefresh,代碼行數:20,代碼來源:RefreshContentWrapper.java

示例4: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    boolean ret = false;
    // Make sure that the infoWindow is shown and we have all the needed references
    if (marker != null && marker.isInfoWindowShown() && map != null && infoWindow != null) {
        // Get a marker position on the screen
        Point point = map.getProjection().toScreenLocation(marker.getPosition());

        // Make a copy of the MotionEvent and adjust it's location
        // so it is relative to the infoWindow left top corner
        MotionEvent copyEv = MotionEvent.obtain(ev);
        copyEv.offsetLocation(
                -point.x + (infoWindow.getWidth() / 2),
                -point.y + infoWindow.getHeight() + bottomOffsetPixels);

        // Dispatch the adjusted MotionEvent to the infoWindow
        ret = infoWindow.dispatchTouchEvent(copyEv);
    }
    // If the infoWindow consumed the touch event, then just return true.
    // Otherwise pass this event to the super class and return it's result
    return ret || super.dispatchTouchEvent(ev);
}
 
開發者ID:kav0rka,項目名稱:VennTracker,代碼行數:23,代碼來源:MapWrapperLayout.java

示例5: canScrollDown

import android.view.MotionEvent; //導入方法依賴的package包/類
public static boolean canScrollDown(View targetView, MotionEvent event) {
    if (canScrollDown(targetView) && targetView.getVisibility() == View.VISIBLE) {
        return true;
    }
    //event == null 時 canScrollDown 不會動態遞歸搜索
    if (targetView instanceof ViewGroup && event != null) {
        ViewGroup viewGroup = (ViewGroup) targetView;
        final int childCount = viewGroup.getChildCount();
        PointF point = new PointF();
        for (int i = 0; i < childCount; i++) {
            View child = viewGroup.getChildAt(i);
            if (isTransformedTouchPointInView(viewGroup, child, event.getX(), event.getY(), point)) {
                event = MotionEvent.obtain(event);
                event.offsetLocation(point.x, point.y);
                return canScrollDown(child, event);
            }
        }
    }
    return false;
}
 
開發者ID:scwang90,項目名稱:SmartRefreshLayout,代碼行數:21,代碼來源:ScrollBoundaryUtil.java

示例6: beginFakeDrag

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Start a fake drag of the pager.
 * <p/>
 * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
 * with the touch scrolling of another view, while still letting the ViewPager
 * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
 * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
 * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
 * <p/>
 * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
 * is already in progress, this method will return false.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    }
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    if (isHorizontalDirection()) {
        mInitialMotionX = mLastMotionX = 0;
    } else if (isVerticalDirection()) {
        mInitialMotionY = mLastMotionY = 0;
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    }
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:40,代碼來源:BaseViewPager.java

示例7: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(@NonNull MotionEvent event) {
    if (mRecyclerWantsTouchEvent) {
        int scrollDiff = mCurrentScroll - mDownScroll;
        MotionEvent recyclerEvent =
                MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(),
                        event.getX(), event.getY() - scrollDiff, event.getMetaState());
        mRecycler.onTouchEvent(recyclerEvent);
        return false;
    }
    return super.onTouchEvent(event);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:RecyclerViewHeader.java

示例8: fakeDragByHorizontally

import android.view.MotionEvent; //導入方法依賴的package包/類
private void fakeDragByHorizontally(float xOffset) {
    mLastMotionX += xOffset;

    float oldScrollX = getScrollX();
    float scrollX = oldScrollX - xOffset;
    final int width = getClientWidth();

    float leftBound = width * mFirstOffset;
    float rightBound = width * mLastOffset;

    final ItemInfo firstItem = mItems.get(0);
    final ItemInfo lastItem = mItems.get(mItems.size() - 1);
    if (firstItem.position != 0) {
        leftBound = firstItem.offset * width;
    }
    if (lastItem.position != mAdapter.getCount() - 1) {
        rightBound = lastItem.offset * width;
    }

    if (scrollX < leftBound) {
        scrollX = leftBound;
    } else if (scrollX > rightBound) {
        scrollX = rightBound;
    }
    // Don't lose the rounded component
    mLastMotionX += scrollX - (int) scrollX;
    scrollTo((int) scrollX, getScrollY());
    pageScrolledHorizontally((int) scrollX);

    // Synthesize an event for the VelocityTracker.
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE,
            mLastMotionX, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:BaseViewPager.java

示例9: obtainMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
public static MotionEvent obtainMotionEvent(
    long downTime,
    long eventTime,
    int action,
    int id1,
    float x1,
    float y1) {
  int[] ids = new int[] {id1};
  MotionEvent.PointerCoords[] coords = new MotionEvent.PointerCoords[] {createCoords(x1, y1)};
  return MotionEvent
      .obtain(downTime, eventTime, action, 1, ids, coords, 0, 1.0f, 1.0f, 0, 0, 0, 0);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:13,代碼來源:MotionEventTestUtils.java

示例10: testOnTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Test
public void testOnTouchEvent() throws Exception {
  for(int action:EVENTS) {
    MotionEvent event = MotionEvent.obtain(100, 100, action,
        10, 10, 0);
    view.onTouchEvent(event);
    event.recycle();
  }
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:10,代碼來源:WXScrollViewTest.java

示例11: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {

  final float x = ev.getX();
  final float y = ev.getY();
  final int action = ev.getAction();

  if (action == MotionEvent.ACTION_DOWN
      && mTouchTarget == null
      && mPinnedSection != null
      && isPinnedViewTouched(mPinnedSection.view, x, y)) { // create touch target

    // user touched pinned view
    mTouchTarget = mPinnedSection.view;
    mTouchPoint.x = x;
    mTouchPoint.y = y;

    // copy down event for eventually be used later
    mDownEvent = MotionEvent.obtain(ev);
  }

  if (mTouchTarget != null) {
    if (isPinnedViewTouched(mTouchTarget, x, y)) { // forward event to pinned view
      mTouchTarget.dispatchTouchEvent(ev);
    }

    if (action == MotionEvent.ACTION_UP) { // perform onClick on pinned view
      super.dispatchTouchEvent(ev);
      performPinnedItemClick();
      clearTouchTarget();

    } else if (action == MotionEvent.ACTION_CANCEL) { // cancel
      clearTouchTarget();

    } else if (action == MotionEvent.ACTION_MOVE) {
      if (Math.abs(y - mTouchPoint.y) > mTouchSlop) {

        // cancel sequence on touch target
        MotionEvent event = MotionEvent.obtain(ev);
        event.setAction(MotionEvent.ACTION_CANCEL);
        mTouchTarget.dispatchTouchEvent(event);
        event.recycle();

        // provide correct sequence to super class for further handling
        super.dispatchTouchEvent(mDownEvent);
        super.dispatchTouchEvent(ev);
        clearTouchTarget();

      }
    }

    return true;
  }

  // call super if this was not our pinned view
  return super.dispatchTouchEvent(ev);
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:58,代碼來源:PinnedSectionListView.java

示例12: setLayoutFrozen

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Enable or disable layout and scroll.  After <code>setLayoutFrozen(true)</code> is called,
 * Layout requests will be postponed until <code>setLayoutFrozen(false)</code> is called;
 * child views are not updated when RecyclerView is frozen, {@link #smoothScrollBy(int, int)},
 * {@link #scrollBy(int, int)}, {@link #scrollToPosition(int)} and
 * {@link #smoothScrollToPosition(int)} are dropped; TouchEvents and GenericMotionEvents are
 * dropped; {@link LayoutManager#onFocusSearchFailed(View, int, Recycler, State)} will not be
 * called.
 *
 * <p>
 * <code>setLayoutFrozen(true)</code> does not prevent app from directly calling {@link
 * LayoutManager#scrollToPosition(int)}, {@link LayoutManager#smoothScrollToPosition(
 * RecyclerView, State, int)}.
 * <p>
 * {@link #setAdapter(Adapter)} and {@link #swapAdapter(Adapter, boolean)} will automatically
 * stop frozen.
 * <p>
 * Note: Running ItemAnimator is not stopped automatically,  it's caller's
 * responsibility to call ItemAnimator.end().
 *
 * @param frozen   true to freeze layout and scroll, false to re-enable.
 */
public void setLayoutFrozen(boolean frozen) {
    if (frozen != mLayoutFrozen) {
        assertNotInLayoutOrScroll("Do not setLayoutFrozen in layout or scroll");
        if (!frozen) {
            mLayoutFrozen = false;
            if (mLayoutRequestEaten && mLayout != null && mAdapter != null) {
                requestLayout();
            }
            mLayoutRequestEaten = false;
        } else {
            final long now = SystemClock.uptimeMillis();
            MotionEvent cancelEvent = MotionEvent.obtain(now, now,
                    MotionEvent.ACTION_CANCEL, 0.0f, 0.0f, 0);
            onTouchEvent(cancelEvent);
            mLayoutFrozen = true;
            mIgnoreMotionEventTillDown = true;
            stopScroll();
        }
    }
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:43,代碼來源:RecyclerView.java

示例13: onActionDown

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public void onActionDown(MotionEvent e) {
    mMotionEvent = MotionEvent.obtain(e);
    mMotionEvent.offsetLocation(-mContentView.getLeft(), -mContentView.getTop());
}
 
開發者ID:Brave-wan,項目名稱:SmartRefresh,代碼行數:6,代碼來源:RefreshContentWrapper.java

示例14: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent me) {
    // Convert multi-pointer up/down events to single up/down events to
    // deal with the typical multi-pointer behavior of two-thumb typing
    final int pointerCount = me.getPointerCount();
    final int action = me.getAction();
    boolean result = false;
    final long now = me.getEventTime();

    if (pointerCount != mOldPointerCount) {
        if (pointerCount == 1) {
            // Send a down event for the latest pointer
            MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN,
                    me.getX(), me.getY(), me.getMetaState());
            result = onModifiedTouchEvent(down, false);
            down.recycle();
            // If it's an up action, then deliver the up as well.
            if (action == MotionEvent.ACTION_UP) {
                result = onModifiedTouchEvent(me, true);
            }
        } else {
            // Send an up event for the last pointer
            MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP,
                    mOldPointerX, mOldPointerY, me.getMetaState());
            result = onModifiedTouchEvent(up, true);
            up.recycle();
        }
    } else {
        if (pointerCount == 1) {
            result = onModifiedTouchEvent(me, false);
            mOldPointerX = me.getX();
            mOldPointerY = me.getY();
        } else {
            // Don't do anything when 2 pointers are down and moving.
            result = true;
        }
    }
    mOldPointerCount = pointerCount;

    return result;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:42,代碼來源:MyKeyboardView.java

示例15: cancelSuperTouch

import android.view.MotionEvent; //導入方法依賴的package包/類
private void cancelSuperTouch(MotionEvent ev) {
    MotionEvent cancel = MotionEvent.obtain(ev);
    cancel.setAction(3);
    super.onTouchEvent(cancel);
    cancel.recycle();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:7,代碼來源:SwitchCompat.java


注:本文中的android.view.MotionEvent.obtain方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。