Example usage for android.view MotionEvent ACTION_MASK

List of usage examples for android.view MotionEvent ACTION_MASK

Introduction

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

Prototype

int ACTION_MASK

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

Click Source Link

Document

Bit mask of the parts of the action code that are the action itself.

Usage

From source file:com.uroad.widget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onInterceptTouchEvent(event);
    }//from  ww  w  . j  ava 2 s  . co  m

    float[] difference = handleMotionEvent(event);

    if (mCurrentView != null && mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView != null && mCurrentView.onRightSide && difference[0] < 0) // move
        // right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView != null && mCurrentView.onLeftSide && difference[0] > 0) // move
        // left
        {
            return super.onInterceptTouchEvent(event);
        }
        //         if (difference == null && ((mCurrentView != null && mCurrentView.onLeftSide) || (mCurrentView != null && mCurrentView.onRightSide))) {
        //            return super.onInterceptTouchEvent(event);
        //         }
        if (difference == null && mCurrentView != null) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:org.glucosio.android.fragment.OverviewFragment.java

public static void disableTouchTheft(View view) {
    view.setOnTouchListener(new View.OnTouchListener() {
        @Override/*ww w.ja v  a2s .  c  o  m*/
        public boolean onTouch(View view, MotionEvent motionEvent) {
            view.getParent().requestDisallowInterceptTouchEvent(true);
            switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
            case MotionEvent.ACTION_UP:
                view.getParent().requestDisallowInterceptTouchEvent(false);
                break;
            }
            return false;
        }
    });
}

From source file:com.wangzhenzhe.library.GalleryWidget.GalleryViewPager.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onInterceptTouchEvent(event);
    }/*from ww  w  .j ava 2  s.c  om*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onInterceptTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onInterceptTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onInterceptTouchEvent(event);
        }
    }
    return false;
}

From source file:org.deviceconnect.android.deviceplugin.host.activity.TouchProfileActivity.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    List<Event> events;
    String state = null;// w  ww  .j a va  2 s  . c  om
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: // 1st touch only.
    case MotionEvent.ACTION_POINTER_DOWN: // Others touch.
        state = HostDeviceApplication.STATE_START;
        // "ontouch" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH);
        if (events != null) {
            sendEventData(state, event, events);
        }

        // "ontouchstart" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_START);
        break;
    case MotionEvent.ACTION_UP: // Last touch remove only.
    case MotionEvent.ACTION_POINTER_UP: // Others touch move.
        state = HostDeviceApplication.STATE_END;
        // "ontouchend" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_END);
        break;
    case MotionEvent.ACTION_MOVE:
        state = HostDeviceApplication.STATE_MOVE;
        // "ontouchmove" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_MOVE);
        break;
    case MotionEvent.ACTION_CANCEL:
        state = HostDeviceApplication.STATE_CANCEL;
        // "ontouchcancel" event processing.
        events = EventManager.INSTANCE.getEventList(mServiceId, TouchProfile.PROFILE_NAME, null,
                TouchProfile.ATTRIBUTE_ON_TOUCH_CANCEL);
        break;
    default:
        return mGestureDetector.onTouchEvent(event);
    }

    if (events != null) {
        sendEventData(state, event, events);
    }
    return mGestureDetector.onTouchEvent(event);
}

From source file:org.deviceconnect.android.deviceplugin.wear.activity.WearTouchProfileActivity.java

@Override
public boolean dispatchTouchEvent(@NonNull final MotionEvent event) {
    boolean execFlag = false;
    int action = (event.getAction() & MotionEvent.ACTION_MASK);
    String strAction = null;//from  ww w  .  j  av  a2s  . c om
    switch (action) {
    case MotionEvent.ACTION_DOWN: // 1st touch only.
    case MotionEvent.ACTION_POINTER_DOWN: // Others touch.
        // "ontouch" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCH) != 0) {
            sendEventData(WearConst.PARAM_TOUCH_TOUCH, event);
        }

        // "ontouchstart" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHSTART) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHSTART;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_UP: // Last touch remove only.
    case MotionEvent.ACTION_POINTER_UP: // Others touch move.
        // "ontouchend" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHEND) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHEND;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_MOVE:
        // "ontouchmove" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHMOVE) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHMOVE;
            execFlag = true;
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        // "ontouchcancel" event processing.
        if ((mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCHANGE) != 0
                || (mRegisterEvent & REGIST_FLAG_TOUCH_TOUCHCANCEL) != 0) {
            strAction = WearConst.PARAM_TOUCH_TOUCHCANCEL;
            execFlag = true;
        }
        break;
    default:
        return mGestureDetector.onTouchEvent(event);
    }

    if (execFlag) {
        sendEventData(strAction, event);
    }
    return mGestureDetector.onTouchEvent(event) || super.dispatchTouchEvent(event);
}

From source file:cn.iotguard.GalleryWidget.GalleryViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        super.onTouchEvent(event);
    }/*from  w w  w.  j  a v a2  s.c  om*/

    float[] difference = handleMotionEvent(event);

    if (mCurrentView.pagerCanScroll()) {
        return super.onTouchEvent(event);
    } else {
        if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right
        {
            return super.onTouchEvent(event);
        }
        if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left
        {
            return super.onTouchEvent(event);
        }
        if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) {
            return super.onTouchEvent(event);
        }
    }

    return false;
}

