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.brotherpowers.audiojournal.View.SwipeBackLayout.java

private void chkDragable() {
    setOnTouchListener(new OnTouchListener() {
        @Override/*w w w .ja v  a  2s .co  m*/
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                lastY = motionEvent.getRawY();
                lastX = motionEvent.getRawX();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                newY = motionEvent.getRawY();
                lastX = motionEvent.getRawX();

                offsetY = Math.abs(newY - lastY);
                lastY = newY;

                offsetX = Math.abs(newX - lastX);
                lastX = newX;

                switch (dragEdge) {
                case TOP:
                case BOTTOM:
                    setEnablePullToBack(offsetY > offsetX);
                case LEFT:
                case RIGHT:
                    setEnablePullToBack(offsetY < offsetX);
                    break;
                }
            }

            return false;
        }
    });
}

From source file:cz.urbangaming.galgs.GAlg.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    int action = MotionEventCompat.getActionMasked(event);
    switch (action) {
    case (MotionEvent.ACTION_DOWN):
        Point2D point2d = new Point2D(event.getRawX(), event.getRawY());
        Log.d(DEBUG_TAG, "Action was DOWN " + point2d.toString());
        switch (currentWorkMode) {
        case WORK_MODE_ADD:
            pointsRenderer.addVertex(point2d);
            break;
        case WORK_MODE_DELETE:
            pointsRenderer.removeVertex(point2d);
            break;
        case WORK_MODE_EDIT:
            pointsRenderer.selectVertex(point2d);
            break;
        default:/*from w  ww . j  a v a2 s .co m*/
            break;
        }
        return true;
    case (MotionEvent.ACTION_MOVE):
        if (currentWorkMode == WORK_MODE_EDIT) {
            pointsRenderer.moveSelectedVertexTo(event.getRawX(), event.getRawY());
        }
        return true;
    case (MotionEvent.ACTION_UP):
        Log.d(DEBUG_TAG, "Action was UP");
        if (currentWorkMode == WORK_MODE_EDIT) {
            pointsRenderer.deselectVertex();
        }
        return true;
    case (MotionEvent.ACTION_CANCEL):
        Log.d(DEBUG_TAG, "Action was CANCEL");
        return true;
    case (MotionEvent.ACTION_OUTSIDE):
        Log.d(DEBUG_TAG, "Movement occurred outside bounds of current screen element");
        return true;
    default:
        return super.onTouchEvent(event);
    }
}

From source file:com.tjw.swipeback.SwipeBackLayout.java

private void chkDragable() {
    setOnTouchListener(new OnTouchListener() {
        @Override/*  w  ww.  j  a v a2s  .  c  o  m*/
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                lastY = motionEvent.getRawY();
                lastX = motionEvent.getRawX();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                newY = motionEvent.getRawY();
                lastX = motionEvent.getRawX();

                offsetY = Math.abs(newY - lastY);
                lastY = newY;

                offsetX = Math.abs(newX - lastX);
                lastX = newX;

                switch (dragEdge) {
                case TOP:
                case BOTTOM:
                    setEnablePullToBack(offsetY > offsetX);
                case LEFT:
                case RIGHT:
                    setEnablePullToBack(offsetY < offsetX);
                    break;
                }
            }

            return false;
        }
    });

}

From source file:com.artemchep.horario.ui.widgets.SwipeBackLayout.java

private void chkDragable() {
    setOnTouchListener(new View.OnTouchListener() {
        @Override// w w w .  ja va2 s. co m
        public boolean onTouch(View view, MotionEvent motionEvent) {

            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                lastY = motionEvent.getRawY();
                lastX = motionEvent.getRawX();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
                newY = motionEvent.getRawY();
                lastX = motionEvent.getRawX();

                offsetY = Math.abs(newY - lastY);
                lastY = newY;

                offsetX = Math.abs(newX - lastX);
                lastX = newX;

                switch (dragEdge) {
                case TOP:
                case BOTTOM:
                    setEnablePullToBack(offsetY > offsetX);
                case LEFT:
                case RIGHT:
                    setEnablePullToBack(offsetY < offsetX);
                    break;
                }
            }

            return false;
        }
    });
}

From source file:ngoctdn.vng.gesture.CupcakeGestureDetector.java

public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        } else {//from w w  w  . ja  va2 s .com
            Log.i(LOG_TAG, "Velocity tracker is null");
        }

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mFirstRawTouchY = ev.getRawY();
        mLastRawTouchY = ev.getRawY();
        mIsDragging = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            // Use Pythagoras to see if drag length is larger than
            // touch slop
            mIsDragging = Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            if (ev.getPointerCount() == 1)
                mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;
            mLastRawTouchY = ev.getRawY();
            // if (mListener != null) {
            // mListener.onScrolling(mLastRawTouchY, ev.getRawY());
            // mLastRawTouchY = ev.getRawY();
            // }

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        if (mActivePointerId == -1 && mListener != null) {
            mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }
        break;
    }

    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            if (null != mVelocityTracker) {

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                // if (mListener != null) {
                // mListener.onScrolling(mFirstTouchY, mLastTouchY);
                // }

                // Compute velocity within the last 1000ms
                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                // If the velocity is greater than minVelocity, call
                // listener
                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }

        if (mListener != null) {
            mLastRawTouchY = ev.getRawY();
            if (mVelocityTracker != null)
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity());
            else
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }

        // Recycle Velocity Tracker
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    return true;
}

