Skip to content

Commit

Permalink
Use View.peformHapticFeedback() instead of Vibrator.vibrate() for lis…
Browse files Browse the repository at this point in the history
…t item long press and checklist long presses so it is enabled/disabled as per device settings. Remove an unused field in FlingDetector. #191 (#660)
  • Loading branch information
Gabor Keszthelyi authored and dmfs committed Feb 5, 2018
1 parent 77b29b0 commit 33cc886
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ of this software and associated documentation files (the "Software"), to deal
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.v4.view.MotionEventCompat;
import android.util.AttributeSet;
import android.util.Log;
import android.util.SparseArray;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
Expand Down Expand Up @@ -495,15 +495,7 @@ private void startDrag()
draggedItem.onDragStart();
requestDisallowInterceptTouchEvent(true);

try
{
Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATION_DURATION);
}
catch (Exception e)
{

}
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
}


Expand Down
3 changes: 1 addition & 2 deletions opentasks/src/main/java/org/dmfs/tasks/TaskListFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
mExpandableListView.expandGroups(mSavedExpandedGroups);
}

FlingDetector swiper = new FlingDetector(mExpandableListView, mGroupDescriptor.getElementViewDescriptor().getFlingContentViewId(),
getActivity().getApplicationContext());
FlingDetector swiper = new FlingDetector(mExpandableListView, mGroupDescriptor.getElementViewDescriptor().getFlingContentViewId());
swiper.setOnFlingListener(this);

return rootView;
Expand Down
12 changes: 4 additions & 8 deletions opentasks/src/main/java/org/dmfs/tasks/utils/FlingDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Rect;
import android.os.Handler;
import android.os.Vibrator;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
Expand Down Expand Up @@ -57,7 +56,6 @@ public class FlingDetector implements OnTouchListener, OnScrollListener
private View mItemChildView;
private VelocityTracker mVelocityTracker;
private int mContentViewId;
private static Context mContext;
private static Handler mHandler;

private int mFlingDirection;
Expand All @@ -68,8 +66,7 @@ public class FlingDetector implements OnTouchListener, OnScrollListener
@Override
public void run()
{
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATION_DURATION);
mListView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);

// if we don't disallow that, fling doesn't work on some devices
mListView.requestDisallowInterceptTouchEvent(true);
Expand Down Expand Up @@ -165,7 +162,7 @@ public interface OnFlingListener
*/
public FlingDetector(ListView listview)
{
this(listview, -1, null);
this(listview, -1);
}


Expand All @@ -177,13 +174,12 @@ public FlingDetector(ListView listview)
* @param flingContentViewId
* The layout id of the inner content view that is supposed to fling
*/
public FlingDetector(ListView listview, int flingContentViewId, Context context)
public FlingDetector(ListView listview, int flingContentViewId)
{
listview.setOnTouchListener(this);
listview.setOnScrollListener(this);
mListView = listview;
mContentViewId = flingContentViewId;
mContext = context;

ViewConfiguration vc = ViewConfiguration.get(listview.getContext());

Expand Down

0 comments on commit 33cc886

Please sign in to comment.