Example usage for android.view MotionEvent getY

List of usage examples for android.view MotionEvent getY

Introduction

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

Prototype

public final float getY() 

Source Link

Document

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

Usage

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

@Override
public boolean onTouchEvent(MotionEvent e) {
    View child;//from  ww w .  ja v a 2 s .  c om
    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.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 ww  w  .  ja v a  2  s .co  m
    int value;
    final Boolean[] isInnerCircle = new Boolean[1];
    isInnerCircle[0] = false;

    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.
            mHapticFeedbackController.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.
                mHapticFeedbackController.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) {
                mHapticFeedbackController.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: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;
        }//  w  w  w. j a v  a2s.com
        break;
    }
    return super.onTouchEvent(ev);
}

From source file:com.netease.qa.emmagee.service.EmmageeService.java

/**
 * create a floating window to show real-time data.
 *//*  ww w  . j a  v  a  2s .c  o  m*/
private void createFloatingWindow() {
    SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = shared.edit();
    editor.putInt("float", 1);
    editor.commit();
    windowManager = (WindowManager) getApplicationContext().getSystemService("window");
    wmParams = ((MyApplication) getApplication()).getMywmParams();
    wmParams.type = 2002;
    wmParams.flags |= 8;
    wmParams.gravity = Gravity.LEFT | Gravity.TOP;
    wmParams.x = 0;
    wmParams.y = 0;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = 1;
    windowManager.addView(viFloatingWindow, wmParams);
    viFloatingWindow.setOnTouchListener(new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            x = event.getRawX();
            y = event.getRawY() - statusBarHeight;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mTouchStartX = event.getX();
                mTouchStartY = event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                updateViewPosition();
                break;
            case MotionEvent.ACTION_UP:
                updateViewPosition();
                mTouchStartX = mTouchStartY = 0;
                break;
            }
            return true;
        }
    });

    btnWifi.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi);
                String buttonText = (String) btnWifi.getText();
                String wifiText = getResources().getString(R.string.open_wifi);
                if (buttonText.equals(wifiText)) {
                    wifiManager.setWifiEnabled(true);
                    btnWifi.setText(R.string.close_wifi);
                } else {
                    wifiManager.setWifiEnabled(false);
                    btnWifi.setText(R.string.open_wifi);
                }
            } catch (Exception e) {
                Toast.makeText(viFloatingWindow.getContext(), getString(R.string.wifi_fail_toast),
                        Toast.LENGTH_LONG).show();
                Log.e(LOG_TAG, e.toString());
            }
        }
    });
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityAddPickupAndDropoff.java

/**
 * When someone presses the map, this method is called and draws the pickup 
 * or dropoff point on the map depending on which of the {@link Button}s, 
 * {@link #btnSelectPickupPoint} or {@link #btnSelectDropoffPoint} that is pressed.
 *//*from   w w w  .ja va 2  s .c  o m*/
