Search in sources :

Example 56 with MotionEvent

use of android.view.MotionEvent in project robolectric by robolectric.

the class VelocityTrackerTest method doMotion.

/**
   * Construct a new MotionEvent involving two pointers at {@code time}. Pointer 2 will be
   * considered active.
   */
private static MotionEvent doMotion(long time, float pointer1X, float pointer1Y, float pointer2X, float pointer2Y) {
    MotionEvent event = MotionEvent.obtain(0, time, MotionEvent.ACTION_MOVE, pointer2X, pointer2Y, 0);
    ShadowMotionEvent shadowEvent = Shadows.shadowOf(event);
    shadowEvent.setPointer2(pointer1X, pointer1Y);
    shadowEvent.setPointerIndex(0);
    // we put our active pointer (the second one down) first, so flip the IDs so that they match up
    // properly
    shadowEvent.setPointerIds(1, 0);
    return event;
}
Also used : MotionEvent(android.view.MotionEvent)

Example 57 with MotionEvent

use of android.view.MotionEvent in project robolectric by robolectric.

the class ShadowViewGroupTest method shouldKnowWhenOnInterceptTouchEventWasCalled.

@Test
public void shouldKnowWhenOnInterceptTouchEventWasCalled() throws Exception {
    ViewGroup viewGroup = new FrameLayout(context);
    MotionEvent touchEvent = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, 0, 0, 0);
    viewGroup.onInterceptTouchEvent(touchEvent);
    assertThat(shadowOf(viewGroup).getInterceptedTouchEvent()).isEqualTo(touchEvent);
}
Also used : ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) MotionEvent(android.view.MotionEvent) Test(org.junit.Test)

Example 58 with MotionEvent

use of android.view.MotionEvent in project xabber-android by redsolution.

the class ContactListFragment method stopMovement.

/**
     * Stop fling scrolling.
     */
private void stopMovement() {
    MotionEvent event = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_CANCEL, 0, 0, 0);
    listView.onTouchEvent(event);
    event.recycle();
}
Also used : MotionEvent(android.view.MotionEvent)

Example 59 with MotionEvent

use of android.view.MotionEvent in project FileDownloader by lingochamp.

the class HybridTestActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hybrid_test);
    uiHandler = new Handler(new Handler.Callback() {

        @Override
        public boolean handleMessage(Message msg) {
            if (msg.what == WHAT_NEED_AUTO_2_BOTTOM) {
                needAuto2Bottom = true;
            }
            return false;
        }
    });
    assignViews();
    scrollView.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                uiHandler.removeMessages(WHAT_NEED_AUTO_2_BOTTOM);
                needAuto2Bottom = false;
            }
            if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) {
                uiHandler.removeMessages(WHAT_NEED_AUTO_2_BOTTOM);
                uiHandler.sendEmptyMessageDelayed(WHAT_NEED_AUTO_2_BOTTOM, 1000);
            }
            return false;
        }
    });
}
Also used : Message(android.os.Message) Handler(android.os.Handler) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 60 with MotionEvent

use of android.view.MotionEvent in project cardslib by gabrielemariotti.

the class BaseDismissAnimation method invokeCallbak.

protected void invokeCallbak(final View dismissView) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    final int dismissPosition = mBaseAdapter.getPosition(((CardViewWrapper) dismissView).getCard());
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);
                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallbacks.onDismiss(mCardListView, dismissPositions);
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    pendingDismiss.view.setAlpha(1f);
                    pendingDismiss.view.setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = 0;
                    pendingDismiss.view.setLayoutParams(lp);
                }
                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mCardListView.dispatchTouchEvent(cancelEvent);
                mPendingDismisses.clear();
            }
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ViewGroup(android.view.ViewGroup) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator) MotionEvent(android.view.MotionEvent)

Aggregations

MotionEvent (android.view.MotionEvent)717 View (android.view.View)255 TextView (android.widget.TextView)113 ImageView (android.widget.ImageView)91 Point (android.graphics.Point)63 OnTouchListener (android.view.View.OnTouchListener)48 GestureDetector (android.view.GestureDetector)47 Paint (android.graphics.Paint)40 ViewGroup (android.view.ViewGroup)36 Test (org.junit.Test)35 AdapterView (android.widget.AdapterView)34 RecyclerView (android.support.v7.widget.RecyclerView)33 ListView (android.widget.ListView)33 SuppressLint (android.annotation.SuppressLint)31 Intent (android.content.Intent)30 Instrumentation (android.app.Instrumentation)27 AbsListView (android.widget.AbsListView)27 OnClickListener (android.view.View.OnClickListener)24 Rect (android.graphics.Rect)22 Handler (android.os.Handler)20