Example usage for android.view MotionEvent ACTION_MOVE

List of usage examples for android.view MotionEvent ACTION_MOVE

Introduction

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

Prototype

int ACTION_MOVE

To view the source code for android.view MotionEvent ACTION_MOVE.

Click Source Link

Document

Constant for #getActionMasked : A change has happened during a press gesture (between #ACTION_DOWN and #ACTION_UP ).

Usage

From source file:com.carlosyzy.newsclient.View.HorizontalListView.java

/** Registers the gesture detector to receive gesture notifications for this view */
private void bindGestureDetector() {
    // Generic touch listener that can be applied to any view that needs to process gestures
    final OnTouchListener gestureListenerHandler = new OnTouchListener() {
        private double xDistance = 0;
        private double yDistance = 0;

        @Override//w ww. j  ava2 s  . c o  m
        public boolean onTouch(final View v, final MotionEvent ev) {
            switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                xDistance = ev.getX();
                yDistance = ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                double moveX = ev.getX() - xDistance;
                double moveY = ev.getY() - yDistance;
                if ((20 * Math.abs(moveX) > Math.abs(ev.getY() - moveY))) {
                    v.getParent().requestDisallowInterceptTouchEvent(true);
                } else {
                    v.getParent().requestDisallowInterceptTouchEvent(false);
                }
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                v.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
            return mGestureDetector.onTouchEvent(ev);
        }
    };

    setOnTouchListener(gestureListenerHandler);
}

From source file:com.amazon.appstream.fireclient.FireClientActivity.java

/**
 * A "touch event" includes mouse motion when the mouse button
 * is down.//from   w w  w  .j  a  v a2s . c o  m
 */
@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    if (mKeyboardActive) {
        if (mGestureDetector.onTouchEvent(event)) {
            return true;
        }
    }

    if (super.dispatchTouchEvent(event))
        return true;

    int flags = 0;
    if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) {
        flags = AppStreamInterface.CET_TOUCH_FLAG;
    }

    event.getPointerCoords(0, mCoordHolder);
    switch (event.getAction()) {
    case MotionEvent.ACTION_MOVE:
        AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, flags);
        break;
    case MotionEvent.ACTION_DOWN:
        AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y,
                AppStreamInterface.CET_MOUSE_1_DOWN | flags);
        break;
    case MotionEvent.ACTION_UP:
        AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y,
                AppStreamInterface.CET_MOUSE_1_UP | flags);
        break;
    }
    return true;
}

From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    final float x = ev.getX();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        break;//from   ww  w .j  av  a2s  .  c  om

    case MotionEvent.ACTION_MOVE:
        break;

    case MotionEvent.ACTION_UP:
        for (int i = 0; i < tabs.size(); i++) {
            float l = getPaddingLeft() + intervalWidth * i + itemWidth * i;
            float r = l + itemWidth;
            if (x >= l && x <= r) {
                clickPosition = i;
                break;
            }
        }
        performClick();
        break;
    }

    return true;
}

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

@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        return false;
    }/*from  w  w w  .j a v a  2 s  .  co m*/
    int action = MotionEventCompat.getActionMasked(event);
    if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) {
        return true;
    }
    mViewDragHelper.processTouchEvent(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
    // to capture the bottom sheet in case it is not captured and the touch slop is passed.
    if (action == MotionEvent.ACTION_MOVE) {

        if (mSlideHelper.canScrollHorizontally() != 0
                && Math.abs(mInitialY - event.getX()) > mViewDragHelper.getTouchSlop()) {
            mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
        } else if (mSlideHelper.canScrollVertically() != 0
                && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) {
            mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
        }
    }
    return true;
}

