类android.view.HapticFeedbackConstants源码实例Demo

下面列出了怎么用android.view.HapticFeedbackConstants的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public void onLongPress(MotionEvent e) {
    unpressTouchedChild();

    final int index = getChildIndex((int) e.getX(), (int) e.getY());
    if (index >= 0 && !mBlockTouchAction) {
        View child = getChildAt(index);
        OnItemLongClickListener onItemLongClickListener = getOnItemLongClickListener();
        if (onItemLongClickListener != null) {
            int adapterIndex = mLeftViewAdapterIndex + index;
            boolean handled = onItemLongClickListener.onItemLongClick(HorizontalListView.this, child, adapterIndex, mAdapter
                    .getItemId(adapterIndex));

            if (handled) {
                // BZZZTT!!1!
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
    }
}
 
源代码2 项目: android_9.0.0_r45   文件: Gallery.java
private boolean dispatchLongPress(View view, int position, long id, float x, float y,
        boolean useOffsets) {
    boolean handled = false;
    
    if (mOnItemLongClickListener != null) {
        handled = mOnItemLongClickListener.onItemLongClick(this, mDownTouchView,
                mDownTouchPosition, id);
    }

    if (!handled) {
        mContextMenuInfo = new AdapterContextMenuInfo(view, position, id);

        if (useOffsets) {
            handled = super.showContextMenuForChild(view, x, y);
        } else {
            handled = super.showContextMenuForChild(this);
        }
    }

    if (handled) {
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }
    
    return handled;
}
 
源代码3 项目: CodeEditor   文件: TouchNavigationMethod.java
@Override
public boolean onDown(MotionEvent e) {
    int x = screenToViewX((int) e.getX());
    int y = screenToViewY((int) e.getY());
    _isCaretTouched = isNearChar(x, y, _textField.getCaretPosition());

    if (_textField.isFlingScrolling()) {
        _textField.stopFlingScrolling();
    } else if (_textField.isSelectText()) {
        if (isNearChar(x, y, _textField.getSelectionStart())) {
            _textField.focusSelectionStart();
            _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            _isCaretTouched = true;
        } else if (isNearChar(x, y, _textField.getSelectionEnd())) {
            _textField.focusSelectionEnd();
            _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            _isCaretTouched = true;
        }
    }

    if (_isCaretTouched) {
        _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }

    return true;
}
 
源代码4 项目: Twire   文件: ChatAdapter.java
private void checkForLink(String message, SpannableStringBuilder spanbuilder) {
    Matcher linkMatcher = Patterns.WEB_URL.matcher(message);
    while (linkMatcher.find()) {
        String url = linkMatcher.group(0);

        if (!url.matches("^https?://.+"))
            url = "http://" + url;

        final String finalUrl = url;
        ClickableSpan clickableSpan = new ClickableSpan() {
            @Override
            public void onClick(View view) {
                CustomTabsIntent.Builder mTabs = new CustomTabsIntent.Builder();
                mTabs.setStartAnimations(context, R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
                mTabs.setExitAnimations(context, R.anim.fade_in_semi_anim, R.anim.slide_out_bottom_anim);
                mTabs.build().launchUrl(context, Uri.parse(finalUrl));

                mRecyclerView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
            }
        };

        spanbuilder.setSpan(clickableSpan, linkMatcher.start(), linkMatcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
源代码5 项目: ticdesign   文件: TrackSelectionAdapterWrapper.java
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;
}
 
源代码6 项目: TelePlus-Android   文件: EntityView.java
public EntityView(Context context, Point pos) {
    super(context);

    uuid = UUID.randomUUID();
    position = pos;

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {
            if (hasPanned || hasTransformed || hasReleased) {
                return;
            }

            recognizedLongPress = true;
            if (delegate != null) {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                delegate.onEntityLongClicked(EntityView.this);
            }
        }
    });
}
 
源代码7 项目: deltachat-android   文件: RepeatableImageKey.java
@TargetApi(VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
  switch (motionEvent.getAction()) {
  case MotionEvent.ACTION_DOWN:
    view.postDelayed(repeater, VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB_MR1
                               ? ViewConfiguration.getKeyRepeatTimeout()
                               : ViewConfiguration.getLongPressTimeout());
    performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
    return false;
  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    view.removeCallbacks(repeater);
    return false;
  default:
    return false;
  }
}
 
源代码8 项目: RemoteControlView   文件: Tools.java
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);
    }
}
 
源代码9 项目: samples   文件: EcoGallery.java
private boolean dispatchLongPress(View view, int position, long id) {
    boolean handled = false;

    if (mOnItemLongClickListener != null) {
        handled = mOnItemLongClickListener.onItemLongClick(this, mDownTouchView, mDownTouchPosition, id);
    }

    if (!handled) {
        mContextMenuInfo = new AdapterContextMenuInfo(view, position, id);
        handled = super.showContextMenuForChild(this);
    }

    if (handled) {
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }

    return handled;
}
 
