Example usage for android.view SoundEffectConstants CLICK

List of usage examples for android.view SoundEffectConstants CLICK

Introduction

In this page you can find the example usage for android.view SoundEffectConstants CLICK.

Prototype

int CLICK

To view the source code for android.view SoundEffectConstants CLICK.

Click Source Link

Usage

From source file:com.yahala.ui.Views.PinnedSectionListView.java

private boolean performPinnedItemClick() {
    if (mPinnedSection == null)
        return false;

    OnItemClickListener listener = getOnItemClickListener();
    if (listener != null) {
        View view = mPinnedSection.view;
        playSoundEffect(SoundEffectConstants.CLICK);
        if (view != null) {
            view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
        }/*  www  . j  a  va 2 s.  co  m*/
        listener.onItemClick(this, view, mPinnedSection.position, mPinnedSection.id);
        return true;
    }
    return false;
}

From source file:com.dm.xz.views.PinnedSectionListView.java

private boolean performPinnedItemClick() {
    if (mPinnedSection == null)
        return false;

    OnItemClickListener listener = getOnItemClickListener();
    if (listener != null && getAdapter().isEnabled(mPinnedSection.position)) {
        View view = mPinnedSection.view;
        playSoundEffect(SoundEffectConstants.CLICK);
        if (view != null) {
            view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
        }//w ww. j a v a  2s  .  com
        listener.onItemClick(this, view, mPinnedSection.position, mPinnedSection.id);
        return true;
    }
    return false;
}

From source file:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java

@SuppressLint("ClickableViewAccessibility")
@Override/*  w  ww. j av  a2  s .  c om*/
public boolean onTouch(View v, MotionEvent event) {
    int x = (int) event.getX();
    int y = (int) event.getY();

    if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
        initialX = x;
        initialY = y;
        dragIndex = TouchMap.UNMAPPED;
        dragging = false;
        dragAsset = "";

        if (AppData.IS_KITKAT && mGlobalPrefs.isImmersiveModeEnabled) {
            // ignore edge swipes.
            // unfortunately KitKat lacks a way to do this on its own,
            // so just ignore all touches along the edges.
            // http://stackoverflow.com/questions/20530333/ignore-immersive-mode-swipe
            View view = getWindow().getDecorView();
            if (y < 10 || y > view.getHeight() - 10 || x < 10 || x > view.getWidth() - 10)
                return false;
        }

        // Get the N64 index of the button that was pressed
        int index = mTouchscreenMap.getButtonPress(x, y);
        if (index != TouchMap.UNMAPPED) {
            dragIndex = index;
            dragAsset = TouchMap.ASSET_NAMES.get(index);
            dragFrame = mTouchscreenMap.getButtonFrame(dragAsset);
        } else {
            // See if analog was pressed
            Point point = mTouchscreenMap.getAnalogDisplacement(x, y);
            int dX = point.x;
            int dY = point.y;
            float displacement = (float) Math.sqrt((dX * dX) + (dY * dY));
            if (mTouchscreenMap.isInCaptureRange(displacement)) {
                dragAsset = ANALOG;
                dragFrame = mTouchscreenMap.getAnalogFrame();
            } else {
                int resId = R.menu.touchscreen_profile_activity;
                int stringId = R.string.touchscreenProfileActivity_menuTitle;

                MenuDialogFragment menuDialogFragment = MenuDialogFragment.newInstance(0, getString(stringId),
                        resId);

                FragmentManager fm = getSupportFragmentManager();
                menuDialogFragment.show(fm, STATE_MENU_DIALOG_FRAGMENT);
            }
        }

        dragX = mProfile.getInt(dragAsset + TAG_X, INITIAL_ASSET_POS);
        dragY = mProfile.getInt(dragAsset + TAG_Y, INITIAL_ASSET_POS);

        return true;
    } else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) {
        if (dragIndex != TouchMap.UNMAPPED || ANALOG.equals(dragAsset)) {
            if (!dragging) {
                int dX = x - initialX;
                int dY = y - initialY;
                float displacement = (float) Math.sqrt((dX * dX) + (dY * dY));
                if (displacement >= 10)
                    dragging = true;
            }
            if (!dragging)
                return false;

            // drag this button or analog stick around

            // calculate the X and Y percentage
            View view = getWindow().getDecorView();
            int newDragX = (x - (initialX - dragFrame.left)) * 100
                    / (view.getWidth() - (dragFrame.right - dragFrame.left));
            int newDragY = (y - (initialY - dragFrame.top)) * 100
                    / (view.getHeight() - (dragFrame.bottom - dragFrame.top));

            newDragX = Math.min(Math.max(newDragX, 0), 100);
            newDragY = Math.min(Math.max(newDragY, 0), 100);

            if (newDragX != dragX || newDragY != dragY) {
                dragX = newDragX;
                dragY = newDragY;
                mProfile.put(dragAsset + TAG_X, String.valueOf(newDragX));
                mProfile.put(dragAsset + TAG_Y, String.valueOf(newDragY));
                mTouchscreenMap.refreshButtonPosition(mProfile, dragAsset);
                mOverlay.postInvalidate();
            }
        }
    } else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
        // if this touch was part of a drag/swipe gesture then don't tap the button
        if (dragging)
            return false;

        // show the editor for the tapped button
        if (ANALOG.equals(dragAsset)) {
            // play the standard button sound effect
            View view = getWindow().getDecorView();
            view.playSoundEffect(SoundEffectConstants.CLICK);

            popupDialog(dragAsset, getString(R.string.controller_analog), -1);
        } else if (dragIndex != TouchMap.UNMAPPED) {
            int index = dragIndex;
            String title = READABLE_NAMES.get(dragIndex);

            // D-pad buttons and TOGGLE_SENSOR are not holdable
            if (DPAD.equals(dragAsset) || TouchMap.TOGGLE_SENSOR == index)
                index = -1;

            // play the standard button sound effect
            View view = getWindow().getDecorView();
            view.playSoundEffect(SoundEffectConstants.CLICK);

            popupDialog(dragAsset, title, index);
        }

        return true;
    }

    return false;
}