@Override
public synchronized boolean onSingleTapUp(MotionEvent e) {
    if (!isSelectingDropoffPoint && !isSelectingPickupPoint) {
        return false;
    }
    GeoPoint gp = mapView.getProjection().fromPixels((int) e.getX(), (int) e.getY());
    MapLocation mapLocation = (MapLocation) GeoHelper.getLocation(gp);
    // If the user is selecting a pickup point
    if (isSelectingPickupPoint) {
        Location temp = findClosestLocationOnRoute(mapLocation);
        //Controls if the user has entered a NEW address
        if (pickupPoint != temp) {
            // Removes old pickup point (thumb)
            if (overlayPickupThumb != null) {
                mapView.getOverlays().remove(overlayPickupThumb);
                overlayPickupThumb = null;
            }
            mapView.invalidate();

            // If no dropoff point is specified, we add the pickup point to the map.
            if (dropoffPoint == null) {
                pickupPoint = temp;
                overlayPickupThumb = drawThumb(pickupPoint, true);
                // Set pickup TextView to the new address
                acPickup.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(pickupPoint))
                        .replace(",", "\n"));
            } else { // If a dropoff point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the pickup point is before the dropoff point.
                if (l.indexOf(temp) < l.indexOf(dropoffPoint)) {
                    //makeToast("The pickup point has to be before the dropoff point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The pickup point has to be before the dropoff point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the pickup point to the map by drawing a thumb
                    pickupPoint = temp;
                    overlayPickupThumb = drawThumb(pickupPoint, true);
                    // Set pickup TextView to the new address
                    acPickup.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(pickupPoint))
                            .replace(",", "\n"));
                }
            }
        }
        // If the user is selecting a dropoff point
    } else if (isSelectingDropoffPoint) {
        Location temp = findClosestLocationOnRoute(mapLocation);
        // Controls if the user has entered a NEW address
        if (dropoffPoint != temp) {
            // Removes old dropoff point (thumb)
            if (overlayDropoffThumb != null) {
                mapView.getOverlays().remove(overlayDropoffThumb);
                overlayDropoffThumb = null;
            }
            mapView.invalidate();

            // If no pickup point is specified, we add the dropoff point to the map.
            if (pickupPoint == null) {
                dropoffPoint = temp;
                overlayDropoffThumb = drawThumb(dropoffPoint, false);
                // Set dropoff TextView to the new address
                acDropoff.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(dropoffPoint))
                        .replace(",", "\n"));
            } else { // If a pickup point is specified:
                List<Location> l = getApp().getSelectedJourney().getRoute().getRouteData();
                // Checks to make sure the dropoff point is after the pickup point.
                if (l.indexOf(temp) > l.indexOf(pickupPoint)) {
                    //makeToast("The droppoff point has to be after the pickup point");
                    AlertDialog.Builder ad = new AlertDialog.Builder(MapActivityAddPickupAndDropoff.this);
                    ad.setMessage("The droppoff point has to be after the pickup point");
                    ad.setTitle("Unable to send request");
                    ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {

                        }
                    });
                    ad.show();
                } else {
                    // Adds the dropoff point to the map by drawing a thumb
                    dropoffPoint = temp;
                    overlayDropoffThumb = drawThumb(dropoffPoint, false);
                    // Set dropoff TextView to the new address
                    acDropoff.setText(GeoHelper.getAddressAtPointString(GeoHelper.getGeoPoint(dropoffPoint))
                            .replace(",", "\n"));
                }
            }
        }
    }
    return true;
}

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 ww w.  ja va 2s. co  m*/
    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: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   www.ja  v a  2  s.c o 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:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

