List of usage examples for android.view View playSoundEffect
public void playSoundEffect(int soundConstant)
From source file:uk.ac.kent.jb509.shopper.utils.SlidingUpPanelLayout.java
@Override public boolean onTouchEvent(final MotionEvent ev) { if (!enabled) { return false; }/*ww w . j av 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; }
From source file:ca.mymenuapp.ui.widgets.SlidingUpPanelLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanSlide || !mIsSlidingEnabled) { return super.onTouchEvent(ev); }/* ww w.ja v a 2 s. c om*/ 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:paulscode.android.mupen64plusae.profile.TouchscreenProfileActivity.java
@SuppressLint("ClickableViewAccessibility") @Override//from ww w .jav a 2 s . co m 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; }