From source file:com.test.hwautotest.emmagee.service.EmmageeService.java

/**
 * create a floating window to show real-time data.
 *///from w  w w  .ja  v a  2 s.  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();
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // state = MotionEvent.ACTION_DOWN;
                startX = x;
                startY = y;
                mTouchStartX = event.getX();
                mTouchStartY = event.getY();
                Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY);
                break;
            case MotionEvent.ACTION_MOVE:
                // state = MotionEvent.ACTION_MOVE;
                updateViewPosition();
                break;

            case MotionEvent.ACTION_UP:
                // state = MotionEvent.ACTION_UP;
                updateViewPosition();
                //               showImg();//?
                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.openwifi);
    //               if (buttonText.equals(wifiText)) {
    //                  wifiManager.setWifiEnabled(true);
    //                  btnWifi.setText(R.string.closewifi);
    //               } else {
    //                  wifiManager.setWifiEnabled(false);
    //                  btnWifi.setText(R.string.openwifi);
    //               }
    //            } catch (Exception e) {
    //               Toast.makeText(viFloatingWindow.getContext(), "?wifi",
    //                     Toast.LENGTH_LONG).show();
    //               Log.e(LOG_TAG, e.toString());
    //            }
    //         }
    //      });

    //?
    imgClose.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showMemi();
        }
    });
}

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

@Override
public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        mDownRawY = event.getRawY();
        mLastTouchRawY = mDownRawY;/*  w  w w.  j a  va  2 s .  co m*/
        break;
    case MotionEvent.ACTION_MOVE:
        float moveRawX = event.getRawX();
        float moveRawY = event.getRawY();
        float dy = moveRawY - mLastTouchRawY;
        float scrollY = getScrollY();

        // move entire layout to display header or footer
        scrollWithLimit(dy, scrollY);

        if (scrollY < 0) {
            performScrollDown(scrollY, moveRawX, moveRawY);
        } else if (scrollY > 0) {
            performScrollUp(scrollY, moveRawX, moveRawY);
        }
        mLastTouchRawY = moveRawY;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        performTouchFinish();
        break;
    }
    return true;
}

From source file:ngoctdn.vng.gesture.DragGestureDetector.java

public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN: {
        mVelocityTracker = VelocityTracker.obtain();
        if (null != mVelocityTracker) {
            mVelocityTracker.addMovement(ev);
        } else {/*from   w w w .  j a v  a2s .  c o m*/
            Log.i(LOG_TAG, "Velocity tracker is null");
        }

        mLastTouchX = getActiveX(ev);
        mLastTouchY = getActiveY(ev);
        mFirstRawTouchY = ev.getRawY();
        mLastRawTouchY = ev.getRawY();
        mIsDragging = false;
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;
    }

    case MotionEvent.ACTION_POINTER_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        break;

    case MotionEvent.ACTION_MOVE: {
        final float x = getActiveX(ev);
        final float y = getActiveY(ev);
        final float dx = x - mLastTouchX, dy = y - mLastTouchY;

        if (!mIsDragging) {
            // Use Pythagoras to see if drag length is larger than
            // touch slop
            mIsDragging = (float) Math.sqrt((dx * dx) + (dy * dy)) >= mTouchSlop;
        }

        if (mIsDragging) {
            if (ev.getPointerCount() == 1)
                mListener.onDrag(mLastRawTouchY, ev.getRawY(), dx, dy);
            mLastTouchX = x;
            mLastTouchY = y;
            mLastRawTouchY = ev.getRawY();
            // if (mListener != null) {
            // mListener.onScrolling(mLastRawTouchY, ev.getRawY());
            // mLastRawTouchY = ev.getRawY();
            // }

            if (null != mVelocityTracker) {
                mVelocityTracker.addMovement(ev);
            }
        }
        if (mActivePointerId == -1 && mListener != null) {
            mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }
        break;
    }

    //      case MotionEvent.ACTION_CANCEL: {
    //         if (mListener != null) {
    //            mLastRawTouchY = ev.getRawY();
    //            mListener.onRelease(mFirstRawTouchY, ev.getRawY());
    //         }
    //         // Recycle Velocity Tracker
    //         if (null != mVelocityTracker) {
    //            mVelocityTracker.recycle();
    //            mVelocityTracker = null;
    //         }
    //         break;
    //      }
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {

        if (mIsDragging) {
            if (null != mVelocityTracker) {

                mLastTouchX = getActiveX(ev);
                mLastTouchY = getActiveY(ev);

                // if (mListener != null) {
                // mListener.onScrolling(mFirstTouchY, mLastTouchY);
                // }

                // Compute velocity within the last 1000ms
                mVelocityTracker.addMovement(ev);
                mVelocityTracker.computeCurrentVelocity(1000);

                final float vX = mVelocityTracker.getXVelocity(), vY = mVelocityTracker.getYVelocity();

                // If the velocity is greater than minVelocity, call
                // listener
                if (Math.max(Math.abs(vX), Math.abs(vY)) >= mMinimumVelocity) {
                    mListener.onFling(mLastTouchX, mLastTouchY, -vX, -vY);
                }
            }
        }

        if (mListener != null) {
            mLastRawTouchY = ev.getRawY();
            if (mVelocityTracker != null)
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), mVelocityTracker.getYVelocity());
            else
                mListener.onRelease(mFirstRawTouchY, ev.getRawY(), 0);
        }

        // Recycle Velocity Tracker
        if (null != mVelocityTracker) {
            mVelocityTracker.recycle();
            mVelocityTracker = null;
        }
        break;
    }
    }

    return true;
}

