Java Code Examples for android.view.HapticFeedbackConstants

The following examples show how to use android.view.HapticFeedbackConstants. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: BigApp_Discuz_Android   Source File: HorizontalListView.java    License: Apache License 2.0 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example 2
Source Project: android_9.0.0_r45   Source File: Gallery.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source Project: CodeEditor   Source File: TouchNavigationMethod.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 4
Source Project: Twire   Source File: ChatAdapter.java    License: GNU General Public License v3.0 6 votes vote down vote up
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);
    }
}
 
Example 5
Source Project: ticdesign   Source File: TrackSelectionAdapterWrapper.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 6
Source Project: TelePlus-Android   Source File: EntityView.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example 7
@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;
  }
}
 
Example 8
Source Project: RemoteControlView   Source File: Tools.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 9
Source Project: samples   Source File: EcoGallery.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 10
Source Project: CodeEditor   Source File: TouchNavigationMethod.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 11
Source Project: TelePlus-Android   Source File: EntityView.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
            }
        }
    });
}
 
Example 12
@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;
}
 
Example 13
Source Project: RxZhihuDaily   Source File: HorizontalListView.java    License: MIT License 6 votes vote down vote up
@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);
            }
        }
    }
}
 
Example 14
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);
	}
}
 
Example 15
Source Project: Status   Source File: CabbageContributorsWedge.java    License: Apache License 2.0 6 votes vote down vote up
@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;
    });
}
 
Example 16
Source Project: FloatingSearchView   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 17
Source Project: prayer-times-android   Source File: AlarmConfigFragment.java    License: Apache License 2.0 6 votes vote down vote up
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;
        });

}
 
Example 18
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();
}
 
Example 19
@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;
  }
}
 
Example 20
Source Project: android_9.0.0_r45   Source File: Gallery.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 21
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);
    }
}
 
Example 22
Source Project: TelePlus-Android   Source File: BaseCell.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
    }
}
 
Example 23
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();
    }
}
 
Example 24
Source Project: TelePlus-Android   Source File: EmojiView.java    License: GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 25
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();
    }
}
 
Example 26
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);
    }
}
 
Example 27
Source Project: DongWeather   Source File: DragSortController.java    License: Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 28
Source Project: onpc   Source File: DragSortController.java    License: GNU General Public License v3.0 5 votes vote down vote up
@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);
    }
}
 
Example 29
Source Project: UltimateSwipeTool   Source File: SwipeViewLayout.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 30
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();
    }
}