android.view.SoundEffectConstants Java Examples

The following examples show how to use android.view.SoundEffectConstants. 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: Gallery.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Handles left, right, and clicking
 * @see android.view.View#onKeyDown
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
        
    case KeyEvent.KEYCODE_DPAD_LEFT:
        if (moveDirection(-1)) {
            playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            return true;
        }
        break;
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (moveDirection(1)) {
            playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            return true;
        }
        break;
    case KeyEvent.KEYCODE_DPAD_CENTER:
    case KeyEvent.KEYCODE_ENTER:
        mReceivedInvokeKeyDown = true;
        // fallthrough to default handling
    }
    
    return super.onKeyDown(keyCode, event);
}
 
Example #2
Source File: CircularView.java    From CircularView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onLongClick(View v) {
    if (mOnCircularViewObjectClickListener != null && isLongClickable()) {
        mLongClickRegistered = true;
        if (mTouchEventMarkerPos == -1) {
            playSoundEffect(SoundEffectConstants.CLICK);
            mOnCircularViewObjectClickListener.onClick(CircularView.this, true);
            mTouchEventMarkerPos = null;
        } else if (mTouchEventMarker != null) {
            playSoundEffect(SoundEffectConstants.CLICK);
            mOnCircularViewObjectClickListener.onMarkerClick(CircularView.this, mTouchEventMarker, mTouchEventMarkerPos, true);
            mTouchEventMarker = null;
            mTouchEventMarkerPos = null;
        }
        return mLongClickRegistered;
    }
    return false;
}
 