From source file:org.videolan.vlc.gui.view.PopupLayout.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (mWindowManager == null)
        return false;
    if (mScaleGestureDetector != null)
        mScaleGestureDetector.onTouchEvent(event);
    if (mGestureDetector != null && mGestureDetector.onTouchEvent(event))
        return true;
    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        initialX = mLayoutParams.x;// w w  w . j  a va 2s.c  om
        initialY = mLayoutParams.y;
        initialTouchX = event.getRawX();
        initialTouchY = event.getRawY();
        updateWindowSize();
        return true;
    case MotionEvent.ACTION_UP:
        return true;
    case MotionEvent.ACTION_MOVE:
        if (mScaleGestureDetector == null || !mScaleGestureDetector.isInProgress()) {
            mLayoutParams.x = initialX + (int) (event.getRawX() - initialTouchX);
            mLayoutParams.y = initialY - (int) (event.getRawY() - initialTouchY);
            containInScreen(mLayoutParams.width, mLayoutParams.height);
            mWindowManager.updateViewLayout(PopupLayout.this, mLayoutParams);
            return true;
        }
    }
    return false;
}

From source file:timer.com.maydaysdk.MayDayMessageChatFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View viewInfo = inflater.inflate(R.layout.messagechat, container, false);

    // Initialize UI
    ImageButton imageButtonChatSend = (ImageButton) viewInfo.findViewById(R.id.imageButton_send);
    ImageButton imageButtonChatClose = (ImageButton) viewInfo.findViewById(R.id.imageButton_chat_close);
    mTextViewAgentName = (TextView) viewInfo.findViewById(R.id.textView_chat_agent_name);
    mLinearLayoutMessage = (LinearLayout) viewInfo.findViewById(R.id.linearLayout_message);
    mImageButtonChatResize = (ImageButton) viewInfo.findViewById(R.id.imageButton_chat_resize);
    mEditTextChatMessage = (EditText) viewInfo.findViewById(R.id.editText_chat_message);
    mAlertDialog = new AlertDialog.Builder(getActivity()).create();

    imageButtonChatClose.setOnClickListener(this);
    mImageButtonChatResize.setOnClickListener(this);
    imageButtonChatSend.setOnClickListener(this);
    mEditTextChatMessage.setOnClickListener(this);

    mListFragment = (MayDayMessageListFragment) getChildFragmentManager().findFragmentById(R.id.message_list);

    // Get RCClient device list
    try {// ww  w  .ja va  2  s.c o  m
        mDevice = RCClient.listDevices().get(0);
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    // Get device resolution width and height
    Point size = new Point();
    getActivity().getWindowManager().getDefaultDisplay().getSize(size);
    final int windowHeight = size.y;

    // Message chat resize from top to bottom
    mLinearLayoutMessage.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) mLinearLayoutMessage
                    .getLayoutParams();
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                break;
            case MotionEvent.ACTION_MOVE:
                int y_cord = (int) event.getRawY();

                if (y_cord > windowHeight) {
                    y_cord = windowHeight;
                }

                layoutParams.topMargin = y_cord - MARGIN_TOP;
                mLinearLayoutMessage.setLayoutParams(layoutParams);
                break;
            default:
                break;
            }
            return true;
        }
    });

    Bundle bundle = getArguments();
    String agentName = "", domainAddress = "";
    // Get the event data from the fragment, which pass agent name and domain address
    if (bundle.getString(MayDayConstant.AGENT_NAME) != null) {
        agentName = bundle.getString(MayDayConstant.AGENT_NAME);
    }
    if (bundle.getString(MayDayConstant.DOMAIN_ADDRESS) != null) {
        domainAddress = bundle.getString(MayDayConstant.DOMAIN_ADDRESS);
    }
    initializeChat(agentName, domainAddress);

    return viewInfo;
}