From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//from  ww w.  ja  va2s.c o  m
    layout = (RelativeLayout) findViewById(R.id.mainlayout);
    IP1 = "";
    IP2 = "";
    angle1 = 0.0f;
    angle2 = 0.0f;
    gyroOrientation[0] = 0.0f;
    gyroOrientation[1] = 0.0f;
    gyroOrientation[2] = 0.0f;

    // initialise gyroMatrix with identity matrix
    gyroMatrix[0] = 1.0f;
    gyroMatrix[1] = 0.0f;
    gyroMatrix[2] = 0.0f;
    gyroMatrix[3] = 0.0f;
    gyroMatrix[4] = 1.0f;
    gyroMatrix[5] = 0.0f;
    gyroMatrix[6] = 0.0f;
    gyroMatrix[7] = 0.0f;
    gyroMatrix[8] = 1.0f;

    // get sensorManager and initialise sensor listeners
    mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    initListeners();

    // wait for one second until gyroscope and magnetometer/accelerometer
    // data is initialised then scedule the complementary filter task
    fuseTimer.scheduleAtFixedRate(new calculateFusedOrientationTask(), 1000, TIME_CONSTANT);

    // GUI stuff
    try {
        client1 = new MyCoapClient(this.IP1);
        client2 = new MyCoapClient(this.IP2);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    json = new JSONObject();
    mHandler = new Handler();
    radioSelection = 0;
    d.setRoundingMode(RoundingMode.HALF_UP);
    d.setMaximumFractionDigits(3);
    d.setMinimumFractionDigits(3);

    /// Application layout here only

    RelativeLayout.LayoutParams left = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams right = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams up = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams down = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    ImageView img_left = new ImageView(this);
    ImageView img_right = new ImageView(this);
    ImageView img_up = new ImageView(this);
    ImageView img_down = new ImageView(this);
    ImageView img_button1 = new ImageView(this);
    ImageView img_button2 = new ImageView(this);
    final EditText edittext1 = new EditText(this);
    final EditText edittext2 = new EditText(this);
    img_left.setImageResource(R.drawable.left_button);
    img_right.setImageResource(R.drawable.right_button);
    img_up.setImageResource(R.drawable.up);
    img_down.setImageResource(R.drawable.down);
    img_button1.setImageResource(R.drawable.button);
    img_button2.setImageResource(R.drawable.button);

    left.setMargins(0, 66, 0, 0);
    right.setMargins(360, 66, 0, 0);
    up.setMargins(240, 90, 0, 0);
    down.setMargins(240, 240, 0, 0);
    button1.setMargins(440, 800, 0, 0);
    button2.setMargins(440, 900, 0, 0);
    text1.setMargins(5, 800, 0, 0);
    text2.setMargins(5, 900, 0, 0);

    layout.addView(img_left, left);
    layout.addView(img_right, right);
    layout.addView(img_up, up);
    layout.addView(img_down, down);
    layout.addView(img_button1, button1);
    layout.addView(edittext1, text1);
    layout.addView(img_button2, button2);
    layout.addView(edittext2, text2);

    img_left.getLayoutParams().height = 560;
    img_left.getLayoutParams().width = 280;
    img_right.getLayoutParams().height = 560;
    img_right.getLayoutParams().width = 280;
    img_up.getLayoutParams().height = 150;
    img_up.getLayoutParams().width = 150;
    img_down.getLayoutParams().height = 150;
    img_down.getLayoutParams().width = 150;
    img_button1.getLayoutParams().height = 100;
    img_button1.getLayoutParams().width = 200;
    edittext1.getLayoutParams().width = 400;
    edittext1.setText("84.248.76.84");
    edittext2.setText("84.248.76.84");
    img_button2.getLayoutParams().height = 100;
    img_button2.getLayoutParams().width = 200;
    edittext2.getLayoutParams().width = 400;

    /////////// Define and Remember Position for EACH PHYSICAL OBJECTS (LAPTOPS) /////////////////////
    img_button1.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 1 IS REMEMBERED
                angle1 = fusedOrientation[0];
                IP1 = edittext1.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO FIRST LAPTOP
                    client1 = new MyCoapClient(IP1);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                //view.setImageResource(R.drawable.left_button);
                break;
            }
            return true;
        }

    });

    img_button2.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 2 IS REMEMBERED
                angle2 = fusedOrientation[0];
                IP2 = edittext2.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO SECOND LAPTOP
                    client2 = new MyCoapClient(IP2);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }

    });

    img_left.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.left_button_press);

                ///////////////////// PERFORM CLICK ACTION BASED ON POSITION OF 2 PHYSICAL OBJECTS (LAPTOPs) HERE/////////////////////////

                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0) {
                        client1.runClient("left pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0) {
                        client2.runClient("left pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.left_button);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("left released");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("left released");
                    }
                }
                break;
            }
            return true;
        }
    });

    img_right.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.right_button_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("right pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("right pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.right_button);
                break;
            }
            return true;
        }
    });

    img_up.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.up_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("up pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("up pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.up);
                break;
            }
            return true;
        }
    });

    img_down.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.down_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("down pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("down pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.down);
                break;
            }
            return true;
        }
    });
}