From source file:org.mozilla.gecko.ui.SimpleScaleGestureDetector.java

/** Forward touch events to this function. */
public void onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        onTouchStart(event);//w  w  w.  j av  a 2s .c o  m
        break;
    case MotionEvent.ACTION_MOVE:
        onTouchMove(event);
        break;
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        onTouchEnd(event);
        break;
    }
}

From source file:net.henryco.opalette.application.programs.sub.programs.bFilter.BlurControl.java

@Override
protected void onFragmentCreate(View view, AppMainProto context, @Nullable Bundle savedInstanceState) {

    Runnable updateFunc = () -> {
        proxyRenderData.setStateUpdated();
        context.getRenderSurface().update();
    };/*  w  w  w  . j  a  v  a  2s.  c o m*/

    listener = event -> {
        final int action = event.getAction();
        final int count = event.getPointerCount();
        switch (action & MotionEvent.ACTION_MASK) {

        case MotionEvent.ACTION_DOWN:
            blurTexture.getFilterTexture().setPointsVisible(true);
            updateFunc.run();

        case MotionEvent.ACTION_MOVE:
            if (count >= 2) {
                blurTexture.getFilterTexture().setPoints(event.getX(0), event.getY(0), event.getX(1),
                        event.getY(1));
                blurTexture.getFilterTexture().setPointsVisible(true);
                updateFunc.run();
            }
            break;

        case MotionEvent.ACTION_UP:
            blurTexture.getFilterTexture().setPointsVisible(false);
            updateFunc.run();
            break;
        }
    };

    OPallViewInjector<AppMainProto> controls = new OPallViewInjector<AppMainProto>(view,
            R.layout.palette_region_layout) {
        @Override
        protected void onInject(AppMainProto context, View view) {

            final TextView inf = (TextView) view.findViewById(R.id.palette_text_info);
            inf.setText(R.string.blur_region_multi_touch_info);

            final TextView reg = (TextView) view.findViewById(R.id.paletteTextRegion);
            final TextView non = (TextView) view.findViewById(R.id.paletteTextNone);
            final Button regButton = (Button) view.findViewById(R.id.bwButtonOn);
            final Button nonButton = (Button) view.findViewById(R.id.bwButtonOff);

            final int fca = ContextCompat.getColor(context.getActivityContext(), TEXT_COLOR_BLACK_OVERLAY);
            final int fcb = 0xFF000000;

            reg.setTextColor(blurTexture.isActive() ? fcb : fca);
            non.setTextColor(blurTexture.isActive() ? fca : fcb);

            backListener = context.getRenderSurface().getLastTouchEventListener();
            context.getRenderSurface().removeTouchEventListener(backListener);

            if (blurTexture.isActive())
                context.getRenderSurface().addOnTouchEventListener(listener);

            regButton.setOnClickListener(
                    v -> OPallAnimated.pressButton75_225(context.getActivityContext(), v, () -> {
                        blurTexture.getFilterTexture().setPointsVisible(true);
                        reg.setTextColor(fcb);
                        non.setTextColor(fca);
                        if (!blurTexture.isActive())
                            context.getRenderSurface().addOnTouchEventListener(listener);
                        blurTexture.setActive(true);
                        updateFunc.run();
                        new Handler().postDelayed(() -> {
                            blurTexture.getFilterTexture().setPointsVisible(false);
                            updateFunc.run();
                        }, 300);
                    }));

            nonButton.setOnClickListener(
                    v -> OPallAnimated.pressButton75_225(context.getActivityContext(), v, () -> {
                        context.getRenderSurface().removeTouchEventListener(listener);
                        non.setTextColor(fcb);
                        reg.setTextColor(fca);
                        blurTexture.setActive(false);
                        resetPoints();
                        updateFunc.run();
                    }));
        }
    };

    context.setTopControlButton(button -> button.setVisible(true).setEnabled(true).setTitle(R.string.options),
            () -> {

                OPallFunction<String, Integer> stringFunc = integer -> context.getActivityContext()
                        .getResources().getString(integer);

                String options = stringFunc.apply(R.string.options);
                String types = stringFunc.apply(R.string.blur_type);
                String pwr = stringFunc.apply(R.string.transition_power);
                String apl = stringFunc.apply(R.string.apply);

                String sb1 = "m_diagShatter";
                String sb2 = "m_blur";
                String sb3 = "m_boxBlur";
                String sb4 = "m_gaussianBlur (recommended)";
                String sb5 = "m_horizontalMotionBlur";

                Runnable blur1 = () -> {
                    blurTexture.getFilterTexture().setBlurMatrix(FilterMatrices.m_diagShatter());
                    updateFunc.run();
                };
                Runnable blur2 = () -> {
                    blurTexture.getFilterTexture().setBlurMatrix(FilterMatrices.m_blur());
                    updateFunc.run();
                };
                Runnable blur3 = () -> {
                    blurTexture.getFilterTexture().setBlurMatrix(FilterMatrices.m_boxBlur());
                    updateFunc.run();
                };
                Runnable blur4 = () -> {
                    blurTexture.getFilterTexture().setBlurMatrix(FilterMatrices.m_gaussianBlur());
                    updateFunc.run();
                };
                Runnable blur5 = () -> {
                    blurTexture.getFilterTexture().setBlurMatrix(FilterMatrices.m_horizontalMotionBlur());
                    updateFunc.run();
                };

                Runnable power = () -> {
                    LinearLayout layout = new LinearLayout(context.getActivityContext());
                    InjectableSeekBar powerBar = new InjectableSeekBar(layout);
                    powerBar.onBarCreate(bar -> bar
                            .setProgress(powerBar.de_norm(blurTexture.getFilterTexture().getPower())));
                    powerBar.setBarListener(new OPallSeekBarListener().onProgress((bar, progress, fromUser) -> {
                        if (fromUser)
                            blurTexture.getFilterTexture().setPower(powerBar.norm(progress));
                    }));
                    OPallViewInjector.inject(context.getActivityContext(), powerBar);
                    new OPallAlertDialog().content(layout).title(pwr).positive(apl, updateFunc)
                            .negative(stringFunc.apply(R.string.cancel))
                            .neutral(stringFunc.apply(R.string.control_top_bar_button_reset), () -> {
                                blurTexture.getFilterTexture().resetPower();
                                updateFunc.run();
                            }).show(context.getActivityContext().getSupportFragmentManager(),
                                    "Blur transition power dialog");
                };

                Runnable type = () -> new OPallOptionListDialog().setTittle(types)
                        .setOptionsNames(sb1, sb2, sb3, sb4, sb5)
                        .setOptionsActions(blur1, blur2, blur3, blur4, blur5)
                        .show(context.getActivityContext().getSupportFragmentManager(), "Blur types dialog");

                new OPallOptionListDialog().setTittle(options).setOptionsNames(types, pwr)
                        .setOptionsActions(type, power)
                        .show(context.getActivityContext().getSupportFragmentManager(), "Blur options dialog");
            });

    OPallViewInjector.inject(context.getActivityContext(), controls);
}