From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (!mCanSlide || !mIsSlidingEnabled) {
        return super.onTouchEvent(ev);
    }/*w  ww  . j  a  v a  2 s  .  c o  m*/

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();
    boolean wantTouchEvents = true;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_UP: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float dx = x - mInitialMotionX;
        final float dy = y - mInitialMotionY;
        final int slop = mDragHelper.getTouchSlop();
        View dragView = mDragView != null ? mDragView : mSlideableView;
        if (dx * dx + dy * dy < slop * slop && isDragViewUnder((int) x, (int) y)) {
            dragView.playSoundEffect(SoundEffectConstants.CLICK);
            if (!isExpanded() && !isAnchored()) {
                expandPane(mAnchorPoint);
            } else {
                collapsePane();
            }
            break;
        }
        break;
    }
    }

    return wantTouchEvents;
}

From source file:org.telegram.ui.Cells.ContextLinkCell.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
        if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
            getBackground().setHotspot(event.getX(), event.getY());
        }//  w  w w . j a v a2 s  .  co  m
    }

    if (mediaWebpage || delegate == null || inlineResult == null) {
        return super.onTouchEvent(event);
    }
    int x = (int) event.getX();
    int y = (int) event.getY();

    boolean result = false;
    int side = AndroidUtilities.dp(48);
    if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
        boolean area = letterDrawable.getBounds().contains(x, y);
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            if (area) {
                buttonPressed = true;
                invalidate();
                result = true;
                radialProgress.swapBackground(getDrawableForCurrentState());
            }
        } else if (buttonPressed) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                buttonPressed = false;
                playSoundEffect(SoundEffectConstants.CLICK);
                didPressedButton();
                invalidate();
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                buttonPressed = false;
                invalidate();
            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                if (!area) {
                    buttonPressed = false;
                    invalidate();
                }
            }
            radialProgress.swapBackground(getDrawableForCurrentState());
        }
    } else {
        if (inlineResult != null && inlineResult.content_url != null && inlineResult.content_url.length() > 0) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                if (letterDrawable.getBounds().contains(x, y)) {
                    buttonPressed = true;
                    result = true;
                }
            } else {
                if (buttonPressed) {
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        buttonPressed = false;
                        playSoundEffect(SoundEffectConstants.CLICK);
                        delegate.didPressedImage(this);
                    } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                        buttonPressed = false;
                    } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                        if (!letterDrawable.getBounds().contains(x, y)) {
                            buttonPressed = false;
                        }
                    }
                }
            }
        }
    }
    if (!result) {
        result = super.onTouchEvent(event);
    }

    return result;
}

