Example usage for android.view MotionEvent getX

List of usage examples for android.view MotionEvent getX

Introduction

In this page you can find the example usage for android.view MotionEvent getX.

Prototype

public final float getX() 

Source Link

Document

#getX(int) for the first pointer index (may be an arbitrary pointer identifier).

Usage

From source file:com.a.mirko.android.datetimepicker.time.RadialPickerLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    final float eventX = event.getX();
    final float eventY = event.getY();
    int degrees;//from   w  w w . j  a va2  s.c  om
    int value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    long millis = SystemClock.uptimeMillis();

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (!mInputEnabled) {
            return true;
        }

        mDownX = eventX;
        mDownY = eventY;

        mLastValueSelected = -1;
        mDoingMove = false;
        mDoingTouch = true;
        // If we're showing the AM/PM, check to see if the user is touching it.
        if (!mHideAmPm) {
            mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
        } else {
            mIsTouchingAmOrPm = -1;
        }
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            // If the touch is on AM or PM, set it as "touched" after the TAP_TIMEOUT
            // in case the user moves their finger quickly.
            tryVibrate();
            mDownDegrees = -1;
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm);
                    mAmPmCirclesView.invalidate();
                }
            }, TAP_TIMEOUT);
        } else {
            // If we're in accessibility mode, force the touch to be legal. Otherwise,
            // it will only register within the given touch target zone.
            boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager);
            // Calculate the degrees that is currently being touched.
            mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle);
            if (mDownDegrees != -1) {
                // If it's a legal touch, set that number as "selected" after the
                // TAP_TIMEOUT in case the user moves their finger quickly.
                tryVibrate();
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mDoingMove = true;
                        int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true);
                        mLastValueSelected = value;
                        mListener.onValueSelected(getCurrentItemShowing(), value, false);
                    }
                }, TAP_TIMEOUT);
            }
        }
        return true;
    case MotionEvent.ACTION_MOVE:
        if (!mInputEnabled) {
            // We shouldn't be in this state, because input is disabled.
            Log.e(TAG, "Input was disabled, but received ACTION_MOVE.");
            return true;
        }

        float dY = Math.abs(eventY - mDownY);
        float dX = Math.abs(eventX - mDownX);

        if (!mDoingMove && dX <= TOUCH_SLOP && dY <= TOUCH_SLOP) {
            // Hasn't registered down yet, just slight, accidental movement of finger.
            break;
        }

        // If we're in the middle of touching down on AM or PM, check if we still are.
        // If so, no-op. If not, remove its pressed state. Either way, no need to check
        // for touches on the other circle.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            mHandler.removeCallbacksAndMessages(null);
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            if (isTouchingAmOrPm != mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPmPressed(-1);
                mAmPmCirclesView.invalidate();
                mIsTouchingAmOrPm = -1;
            }
            break;
        }

        if (mDownDegrees == -1) {
            // Original down was illegal, so no movement will register.
            break;
        }

        // We're doing a move along the circle, so move the selection as appropriate.
        mDoingMove = true;
        mHandler.removeCallbacksAndMessages(null);
        degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle);
        if (degrees != -1) {
            value = reselectSelector(degrees, isInnerCircle[0], false, true);
            if (value != mLastValueSelected) {
                tryVibrate();
                mLastValueSelected = value;
                mListener.onValueSelected(getCurrentItemShowing(), value, false);
            }
        }
        return true;
    case MotionEvent.ACTION_UP:
        if (!mInputEnabled) {
            // If our touch input was disabled, tell the listener to re-enable us.
            Log.d(TAG, "Input was disabled, but received ACTION_UP.");
            mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false);
            return true;
        }

        mHandler.removeCallbacksAndMessages(null);
        mDoingTouch = false;

        // If we're touching AM or PM, set it as selected, and tell the listener.
        if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) {
            int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY);
            mAmPmCirclesView.setAmOrPmPressed(-1);
            mAmPmCirclesView.invalidate();

            if (isTouchingAmOrPm == mIsTouchingAmOrPm) {
                mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm);
                if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) {
                    mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false);
                    setValueForItem(AMPM_INDEX, isTouchingAmOrPm);
                }
            }
            mIsTouchingAmOrPm = -1;
            break;
        }

        // If we have a legal degrees selected, set the value and tell the listener.
        if (mDownDegrees != -1) {
            degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle);
            if (degrees != -1) {
                value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false);
                if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) {
                    int amOrPm = getIsCurrentlyAmOrPm();
                    if (amOrPm == AM && value == 12) {
                        value = 0;
                    } else if (amOrPm == PM && value != 12) {
                        value += 12;
                    }
                }
                setValueForItem(getCurrentItemShowing(), value);
                mListener.onValueSelected(getCurrentItemShowing(), value, true);
            }
        }
        mDoingMove = false;
        return true;
    default:
        break;
    }
    return false;
}

From source file:com.acbelter.scheduleview.ScheduleView.java

@Override
public boolean onTouchEvent(MotionEvent e) {
    View child;//  www.  j a  v a  2s.c o  m
    for (int i = 0; i < getChildCount(); i++) {
        child = getChildAt(i);
        child.getHitRect(mClickedViewBounds);
        if (mClickedViewBounds.contains((int) e.getX(), (int) e.getY())) {
            if (DEBUG) {
                Log.d(TAG, "dispatchTouchEvent() to child " + i);
            }
            // FIXME Add fade animation
            child.dispatchTouchEvent(e);
        }
    }
    return mGestureDetector.onTouchEvent(e);
}

From source file:com.benefit.buy.library.viewpagerindicator.CirclePageIndicator.java