From source file:com.brandon.mailbox.RecyclerSwipeListener.java

private boolean handleTouchEvent(MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }//from   ww  w .  ja va 2s .  c  o m
    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            break;
        }
        // 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;
        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 && mAnimatingPosition != mRecyclerView.getChildLayoutPosition(mDownView)) {
            mAlpha = ViewCompat.getAlpha(mDownView);
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildLayoutPosition(mDownView);
            mSwipingLeft = mSwipeListener.canSwipeLeft(mDownPosition);
            mSwipingRight = mSwipeListener.canSwipeRight(mDownPosition);
            if (mSwipingLeft || mSwipingRight) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        break;
    }
    case MotionEvent.ACTION_CANCEL: {
        if (mVelocityTracker == null) {
            break;
        }
        if (mDownView != null && mSwiping) {
            // cancel
            ViewCompat.animate(mDownView).translationX(0).alpha(mAlpha).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }
    case MotionEvent.ACTION_UP: {
        if (mVelocityTracker == null) {
            break;
        }
        mFinalDelta = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(mFinalDelta) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = mFinalDelta > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (mFinalDelta < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != mAnimatingPosition && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            mAnimatingPosition = mDownPosition;
            ViewCompat.animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new ViewPropertyAnimatorListener() {
                        @Override
                        public void onAnimationStart(View view) {
                            // Do nothing.
                        }

                        @Override
                        public void onAnimationEnd(View view) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                performDismiss(downView, downPosition);
                            }
                        }

                        @Override
                        public void onAnimationCancel(View view) {
                            // Do nothing.
                        }
                    });
        } else {
            // cancel
            ViewCompat.animate(mDownView).translationX(0).alpha(mAlpha).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }
    case MotionEvent.ACTION_MOVE: {
        if (mVelocityTracker == null || mPaused) {
            break;
        }
        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
        }
        if (deltaX < 0 && !mSwipingLeft)
            mSwiping = false;
        if (deltaX > 0 && !mSwipingRight)
            mSwiping = false;
        if (mSwiping) {
            ViewCompat.setTranslationX(mDownView, deltaX - mSwipingSlop);
            ViewCompat.setAlpha(mDownView,
                    Math.max(0f, Math.min(mAlpha, mAlpha * (1f - Math.abs(deltaX) / mViewWidth))));
            return true;
        }
        break;
    }
    }
    return false;
}

From source file:sjizl.com.FileUploadTest.java