From source file:com.tsoliveira.android.listeners.DragDropTouchListener.java

@Override
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) {
    if (!enabled)
        return false;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        return down(event);

    case MotionEvent.ACTION_MOVE:
        return dragging && move(event);

    case MotionEvent.ACTION_UP:
        return up(event);

    case MotionEvent.ACTION_CANCEL:
        return cancel(event);

    }//from w  w w .ja v  a  2s .c o m
    return false;
}

From source file:org.wikipedia.page.bottomcontent.BottomContentHandler.java

public BottomContentHandler(PageViewFragmentInternal parentFragment, CommunicationBridge bridge,
        ObservableWebView webview, LinkHandler linkHandler, ViewGroup hidingView, PageTitle pageTitle) {
    this.parentFragment = parentFragment;
    this.bridge = bridge;
    this.webView = webview;
    this.linkHandler = linkHandler;
    this.pageTitle = pageTitle;
    activity = parentFragment.getActivity();
    app = (WikipediaApp) activity.getApplicationContext();
    displayDensity = activity.getResources().getDisplayMetrics().density;

    bottomContentContainer = hidingView;
    webview.addOnScrollChangeListener(this);
    webview.addOnContentHeightChangedListener(this);

    pageLastUpdatedText = (TextView) bottomContentContainer.findViewById(R.id.page_last_updated_text);
    pageLicenseText = (TextView) bottomContentContainer.findViewById(R.id.page_license_text);
    readMoreContainer = bottomContentContainer.findViewById(R.id.read_more_container);
    readMoreList = (ListView) bottomContentContainer.findViewById(R.id.read_more_list);

    // set up pass-through scroll functionality for the ListView
    readMoreList.setOnTouchListener(new View.OnTouchListener() {
        private int touchSlop = ViewConfiguration.get(readMoreList.getContext()).getScaledTouchSlop();
        private boolean slopReached;
        private boolean doingSlopEvent;
        private boolean isPressed = false;
        private float startY;
        private float amountScrolled;

        @Override//from ww w.j av  a 2 s .c  o  m
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getActionMasked() & MotionEvent.ACTION_MASK;
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                isPressed = true;
                startY = event.getY();
                amountScrolled = 0;
                slopReached = false;
                break;
            case MotionEvent.ACTION_MOVE:
                if (isPressed && !doingSlopEvent) {
                    int contentHeight = (int) (webView.getContentHeight() * displayDensity);
                    int maxScroll = contentHeight - webView.getScrollY() - webView.getHeight();
                    int scrollAmount = Math.min((int) (startY - event.getY()), maxScroll);
                    // manually scroll the WebView that's underneath us...
                    webView.scrollBy(0, scrollAmount);
                    amountScrolled += scrollAmount;
                    if (Math.abs(amountScrolled) > touchSlop && !slopReached) {
                        slopReached = true;
                        // send an artificial Move event that scrolls it by an amount
                        // that's greater than the touch slop, so that the currently
                        // highlighted item is unselected.
                        MotionEvent moveEvent = MotionEvent.obtain(event);
                        moveEvent.setLocation(event.getX(), event.getY() + touchSlop * 2);
                        doingSlopEvent = true;
                        readMoreList.dispatchTouchEvent(moveEvent);
                        doingSlopEvent = false;
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                isPressed = false;
                break;
            default:
                break;
            }
            return false;
        }
    });

    funnel = new SuggestedPagesFunnel(app, pageTitle.getSite());

    // preload the display density, since it will be used in a lot of places
    displayDensity = activity.getResources().getDisplayMetrics().density;
    // hide ourselves by default
    hide();
}