@Override
public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }//  ww  w.j ava 2 s. c om
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }
    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;
    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;
        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }
        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }
        break;
    }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;
            if ((mCurrentPage > 0) && (ev.getX() < (halfWidth - sixthWidth))) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < (count - 1)) && (ev.getX() > (halfWidth + sixthWidth))) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }
        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging()) {
            mViewPager.endFakeDrag();
        }
        break;
    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }
    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }
    return true;
}

From source file:android.support.design.widget.FloatingActionButton.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // Skipping the gesture if it doesn't start in in the FAB 'content' area
        if (getContentRect(mTouchArea) && !mTouchArea.contains((int) ev.getX(), (int) ev.getY())) {
            return false;
        }/*from   w w  w. j  av  a  2  s.co  m*/
        break;
    }
    return super.onTouchEvent(ev);
}

From source file:com.abslyon.abetterselection.CoverFlow.CoverFlowView.java

private void touchMoved(MotionEvent event) {
    float pos = (event.getX() / mWidth) * MOVE_POS_MULTIPLE - 5;
    pos /= 2;//from  ww  w.  jav  a  2 s.c om

    if (!mTouchMoved) {
        float dx = Math.abs(event.getX() - mTouchStartX);
        float dy = Math.abs(event.getY() - mTouchStartY);

        if (dx < TOUCH_MINIMUM_MOVE && dy < TOUCH_MINIMUM_MOVE) {
            return;
        }

        mTouchMoved = true;

        stopLongClick();
    }

    mOffset = mStartOffset + mTouchStartPos - pos;

    invalidate();
    mVelocity.addMovement(event);
}

From source file:adapters.CirclePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*  w  w  w  .j a va 2s .c o  m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:cn.chuangblog.simplebanner1.indicator.CirclePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*w ww . ja va  2 s .  c  o m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = InfiniteViewPager.FakePositionHelper.getAdapterSize(mViewPager);
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.android.nobug.view.viewpager.indicator.CirclePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*  ww w  .  java2 s.  c  o  m*/

    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:ca.psiphon.ploggy.FragmentSelfStatusDetails.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.self_status_details, container, false);

    mFragmentComposeMessage = new FragmentComposeMessage();
    FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
    transaction.add(R.id.fragment_self_status_details_compose_message, mFragmentComposeMessage).commit();

    mScrollView = (ScrollView) view.findViewById(R.id.self_status_details_scroll_view);
    mAvatarImage = (ImageView) view.findViewById(R.id.self_status_details_avatar_image);
    mNicknameText = (TextView) view.findViewById(R.id.self_status_details_nickname_text);
    mFingerprintText = (TextView) view.findViewById(R.id.self_status_details_fingerprint_text);
    mMessagesList = (ListView) view.findViewById(R.id.self_status_details_messages_list);
    mLocationLabel = (TextView) view.findViewById(R.id.self_status_details_location_label);
    mLocationStreetAddressLabel = (TextView) view
            .findViewById(R.id.self_status_details_location_street_address_label);
    mLocationStreetAddressText = (TextView) view
            .findViewById(R.id.self_status_details_location_street_address_text);
    mLocationCoordinatesLabel = (TextView) view
            .findViewById(R.id.self_status_details_location_coordinates_label);
    mLocationCoordinatesText = (TextView) view.findViewById(R.id.self_status_details_location_coordinates_text);
    mLocationPrecisionLabel = (TextView) view.findViewById(R.id.self_status_details_location_precision_label);
    mLocationPrecisionText = (TextView) view.findViewById(R.id.self_status_details_location_precision_text);
    mLocationTimestampLabel = (TextView) view.findViewById(R.id.self_status_details_location_timestamp_label);
    mLocationTimestampText = (TextView) view.findViewById(R.id.self_status_details_location_timestamp_text);

    // TODO: use header/footer of listview instead of hack embedding of listview in scrollview
    // from: http://stackoverflow.com/questions/4490821/scrollview-inside-scrollview/11554823#11554823
    mScrollView.setOnTouchListener(new View.OnTouchListener() {
        @Override/*from   w  w  w. j  a  va 2 s  . co  m*/
        public boolean onTouch(View view, MotionEvent event) {
            mMessagesList.requestDisallowInterceptTouchEvent(false);
            return false;
        }
    });
    mMessagesList.setOnTouchListener(new View.OnTouchListener() {
        private float downX, downY;

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // We want to capture vertical scrolling motions for use by
            // the messages list, but we don't want to capture horizontal
            // swiping that should be used to switch tabs. So we're going
            // to decide based on whether the move looks more X-ish or Y-ish.
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                downX = event.getX();
                downY = event.getY();

                // Make sure the parent is allowed to intercept.
                view.getParent().requestDisallowInterceptTouchEvent(false);
            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                float deltaX = downX - event.getX();
                float deltaY = downY - event.getY();
                if (Math.abs(deltaY) > Math.abs(deltaX)) {
                    // Looks like a Y-ish scroll attempt. Disallow parent from intercepting.
                    view.getParent().requestDisallowInterceptTouchEvent(true);
                }
            }

            return false;
        }
    });

    try {
        mMessageAdapter = new MessageAdapter(getActivity(), MessageAdapter.Mode.SELF_MESSAGES);
        mMessagesList.setAdapter(mMessageAdapter);
    } catch (Utils.ApplicationError e) {
        Log.addEntry(LOG_TAG, "failed to load self messages");
    }

    show(view);

    // Refresh the message list every 5 seconds. This updates "time ago" displays.
    // TODO: event driven redrawing?
    mRefreshUIExecutor = new Utils.FixedDelayExecutor(new Runnable() {
        @Override
        public void run() {
            show();
        }
    }, 5000);

    Events.register(this);

    return view;
}

From source file:cn.panorama.slook.view.CirclePageIndicator.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from  w  ww. j a  va 2 s .  c om*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}