Example usage for android.view MotionEvent getAction

List of usage examples for android.view MotionEvent getAction

Introduction

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

Prototype

public final int getAction() 

Source Link

Document

Return the kind of action being performed.

Usage

From source file:cc.flydev.launcher.Workspace.java

protected void onWallpaperTap(MotionEvent ev) {
    final int[] position = mTempCell;
    getLocationOnScreen(position);/*w  w w  .jav a  2s  .c om*/

    int pointerIndex = ev.getActionIndex();
    position[0] += (int) ev.getX(pointerIndex);
    position[1] += (int) ev.getY(pointerIndex);

    mWallpaperManager.sendWallpaperCommand(getWindowToken(),
            ev.getAction() == MotionEvent.ACTION_UP ? WallpaperManager.COMMAND_TAP
                    : WallpaperManager.COMMAND_SECONDARY_TAP,
            position[0], position[1], 0, null);
}

From source file:com.android.launcher3.Launcher.java

public View.OnTouchListener getHapticFeedbackTouchListener() {
    if (mHapticFeedbackTouchListener == null) {
        mHapticFeedbackTouchListener = new View.OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            @Override/*from   w  ww  .j a  va  2  s.co m*/
            public boolean onTouch(View v, MotionEvent event) {
                if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
                    v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                }
                return false;
            }
        };
    }
    return mHapticFeedbackTouchListener;
}

From source file:com.irccloud.android.activity.MainActivity.java

private void show_topic_popup() {
    if (buffer == null)
        return;/*www  .j  ava  2  s. c o  m*/
    ChannelsDataSource.Channel c = ChannelsDataSource.getInstance().getChannelForBuffer(buffer.bid);
    if (c != null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
        View v = getLayoutInflater().inflate(R.layout.dialog_topic, null);
        if (c.topic_text.length() > 0) {
            String author = "";
            if (c.topic_author != null && c.topic_author.length() > 0) {
                author = " Set by " + c.topic_author;
                if (c.topic_time > 0) {
                    author += " on " + DateFormat.getDateTimeInstance().format(new Date(c.topic_time * 1000));
                }
                v.findViewById(R.id.setBy).setVisibility(View.VISIBLE);
                ((TextView) v.findViewById(R.id.setBy)).setText(author);
            }
            ((TextView) v.findViewById(R.id.topic)).setText(ColorFormatter.html_to_spanned(
                    ColorFormatter.emojify(ColorFormatter.irc_to_html(TextUtils.htmlEncode(c.topic_text))),
                    true, server));
        } else {
            ((TextView) v.findViewById(R.id.topic)).setText("No topic set.");
        }
        if (c.mode.length() > 0) {
            v.findViewById(R.id.mode).setVisibility(View.VISIBLE);
            ((TextView) v.findViewById(R.id.mode)).setText("Mode: +" + c.mode);

            for (ChannelsDataSource.Mode m : c.modes) {
                switch (m.mode) {
                case "i":
                    v.findViewById(R.id.mode_i).setVisibility(View.VISIBLE);
                    break;
                case "k":
                    v.findViewById(R.id.mode_k).setVisibility(View.VISIBLE);
                    ((TextView) v.findViewById(R.id.key)).setText(m.param);
                    break;
                case "m":
                    v.findViewById(R.id.mode_m).setVisibility(View.VISIBLE);
                    break;
                case "n":
                    v.findViewById(R.id.mode_n).setVisibility(View.VISIBLE);
                    break;
                case "p":
                    v.findViewById(R.id.mode_p).setVisibility(View.VISIBLE);
                    break;
                case "s":
                    v.findViewById(R.id.mode_s).setVisibility(View.VISIBLE);
                    break;
                case "t":
                    v.findViewById(R.id.mode_t).setVisibility(View.VISIBLE);
                    break;
                }
            }
        }
        builder.setView(v);
        builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        boolean canEditTopic;
        if (c.hasMode("t")) {
            UsersDataSource.User self_user = UsersDataSource.getInstance().getUser(buffer.bid, server.nick);
            canEditTopic = (self_user != null
                    && (self_user.mode.contains(server != null ? server.MODE_OPER : "Y")
                            || self_user.mode.contains(server != null ? server.MODE_OWNER : "q")
                            || self_user.mode.contains(server != null ? server.MODE_ADMIN : "a")
                            || self_user.mode.contains(server != null ? server.MODE_OP : "o")
                            || self_user.mode.contains(server != null ? server.MODE_HALFOP : "h")));
        } else {
            canEditTopic = true;
        }

        if (canEditTopic) {
            builder.setPositiveButton("Edit Topic", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    editTopic();
                }
            });
        }
        final AlertDialog dialog = builder.create();
        dialog.setOwnerActivity(MainActivity.this);
        dialog.show();

        ((TextView) v.findViewById(R.id.topic)).setMovementMethod(new LinkMovementMethod() {
            @Override
            public boolean onTouchEvent(TextView widget, Spannable buffer, MotionEvent event) {
                if (super.onTouchEvent(widget, buffer, event) && event.getAction() == MotionEvent.ACTION_UP) {
                    dialog.dismiss();
                    return true;
                }
                return false;
            }
        });
    }
}

