Skip to content

Commit

Permalink
Switching from blink to ripple
Browse files Browse the repository at this point in the history
  • Loading branch information
harshad1 committed Jun 5, 2024
1 parent ddfdbb2 commit f0506b4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ private void showAndFlash(final File file) {
_recyclerView.postDelayed(() -> {
final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
if (holder != null) {
GsContextUtils.blinkView(holder.itemView);
GsContextUtils.rippleView(holder.itemView);
}
}, 100);
}
Expand All @@ -621,7 +621,7 @@ public int getFilePosition(final File file) {
private void stopBlinking() {
if (_recyclerView != null) {
for (int i = 0; i < _recyclerView.getChildCount(); i++) {
GsContextUtils.stopBlinking(_recyclerView.getChildAt(i));
GsContextUtils.stopRipple(_recyclerView.getChildAt(i));
}
}
}
Expand Down
26 changes: 21 additions & 5 deletions app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.graphics.drawable.VectorDrawable;
import android.media.MediaMetadataRetriever;
import android.media.MediaScannerConnection;
Expand Down Expand Up @@ -2881,11 +2882,6 @@ public boolean isDarkModeEnabled(final Context context) {
return false;
}

/**
* Blinks the view passed in as parameter
*
* @param view View to be blinked
*/
public static void blinkView(final View view) {

if (view == null) {
Expand Down Expand Up @@ -2927,6 +2923,26 @@ public static void stopBlinking(final View view) {

}

public static void rippleView(final View view) {
if (view != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final Drawable drawable = view.getForeground();
if (drawable instanceof RippleDrawable) {
drawable.setState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled});
view.postDelayed(() -> drawable.setState(new int[]{}), 250);
}
}
}

public static void stopRipple(final View view) {
if (view != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Drawable drawable = view.getForeground();
if (drawable instanceof RippleDrawable) {
drawable.setState(new int[]{});
drawable.jumpToCurrentState();
}
}
}

public static boolean fadeInOut(final View in, final View out, final boolean animate) {
// Do nothing if we are already in the correct state
if (in.getVisibility() == View.VISIBLE && out.getVisibility() == View.GONE) {
Expand Down

0 comments on commit f0506b4

Please sign in to comment.