@SuppressLint("NewApi")
@Override//  www . j a  va2 s  .  co m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.fileuploadtest2);
    //ac_image_grid
    TextView textView2_under_title;
    final ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext()));
    progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole);
    progressBar_hole.setVisibility(View.INVISIBLE);
    right_lin = (LinearLayout) findViewById(R.id.right_lin);
    rand = CommonUtilities.randInt(111, 999);
    middle_lin = (LinearLayout) findViewById(R.id.middle_lin);
    //right_lin.setBackgroundColor(Color.BLUE);
    right_lin = (LinearLayout) findViewById(R.id.right_lin);
    left_lin1 = (LinearLayout) findViewById(R.id.left_lin1);

    left_lin3 = (LinearLayout) findViewById(R.id.left_lin3);
    left_lin4 = (LinearLayout) findViewById(R.id.left_lin4);
    middle_lin = (LinearLayout) findViewById(R.id.middle_lin);

    upload_photo_text = (LinearLayout) findViewById(R.id.upload_photo_text);

    textView2_under_title = (TextView) findViewById(R.id.textView2_under_title);
    ((LinearLayout) textView2_under_title.getParent()).removeView(textView2_under_title);
    textView2_under_title.setVisibility(View.GONE);
    ImageView imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    Button upload_photo0 = (Button) findViewById(R.id.upload_photo0);
    Button upload_photo1 = (Button) findViewById(R.id.upload_photo1);
    Button upload_photo2 = (Button) findViewById(R.id.upload_photo2);

    upload_photo0.setVisibility(View.GONE);
    upload_photo1.setVisibility(View.GONE);
    upload_photo2.setVisibility(View.GONE);

    upload_photo0.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            CommonUtilities.custom_toast(getApplicationContext(), FileUploadTest.this, "UploadActivity! ", null,
                    R.drawable.iconbd);

            Intent dashboard = new Intent(getApplicationContext(), UploadActivity.class);

            startActivity(dashboard);
        }
    });
    upload_photo1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show();
            Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class);

            startActivity(dashboard);
        }
    });

    upload_photo2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show();
            Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class);

            startActivity(dashboard);
        }
    });

    final ImageView left_button;

    left_button = (ImageView) findViewById(R.id.imageView1_back);
    Button button1 = (Button) findViewById(R.id.upload_photo1);

    SharedPreferences sp = getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
    naam = sp.getString("naam", null);
    username = sp.getString("username", null);
    password = sp.getString("password", null);
    foto = sp.getString("foto", null);
    foto_num = sp.getString("foto_num", null);
    imageLoader.displayImage("http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, imageView2_dashboard,
            options);

    Brows();

    listView.setLongClickable(true);
    registerForContextMenu(listView);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //startImagePagerActivity(position);

            if (position == 0) {
                openGallery(SELECT_FILE1);
            } else {

                listView.showContextMenuForChild(view);
                //  registerForContextMenu(view); 
                //  openContextMenu(view);
                //  unregisterForContextMenu(view);
            }

        }
    });

    left_lin1.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
                left_lin1.setBackgroundColor(Color.DKGRAY);
                v.setBackgroundColor(Color.DKGRAY);
                onBackPressed();
            } else if (event.getAction() == MotionEvent.ACTION_UP
                    || event.getAction() == MotionEvent.ACTION_CANCEL) {
                left_lin1.setBackgroundColor(Color.BLACK);
                v.setBackgroundColor(Color.BLACK);
            }
            return false;
        }
    });
    CommonUtilities u = new CommonUtilities();
    u.setHeaderConrols(getApplicationContext(), this,

            right_lin,

            left_lin3, left_lin4, left_lin1, left_button);
    ;

    middle_lin.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
                middle_lin.setBackgroundColor(Color.DKGRAY);
                v.setBackgroundColor(Color.DKGRAY);
            } else if (event.getAction() == MotionEvent.ACTION_UP
                    || event.getAction() == MotionEvent.ACTION_CANCEL) {
                middle_lin.setBackgroundColor(Color.BLACK);
                v.setBackgroundColor(Color.BLACK);
            }
            return false;
        }
    });

}

From source file:br.com.halph.agendafeliz.util.SwipeableRecyclerViewTouchListener.java

private boolean handleTouchEvent(MotionEvent motionEvent) {
    if (mViewWidth < 2) {
        mViewWidth = mRecyclerView.getWidth();
    }/*from  ww  w .  j av a 2  s .c  om*/

    switch (motionEvent.getActionMasked()) {
    case MotionEvent.ACTION_DOWN: {
        if (mPaused) {
            break;
        }

        // 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;
        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 && mAnimatingPosition != mRecyclerView.getChildLayoutPosition(mDownView)) {
            mAlpha = ViewCompat.getAlpha(mDownView);
            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mRecyclerView.getChildLayoutPosition(mDownView);
            mSwipingLeft = mSwipeListener.canSwipeLeft(mDownPosition);
            mSwipingRight = mSwipeListener.canSwipeRight(mDownPosition);
            if (mSwipingLeft || mSwipingRight) {
                mVelocityTracker = VelocityTracker.obtain();
                mVelocityTracker.addMovement(motionEvent);
            } else {
                mDownView = null;
            }
        }
        break;
    }

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

        if (mDownView != null && mSwiping) {
            // cancel
            ViewCompat.animate(mDownView).translationX(0).alpha(mAlpha).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

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

        mFinalDelta = motionEvent.getRawX() - mDownX;
        mVelocityTracker.addMovement(motionEvent);
        mVelocityTracker.computeCurrentVelocity(1000);
        float velocityX = mVelocityTracker.getXVelocity();
        float absVelocityX = Math.abs(velocityX);
        float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
        boolean dismiss = false;
        boolean dismissRight = false;
        if (Math.abs(mFinalDelta) > mViewWidth / 2 && mSwiping) {
            dismiss = true;
            dismissRight = mFinalDelta > 0;
        } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity
                && absVelocityY < absVelocityX && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (mFinalDelta < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
        }
        if (dismiss && mDownPosition != mAnimatingPosition && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            final View downView = mDownView; // mDownView gets null'd before animation ends
            final int downPosition = mDownPosition;
            ++mDismissAnimationRefCount;
            mAnimatingPosition = mDownPosition;
            ViewCompat.animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0)
                    .setDuration(mAnimationTime).setListener(new ViewPropertyAnimatorListener() {
                        @Override
                        public void onAnimationStart(View view) {
                            // Do nothing.
                        }

                        @Override
                        public void onAnimationEnd(View view) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                performDismiss(downView, downPosition);
                            }
                        }

                        @Override
                        public void onAnimationCancel(View view) {
                            // Do nothing.
                        }
                    });
        } else {
            // cancel
            ViewCompat.animate(mDownView).translationX(0).alpha(mAlpha).setDuration(mAnimationTime)
                    .setListener(null);
        }
        mVelocityTracker.recycle();
        mVelocityTracker = null;
        mDownX = 0;
        mDownY = 0;
        mDownView = null;
        mDownPosition = ListView.INVALID_POSITION;
        mSwiping = false;
        break;
    }

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

        mVelocityTracker.addMovement(motionEvent);
        float deltaX = motionEvent.getRawX() - mDownX;
        float deltaY = motionEvent.getRawY() - mDownY;
        if (!mSwiping && Math.abs(deltaX) > mSlop && Math.abs(deltaY) < Math.abs(deltaX) / 2) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
        }

        if (deltaX < 0 && !mSwipingLeft)
            mSwiping = false;
        if (deltaX > 0 && !mSwipingRight)
            mSwiping = false;

        if (mSwiping) {
            ViewCompat.setTranslationX(mDownView, deltaX - mSwipingSlop);
            ViewCompat.setAlpha(mDownView,
                    Math.max(0f, Math.min(mAlpha, mAlpha * (1f - Math.abs(deltaX) / mViewWidth))));
            return true;
        }
        break;
    }
    }

    return false;
}

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