From source file:android.support.v7ox.widget.SwitchCompat.java

/**
 * Called from onTouchEvent to end a drag operation.
 *
 * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL
 *//*  ww w .ja v a 2 s.c om*/
private void stopDrag(MotionEvent ev) {
    mTouchMode = TOUCH_MODE_IDLE;

    // Commit the change if the event is up and not canceled and the switch
    // has not been disabled during the drag.
    final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled();
    final boolean oldState = isChecked();
    final boolean newState;
    if (commitChange) {
        mVelocityTracker.computeCurrentVelocity(1000);
        final float xvel = mVelocityTracker.getXVelocity();
        if (Math.abs(xvel) > mMinFlingVelocity) {
            newState = ViewUtils.isLayoutRtl(this) ? (xvel < 0) : (xvel > 0);
        } else {
            newState = getTargetCheckedState();
        }
    } else {
        newState = oldState;
    }

    if (newState != oldState) {
        playSoundEffect(SoundEffectConstants.CLICK);
    }
    // Always call setChecked so that the thumb is moved back to the correct edge
    setChecked(newState);
    cancelSuperTouch(ev);
}

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

/**
 * Called from onTouchEvent to end a drag operation.
 *
 * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL
 *//*from  w  w w  .j ava2s  .  c  om*/
private void stopDrag(MotionEvent ev) {
    mTouchMode = TOUCH_MODE_IDLE;

    // Commit the change if the event is up and not canceled and the switch
    // has not been disabled during the drag.
    final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled();
    final boolean oldState = isChecked();
    final boolean newState;
    if (commitChange) {
        mVelocityTracker.computeCurrentVelocity(1000);
        final float xvel = mVelocityTracker.getXVelocity();
        if (Math.abs(xvel) > mMinFlingVelocity) {
            newState = ViewUtils.isLayoutRtl(this) ? (xvel < 0) : (xvel > 0);
        } else {
            newState = getTargetCheckedState();
        }
    } else {
        newState = oldState;
    }

    if (newState != oldState) {
        playSoundEffect(SoundEffectConstants.CLICK);
        setChecked(newState);
    }
    cancelSuperTouch(ev);
}

From source file:org.mariotaku.multivalueswitch.library.MultiValueSwitch.java

/**
 * Called from onTouchEvent to end a drag operation.
 *
 * @param ev Event that triggered the end of drag mode - ACTION_UP or ACTION_CANCEL
 *//* w w w .j  av  a2 s  . c om*/