Example #3
Source File: EntryListDialogFragment.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onSingleTapUp(MotionEvent e) {
    View view = mList.findChildViewUnder(e.getX(), e.getY());

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

        int pos = mList.getChildPosition(view);

        Intent i = new Intent(getActivity(), ViewEntryActivity.class);
        Bundle b = new Bundle();
        b.putParcelable(ViewEntryActivity.ENTRY_KEY, mItems.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 #4
Source File: Chip.java    From Carbon with Apache License 2.0 6 votes vote down vote up
@Override
public boolean performClick() {
    toggle();

    if (onCheckedChangeListener != null)
        onCheckedChangeListener.onCheckedChanged(this, isChecked());

    final boolean handled = super.performClick();
    if (!handled) {
        // View only makes a sound effect if the onClickListener was
        // called, so we'll need to make one here instead.
        playSoundEffect(SoundEffectConstants.CLICK);
    }

    return handled;
}
 
Example #5
Source File: FocusHelper.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #6
Source File: EcoGallery.java    From samples with Apache License 2.0 6 votes vote down vote up
/**
 * Handles left, right, and clicking
 *
 * @see View#onKeyDown
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {

        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (movePrevious()) {
                playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
            }
            return true;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (moveNext()) {
                playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
            }
            return true;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            mReceivedInvokeKeyDown = true;
            // fallthrough to default handling
    }

    return super.onKeyDown(keyCode, event);
}
 
Example #7
Source File: PinnedSectionListView.java    From Kernel-Tuner with GNU General Public License v3.0 5 votes vote down vote up
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);
        }
        listener.onItemClick(this, view, mPinnedSection.position, mPinnedSection.id);
        return true;
    }
    return false;
}
 
Example #8
Source File: StickyRecyclerHeadersTouchListener.java    From ZhiHu-TopAnswer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onSingleTapUp(MotionEvent e) {
  int position = mDecor.findHeaderPositionUnder((int) e.getX(), (int) e.getY());
  if (position != -1) {
    View headerView = mDecor.getHeaderView(mRecyclerView, position);
    long headerId = getAdapter().getHeaderId(position);
    mOnHeaderClickListener.onHeaderClick(headerView, position, headerId);
    mRecyclerView.playSoundEffect(SoundEffectConstants.CLICK);
    headerView.onTouchEvent(e);
    return true;
  }
  return false;
}
 
Example #9
Source File: CustomViewAbove.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public boolean arrowScroll(int direction) {
	View currentFocused = findFocus();
	if (currentFocused == this) currentFocused = null;

	boolean handled = false;

	View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
			direction);
	if (nextFocused != null && nextFocused != currentFocused) {
		if (direction == View.FOCUS_LEFT) {
			handled = nextFocused.requestFocus();
		} else if (direction == View.FOCUS_RIGHT) {
			// If there is nothing to the right, or this is causing us to
			// jump to the left, then what we really want to do is page right.
			if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
				handled = pageRight();
			} else {
				handled = nextFocused.requestFocus();
			}
		}
	} else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
		// Trying to move left and nothing there; try to page.
		handled = pageLeft();
	} else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
		// Trying to move right and nothing there; try to page.
		handled = pageRight();
	}
	if (handled) {
		playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
	}
	return handled;
}
 
Example #10
Source File: TabView.java    From TabView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean performClick() {
    toggle();
    final boolean handled = super.performClick();
    if (!handled) {
        // View only makes a sound effect if the onClickListener was
        // called, so we'll need to make one here instead.
        playSoundEffect(SoundEffectConstants.CLICK);
    }

    return handled;
}
 
Example #11
Source File: CheckableImageButton.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
@Override // borrowed from CompoundButton#performClick()
public boolean performClick() {
    toggle();
    final boolean handled = super.performClick();
    if (!handled) {
        // View only makes a sound effect if the onClickListener was
        // called, so we'll need to make one here instead.
        playSoundEffect(SoundEffectConstants.CLICK);
    }
    return handled;
}
 
Example #12
Source File: StickyRecyclerHeadersTouchListener.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onSingleTapUp(@NonNull MotionEvent e) {
    int position = mDecor.findHeaderPositionUnder((int) e.getX(), (int) e.getY());
    if (position != -1) {
        View headerView = mDecor.getHeaderView(mRecyclerView, position);
        long headerId = getAdapter().getHeaderId(position);
        mOnHeaderClickListener.onHeaderClick(headerView, position, headerId);
        mRecyclerView.playSoundEffect(SoundEffectConstants.CLICK);
        headerView.onTouchEvent(e);
        return true;
    }
    return false;
}
 
Example #13
Source File: CustomViewAbove.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) currentFocused = null;

    boolean handled = false;

    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
            direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            handled = nextFocused.requestFocus();
        } else if (direction == View.FOCUS_RIGHT) {
            // If there is nothing to the right, or this is causing us to
            // jump to the left, then what we really want to do is page right.
            if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}
 
Example #14
Source File: OdysseyRecyclerView.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: PinnedSectionListView.java    From AndroidWeekly with Apache License 2.0 5 votes vote down vote up
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);
        }
        listener.onItemClick(this, view, mPinnedSection.position, mPinnedSection.id);
        return true;
    }
    return false;
}
 
Example #16
Source File: EntriesListFragment.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: TabLayout.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean performClick() {
  final boolean handled = super.performClick();

  if (tab != null) {
    if (!handled) {
      playSoundEffect(SoundEffectConstants.CLICK);
    }
    tab.select();
    return true;
  } else {
    return handled;
  }
}
 
Example #18
Source File: CustomViewAbove.java    From Moring-Alarm with Apache License 2.0 5 votes vote down vote up
public boolean arrowScroll(int direction) {
	View currentFocused = findFocus();
	if (currentFocused == this) currentFocused = null;

	boolean handled = false;

	View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
			direction);
	if (nextFocused != null && nextFocused != currentFocused) {
		if (direction == View.FOCUS_LEFT) {
			handled = nextFocused.requestFocus();
		} else if (direction == View.FOCUS_RIGHT) {
			// If there is nothing to the right, or this is causing us to
			// jump to the left, then what we really want to do is page right.
			if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
				handled = pageRight();
			} else {
				handled = nextFocused.requestFocus();
			}
		}
	} else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
		// Trying to move left and nothing there; try to page.
		handled = pageLeft();
	} else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
		// Trying to move right and nothing there; try to page.
		handled = pageRight();
	}
	if (handled) {
		playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
	}
	return handled;
}
 
Example #19
Source File: SuperCheckBox.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
@Override
public boolean performClick() {
    final boolean handled = super.performClick();
    if (!handled) {
        // View only makes a sound effect if the onClickListener was
        // called, so we'll need to make one here instead.
        playSoundEffect(SoundEffectConstants.CLICK);
    }
    return handled;
}
 
Example #20
Source File: PLA_AdapterView.java    From EverMemo with MIT License 5 votes vote down vote up
/**
 * Call the OnItemClickListener, if it is defined.
 *
 * @param view The view within the AdapterView that was clicked.
 * @param position The position of the view in the adapter.
 * @param id The row id of the item that was clicked.
 * @return True if there was an assigned OnItemClickListener that was
 *         called, false otherwise is returned.
 */
public boolean performItemClick(View view, int position, long id) {
	if (mOnItemClickListener != null) {
		playSoundEffect(SoundEffectConstants.CLICK);
		mOnItemClickListener.onItemClick(this, view, position, id);
		return true;
	}

	return false;
}
 
Example #21
Source File: CustomViewAbove.java    From WeatherStream with Apache License 2.0 5 votes vote down vote up
public boolean arrowScroll(int direction) {
	View currentFocused = findFocus();
	if (currentFocused == this) currentFocused = null;

	boolean handled = false;

	View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
			direction);
	if (nextFocused != null && nextFocused != currentFocused) {
		if (direction == View.FOCUS_LEFT) {
			handled = nextFocused.requestFocus();
		} else if (direction == View.FOCUS_RIGHT) {
			// If there is nothing to the right, or this is causing us to
			// jump to the left, then what we really want to do is page right.
			if (currentFocused != null && nextFocused.getLeft() <= currentFocused.getLeft()) {
				handled = pageRight();
			} else {
				handled = nextFocused.requestFocus();
			}
		}
	} else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
		// Trying to move left and nothing there; try to page.
		handled = pageLeft();
	} else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
		// Trying to move right and nothing there; try to page.
		handled = pageRight();
	}
	if (handled) {
		playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
	}
	return handled;
}
 