@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
    if (!child.isShown()) {
        mIgnoreEvents = true;//  w  w w .ja  v a 2s. com
        return false;
    }
    int action = MotionEventCompat.getActionMasked(event);
    // Record the velocity
    if (action == MotionEvent.ACTION_DOWN) {
        reset();
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    switch (action) {
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mTouchingScrollingChild = false;
        mActivePointerId = MotionEvent.INVALID_POINTER_ID;
        // Reset the ignore flag
        if (mIgnoreEvents) {
            mIgnoreEvents = false;
            return false;
        }
        break;
    case MotionEvent.ACTION_DOWN:
        int initialX = (int) event.getX();
        mInitialY = (int) event.getY();
        View scroll = mNestedScrollingChildRef.get();
        if (scroll != null && parent.isPointInChildBounds(scroll, initialX, mInitialY)) {
            mActivePointerId = event.getPointerId(event.getActionIndex());
            mTouchingScrollingChild = true;
        }
        mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID
                && !parent.isPointInChildBounds(child, initialX, mInitialY);
        break;
    }
    if (!mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent(event)) {
        return true;
    }
    // We have to handle cases that the ViewDragHelper does not capture the bottom sheet because
    // it is not the top most view of its parent. This is not necessary when the touch event is
    // happening over the scrolling content as nested scrolling logic handles that case.
    View scroll = mNestedScrollingChildRef.get();
    return action == MotionEvent.ACTION_MOVE && scroll != null && !mIgnoreEvents && mState != STATE_DRAGGING
            && !parent.isPointInChildBounds(scroll, (int) event.getX(), (int) event.getY())
            && Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop();
}

From source file:cl.monsoon.s1next.widget.PhotoView.java

@Override
public boolean onDoubleTapEvent(MotionEvent e) {
    final int action = e.getAction();
    boolean handled = false;

    switch (action) {
    case MotionEvent.ACTION_DOWN:
        if (mQuickScaleEnabled) {
            mDownFocusX = e.getX();/*  w w w .ja  va  2 s. c o  m*/
            mDownFocusY = e.getY();
        }

        break;
    case MotionEvent.ACTION_UP:
        if (mQuickScaleEnabled) {
            handled = scale(e);
        }

        break;
    case MotionEvent.ACTION_MOVE:
        if (mQuickScaleEnabled && mDoubleTapOccurred) {
            final int deltaX = (int) (e.getX() - mDownFocusX);
            final int deltaY = (int) (e.getY() - mDownFocusY);
            int distance = (deltaX * deltaX) + (deltaY * deltaY);
            if (distance > sTouchSlopSquare) {
                mDoubleTapOccurred = false;
            }
        }

        break;
    }
    return handled;
}