private void stopDrag(MotionEvent ev) {
    mTouchMode = TOUCH_MODE_IDLE;

    // Commit the change if the event is up and not canceled and the switch
    // has not been disabled during the drag.
    final boolean commitChange = ev.getAction() == MotionEvent.ACTION_UP && isEnabled();
    final int oldState = getCheckedPosition();
    final int newState;
    if (commitChange) {
        mVelocityTracker.computeCurrentVelocity(1000);
        final float xvel = mVelocityTracker.getXVelocity();
        if (Math.abs(xvel) > mMinFlingVelocity) {
            int diff = Math.round(xvel / (ViewUtils.isLayoutRtl(this) ? -Math.abs(xvel) : Math.abs(xvel)));
            newState = Math.min(getMax() - 1, Math.max(0, getCheckedPosition() + diff));
        } else {
            newState = getCheckedPosition();
        }
    } else {
        newState = oldState;
    }

    if (newState != oldState) {
        playSoundEffect(SoundEffectConstants.CLICK);
    }
    // Always call setChecked so that the thumb is moved back to the correct edge
    setCheckedPosition(newState);
    cancelSuperTouch(ev);
}

From source file:cn.oddcloud.www.navigationtabbar.ntb.NavigationTabBar.java

@Override
public boolean onTouchEvent(final MotionEvent event) {
    // Return if animation is running
    if (mAnimator.isRunning())
        return true;
    // If is not idle state, return
    if (mScrollState != ViewPager.SCROLL_STATE_IDLE)
        return true;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        // Action down touch
        mIsActionDown = true;//w  w  w . ja v  a  2  s .c om
        if (!mIsViewPagerMode)
            break;
        if (!mIsSwiped)
            break;
        // Detect if we touch down on pointer, later to move
        if (mIsHorizontalOrientation)
            mIsPointerActionDown = (int) (event.getX() / mModelSize) == mIndex;
        else
            mIsPointerActionDown = (int) (event.getY() / mModelSize) == mIndex;
        break;
    case MotionEvent.ACTION_MOVE:
        // If pointer touched, so move
        if (mIsPointerActionDown) {
            if (mIsHorizontalOrientation)
                mViewPager.setCurrentItem((int) (event.getX() / mModelSize), true);
            else
                mViewPager.setCurrentItem((int) (event.getY() / mModelSize), true);
            break;
        }
        if (mIsActionDown)
            break;
    case MotionEvent.ACTION_UP:
        // Press up and set model index relative to current coordinate
        if (mIsActionDown) {
            playSoundEffect(SoundEffectConstants.CLICK);
            if (mIsHorizontalOrientation)
                setModelIndex((int) (event.getX() / mModelSize));
            else
                setModelIndex((int) (event.getY() / mModelSize));
        }
    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_OUTSIDE:
    default:
        // Reset action touch variables
        mIsPointerActionDown = false;
        mIsActionDown = false;
        break;
    }

    return true;
}

From source file:uk.ac.kent.jb509.shopper.utils.SlidingUpPanelLayout.java

@Override
public boolean onTouchEvent(final MotionEvent ev) {
    if (!enabled) {
        return false;
    }/*from w w w .j  a v  a  2  s  .c  om*/
    if (!mCanSlide || !mIsSlidingEnabled) {
        return super.onTouchEvent(ev);
    }

    mDragHelper.processTouchEvent(ev);

    final int action = ev.getAction();
    final boolean wantTouchEvents = true;

    switch (action & MotionEventCompat.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialMotionX = x;
        mInitialMotionY = y;
        break;
    }

    case MotionEvent.ACTION_UP: {
        final float x = ev.getX();
        final float y = ev.getY();
        final float dx = x - mInitialMotionX;
        final float dy = y - mInitialMotionY;
        final int slop = mDragHelper.getTouchSlop();
        if (dx * dx + dy * dy < slop * slop && isDragViewHit((int) x, (int) y)) {
            final View v = mDragView != null ? mDragView : mSlideableView;
            v.playSoundEffect(SoundEffectConstants.CLICK);
            if (!isExpanded() && !isAnchored()) {
                expandPane(mSlideableView, 0, mAnchorPoint);
            } else {
                collapsePane();
            }
            break;
        }
        break;
    }
    }

    return wantTouchEvents;
}