Example usage for android.view MotionEvent getRawY

List of usage examples for android.view MotionEvent getRawY

Introduction

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

Prototype

public final float getRawY() 

Source Link

Document

Returns the original raw Y coordinate of this event.

Usage

From source file:com.scigames.slidegame.Registration1UserNameActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    View v = getCurrentFocus();/*from www. ja  v a 2 s  . com*/
    boolean ret = super.dispatchTouchEvent(event);

    if (v instanceof EditText) {
        View w = getCurrentFocus();
        int scrcoords[] = new int[2];
        w.getLocationOnScreen(scrcoords);
        float x = event.getRawX() + w.getLeft() - scrcoords[0];
        float y = event.getRawY() + w.getTop() - scrcoords[1];

        Log.d("Activity",
                "Touch event " + event.getRawX() + "," + event.getRawY() + " " + x + "," + y + " rect "
                        + w.getLeft() + "," + w.getTop() + "," + w.getRight() + "," + w.getBottom() + " coords "
                        + scrcoords[0] + "," + scrcoords[1]);
        if (event.getAction() == MotionEvent.ACTION_UP
                && (x < w.getLeft() || x >= w.getRight() || y < w.getTop() || y > w.getBottom())) {

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }
    }
    return ret;
}

From source file:com.codingfeel.sm.views.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionDown(MotionEvent motionEvent) {
    // Find the child view that was touched (perform a hit test)
    Rect rect = new Rect();
    int childCount = mRecyclerView.getChildCount();
    int[] listViewCoords = new int[2];
    mRecyclerView.getLocationOnScreen(listViewCoords);
    int x = (int) motionEvent.getRawX() - listViewCoords[0];
    int y = (int) motionEvent.getRawY() - listViewCoords[1];
    View child;/*  w  w w .j  av a 2 s.c  o m*/
    for (int i = 0; i < childCount; i++) {
        child = mRecyclerView.getChildAt(i);
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            mDownView = child;
            break;
        }
    }

    if (mDownView != null) {
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        mDownPosition = mRecyclerView.getChildAdapterPosition(mDownView);
        if (mCallbacks.canDismiss(mDownPosition)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        } else {
            mDownView = null;
        }
    }
}

From source file:com.malinskiy.superrecyclerview.swipe.SwipeDismissRecyclerViewTouchListener.java

private void caseMotionActionDown(MotionEvent motionEvent) {
    // Find the child view that was touched (perform a hit test)
    Rect rect = new Rect();
    int childCount = mRecyclerView.getChildCount();
    int[] listViewCoords = new int[2];
    mRecyclerView.getLocationOnScreen(listViewCoords);
    int x = (int) motionEvent.getRawX() - listViewCoords[0];
    int y = (int) motionEvent.getRawY() - listViewCoords[1];
    View child;/*from   w w  w  . j  a va  2s.c om*/
    for (int i = 0; i < childCount; i++) {
        child = mRecyclerView.getChildAt(i);
        child.getHitRect(rect);
        if (rect.contains(x, y)) {
            mDownView = child;
            break;
        }
    }

    if (mDownView != null) {
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        mDownPosition = mRecyclerView.getChildLayoutPosition(mDownView);
        if (mCallbacks.canDismiss(mDownPosition)) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker.addMovement(motionEvent);
        } else {
            mDownView = null;
        }
    }
}

From source file:com.wojtechnology.sunami.OuterLayout.java

private boolean isDraggableTarget(MotionEvent event) {
    int[] draggableLocation = new int[2];
    mSongHint.getLocationOnScreen(draggableLocation);
    int upperLimit = draggableLocation[1] + mSongHint.getMeasuredHeight();
    int lowerLimit = draggableLocation[1];
    int y = (int) event.getRawY();
    return (y > lowerLimit && y < upperLimit);
}

From source file:com.qa.perf.emmageeplus.service.EmmageeService.java

/**
 * create a floating window to show real-time data.
 *//*from w w  w .  ja  v a  2  s.co  m*/
