Java Code Examples for android.view.MotionEvent#BUTTON_TERTIARY

The following examples show how to use android.view.MotionEvent#BUTTON_TERTIARY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Called on click. This is called before the onUpOrCancel event.
 * @param time      The current time of the app in ms.
 * @param x         The x coordinate of the position of the click.
 * @param y         The y coordinate of the position of the click.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that were pressed when onDown was invoked.
 */
public void click(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.click(x, y)) {
        mNewTabButton.handleClick(time);
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    if (clickedTab == null || clickedTab.isDying()) return;
    if (clickedTab.checkCloseHitTest(x, y)
            || (fromMouse && (buttons & MotionEvent.BUTTON_TERTIARY) != 0)) {
        clickedTab.getCloseButton().handleClick(time);
    } else {
        clickedTab.handleClick(time);
    }
}
 
Example 2
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called on onDown event.
 * @param time      The time stamp in millisecond of the event.
 * @param x         The x position of the event.
 * @param y         The y position of the event.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that are pressed.
 */
public void onDown(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.onDown(x, y)) {
        mRenderHost.requestRender();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    final int index = clickedTab != null
            ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId())
            : TabModel.INVALID_TAB_INDEX;
    // http://crbug.com/472186 : Needs to handle a case that index is invalid.
    // The case could happen when the current tab is touched while we're inflating the rest of
    // the tabs from disk.
    mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length
            ? mStripTabs[index]
            : null;
    boolean clickedClose = clickedTab != null
                           && clickedTab.checkCloseHitTest(x, y);
    if (clickedClose) {
        clickedTab.setClosePressed(true);
        mLastPressedCloseButton = clickedTab.getCloseButton();
        mRenderHost.requestRender();
    }

    if (!mScroller.isFinished()) {
        mScroller.forceFinished(true);
        mInteractingTab = null;
    }

    if (fromMouse && !clickedClose && clickedTab != null
            && clickedTab.getVisiblePercentage() >= 1.f
            && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) {
        startReorderMode(time, x, x);
    }
}
 
Example 3
Source File: StripLayoutHelper.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Called on click. This is called before the onUpOrCancel event.
 * @param time      The current time of the app in ms.
 * @param x         The x coordinate of the position of the click.
 * @param y         The y coordinate of the position of the click.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that were pressed when onDown was invoked.
 */
public void click(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.click(x, y) && mModel != null) {
        mTabCreator.launchNTP();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    if (clickedTab == null || clickedTab.isDying()) return;
    if (clickedTab.checkCloseHitTest(x, y)
            || (fromMouse && (buttons & MotionEvent.BUTTON_TERTIARY) != 0)) {
        // 1. Start the close animation.
        startAnimation(buildTabClosedAnimation(clickedTab), true);

        // 2. Set the dying state of the tab.
        clickedTab.setIsDying(true);

        // 3. Fake a selection on the next tab now.
        Tab nextTab = mModel.getNextTabIfClosed(clickedTab.getId());
        if (nextTab != null) tabSelected(time, nextTab.getId(), clickedTab.getId());

        // 4. Find out if we're closing the last tab.  This determines if we resize immediately.
        boolean lastTab = mStripTabs.length == 0
                || mStripTabs[mStripTabs.length - 1].getId() == clickedTab.getId();

        // 5. Resize the tabs appropriately.
        resizeTabStrip(!lastTab);
    } else {
        int newIndex = TabModelUtils.getTabIndexById(mModel, clickedTab.getId());
        TabModelUtils.setIndex(mModel, newIndex);
    }
}
 
Example 4
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called on onDown event.
 * @param time      The time stamp in millisecond of the event.
 * @param x         The x position of the event.
 * @param y         The y position of the event.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that are pressed.
 */
public void onDown(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.onDown(x, y)) {
        mRenderHost.requestRender();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    final int index = clickedTab != null
            ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId())
            : TabModel.INVALID_TAB_INDEX;
    // http://crbug.com/472186 : Needs to handle a case that index is invalid.
    // The case could happen when the current tab is touched while we're inflating the rest of
    // the tabs from disk.
    mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length
            ? mStripTabs[index]
            : null;
    boolean clickedClose = clickedTab != null
                           && clickedTab.checkCloseHitTest(x, y);
    if (clickedClose) {
        clickedTab.setClosePressed(true);
        mLastPressedCloseButton = clickedTab.getCloseButton();
        mRenderHost.requestRender();
    }

    if (!mScroller.isFinished()) {
        mScroller.forceFinished(true);
        mInteractingTab = null;
    }

    if (fromMouse && !clickedClose && clickedTab != null
            && clickedTab.getVisiblePercentage() >= 1.f
            && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) {
        startReorderMode(time, x, x);
    }
}
 
Example 5
Source File: StripLayoutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Called on click. This is called before the onUpOrCancel event.
 * @param time      The current time of the app in ms.
 * @param x         The x coordinate of the position of the click.
 * @param y         The y coordinate of the position of the click.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that were pressed when onDown was invoked.
 */
