Search in sources :

Example 21 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ParanoidAndroid.

the class EventSenderImpl method executeTouchEvent.

private void executeTouchEvent(int action) {
    int numPoints = getTouchPoints().size();
    int[] pointerIds = new int[numPoints];
    MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[numPoints];
    for (int i = 0; i < numPoints; ++i) {
        boolean isNeeded = false;
        switch(action) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                isNeeded = true;
                break;
            case MotionEvent.ACTION_MOVE:
                isNeeded = getTouchPoints().get(i).hasMoved();
                break;
            case MotionEvent.ACTION_CANCEL:
                isNeeded = getTouchPoints().get(i).isCancelled();
                break;
            default:
                Log.w(LOG_TAG + "::executeTouchEvent(),", "action not supported:" + action);
                break;
        }
        numPoints = 0;
        if (isNeeded) {
            pointerIds[numPoints] = getTouchPoints().get(i).getId();
            pointerCoords[numPoints] = new MotionEvent.PointerCoords();
            pointerCoords[numPoints].x = getTouchPoints().get(i).getX();
            pointerCoords[numPoints].y = getTouchPoints().get(i).getY();
            ++numPoints;
        }
    }
    if (numPoints == 0) {
        return;
    }
    MotionEvent event = MotionEvent.obtain(mTouchPoints.get(0).getDownTime(), SystemClock.uptimeMillis(), action, numPoints, pointerIds, pointerCoords, mTouchMetaState, 1.0f, 1.0f, 0, 0, 0, 0);
    mWebView.onTouchEvent(event);
}
Also used : MotionEvent(android.view.MotionEvent)

Example 22 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ParanoidAndroid.

the class Input method injectMotionEvent.

/**
     * Builds a MotionEvent and injects it into the event stream.
     *
     * @param inputSource the InputDevice.SOURCE_* sending the input event
     * @param action the MotionEvent.ACTION_* for the event
     * @param when the value of SystemClock.uptimeMillis() at which the event happened
     * @param x x coordinate of event
     * @param y y coordinate of event
     * @param pressure pressure of event
     */
private void injectMotionEvent(int inputSource, int action, long when, float x, float y, float pressure) {
    final float DEFAULT_SIZE = 1.0f;
    final int DEFAULT_META_STATE = 0;
    final float DEFAULT_PRECISION_X = 1.0f;
    final float DEFAULT_PRECISION_Y = 1.0f;
    final int DEFAULT_DEVICE_ID = 0;
    final int DEFAULT_EDGE_FLAGS = 0;
    MotionEvent event = MotionEvent.obtain(when, when, action, x, y, pressure, DEFAULT_SIZE, DEFAULT_META_STATE, DEFAULT_PRECISION_X, DEFAULT_PRECISION_Y, DEFAULT_DEVICE_ID, DEFAULT_EDGE_FLAGS);
    event.setSource(inputSource);
    Log.i(TAG, "injectMotionEvent: " + event);
    InputManager.getInstance().injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_WAIT_FOR_FINISH);
}
Also used : MotionEvent(android.view.MotionEvent)

Example 23 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ParanoidAndroid.

the class KeyboardView method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent me) {
    // Convert multi-pointer up/down events to single up/down events to 
    // deal with the typical multi-pointer behavior of two-thumb typing
    final int pointerCount = me.getPointerCount();
    final int action = me.getAction();
    boolean result = false;
    final long now = me.getEventTime();
    if (pointerCount != mOldPointerCount) {
        if (pointerCount == 1) {
            // Send a down event for the latest pointer
            MotionEvent down = MotionEvent.obtain(now, now, MotionEvent.ACTION_DOWN, me.getX(), me.getY(), me.getMetaState());
            result = onModifiedTouchEvent(down, false);
            down.recycle();
            // If it's an up action, then deliver the up as well.
            if (action == MotionEvent.ACTION_UP) {
                result = onModifiedTouchEvent(me, true);
            }
        } else {
            // Send an up event for the last pointer
            MotionEvent up = MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, mOldPointerX, mOldPointerY, me.getMetaState());
            result = onModifiedTouchEvent(up, true);
            up.recycle();
        }
    } else {
        if (pointerCount == 1) {
            result = onModifiedTouchEvent(me, false);
            mOldPointerX = me.getX();
            mOldPointerY = me.getY();
        } else {
            // Don't do anything when 2 pointers are down and moving.
            result = true;
        }
    }
    mOldPointerCount = pointerCount;
    return result;
}
Also used : Paint(android.graphics.Paint) MotionEvent(android.view.MotionEvent)

Example 24 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ParanoidAndroid.

