Haptic effect on swiping the notification item
Haptic once the swiping on the notification item is going to snap in either directions. The snap-in scenario is about the notification item when there is a "snap back point" i.e. if swiping the item back till a certain point it just snaps back to initial state but once it goes past a certain location it snaps into the new location. - screenshot, https://screenshot.googleplex.com/6A8Gxs7yRwqAVk2 Bug: 175364588 Test: manual Change-Id: I7e2ed19bfb7f863502e10233e3e23ee5d434b3b4
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package com.android.settings.notification.history;
|
||||
|
||||
import static android.view.HapticFeedbackConstants.CLOCK_TICK;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -15,6 +20,9 @@ public class NotificationHistoryRecyclerView extends RecyclerView {
|
||||
|
||||
private OnItemSwipeDeleteListener listener;
|
||||
|
||||
/** The amount of horizontal displacement caused by user's action, used to track the swiping. */
|
||||
private float dXLast;
|
||||
|
||||
public NotificationHistoryRecyclerView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
@@ -57,6 +65,27 @@ public class NotificationHistoryRecyclerView extends RecyclerView {
|
||||
listener.onItemSwipeDeleted(viewHolder.getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
/** Performs haptic effect once the swiping goes past a certain location. */
|
||||
@Override
|
||||
public void onChildDraw(@NonNull Canvas c, @NonNull RecyclerView recyclerView,
|
||||
@NonNull ViewHolder viewHolder, float dX, float dY, int actionState,
|
||||
boolean isCurrentlyActive) {
|
||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||
if (isCurrentlyActive) {
|
||||
View view = viewHolder.itemView;
|
||||
float swipeThreshold = getSwipeThreshold(viewHolder);
|
||||
float snapOffset = swipeThreshold * view.getWidth();
|
||||
boolean snapIntoNewLocation = dX < -snapOffset || dX > snapOffset;
|
||||
boolean snapIntoNewLocationLast = dXLast < -snapOffset || dXLast > snapOffset;
|
||||
if (snapIntoNewLocation != snapIntoNewLocationLast) {
|
||||
view.performHapticFeedback(CLOCK_TICK);
|
||||
}
|
||||
dXLast = dX;
|
||||
} else {
|
||||
dXLast = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnItemSwipeDeleteListener {
|
||||
|
Reference in New Issue
Block a user