Java Code Examples for android.view.View.playSoundEffect()

The following are Jave code examples for showing how to use playSoundEffect() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: LaunchEnr   File: FocusHelper.java   Source Code and License Vote up 6 votes
/**
 * Helper method to be used for playing sound effects.
 */
@Thunk private static void playSoundEffect(int keyCode, View v) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_MOVE_END:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_MOVE_HOME:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
            break;
        default:
            break;
    }
}
 
Example 2
Project: FlickLauncher   File: FocusHelper.java   Source Code and License Vote up 6 votes
/**
 * Helper method to be used for playing sound effects.
 */
@Thunk static void playSoundEffect(int keyCode, View v) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_MOVE_END:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_MOVE_HOME:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
            break;
        default:
            break;
    }
}
 
Example 3
Project: SimpleUILauncher   File: FocusHelper.java   Source Code and License Vote up 6 votes
/**
 * Helper method to be used for playing sound effects.
 */
@Thunk static void playSoundEffect(int keyCode, View v) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
        case KeyEvent.KEYCODE_PAGE_DOWN:
        case KeyEvent.KEYCODE_MOVE_END:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            break;
        case KeyEvent.KEYCODE_DPAD_UP:
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_MOVE_HOME:
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
            break;
        default:
            break;
    }
}
 
Example 4
Project: mapbox-navigation-android   File: FeedbackClickListener.java   Source Code and License Vote up 5 votes
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent motionEvent) {
  View child = rv.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
  if (child != null && gestureDetector.onTouchEvent(motionEvent)) {
    child.playSoundEffect(SoundEffectConstants.CLICK);
    int position = rv.getChildAdapterPosition(child);
    callback.onFeedbackItemClick(position);
  }
  return false;
}
 
Example 5
Project: airgram   File: RecyclerListView.java   Source Code and License Vote up 4 votes
public RecyclerListViewItemClickListener(Context context) {
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (currentChildView != null && onItemClickListener != null) {
                currentChildView.setPressed(true);
                final View view = currentChildView;
                if (instantClick) {
                    view.playSoundEffect(SoundEffectConstants.CLICK);
                    onItemClickListener.onItemClick(view, currentChildPosition);
                }
                AndroidUtilities.runOnUIThread(clickRunnable = new Runnable() {
                    @Override
                    public void run() {
                        if (this == clickRunnable) {
                            clickRunnable = null;
                        }
                        if (view != null) {
                            view.setPressed(false);
                            if (!instantClick) {
                                view.playSoundEffect(SoundEffectConstants.CLICK);
                                if (onItemClickListener != null) {
                                    onItemClickListener.onItemClick(view, currentChildPosition);
                                }
                            }
                        }
                    }
                }, ViewConfiguration.getPressedStateDuration());

                if (selectChildRunnable != null) {
                    AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
                    selectChildRunnable = null;
                    currentChildView = null;
                    interceptedByChild = false;
                }
            }
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event) {
            if (currentChildView != null) {
                if (onItemLongClickListener != null) {
                    if (onItemLongClickListener.onItemClick(currentChildView, currentChildPosition)) {
                        currentChildView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    }
                }
            }
        }
    });
}
 
Example 6
Project: PlusGram   File: RecyclerListView.java   Source Code and License Vote up 4 votes
public RecyclerListViewItemClickListener(Context context) {
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            if (currentChildView != null && onItemClickListener != null) {
                currentChildView.setPressed(true);
                final View view = currentChildView;
                if (instantClick) {
                    view.playSoundEffect(SoundEffectConstants.CLICK);
                    onItemClickListener.onItemClick(view, currentChildPosition);
                }
                AndroidUtilities.runOnUIThread(clickRunnable = new Runnable() {
                    @Override
                    public void run() {
                        if (this == clickRunnable) {
                            clickRunnable = null;
                        }
                        if (view != null) {
                            view.setPressed(false);
                            if (!instantClick) {
                                view.playSoundEffect(SoundEffectConstants.CLICK);
                                if (onItemClickListener != null) {
                                    onItemClickListener.onItemClick(view, currentChildPosition);
                                }
                            }
                        }
                    }
                }, ViewConfiguration.getPressedStateDuration());

                if (selectChildRunnable != null) {
                    AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
                    selectChildRunnable = null;
                    currentChildView = null;
                    interceptedByChild = false;
                }
            }
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event) {
            if (currentChildView != null) {
                View child = currentChildView;
                if (onItemLongClickListener != null) {
                    if (onItemLongClickListener.onItemClick(currentChildView, currentChildPosition)) {
                        child.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    }
                }
            }
        }
    });
}