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

The following examples show how to use android.view.View#playSoundEffect() . These examples are extracted from open source projects. 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
/**
 * 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
@Override
public boolean onSingleTapUp(MotionEvent e) {
    View view = mRecyclerView.findChildViewUnder(e.getX(), e.getY());

    if (view != null) {
        view.playSoundEffect(SoundEffectConstants.CLICK);

        int pos = mRecyclerView.getChildPosition(view);

        Intent i = new Intent(getActivity(), ViewEntryActivity.class);
        Bundle b = new Bundle();
        b.putParcelable(ViewEntryActivity.ENTRY_KEY, mDisplayedEntries.get(pos));
        i.putExtras(b);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.buildDrawingCache(true);
            Bitmap drawingCache = view.getDrawingCache(true);
            Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0).toBundle();
            getActivity().startActivity(i, bundle);
        } else {
            startActivity(i);
        }
    }

    return super.onSingleTapUp(e);
}
 
Example 3
@Override
public void onClick(View widget) {
	final Uri uri = Uri.parse(getURL());
	final Context context = widget.getContext();
	final boolean candidateToProcessDirectly = "xmpp".equals(uri.getScheme()) || ("https".equals(uri.getScheme()) && "conversations.im".equals(uri.getHost()) && uri.getPathSegments().size() > 1 && Arrays.asList("j","i").contains(uri.getPathSegments().get(0)));
	if (candidateToProcessDirectly && context instanceof ConversationsActivity) {
		if (((ConversationsActivity) context).onXmppUriClicked(uri)) {
			widget.playSoundEffect(0);
			return;
		}
	}
	final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
	}
	//intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
	try {
		context.startActivity(intent);
		widget.playSoundEffect(0);
	} catch (ActivityNotFoundException e) {
		Toast.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
	}
}
 
Example 4
/**
 * 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 5
@Override
public void onClick(View widget) {
    final Uri uri = Uri.parse(getURL());
    final Context context = widget.getContext();
    final boolean candidateToProcessDirectly = "xmpp".equals(uri.getScheme()) || ("https".equals(uri.getScheme()) && Config.inviteHostURL.equals(uri.getHost()) && uri.getPathSegments().size() > 1 && Arrays.asList("j", "i").contains(uri.getPathSegments().get(0)));
    if (candidateToProcessDirectly && context instanceof ConversationsActivity) {
        if (((ConversationsActivity) context).onXmppUriClicked(uri)) {
            widget.playSoundEffect(0);
            return;
        }
    }
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
    }
    //intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    try {
        context.startActivity(intent);
        widget.playSoundEffect(0);
    } catch (ActivityNotFoundException e) {
        ToastCompat.makeText(context, R.string.no_application_found_to_open_link, Toast.LENGTH_SHORT).show();
    }
}
 
Example 6
Source Project: android_tv_metro   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void playKeySound(View view, int soundKey) {
   	if (null != view) {
   		if (soundKey == SOUND_KEYSTONE_KEY) {
   			view.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
   		} else if (soundKey == SOUND_ERROR_KEY) {
   			view.playSoundEffect(5);
   		}
	}
}
 
Example 7
@Override
boolean performItemClick(RecyclerView parent, View view, int position, long id) {
    if (mItemClickListener != null) {
        view.playSoundEffect(SoundEffectConstants.CLICK);
        mItemClickListener.onItemClick(parent, view, position, id);
        return true;
    }

    return false;
}
 
Example 8
Source Project: android_tv_metro   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
public static void playKeySound(View view, int soundKey) {
   	if (null != view) {
   		if (soundKey == SOUND_KEYSTONE_KEY) {
   			view.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
   		} else if (soundKey == SOUND_ERROR_KEY) {
   			view.playSoundEffect(5);
   		}
	}
}
 
Example 9
@Override
public boolean onSingleTapUp(MotionEvent e) {
    View view = mRecyclerView.findChildViewUnder(e.getX(), e.getY());

    if (mActionMode != null) {
        toggleSelectedItem(mRecyclerView.getChildPosition(view));
    } else {
        if ( view != null ) {
            view.playSoundEffect(SoundEffectConstants.CLICK);

            int pos = mRecyclerView.getChildPosition(view);

            Intent i = new Intent(getActivity(), ViewEntryActivity.class);
            Bundle b = new Bundle();
            b.putParcelable(ViewEntryActivity.ENTRY_KEY, ((MainActivity) getActivity()).entries.get(pos - mAdapter.getSectionOffset(pos)));
            i.putExtras(b);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.buildDrawingCache(true);
                Bitmap drawingCache = view.getDrawingCache(true);
                Bundle bundle = ActivityOptions.makeThumbnailScaleUpAnimation(view, drawingCache, 0, 0).toBundle();
                getActivity().startActivity(i, bundle);
            } else {
                startActivity(i);
            }

        }
    }

    return super.onSingleTapUp(e);
}
 
Example 10
Source Project: PlayWidget   File: ItemClickSupport.java    License: MIT License 5 votes vote down vote up
@Override
boolean performItemClick(RecyclerView parent, View view, int position, long id) {
    if (mItemClickListener != null) {
        view.playSoundEffect(SoundEffectConstants.CLICK);
        mItemClickListener.onItemClick(parent, view, position, id);
        return true;
    }

    return false;
}
 
Example 11
@Override
public boolean onInterceptTouchEvent(@NonNull RecyclerView view, @NonNull MotionEvent motionEvent) {
    final View childView = view.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
    if (childView != null && mGestureDetector.onTouchEvent(motionEvent)) {
        childView.playSoundEffect(SoundEffectConstants.CLICK);
        mOnItemClickListener.onItemClick(view.getChildAdapterPosition(childView));
        return true;
    }
    return false;
}
 
Example 12
Source Project: GridBuilder   File: GridBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (!(v instanceof IGridItemView)) {
        return;
    }

    GridItem gridItem = ((IGridItemView) v).getGridItem();

    if (null != mItemSelectedListener) {
        mItemSelectedListener.onItemSelected(gridItem, v, hasFocus);
    }

    if (hasFocus) {
        v.bringToFront();
        mGridLayout.invalidate();
        enlargeItem(v, gridItem);
        refreshReflection(mBaseHeight);
        if (mSoundEffectsEnabled) {
            v.setSoundEffectsEnabled(true);
            v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
            v.setSoundEffectsEnabled(false);
        }
    } else {
        narrowItem(v, gridItem);
        if (null == mGridLayout.getFocusedChild()) {
            refreshReflection(mBaseHeight);
        }
    }
}
 
Example 13
Source Project: 365browser   File: AppMenuButtonHelper.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
    if (action == AccessibilityNodeInfo.ACTION_CLICK) {
        if (!mMenuHandler.isAppMenuShowing()) {
            showAppMenu(host, false);
        } else {
            mMenuHandler.hideAppMenu();
        }
        host.playSoundEffect(SoundEffectConstants.CLICK);
        host.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
        return true;
    }
    return super.performAccessibilityAction(host, action, args);
}
 
Example 14
Source Project: MultiView   File: ItemClickSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
boolean performItemClick(RecyclerView parent, View view, int position, long id) {
    if (mItemClickListener != null) {
        view.playSoundEffect(SoundEffectConstants.CLICK);
        mItemClickListener.onItemClick(parent, view, position, id);
        return true;
    }

    return false;
}
 
Example 15
@Override
public void onClick(View v) {
    if (!drawerTouchLocked) {
        MaterialHeadItem headItem = findHeadItemNumber(MaterialHeadItem.THIRD_HEADITEM);
        if (headItem != null) {

            headItemThirdPhoto.setSoundEffectsEnabled(true);
            v.playSoundEffect(android.view.SoundEffectConstants.CLICK);
            headItemThirdPhoto.setSoundEffectsEnabled(false);

            if (headItemChangedListener != null)
                headItemChangedListener.onBeforeChangeHeadItem(headItem);

            switchHeadItemsIcon(headItem, true);

            if (headItemChangedListener != null)
                headItemChangedListener.onAfterChangeHeadItem(headItem);
        } else {// if there is no second account user clicked for open it
            //accountListener.onAccountOpening(currentAccount);
            if (headItemManager.get(0).getBackgroundOnClickListener() != null) {

                headItemThirdPhoto.setSoundEffectsEnabled(true);
                v.playSoundEffect(android.view.SoundEffectConstants.CLICK);
                headItemThirdPhoto.setSoundEffectsEnabled(false);

                headItemManager.get(0).getBackgroundOnClickListener().onClick(headItemManager.get(0));

                if (headItemManager.get(0).isCloseDrawerBackgroundOnClick() && !deviceSupportMultiPane()) {
                    drawerLayout.closeDrawer(drawerViewGroup);
                }
            }
        }
    }
}
 
Example 16
@Override
boolean performItemClick(RecyclerView parent, View view, int position, long id) {
  if (mItemClickListener != null) {
    view.playSoundEffect(SoundEffectConstants.CLICK);
    mItemClickListener.onItemClick(parent, view, position, id);
    return true;
  }

  return false;
}
 
Example 17
public RecyclerListViewItemClickListener(Context context)
{
    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener()
    {
        @Override
        public boolean onSingleTapUp(MotionEvent e)
        {
            if (currentChildView != null && (onItemClickListener != null || onItemClickListenerExtended != null))
            {
                onChildPressed(currentChildView, true);
                final View view = currentChildView;
                final int position = currentChildPosition;
                final float x = e.getX();
                final float y = e.getY();
                if (instantClick && position != -1)
                {
                    view.playSoundEffect(SoundEffectConstants.CLICK);
                    if (onItemClickListener != null)
                    {
                        onItemClickListener.onItemClick(view, position);
                    }
                    else if (onItemClickListenerExtended != null)
                    {
                        onItemClickListenerExtended.onItemClick(view, position, x, y);
                    }
                }
                AndroidUtilities.runOnUIThread(clickRunnable = new Runnable()
                {
                    @Override
                    public void run()
                    {
                        if (this == clickRunnable)
                        {
                            clickRunnable = null;
                        }
                        if (view != null)
                        {
                            onChildPressed(view, false);
                            if (!instantClick)
                            {
                                view.playSoundEffect(SoundEffectConstants.CLICK);
                                if (position != -1)
                                {
                                    if (onItemClickListener != null)
                                    {
                                        onItemClickListener.onItemClick(view, position);
                                    }
                                    else if (onItemClickListenerExtended != null)
                                    {
                                        onItemClickListenerExtended.onItemClick(view, position, x, y);
                                    }
                                }
                            }
                        }
                    }
                }, ViewConfiguration.getPressedStateDuration());

                if (selectChildRunnable != null)
                {
                    View pressedChild = currentChildView;
                    AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
                    selectChildRunnable = null;
                    currentChildView = null;
                    interceptedByChild = false;
                    removeSelection(pressedChild, e);
                }
            }
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event)
        {
            if (currentChildView == null || currentChildPosition == -1 || onItemLongClickListener == null && onItemLongClickListenerExtended == null)
            {
                return;
            }
            View child = currentChildView;
            if (onItemLongClickListener != null)
            {
                if (onItemLongClickListener.onItemClick(currentChildView, currentChildPosition))
                {
                    child.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                }
            }
            else if (onItemLongClickListenerExtended != null)
            {
                if (onItemLongClickListenerExtended.onItemClick(currentChildView, currentChildPosition, event.getX(), event.getY()))
                {
                    child.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                    longPressCalled = true;
                }
            }
        }
    });
}
 
Example 18
Source Project: iBeebo   File: Utility.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void playClickSound(View view) {
    view.playSoundEffect(SoundEffectConstants.CLICK);
}
 
Example 19
Source Project: iBeebo   File: Utility.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void playClickSound(View view) {
    view.playSoundEffect(SoundEffectConstants.CLICK);
}
 
Example 20
public boolean onTouchEvent(MotionEvent motionevent)
{
    boolean flag;
    if (!mCanSlide || !mIsSlidingEnabled)
    {
        flag = super.onTouchEvent(motionevent);
    } else
    {
        mDragHelper.processTouchEvent(motionevent);
        int i = motionevent.getAction();
        flag = true;
        switch (i & 0xff)
        {
        default:
            return flag;

        case 0: // '\0'
            float f4 = motionevent.getX();
            float f5 = motionevent.getY();
            mInitialMotionX = f4;
            mInitialMotionY = f5;
            return flag;

        case 1: // '\001'
            dispatchOnPanelLastOffset(mSlideableView);
            break;
        }
        float f = motionevent.getX();
        float f1 = motionevent.getY();
        float f2 = f - mInitialMotionX;
        float f3 = f1 - mInitialMotionY;
        int j = mDragHelper.getTouchSlop();
        View view;
        if (mDragView != null)
        {
            view = mDragView;
        } else
        {
            view = mSlideableView;
        }
        if (f2 * f2 + f3 * f3 < (float)(j * j) && isDragViewUnder((int)f, (int)f1))
        {
            view.playSoundEffect(0);
            if (!isExpanded() && !isAnchored())
            {
                expandPane(mAnchorPoint);
                return flag;
            } else
            {
                collapsePane();
                return flag;
            }
        }
    }
    return flag;
}