the class SoftInputWindow method dispatchTouchEvent.

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    getWindow().getDecorView().getHitRect(mBounds);
    if (ev.isWithinBoundsNoHistory(mBounds.left, mBounds.top, mBounds.right - 1, mBounds.bottom - 1)) {
        return super.dispatchTouchEvent(ev);
    } else {
        MotionEvent temp = ev.clampNoHistory(mBounds.left, mBounds.top, mBounds.right - 1, mBounds.bottom - 1);
        boolean handled = super.dispatchTouchEvent(temp);
        temp.recycle();
        return handled;
    }
}
Also used : MotionEvent(android.view.MotionEvent)

Example 25 with MotionEvent

use of android.view.MotionEvent in project android_frameworks_base by ParanoidAndroid.

the class RecentsHorizontalScrollView method update.

private void update() {
    for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
        View v = mLinearLayout.getChildAt(i);
        addToRecycledViews(v);
        mAdapter.recycleView(v);
    }
    LayoutTransition transitioner = getLayoutTransition();
    setLayoutTransition(null);
    mLinearLayout.removeAllViews();
    Iterator<View> recycledViews = mRecycledViews.iterator();
    for (int i = 0; i < mAdapter.getCount(); i++) {
        View old = null;
        if (recycledViews.hasNext()) {
            old = recycledViews.next();
            recycledViews.remove();
            old.setVisibility(VISIBLE);
        }
        final View view = mAdapter.getView(i, old, mLinearLayout);
        if (mPerformanceHelper != null) {
            mPerformanceHelper.addViewCallback(view);
        }
        OnTouchListener noOpListener = new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        };
        view.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                mCallback.dismiss();
            }
        });
        // We don't want a click sound when we dimiss recents
        view.setSoundEffectsEnabled(false);
        OnClickListener launchAppListener = new OnClickListener() {

            public void onClick(View v) {
                mCallback.handleOnClick(view);
            }
        };
        RecentsPanelView.ViewHolder holder = (RecentsPanelView.ViewHolder) view.getTag();
        final View thumbnailView = holder.thumbnailView;
        OnLongClickListener longClickListener = new OnLongClickListener() {

            public boolean onLongClick(View v) {
                final View anchorView = view.findViewById(R.id.app_description);
                mCallback.handleLongPress(view, anchorView, thumbnailView);
                return true;
            }
        };
        thumbnailView.setClickable(true);
        thumbnailView.setOnClickListener(launchAppListener);
        thumbnailView.setOnLongClickListener(longClickListener);
        // We don't want to dismiss recents if a user clicks on the app title
        // (we also don't want to launch the app either, though, because the
        // app title is a small target and doesn't have great click feedback)
        final View appTitle = view.findViewById(R.id.app_label);
        appTitle.setContentDescription(" ");
        appTitle.setOnTouchListener(noOpListener);
        mLinearLayout.addView(view);
    }
    setLayoutTransition(transitioner);
    // Scroll to end after initial layout.
    final OnGlobalLayoutListener updateScroll = new OnGlobalLayoutListener() {

        public void onGlobalLayout() {
            mLastScrollPosition = scrollPositionOfMostRecent();
            scrollTo(mLastScrollPosition, 0);
            final ViewTreeObserver observer = getViewTreeObserver();
            if (observer.isAlive()) {
                observer.removeOnGlobalLayoutListener(this);
            }
        }
    };
    getViewTreeObserver().addOnGlobalLayoutListener(updateScroll);
}
Also used : OnGlobalLayoutListener(android.view.ViewTreeObserver.OnGlobalLayoutListener) LayoutTransition(android.animation.LayoutTransition) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) MotionEvent(android.view.MotionEvent) ViewTreeObserver(android.view.ViewTreeObserver)

Aggregations

MotionEvent (android.view.MotionEvent)1088 View (android.view.View)497 TextView (android.widget.TextView)264 ImageView (android.widget.ImageView)190 GestureDetector (android.view.GestureDetector)95 Point (android.graphics.Point)81 AdapterView (android.widget.AdapterView)80 ViewGroup (android.view.ViewGroup)75 Paint (android.graphics.Paint)72 ListView (android.widget.ListView)70 SuppressLint (android.annotation.SuppressLint)69 OnTouchListener (android.view.View.OnTouchListener)69 Intent (android.content.Intent)68 RecyclerView (android.support.v7.widget.RecyclerView)53 Test (org.junit.Test)47 ScrollView (android.widget.ScrollView)46 Handler (android.os.Handler)43 AbsListView (android.widget.AbsListView)42 WindowManager (android.view.WindowManager)41 LinearLayout (android.widget.LinearLayout)40