@Override
public boolean onInterceptTouchEvent(final RecyclerView recyclerView, final MotionEvent event) {
    if (event.getPointerCount() > 1) {
        // Ignore subsequent pointers.
        return false;
    }/*  w w  w  .  j av a 2  s.  c  o m*/

    // We are not yet tracking a swipe gesture. Begin detection by spying on
    // touch events bubbling down to our children.
    final int action = event.getActionMasked();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (!hasGestureSwipeTarget()) {
            onGestureStart();

            mVelocityTracker.addMovement(event);
            mInitialX = event.getX();
            mInitialY = event.getY();

            final View viewAtPoint = mRecyclerView.findChildViewUnder(mInitialX, mInitialY);
            final ConversationListItemView child = (ConversationListItemView) viewAtPoint;
            if (viewAtPoint instanceof ConversationListItemView && child != null && child.isSwipeAnimatable()) {
                // Begin detecting swipe on the target for the rest of the gesture.
                mListItemView = child;
                if (mListItemView.isAnimating()) {
                    mListItemView = null;
                }
            } else {
                mListItemView = null;
            }
        }
        break;
    case MotionEvent.ACTION_MOVE:
        if (hasValidGestureSwipeTarget()) {
            mVelocityTracker.addMovement(event);

            final int historicalCount = event.getHistorySize();
            // First consume the historical events, then consume the current ones.
            for (int i = 0; i < historicalCount + 1; i++) {
                float currX;
                float currY;
                if (i < historicalCount) {
                    currX = event.getHistoricalX(i);
                    currY = event.getHistoricalY(i);
                } else {
                    currX = event.getX();
                    currY = event.getY();
                }
                final float deltaX = currX - mInitialX;
                final float deltaY = currY - mInitialY;
                final float absDeltaX = Math.abs(deltaX);
                final float absDeltaY = Math.abs(deltaY);

                if (!mIsSwiping && absDeltaY > mTouchSlop
                        && absDeltaY > (ERROR_FACTOR_MULTIPLIER * absDeltaX)) {
                    // Stop detecting swipe for the remainder of this gesture.
                    onGestureEnd();
                    return false;
                }

                if (absDeltaX > mTouchSlop) {
                    // Swipe detected. Return true so we can handle the gesture in
                    // onTouchEvent.
                    mIsSwiping = true;

                    // We don't want to suddenly jump the slop distance.
                    mInitialX = event.getX();
                    mInitialY = event.getY();

                    onSwipeGestureStart(mListItemView);
                    return true;
                }
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        if (hasGestureSwipeTarget()) {
            onGestureEnd();
        }
        break;
    }

    // Start intercepting touch events from children if we detect a swipe.
    return mIsSwiping;
}

From source file:com.achep.acdisplay.ui.widgets.CircleView.java

public boolean sendTouchEvent(@NonNull MotionEvent event) {
    final int action = event.getActionMasked();

    // If current circle is canceled then
    // ignore all actions except of touch down (to reset state.)
    if (mCanceled && action != MotionEvent.ACTION_DOWN)
        return false;

    // Cancel the current circle on two-or-more-fingers touch.
    if (event.getPointerCount() > 1) {
        cancelCircle();//from  w  w  w.j a  v  a 2 s  . c o  m
        return false;
    }

    final float x = event.getX();
    final float y = event.getY();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        clearAnimation();
        Config config = Config.getInstance();

        // Corner actions
        int width = getWidth();
        int height = getHeight();
        int radius = Math.min(width, height) / 3;
        if (MathUtils.isInCircle(x, y, 0, 0, radius)) { // Top left
            mCornerActionId = config.getCornerActionLeftTop();
        } else if (MathUtils.isInCircle(x, y, -width, 0, radius)) { // Top right
            mCornerActionId = config.getCornerActionRightTop();
        } else if (MathUtils.isInCircle(x, y, 0, -height, radius)) { // Bottom left
            mCornerActionId = config.getCornerActionLeftBottom();
        } else if (MathUtils.isInCircle(x, y, -width, -height, radius)) { // Bottom right
            mCornerActionId = config.getCornerActionRightBottom();
        } else {
            // The default action is unlocking.
            mCornerActionId = Config.CORNER_UNLOCK;
        }

        // Update colors and icon drawable.
        boolean needsColorReset = updateIcon();
        setInnerColor(getColor(config.getCircleInnerColor()), needsColorReset);
        setOuterColor(getColor(config.getCircleOuterColor()));

        // Initialize circle
        mRadiusTargetAimed = false;
        mRadiusMaxPeak = 0;
        mPoint[0] = x;
        mPoint[1] = y;
        mCanceled = false;

        if (mHandler.hasMessages(ACTION_UNLOCK)) {
            // Cancel unlocking process.
            mHandler.sendEmptyMessage(ACTION_UNLOCK_CANCEL);
        }

        mHandler.removeCallbacksAndMessages(null);
        mHandler.sendEmptyMessageDelayed(MSG_CANCEL, 1000);
        mHandler.sendEmptyMessage(ACTION_START);
        break;
    case MotionEvent.ACTION_MOVE:
        setRadius(x, y);
        break;
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mRadiusTargetAimed || action == MotionEvent.ACTION_CANCEL) {
            cancelCircle();
            break;
        }

        startUnlock();
        break;
    }
    return true;
}

From source file:com.android.gallery3d.filtershow.imageshow.ImageShow.java

@Override
public boolean onDoubleTap(MotionEvent arg0) {
    mZoomIn = !mZoomIn;/*from ww w . j  a  v  a  2s.c  o m*/
    float scale = 1.0f;
    final float x = arg0.getX();
    final float y = arg0.getY();
    if (mZoomIn) {
        scale = MasterImage.getImage().getMaxScaleFactor();
    }
    if (scale != MasterImage.getImage().getScaleFactor()) {
        if (mAnimatorScale != null) {
            mAnimatorScale.cancel();
        }
        mAnimatorScale = ValueAnimator.ofFloat(MasterImage.getImage().getScaleFactor(), scale);
        float translateX = (getWidth() / 2 - x);
        float translateY = (getHeight() / 2 - y);
        Point translation = MasterImage.getImage().getTranslation();
        int startTranslateX = translation.x;
        int startTranslateY = translation.y;
        if (scale != 1.0f) {
            translation.x = (int) (mOriginalTranslation.x + translateX);
            translation.y = (int) (mOriginalTranslation.y + translateY);
        } else {
            translation.x = 0;
            translation.y = 0;
        }
        constrainTranslation(translation, scale);

        startAnimTranslation(startTranslateX, translation.x, startTranslateY, translation.y,
                mAnimationZoomDelay);
        mAnimatorScale.setDuration(mAnimationZoomDelay);
        mAnimatorScale.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                MasterImage.getImage().setScaleFactor((Float) animation.getAnimatedValue());
                invalidate();
            }
        });
        mAnimatorScale.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                applyTranslationConstraints();
                MasterImage.getImage().needsUpdatePartialPreview();
                invalidate();
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        mAnimatorScale.start();
    }
    return true;
}