源代码10 项目: CodeEditor   文件: TouchNavigationMethod.java
@Override
public boolean onDown(MotionEvent e) {
    int x = screenToViewX((int) e.getX());
    int y = screenToViewY((int) e.getY());
    _isCaretTouched = isNearChar(x, y, _textField.getCaretPosition());

    if (_textField.isFlingScrolling()) {
        _textField.stopFlingScrolling();
    } else if (_textField.isSelectText()) {
        if (isNearChar(x, y, _textField.getSelectionStart())) {
            _textField.focusSelectionStart();
            _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            _isCaretTouched = true;
        } else if (isNearChar(x, y, _textField.getSelectionEnd())) {
            _textField.focusSelectionEnd();
            _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            _isCaretTouched = true;
        }
    }

    if (_isCaretTouched) {
        _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }

    return true;
}
 
源代码11 项目: TelePlus-Android   文件: EntityView.java
public EntityView(Context context, Point pos) {
    super(context);

    uuid = UUID.randomUUID();
    position = pos;

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        public void onLongPress(MotionEvent e) {
            if (hasPanned || hasTransformed || hasReleased) {
                return;
            }

            recognizedLongPress = true;
            if (delegate != null) {
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
                delegate.onEntityLongClicked(EntityView.this);
            }
        }
    });
}
 
源代码12 项目: lua-for-android   文件: TouchNavigationMethod.java
@Override
public boolean onDown(MotionEvent e) {
    int x = screenToViewX((int) e.getX());
    int y = screenToViewY((int) e.getY());
    _isCaretTouched = isNearChar(x, y, _textField.getCaretPosition());

    if (_textField.isFlingScrolling()) {
        _textField.stopFlingScrolling();
    } else if (_textField.isSelectText()) {
        if (isNearChar(x, y, _textField.getSelectionStart())) {
            _textField.focusSelectionStart();
            _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            _isCaretTouched = true;
        } else if (isNearChar(x, y, _textField.getSelectionEnd())) {
            _textField.focusSelectionEnd();
            _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            _isCaretTouched = true;
        }
    }

    if (_isCaretTouched) {
        _textField.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    }

    return true;
}
 
源代码13 项目: RxZhihuDaily   文件: HorizontalListView.java
@Override
public void onLongPress(MotionEvent e) {
    unpressTouchedChild();

    final int index = getChildIndex((int) e.getX(), (int) e.getY());
    if (index >= 0 && !mBlockTouchAction) {
        View child = getChildAt(index);
        OnItemLongClickListener onItemLongClickListener = getOnItemLongClickListener();
        if (onItemLongClickListener != null) {
            int adapterIndex = mLeftViewAdapterIndex + index;
            boolean handled = onItemLongClickListener.onItemLongClick(HorizontalListView.this, child, adapterIndex, mAdapter
                    .getItemId(adapterIndex));

            if (handled) {
                // BZZZTT!!1!
                performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
    }
}
 
源代码14 项目: Pocket-Plays-for-Twitch   文件: ChatAdapter.java
private void checkForLink(String message, SpannableStringBuilder spanbuilder) {
	linkMatcher = linkPattern.matcher(message);
	while(linkMatcher.find()) {
		final String url = linkMatcher.group(1);

		ClickableSpan clickableSpan = new ClickableSpan() {
			@Override
			public void onClick(View view) {
				CustomTabsIntent.Builder mTabs = new CustomTabsIntent.Builder();
				mTabs.setStartAnimations(context, R.anim.slide_in_bottom_anim, R.anim.fade_out_semi_anim);
				mTabs.setExitAnimations(context, R.anim.fade_in_semi_anim, R.anim.slide_out_bottom_anim);
				mTabs.build().launchUrl(context, Uri.parse(url));

				mRecyclerView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
			}
		};

		int start = message.indexOf(url);
		spanbuilder.setSpan(clickableSpan, start, start + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
	}
}
 
源代码15 项目: Status   文件: CabbageContributorsWedge.java
@Override
public void bind(Context context, final ViewHolder viewHolder) {
    super.bind(context, viewHolder);
    viewHolder.itemView.findViewById(R.id.first).setOnLongClickListener(v -> {
        v.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        Glide.with(v.getContext()).load(CABBAGE_URL).into(new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                ImageView imageView = viewHolder.itemView.findViewById(R.id.firstImage);
                if (imageView != null)
                    imageView.setImageDrawable(resource);
            }
        });

        return false;
    });
}
 
源代码16 项目: FloatingSearchView   文件: MainActivity.java
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_clear:
            mSearchView.setText(null);
            mSearchView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
            break;
        case R.id.menu_toggle_icon:
            item.setChecked(!item.isChecked());
            mSearchView.showIcon(item.isChecked());
            break;
        case R.id.menu_tts:
            PackageUtils.startTextToSpeech(this, getString(R.string.speech_prompt), REQ_CODE_SPEECH_INPUT);
            break;
        case R.id.menu_icon_search:
        case R.id.menu_icon_drawer:
        case R.id.menu_icon_custom:
            updateNavigationIcon(item.getItemId());
            Toast.makeText(MainActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
            break;
    }
    return true;
}
 