From source file:com.android.launcher3.Workspace.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mXDown = ev.getX();/* w ww.j a va  2 s . co m*/
        mYDown = ev.getY();
        mTouchDownTime = System.currentTimeMillis();
        break;
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
        if (mTouchState == TOUCH_STATE_REST) {
            final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage);
            if (currentPage != null && !currentPage.lastDownOnOccupiedCell()) {
                onWallpaperTap(ev);
            }
        }
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:android.app.Activity.java

/**
 * Called to process touch screen events.  You can override this to
 * intercept all touch screen events before they are dispatched to the
 * window.  Be sure to call this implementation for touch screen events
 * that should be handled normally./*  w w w  .  ja  v  a  2  s  . com*/
 * 
 * @param ev The touch screen event.
 * 
 * @return boolean Return true if this event was consumed.
 */
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        onUserInteraction();
    }
    if (getWindow().superDispatchTouchEvent(ev)) {
        return true;
    }
    return onTouchEvent(ev);
}

From source file:android.support.v7.widget.RecyclerView.java

private boolean dispatchOnItemTouchIntercept(MotionEvent e) {
    final int action = e.getAction();
    if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_DOWN) {
        mActiveOnItemTouchListener = null;
    }//  www  .j  a v a2s.co m

    final int listenerCount = mOnItemTouchListeners.size();
    for (int i = 0; i < listenerCount; i++) {
        final OnItemTouchListener listener = mOnItemTouchListeners.get(i);
        if (listener.onInterceptTouchEvent(this, e) && action != MotionEvent.ACTION_CANCEL) {
            mActiveOnItemTouchListener = listener;
            return true;
        }
    }
    return false;
}

From source file:android.support.v7.widget.RecyclerView.java

private boolean dispatchOnItemTouch(MotionEvent e) {
    final int action = e.getAction();
    if (mActiveOnItemTouchListener != null) {
        if (action == MotionEvent.ACTION_DOWN) {
            // Stale state from a previous gesture, we're starting a new one. Clear it.
            mActiveOnItemTouchListener = null;
        } else {/*  ww  w .j a  v  a2 s. c  o  m*/
            mActiveOnItemTouchListener.onTouchEvent(this, e);
            if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
                // Clean up for the next gesture.
                mActiveOnItemTouchListener = null;
            }
            return true;
        }
    }

    // Listeners will have already received the ACTION_DOWN via dispatchOnItemTouchIntercept
    // as called from onInterceptTouchEvent; skip it.
    if (action != MotionEvent.ACTION_DOWN) {
        final int listenerCount = mOnItemTouchListeners.size();
        for (int i = 0; i < listenerCount; i++) {
            final OnItemTouchListener listener = mOnItemTouchListeners.get(i);
            if (listener.onInterceptTouchEvent(this, e)) {
                mActiveOnItemTouchListener = listener;
                return true;
            }
        }
    }
    return false;
}

