@Test public void testLongPress_SelectsItem() { mSelectionPredicate.setReturnValue(true); mDetailsLookup.initAt(7); mInputDelegate.onLongPress(TAP); mSelection.assertSelection(7); }
@Override public void onLongPress(@NonNull MotionEvent e) { if (!mDetailsLookup.overItemWithSelectionKey(e)) { if (DEBUG) Log.d(TAG, "Ignoring LongPress on non-model-backed item."); return; } ItemDetails<K> item = mDetailsLookup.getItemDetails(e); if (item == null) { return; } boolean handled = false; if (isRangeExtension(e)) { extendSelectionRange(item); handled = true; } else { if (!mSelectionTracker.isSelected(item.getSelectionKey()) && mSelectionPredicate.canSetStateForKey(item.getSelectionKey(), true)) { if (selectItem(item)) { if (mSelectionPredicate.canSelectMultiple()) { mGestureStarter.run(); } handled = true; } } else { mOnDragInitiatedListener.onDragInitiated(e); handled = true; } } if (handled) { mHapticPerformer.run(); } }
TouchInputHandler extends MotionInputHandler<K> { @Override public void onLongPress(@NonNull MotionEvent e) { if (!mDetailsLookup.overItemWithSelectionKey(e)) { if (DEBUG) Log.d(TAG, "Ignoring LongPress on non-model-backed item."); return; } ItemDetails<K> item = mDetailsLookup.getItemDetails(e); if (item == null) { return; } boolean handled = false; if (isRangeExtension(e)) { extendSelectionRange(item); handled = true; } else { if (!mSelectionTracker.isSelected(item.getSelectionKey()) && mSelectionPredicate.canSetStateForKey(item.getSelectionKey(), true)) { if (selectItem(item)) { if (mSelectionPredicate.canSelectMultiple()) { mGestureStarter.run(); } handled = true; } } else { mOnDragInitiatedListener.onDragInitiated(e); handled = true; } } if (handled) { mHapticPerformer.run(); } } }
TouchInputHandler extends MotionInputHandler<K> { @Override public void onLongPress(@NonNull MotionEvent e) { if (!mDetailsLookup.overItemWithSelectionKey(e)) { if (DEBUG) Log.d(TAG, "Ignoring LongPress on non-model-backed item."); return; } ItemDetails<K> item = mDetailsLookup.getItemDetails(e); if (item == null) { return; } boolean handled = false; if (isRangeExtension(e)) { extendSelectionRange(item); handled = true; } else { if (!mSelectionTracker.isSelected(item.getSelectionKey()) && mSelectionPredicate.canSetStateForKey(item.getSelectionKey(), true)) { if (selectItem(item)) { if (mSelectionPredicate.canSelectMultiple()) { mGestureStarter.run(); } handled = true; } } else { mOnDragInitiatedListener.onDragInitiated(e); handled = true; } } if (handled) { mHapticPerformer.run(); } } TouchInputHandler(
            @NonNull SelectionTracker<K> selectionTracker,
            @NonNull ItemKeyProvider<K> keyProvider,
            @NonNull ItemDetailsLookup<K> detailsLookup,
            @NonNull SelectionPredicate<K> selectionPredicate,
            @NonNull Runnable gestureStarter,
            @NonNull OnDragInitiatedListener onDragInitiatedListener,
            @NonNull OnItemActivatedListener<K> onItemActivatedListener,
            @NonNull FocusDelegate<K> focusDelegate,
            @NonNull Runnable hapticPerformer); }
TouchInputHandler extends MotionInputHandler<K> { @Override public void onLongPress(@NonNull MotionEvent e) { if (!mDetailsLookup.overItemWithSelectionKey(e)) { if (DEBUG) Log.d(TAG, "Ignoring LongPress on non-model-backed item."); return; } ItemDetails<K> item = mDetailsLookup.getItemDetails(e); if (item == null) { return; } boolean handled = false; if (isRangeExtension(e)) { extendSelectionRange(item); handled = true; } else { if (!mSelectionTracker.isSelected(item.getSelectionKey()) && mSelectionPredicate.canSetStateForKey(item.getSelectionKey(), true)) { if (selectItem(item)) { if (mSelectionPredicate.canSelectMultiple()) { mGestureStarter.run(); } handled = true; } } else { mOnDragInitiatedListener.onDragInitiated(e); handled = true; } } if (handled) { mHapticPerformer.run(); } } TouchInputHandler(
            @NonNull SelectionTracker<K> selectionTracker,
            @NonNull ItemKeyProvider<K> keyProvider,
            @NonNull ItemDetailsLookup<K> detailsLookup,
            @NonNull SelectionPredicate<K> selectionPredicate,
            @NonNull Runnable gestureStarter,
            @NonNull OnDragInitiatedListener onDragInitiatedListener,
            @NonNull OnItemActivatedListener<K> onItemActivatedListener,
            @NonNull FocusDelegate<K> focusDelegate,
            @NonNull Runnable hapticPerformer); @Override boolean onSingleTapUp(@NonNull MotionEvent e); @Override void onLongPress(@NonNull MotionEvent e); }
TouchInputHandler extends MotionInputHandler<K> { @Override public void onLongPress(@NonNull MotionEvent e) { if (!mDetailsLookup.overItemWithSelectionKey(e)) { if (DEBUG) Log.d(TAG, "Ignoring LongPress on non-model-backed item."); return; } ItemDetails<K> item = mDetailsLookup.getItemDetails(e); if (item == null) { return; } boolean handled = false; if (isRangeExtension(e)) { extendSelectionRange(item); handled = true; } else { if (!mSelectionTracker.isSelected(item.getSelectionKey()) && mSelectionPredicate.canSetStateForKey(item.getSelectionKey(), true)) { if (selectItem(item)) { if (mSelectionPredicate.canSelectMultiple()) { mGestureStarter.run(); } handled = true; } } else { mOnDragInitiatedListener.onDragInitiated(e); handled = true; } } if (handled) { mHapticPerformer.run(); } } TouchInputHandler(
            @NonNull SelectionTracker<K> selectionTracker,
            @NonNull ItemKeyProvider<K> keyProvider,
            @NonNull ItemDetailsLookup<K> detailsLookup,
            @NonNull SelectionPredicate<K> selectionPredicate,
            @NonNull Runnable gestureStarter,
            @NonNull OnDragInitiatedListener onDragInitiatedListener,
            @NonNull OnItemActivatedListener<K> onItemActivatedListener,
            @NonNull FocusDelegate<K> focusDelegate,
            @NonNull Runnable hapticPerformer); @Override boolean onSingleTapUp(@NonNull MotionEvent e); @Override void onLongPress(@NonNull MotionEvent e);  }