mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-02 14:27:10 +01:00
Vibrate the phone if swiping distance exceeds threshold.
This commit is contained in:
parent
98b324f190
commit
47c1069d1e
@ -6,6 +6,7 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
<uses-permission android:name="android.permission.SET_WALLPAPER" />
|
||||||
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
|
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
|
||||||
|
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
android:maxSdkVersion="22" />
|
android:maxSdkVersion="22" />
|
||||||
|
@ -10,7 +10,6 @@ import android.graphics.PorterDuff;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -511,12 +510,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
switch (post.getVoteType()) {
|
switch (post.getVoteType()) {
|
||||||
case 1:
|
case 1:
|
||||||
//Upvoted
|
//Upvoted
|
||||||
Log.i("asdasdf", "upvoted");
|
|
||||||
((PostBaseViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
((PostBaseViewHolder) holder).upvoteButton.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
((PostBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
|
((PostBaseViewHolder) holder).scoreTextView.setTextColor(mUpvotedColor);
|
||||||
break;
|
break;
|
||||||
case -1:
|
case -1:
|
||||||
Log.i("asdasdf", "downvoted");
|
|
||||||
//Downvoted
|
//Downvoted
|
||||||
((PostBaseViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
((PostBaseViewHolder) holder).downvoteButton.setColorFilter(mDownvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
((PostBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
|
((PostBaseViewHolder) holder).scoreTextView.setTextColor(mDownvotedColor);
|
||||||
@ -1527,14 +1524,12 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
|
|
||||||
if (previousVoteType != 1) {
|
if (previousVoteType != 1) {
|
||||||
//Not upvoted before
|
//Not upvoted before
|
||||||
Log.i("asdasdf", "not 1 before");
|
|
||||||
post.setVoteType(1);
|
post.setVoteType(1);
|
||||||
newVoteType = APIUtils.DIR_UPVOTE;
|
newVoteType = APIUtils.DIR_UPVOTE;
|
||||||
upvoteButton
|
upvoteButton
|
||||||
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
scoreTextView.setTextColor(mUpvotedColor);
|
scoreTextView.setTextColor(mUpvotedColor);
|
||||||
} else {
|
} else {
|
||||||
Log.i("asdasdf", "1 before");
|
|
||||||
//Upvoted before
|
//Upvoted before
|
||||||
post.setVoteType(0);
|
post.setVoteType(0);
|
||||||
newVoteType = APIUtils.DIR_UNVOTE;
|
newVoteType = APIUtils.DIR_UNVOTE;
|
||||||
@ -1548,13 +1543,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
@Override
|
@Override
|
||||||
public void onVoteThingSuccess(int position1) {
|
public void onVoteThingSuccess(int position1) {
|
||||||
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
|
if (newVoteType.equals(APIUtils.DIR_UPVOTE)) {
|
||||||
Log.i("asdasdf", "1");
|
|
||||||
post.setVoteType(1);
|
post.setVoteType(1);
|
||||||
upvoteButton
|
upvoteButton
|
||||||
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
.setColorFilter(mUpvotedColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
scoreTextView.setTextColor(mUpvotedColor);
|
scoreTextView.setTextColor(mUpvotedColor);
|
||||||
} else {
|
} else {
|
||||||
Log.i("asdasdf", "0");
|
|
||||||
post.setVoteType(0);
|
post.setVoteType(0);
|
||||||
upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
upvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||||
scoreTextView.setTextColor(mPostIconAndInfoColor);
|
scoreTextView.setTextColor(mPostIconAndInfoColor);
|
||||||
|
@ -14,6 +14,8 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.CountDownTimer;
|
import android.os.CountDownTimer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.os.VibrationEffect;
|
||||||
|
import android.os.Vibrator;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -621,11 +623,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
((ActivityToolbarInterface) activity).displaySortType();
|
((ActivityToolbarInterface) activity).displaySortType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vibrator v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
|
||||||
|
// Vibrate for 500 milliseconds
|
||||||
backgroundLeft = new ColorDrawable(customThemeWrapper.getDownvoted());
|
backgroundLeft = new ColorDrawable(customThemeWrapper.getDownvoted());
|
||||||
backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted());
|
backgroundRight = new ColorDrawable(customThemeWrapper.getUpvoted());
|
||||||
drawableLeft = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null);
|
drawableLeft = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_downward_black_24dp, null);
|
||||||
drawableRight = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null);
|
drawableRight = ResourcesCompat.getDrawable(activity.getResources(), R.drawable.ic_arrow_upward_black_24dp, null);
|
||||||
touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
|
touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
|
||||||
|
boolean exceedThreshold = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
|
||||||
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
|
||||||
@ -660,18 +666,42 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
View itemView = viewHolder.itemView;
|
View itemView = viewHolder.itemView;
|
||||||
int horizontalOffset = (int) Utils.convertDpToPixel(16, activity);
|
int horizontalOffset = (int) Utils.convertDpToPixel(16, activity);
|
||||||
if (dX > 0) {
|
if (dX > 0) {
|
||||||
if (dX > (itemView.getRight() - itemView.getLeft()) * 0.3) {
|
if (dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
|
||||||
|
if (!exceedThreshold) {
|
||||||
|
exceedThreshold = true;
|
||||||
|
if (v != null) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
v.vibrate(VibrationEffect.createOneShot(10, 175));
|
||||||
|
} else {
|
||||||
|
//deprecated in API 26
|
||||||
|
v.vibrate(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
backgroundLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
|
backgroundLeft.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
|
||||||
} else {
|
} else {
|
||||||
|
exceedThreshold = false;
|
||||||
backgroundLeft.setBounds(0, 0, 0, 0);
|
backgroundLeft.setBounds(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
drawableLeft.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableLeft.getIntrinsicWidth(), (itemView.getBottom() - itemView.getTop() - drawableLeft.getIntrinsicHeight()) / 2, itemView.getLeft() + ((int) dX) - horizontalOffset, (itemView.getBottom() - itemView.getTop() + drawableLeft.getIntrinsicHeight()) / 2);
|
drawableLeft.setBounds(itemView.getLeft() + ((int) dX) - horizontalOffset - drawableLeft.getIntrinsicWidth(), (itemView.getBottom() - itemView.getTop() - drawableLeft.getIntrinsicHeight()) / 2, itemView.getLeft() + ((int) dX) - horizontalOffset, (itemView.getBottom() - itemView.getTop() + drawableLeft.getIntrinsicHeight()) / 2);
|
||||||
backgroundLeft.draw(c);
|
backgroundLeft.draw(c);
|
||||||
drawableLeft.draw(c);
|
drawableLeft.draw(c);
|
||||||
} else if (dX < 0) {
|
} else if (dX < 0) {
|
||||||
if (-dX > (itemView.getRight() - itemView.getLeft()) * 0.3) {
|
if (-dX > (itemView.getRight() - itemView.getLeft()) * swipeActionThreshold) {
|
||||||
|
if (!exceedThreshold) {
|
||||||
|
exceedThreshold = true;
|
||||||
|
if (v != null) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
v.vibrate(VibrationEffect.createOneShot(10, 175));
|
||||||
|
} else {
|
||||||
|
//deprecated in API 26
|
||||||
|
v.vibrate(50);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
backgroundRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
|
backgroundRight.setBounds(0, itemView.getTop(), itemView.getRight(), itemView.getBottom());
|
||||||
} else {
|
} else {
|
||||||
|
exceedThreshold = false;
|
||||||
backgroundRight.setBounds(0, 0, 0, 0);
|
backgroundRight.setBounds(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
drawableRight.setBounds(itemView.getRight() + ((int) dX) + horizontalOffset, (itemView.getBottom() - itemView.getTop() - drawableRight.getIntrinsicHeight()) / 2, itemView.getRight() + ((int) dX) + horizontalOffset + drawableRight.getIntrinsicWidth(), (itemView.getBottom() - itemView.getTop() + drawableRight.getIntrinsicHeight()) / 2);
|
drawableRight.setBounds(itemView.getRight() + ((int) dX) + horizontalOffset, (itemView.getBottom() - itemView.getTop() - drawableRight.getIntrinsicHeight()) / 2, itemView.getRight() + ((int) dX) + horizontalOffset + drawableRight.getIntrinsicWidth(), (itemView.getBottom() - itemView.getTop() + drawableRight.getIntrinsicHeight()) / 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user