From source file:com.appunite.list.AbsHorizontalListView.java

private void onSecondaryPointerUp(MotionEvent ev) {
    final int pointerIndex = (ev.getAction()
            & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
    final int pointerId = ev.getPointerId(pointerIndex);
    if (pointerId == mActivePointerId) {
        // This was our active pointer going up. Choose a new
        // active pointer and adjust accordingly.
        // TODO: Make this decision more intelligent.
        final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
        mMotionX = (int) ev.getX(newPointerIndex);
        mMotionY = (int) ev.getY(newPointerIndex);
        mMotionCorrection = 0;// w  ww  . j a  va 2 s.c om
        mActivePointerId = ev.getPointerId(newPointerIndex);
    }
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    View v;//from ww  w  .  j a  v  a  2s. c  om

    if (mPositionScroller != null) {
        mPositionScroller.stop();
    }

    if (!mIsAttached) {
        // Something isn't right.
        // Since we rely on being attached to get data set change notifications,
        // don't risk doing anything where we might try to resync and find things
        // in a bogus state.
        return false;
    }

    switch (action & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        int touchMode = mTouchMode;
        if (touchMode == TOUCH_MODE_OVERFLING || touchMode == TOUCH_MODE_OVERSCROLL) {
            mMotionCorrection = 0;
            return true;
        }

        final int x = (int) ev.getX();
        final int y = (int) ev.getY();
        mActivePointerId = ev.getPointerId(0);

        int motionPosition = findMotionCol(x);
        if (touchMode != TOUCH_MODE_FLING && motionPosition >= 0) {
            // User clicked on an actual view (and was not stopping a fling).
            // Remember where the motion event started
            v = getChildAt(motionPosition - mFirstPosition);
            mMotionViewOriginalLeft = v.getLeft();
            mMotionX = x;
            mMotionY = y;
            mMotionPosition = motionPosition;
            mTouchMode = TOUCH_MODE_DOWN;
            clearScrollingCache();
        }
        mLastX = Integer.MIN_VALUE;
        initOrResetVelocityTracker();
        mVelocityTracker.addMovement(ev);
        if (touchMode == TOUCH_MODE_FLING) {
            return true;
        }
        break;
    }

    case MotionEvent.ACTION_MOVE: {
        switch (mTouchMode) {
        case TOUCH_MODE_DOWN:
            int pointerIndex = ev.findPointerIndex(mActivePointerId);
            if (pointerIndex == -1) {
                pointerIndex = 0;
                mActivePointerId = ev.getPointerId(pointerIndex);
            }
            final int x = (int) ev.getX(pointerIndex);
            initVelocityTrackerIfNotExists();
            mVelocityTracker.addMovement(ev);
            if (startScrollIfNeeded(x)) {
                return true;
            }
            break;
        }
        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP: {
        mTouchMode = TOUCH_MODE_REST;
        mActivePointerId = INVALID_POINTER;
        recycleVelocityTracker();
        reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        break;
    }

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
        break;
    }
    }

    return false;
}

From source file:com.appunite.list.AbsHorizontalListView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override/*from  w  ww  .j a  va2  s  .  c  om*/
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_SCROLL: {
            if (mTouchMode == TOUCH_MODE_REST) {
                final float hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                if (hscroll != 0) {
                    final int delta = (int) (hscroll * getHorizontalScrollFactorUnhide());
                    if (!trackMotionScroll(delta, delta)) {
                        return true;
                    }
                }
            }
        }
        }
    }
    return super.onGenericMotionEvent(event);
}