下面列出了android.view.View#performHapticFeedback ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Called from EmoteGridFragments when an Emote in the emotekeyboard has been clicked
*
* @param clickedEmote
*/
@Override
public void onEmoteClicked(Emote clickedEmote, View view) {
view.performHapticFeedback(VIBRATION_FEEDBACK);
if (clickedEmote != null) {
int startPosition = mSendText.getSelectionStart();
String emoteKeyword = clickedEmote.getKeyword();
if (startPosition != 0 && mSendText.getText().charAt(startPosition - 1) != ' ') {
emoteKeyword = " " + emoteKeyword;
}
mSendText.getText().insert(startPosition, emoteKeyword);
if (recentEmotesFragment != null) {
recentEmotesFragment.addEmote(clickedEmote);
}
}
}
boolean performLongPress(final View child,
final int longPressPosition, final long longPressId) {
// CHOICE_MODE_MULTIPLE_MODAL takes over long press.
if (mChoiceMode == AbsListView.CHOICE_MODE_MULTIPLE_MODAL) {
if (mChoiceActionMode == null) {
setItemChecked(longPressPosition, true);
child.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
return true;
}
boolean handled = false;
if (mOnItemLongClickListener != null) {
handled = mOnItemLongClickListener.onItemLongClick(this, child,
longPressPosition, longPressId);
}
if (handled) {
child.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
return handled;
}
public static void startDrag(View view){
DraggableInfo tag = (DraggableInfo) view.getTag();
if (tag == null){
tag = new DraggableInfo("Text", 0, 0, 1);
}
Intent intent = new Intent();
intent.putExtra("data", tag);
ClipData dragData = ClipData.newIntent("value", intent);
View.DragShadowBuilder myShadow = new View.DragShadowBuilder(view);
// 震动反馈,不需要震动权限
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view.startDragAndDrop(dragData, myShadow, null, 0);
}else{
view.startDrag(dragData, myShadow, null, 0);
}
}
@Override
public void onKey(final int primaryCode, final int[] keyCodes) {
final Editable editable;
final View view;
if (mIsSixDigit) {
editable = mPinEntryView.getText();
view = mPinEntryView;
} else {
editable = mPinLongText.getEditableText();
view = mPinLongText;
}
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
if (primaryCode >= 0 && primaryCode <= 9)
editable.append(String.valueOf(primaryCode));
else if (primaryCode == -2)
clear();
else if (primaryCode == -1)
view.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
}
/**
* Called from EmoteGridFragments when an Emote in the emotekeyboard has been clicked
* @param clickedEmote
*/
@Override
public void onEmoteClicked(Emote clickedEmote, View view) {
view.performHapticFeedback(VIBRATION_FEEDBACK);
if (clickedEmote != null) {
int startPosition = mSendText.getSelectionStart();
String emoteKeyword = clickedEmote.getKeyword();
if (startPosition != 0 && mSendText.getText().charAt(startPosition - 1) != ' ') {
emoteKeyword = " " + emoteKeyword;
}
mSendText.getText().insert(startPosition, emoteKeyword);
if (recentEmotesFragment != null) {
recentEmotesFragment.addEmote(clickedEmote);
}
}
}
private void growView(@NonNull View view) {
view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
view.animate()
.scaleY(1.5f)
.scaleX(1.5f)
.translationY(-selectedVerticalTranslation)
.setDuration(200)
.setInterpolator(INTERPOLATOR)
.start();
}
private void emoteButtonClicked(View clickedView) {
clickedView.performHapticFeedback(VIBRATION_FEEDBACK);
if (hasSoftKeyboardBeenShown) {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
}
if (!isEmoteKeyboardOpen) {
if (!hasSoftKeyboardBeenShown) {
Log.d(LOG_TAG, "SHOW SOFT KEYBOARD");
hideKeyboardWhenShown = true;
if (mSendText.requestFocus()) {
openSoftKeyboard();
}
}
showEmoteKeyboard();
} else {
if (isSoftKeyboardOpen) {
closeSoftKeyboard();
} else {
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
openSoftKeyboard();
}
}
}
public void performHapticFeedback(final View viewToPerformHapticFeedbackOn) {
if (!mSettingsValues.mVibrateOn) {
return;
}
if (mSettingsValues.mKeypressVibrationDuration >= 0) {
vibrate(mSettingsValues.mKeypressVibrationDuration);
return;
}
// Go ahead with the system default
if (viewToPerformHapticFeedbackOn != null) {
viewToPerformHapticFeedbackOn.performHapticFeedback(
HapticFeedbackConstants.KEYBOARD_TAP,
HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
}
@Override
boolean performItemLongClick(RecyclerView parent, View view, int position, long id) {
if (mItemLongClickListener != null) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return mItemLongClickListener.onItemLongClick(parent, view, position, id);
}
return false;
}
@Override
public void onClick(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
mError.hideImmediately();
doOnClick(v);
updateDeleteButtons();
}
@Override
boolean performItemLongClick(RecyclerView parent, View view, int position, long id) {
if (mItemLongClickListener != null) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return mItemLongClickListener.onItemLongClick(parent, view, position, id);
}
return false;
}
@Override
boolean performItemLongClick(RecyclerView parent, View view, int position, long id) {
if (mItemLongClickListener != null) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return mItemLongClickListener.onItemLongClick(parent, view, position, id);
}
return false;
}
public void onClick(View sender) {
onPlay(mStartPos);
sender.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
}
public static void vibrate(Context context, View view) {
// Vibrator vibrator = (Vibrator)
// context.getSystemService(Context.VIBRATOR_SERVICE);
// vibrator.vibrate(30);
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void vibrateForDatePicker(View view) {
// Using a different haptic feedback constant
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY
/*(5) - HapticFeedbackConstants.CALENDAR_DATE*/);
}
public void onTouchDownAllAppsButton(View v) {
// Provide the same haptic feedback that the system offers for virtual
// keys.
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
}
public static void vibrate(Context context, View view) {
// Vibrator vibrator = (Vibrator)
// context.getSystemService(Context.VIBRATOR_SERVICE);
// vibrator.vibrate(30);
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}
/**
* @see #showWidget(com.achep.acdisplay.ui.components.Widget)
*/
protected void showWidget(@NonNull Widget widget, boolean animate) {
mHandler.removeMessages(MSG_SHOW_HOME_WIDGET);
mHasPinnedWidget = false;
Log.d(TAG, "showing widget " + widget);
View iconView;
if (mSelectedWidget != null) {
iconView = mSelectedWidget.getIconView();
if (iconView != null) {
iconView.setSelected(false);
}
mSelectedWidget.onViewDetached();
}
mSelectedWidget = widget;
resetSceneContainerParams();
animate &= isAnimatableAuto();
SceneCompat scene = findSceneByWidget(mSelectedWidget);
if (scene == null) scene = mSceneMainClock;
if (mCurrentScene != scene) {
goScene(scene, animate);
} else if (animate) {
final ViewGroup viewGroup = mSelectedWidget.getView();
maybeBeginDelayedTransition(viewGroup, mTransitionJit);
}
mSelectedWidget.onViewAttached();
mBackground.dispatchSetBackground(
mSelectedWidget.getBackground(),
mSelectedWidget.getBackgroundMask());
updateStatusClockVisibility(!mSelectedWidget.hasClock() && getConfig().isFullScreen());
iconView = mSelectedWidget.getIconView();
if (iconView != null) {
iconView.setSelected(true);
iconView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
}
if (!isResumed()) {
return;
}
// Start timeout on main or media widgets, and
// pause it otherwise.
if (widget.isHomeWidget()) {
mTimeout.resume();
} else {
mTimeout.setTimeoutDelayed(mTimeoutNormal, true);
mTimeout.pause();
}
}
@Override
public boolean onLongClick(View view) {
listener.onRowLongClicked(getAdapterPosition());
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
return true;
}
/**
* Event handler for the search button
*
* @param v
* The view that was clicked.
*/
public void onClickSearchButton(View v) {
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
onSearchRequested();
}