Example #22
Source File: PinnedSectionListView.java    From PullToRefresh-PinnedSection-ListView with MIT License 5 votes vote down vote up
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);
        }
        listener.onItemClick(this, view, mPinnedSection.position, mPinnedSection.id);
        return true;
    }
    return false;
}
 
Example #23
Source File: BeautyBox.java    From FuAgoraDemoDroid with MIT License 5 votes vote down vote up
@Override
public boolean performClick() {
    toggle();

    final boolean handled = super.performClick();
    if (!handled) {
        // View only makes a sound effect if the onClickListener was
        // called, so we'll need to make one here instead.
        playSoundEffect(SoundEffectConstants.CLICK);
    }

    return handled;
}
 
Example #24
Source File: IcsAdapterView.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * Call the OnItemClickListener, if it is defined.
 *
 * @param view The view within the AdapterView that was clicked.
 * @param position The position of the view in the adapter.
 * @param id The row id of the item that was clicked.
 * @return True if there was an assigned OnItemClickListener that was
 *         called, false otherwise is returned.
 */
public boolean performItemClick(View view, int position, long id) {
    if (mOnItemClickListener != null) {
        playSoundEffect(SoundEffectConstants.CLICK);
        if (view != null) {
            view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
        }
        mOnItemClickListener.onItemClick(/*this*/null, view, position, id);
        return true;
    }

    return false;
}
 
Example #25
Source File: ShutterButton.java    From android-mrz-reader with Apache License 2.0 5 votes vote down vote up
@Override
public boolean performClick() {
 boolean result = super.performClick();
 playSoundEffect(SoundEffectConstants.CLICK);
 if (mListener != null) {
	 mListener.onShutterButtonClick(this);
 }
 return result;
}
 
Example #26
Source File: HListView.java    From letv with Apache License 2.0 5 votes vote down vote up
boolean arrowScroll(int direction) {
    try {
        this.mInLayout = true;
        boolean handled = arrowScrollImpl(direction);
        if (handled) {
            playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
        }
        this.mInLayout = false;
        return handled;
    } catch (Throwable th) {
        this.mInLayout = false;
    }
}
 
Example #27
Source File: ActionMenuPresenter.java    From android-apps with MIT License 5 votes vote down vote up
@Override
public boolean performClick() {
    if (super.performClick()) {
        return true;
    }

    playSoundEffect(SoundEffectConstants.CLICK);
    showOverflowMenu();
    return true;
}
 
Example #28
Source File: MaterialAnimatedSwitch.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void doActionDown() {
  if (actualState.equals(MaterialAnimatedSwitchState.RELEASE) || actualState.equals(
      MaterialAnimatedSwitchState.INIT) || actualState == null) {
    actualState = MaterialAnimatedSwitchState.PRESS;
    setState(actualState);
  } else {
    actualState = MaterialAnimatedSwitchState.RELEASE;
    setState(actualState);
  }
  playSoundEffect(SoundEffectConstants.CLICK);
}
 
Example #29
Source File: TabLayout.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean performClick() {
    final boolean handled = super.performClick();

    if (mTab != null) {
        if (!handled) {
            playSoundEffect(SoundEffectConstants.CLICK);
        }
        mTab.select();
        return true;
    } else {
        return handled;
    }
}
 
Example #30
Source File: GridBuilder.java    From GridBuilder with 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);
        }
    }
}