private void createFloatingWindow() {
    getSharedPreferences("float_flag", Activity.MODE_PRIVATE).edit().putInt("float", 1).apply();
    windowManager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    wmParams = ((MyApplication) getApplication()).getMywmParams();
    wmParams.type = WindowManager.LayoutParams.TYPE_PHONE;
    wmParams.flags |= 8;
    wmParams.gravity = Gravity.START | 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:com.appnexus.opensdkapp.MainActivity.java

/**
 * Special handling for our "native" log button
 *///from  w w  w. j a v a  2  s  .  c om

@Override
public boolean dispatchTouchEvent(MotionEvent motionEvent) {
    // don't handle specially if log button is not showing
    if (btnLog.getVisibility() == View.GONE)
        return super.dispatchTouchEvent(motionEvent);

    float x = motionEvent.getRawX() - contentView.getLeft();
    float y = motionEvent.getRawY() - contentView.getTop();

    // if the user presses btnMore, don't handle specially, btnMore will handle it
    if ((btnMore.getTop() < y) && (btnMore.getBottom() > y) && (btnMore.getLeft() < x)
            && (x < btnMore.getRight())) {
        return super.dispatchTouchEvent(motionEvent);
    }

    // if the user presses outside the bounds of btnLog, "close it"
    if (y < (btnLog.getTop()) || (btnLog.getBottom() < y) || (x < btnLog.getLeft())
            || (btnLog.getRight() < x)) {
        btnLog.setVisibility(View.GONE);
    }

    return super.dispatchTouchEvent(motionEvent);
}

From source file:com.haarman.listviewanimations.itemmanipulation.SwipeDismissListViewTouchListener.java

private boolean handleMoveEvent(MotionEvent motionEvent) {
    if (mPaused || (mVelocityTracker == null)) {
        return false;
    }//from www  .j  av a2s.com

    mVelocityTracker.addMovement(motionEvent);
    float deltaX = motionEvent.getRawX() - mDownX;
    float deltaY = motionEvent.getRawY() - mDownY;
    if (mTouchChildTouched && !mDisallowSwipe && Math.abs(deltaX) > mSlop
            && Math.abs(deltaX) > Math.abs(deltaY)) {
        mSwiping = true;
        mListView.requestDisallowInterceptTouchEvent(true);

        // Cancel ListView's touch (un-highlighting the item)
        MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
        cancelEvent.setAction(MotionEvent.ACTION_CANCEL
                | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
        mListView.onTouchEvent(cancelEvent);
    }

    if (mSwiping) {
        if (!mSwipeInitiated) {
            Log.d("SwipeDismissListViewTouchListener", "swipe/begin");
        }
        mSwipeInitiated = true;
        ViewHelper.setTranslationX(mCurrentDismissData.view, deltaX);
        ViewHelper.setAlpha(mCurrentDismissData.view,
                Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
        for (View v : getAllTreeChildViews(mCurrentDismissData.view)) {
            ViewHelper.setTranslationX(v, deltaX);
            ViewHelper.setAlpha(v, Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
        }
        return true;
    }
    return false;
}

From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissTouchListener.java

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
    // offset because the view is translated during swipe
    motionEvent.offsetLocation(mTranslationX, 0);

    if (mViewWidth < 2) {
        mViewWidth = mView.getWidth();/*w  ww . ja  v  a  2  s.c  o m*/
    }

    switch (MotionEventCompat.getActionMasked(motionEvent)) {
    case MotionEvent.ACTION_DOWN: {
        // TODO: ensure this is a finger, and set a flag
        mDownX = motionEvent.getRawX();
        mDownY = motionEvent.getRawY();
        mVelocityTracker = VelocityTracker.obtain();
        mVelocityTracker.addMovement(motionEvent);
        view.onTouchEvent(motionEvent);
        return false;
    }

    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }

        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = Math.abs(mVelocityTracker.getXVelocity());
        float velocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(deltaY) < Math.abs(deltaX)) {
            if (Math.abs(deltaX) > Math.round(mViewWidth * SWIPE_SENSITIVITY)) {
                dismiss = true;
                dismissRight = deltaX > 0;
            } else if (Math.abs(deltaX) > mSlop && mMinFlingVelocity <= velocityX
                    && velocityX <= mMaxFlingVelocity && velocityY < velocityX) {
                dismiss = true;
                dismissRight = mVelocityTracker.getXVelocity() > 0;
            }
        }
        if (dismiss) {
            // dismiss
            mView.animate().translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            performDismiss();
                        }
                    });
        } else {
            // cancel
            mView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
        }
        mVelocityTracker = null;
        mTranslationX = 0;
        mDownX = 0;
        mDownY = 0;
        mSwiping = false;
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null) {
            break;
        }

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        if (Math.abs(deltaX) > mSlop) {
            mSwiping = true;
            mView.getParent().requestDisallowInterceptTouchEvent(true);

            // Cancel listview's touch
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (MotionEventCompat
                    .getActionIndex(motionEvent) << MotionEventCompat.ACTION_POINTER_INDEX_SHIFT));
            mView.onTouchEvent(cancelEvent);
        }

        if (mSwiping) {
            mTranslationX = deltaX;
            setTranslationX(mView, deltaX);
            // TODO: use an ease-out interpolator or such
            setAlpha(mView, Math.max(0f, Math.min(1f, 1f - Math.abs(deltaX) / SWIPE_SENSITIVITY * mViewWidth)));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Evaluate if this should intercept touch event to enable pull actions
 * @param ev MotionEvent//from  w  ww. j a  v  a2s.  c  o m
 * @param contentView content view to help evaluate
 * @return true if intercepts; false otherwise
 */
private boolean shouldInterceptTouchEvent(MotionEvent ev, View contentView) {
    boolean shouldIntercept;
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        mInterceptDownY = ev.getRawY();
        break;
    case MotionEvent.ACTION_MOVE:
        mInterceptMoveY = ev.getRawY();
        mLastTouchRawY = mInterceptMoveY;
        if (Math.abs(mInterceptMoveY - mInterceptDownY) > mTouchSlop) {
            if (mEnableRefresh && mInterceptMoveY - mInterceptDownY > 0) {
                // pull down, evaluate if content view is at top
                shouldIntercept = !ViewCompat.canScrollVertically(contentView, -1);
                return shouldIntercept;
            } else if (mEnableLoadMore && mInterceptMoveY - mInterceptDownY < 0) {
                // pull up, evaluate if content view is at bottom
                shouldIntercept = !ViewCompat.canScrollVertically(contentView, 1);
                return shouldIntercept;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        break;
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:com.jainbooks.activitys.DashboardActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    View currentView = getCurrentFocus();

    boolean retVal = super.dispatchTouchEvent(event);
    if (currentView instanceof EditText) {
        View cView = getCurrentFocus();
        int scrCoordinates[] = new int[2];
        cView.getLocationOnScreen(scrCoordinates);
        float xPos = event.getRawX() + cView.getLeft() - scrCoordinates[0];
        float yPos = event.getRawY() + cView.getTop() - scrCoordinates[1];

        if (event.getAction() == MotionEvent.ACTION_UP && (xPos < cView.getLeft() || xPos >= cView.getRight()
                || yPos < cView.getTop() || yPos > cView.getBottom())) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        }// www . j  a v a  2s  .  co m
    }
    return retVal;
}