public void click(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.click(x, y) && mModel != null) {
        if (!mModel.isIncognito()) mModel.commitAllTabClosures();
        mTabCreator.launchNTP();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    if (clickedTab == null || clickedTab.isDying()) return;
    if (clickedTab.checkCloseHitTest(x, y)
            || (fromMouse && (buttons & MotionEvent.BUTTON_TERTIARY) != 0)) {
        // 1. Start the close animation.
        startAnimation(buildTabClosedAnimation(clickedTab), true);

        // 2. Set the dying state of the tab.
        clickedTab.setIsDying(true);

        // 3. Fake a selection on the next tab now.
        Tab nextTab = mModel.getNextTabIfClosed(clickedTab.getId());
        if (nextTab != null) tabSelected(time, nextTab.getId(), clickedTab.getId());

        // 4. Find out if we're closing the last tab.  This determines if we resize immediately.
        boolean lastTab = mStripTabs.length == 0
                || mStripTabs[mStripTabs.length - 1].getId() == clickedTab.getId();

        // 5. Resize the tabs appropriately.
        resizeTabStrip(!lastTab);
    } else {
        int newIndex = TabModelUtils.getTabIndexById(mModel, clickedTab.getId());
        TabModelUtils.setIndex(mModel, newIndex);
    }
}
 
Example 6
Source File: StripLayoutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Called on onDown event.
 * @param time      The time stamp in millisecond of the event.
 * @param x         The x position of the event.
 * @param y         The y position of the event.
 * @param fromMouse Whether the event originates from a mouse.
 * @param buttons   State of all buttons that are pressed.
 */
public void onDown(long time, float x, float y, boolean fromMouse, int buttons) {
    resetResizeTimeout(false);

    if (mNewTabButton.onDown(x, y)) {
        mRenderHost.requestRender();
        return;
    }

    final StripLayoutTab clickedTab = getTabAtPosition(x);
    final int index = clickedTab != null
            ? TabModelUtils.getTabIndexById(mModel, clickedTab.getId())
            : TabModel.INVALID_TAB_INDEX;
    // http://crbug.com/472186 : Needs to handle a case that index is invalid.
    // The case could happen when the current tab is touched while we're inflating the rest of
    // the tabs from disk.
    mInteractingTab = index != TabModel.INVALID_TAB_INDEX && index < mStripTabs.length
            ? mStripTabs[index]
            : null;
    boolean clickedClose = clickedTab != null
                           && clickedTab.checkCloseHitTest(x, y);
    if (clickedClose) {
        clickedTab.setClosePressed(true);
        mLastPressedCloseButton = clickedTab.getCloseButton();
        mRenderHost.requestRender();
    }

    if (!mScroller.isFinished()) {
        mScroller.forceFinished(true);
        mInteractingTab = null;
    }

    if (fromMouse && !clickedClose && clickedTab != null
            && clickedTab.getVisiblePercentage() >= 1.f
            && (buttons & MotionEvent.BUTTON_TERTIARY) == 0) {
        startReorderMode(time, x, x);
    }
}
 
Example 7
Source File: TouchPaint.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
private boolean onTouchOrHoverEvent(MotionEvent event, boolean isTouch) {
    final int buttonState = event.getButtonState();
    int pressedButtons = buttonState & ~mOldButtonState;
    mOldButtonState = buttonState;

    if ((pressedButtons & MotionEvent.BUTTON_SECONDARY) != 0) {
        // Advance color when the right mouse button or first stylus button
        // is pressed.
        advanceColor();
    }

    PaintMode mode;
    if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) {
        // Splat paint when the middle mouse button or second stylus button is pressed.
        mode = PaintMode.Splat;
    } else if (isTouch || (buttonState & MotionEvent.BUTTON_PRIMARY) != 0) {
        // Draw paint when touching or if the primary button is pressed.
        mode = PaintMode.Draw;
    } else {
        // Otherwise, do not paint anything.
        return false;
    }

    final int action = event.getActionMasked();
    if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE
            || action == MotionEvent.ACTION_HOVER_MOVE) {
        final int N = event.getHistorySize();
        final int P = event.getPointerCount();
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < P; j++) {
                paint(getPaintModeForTool(event.getToolType(j), mode),
                        event.getHistoricalX(j, i),
                        event.getHistoricalY(j, i),
                        event.getHistoricalPressure(j, i),
                        event.getHistoricalTouchMajor(j, i),
                        event.getHistoricalTouchMinor(j, i),
                        event.getHistoricalOrientation(j, i),
                        event.getHistoricalAxisValue(MotionEvent.AXIS_DISTANCE, j, i),
                        event.getHistoricalAxisValue(MotionEvent.AXIS_TILT, j, i));
            }
        }
        for (int j = 0; j < P; j++) {
            paint(getPaintModeForTool(event.getToolType(j), mode),
                    event.getX(j),
                    event.getY(j),
                    event.getPressure(j),
                    event.getTouchMajor(j),
                    event.getTouchMinor(j),
                    event.getOrientation(j),
                    event.getAxisValue(MotionEvent.AXIS_DISTANCE, j),
                    event.getAxisValue(MotionEvent.AXIS_TILT, j));
        }
        mCurX = event.getX();
        mCurY = event.getY();
    }
    return true;
}