源代码17 项目: prayer-times-android   文件: AlarmConfigFragment.java
private void initDelete() {
    mDelete.setOnClickListener(v -> new AlertDialog.Builder(getActivity())
            .setTitle(mTimes.getName())
            .setMessage(getString(R.string.delAlarmConfirm, mAlarm.getTitle()))
            .setNegativeButton(R.string.no, (dialog, which) -> dialog.dismiss())
            .setPositiveButton(R.string.yes, (dialog, which) -> {
                mTimes.getUserAlarms().remove(mAlarm);
                dismiss();
            }).show());

    if (BuildConfig.DEBUG)
        mDelete.setOnLongClickListener(v -> {
            getActivity().getWindow().getDecorView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
            AlarmService.setAlarm(getActivity(), new Pair<>(mAlarm, LocalDateTime.now().plusSeconds(5)));
            return true;
        });

}
 
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();
}
 
源代码19 项目: mollyim-android   文件: RepeatableImageKey.java
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
  switch (motionEvent.getAction()) {
  case MotionEvent.ACTION_DOWN:
    view.postDelayed(repeater, ViewConfiguration.getKeyRepeatTimeout());
    performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
    return false;
  case MotionEvent.ACTION_CANCEL:
  case MotionEvent.ACTION_UP:
    view.removeCallbacks(repeater);
    return false;
  default:
    return false;
  }
}
 
源代码20 项目: android_9.0.0_r45   文件: Gallery.java
@Override
public void onLongPress(@NonNull MotionEvent e) {
    if (mDownTouchPosition < 0) {
        return;
    }
    
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);

    final long id = getItemIdAtPosition(mDownTouchPosition);
    dispatchLongPress(mDownTouchView, mDownTouchPosition, id, e.getX(), e.getY(), true);
}
 
源代码21 项目: openboard   文件: AudioAndHapticFeedbackManager.java
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);
    }
}
 
源代码22 项目: TelePlus-Android   文件: BaseCell.java
public void run() {
    if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
        checkingForLongPress = false;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        onLongPress();
        MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
        onTouchEvent(event);
        event.recycle();
    }
}
 
源代码23 项目: TelePlus-Android   文件: SharedLinkCell.java
public void run() {
    if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
        checkingForLongPress = false;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        if (pressedLink >= 0) {
            delegate.onLinkLongPress(links.get(pressedLink));
        }
        MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
        onTouchEvent(event);
        event.recycle();
    }
}
 
源代码24 项目: TelePlus-Android   文件: EmojiView.java
private void postBackspaceRunnable(final int time) {
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            if (!backspacePressed) {
                return;
            }
            if (listener != null && listener.onBackspace()) {
                backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
            }
            backspaceOnce = true;
            postBackspaceRunnable(Math.max(50, time - 100));
        }
    }, time);
}
 
源代码25 项目: TelePlus-Android   文件: ChatAttachAlert.java
public void run() {
    if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
        checkingForLongPress = false;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        onLongPress();
        MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
        onTouchEvent(event);
        event.recycle();
    }
}
 
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);
    }
}
 
源代码27 项目: DongWeather   文件: DragSortController.java
@Override
public void onLongPress(MotionEvent e) {
    // Log.d("mobeta", "lift listener long pressed");
    if (mHitPos != MISS && mDragInitMode == ON_LONG_PRESS) {
        mDslv.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        startDrag(mHitPos, mCurrX - mItemX, mCurrY - mItemY);
    }
}
 
源代码28 项目: onpc   文件: DragSortController.java
@Override
public void onLongPress(MotionEvent e)
{
    // Log.d("mobeta", "lift listener long pressed");
    if (mHitPos != MISS && mDragInitMode == ON_LONG_PRESS)
    {
        mDslv.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        startDrag(mHitPos, mCurrX - mItemX, mCurrY - mItemY);
    }
}
 
源代码29 项目: UltimateSwipeTool   文件: SwipeViewLayout.java
private boolean performAdapterViewItemLongClick() {
    if (getOpenStatus() != Status.Close) return false;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeViewLayout.this);
        if (p == AdapterView.INVALID_POSITION) return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeViewLayout.this, p, vId);

        } catch (Exception e) {
            e.printStackTrace();

            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeViewLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
 
源代码30 项目: TelePlus-Android   文件: SharedLinkCell.java
public void run() {
    if (checkingForLongPress && getParent() != null && currentPressCount == pressCount) {
        checkingForLongPress = false;
        performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
        if (pressedLink >= 0) {
            delegate.onLinkLongPress(links.get(pressedLink));
        }
        MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_CANCEL, 0, 0, 0);
        onTouchEvent(event);
        event.recycle();
    }
}
 
 类所在包
 类方法
 同包方法