diff options
| author | 2023-03-08 16:14:24 -0500 | |
|---|---|---|
| committer | 2023-06-03 00:05:39 -0700 | |
| commit | 096cdc57bb0e78beae485a3283bc1dcd26d17bad (patch) | |
| tree | 9c1083c58c3d6b3fa62d40db7a3a9cf6730e741d /src/android | |
| parent | android: Inherit from Material 3 themes (diff) | |
| download | yuzu-096cdc57bb0e78beae485a3283bc1dcd26d17bad.tar.gz yuzu-096cdc57bb0e78beae485a3283bc1dcd26d17bad.tar.xz yuzu-096cdc57bb0e78beae485a3283bc1dcd26d17bad.zip | |
android: Remove DividerItemDecoration
Removed in favor of material components version
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/DividerItemDecoration.java | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/DividerItemDecoration.java b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/DividerItemDecoration.java deleted file mode 100644 index f725382e6..000000000 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/DividerItemDecoration.java +++ /dev/null | |||
| @@ -1,130 +0,0 @@ | |||
| 1 | package org.yuzu.yuzu_emu.ui; | ||
| 2 | |||
| 3 | import android.content.Context; | ||
| 4 | import android.content.res.TypedArray; | ||
| 5 | import android.graphics.Canvas; | ||
| 6 | import android.graphics.Rect; | ||
| 7 | import android.graphics.drawable.Drawable; | ||
| 8 | import android.util.AttributeSet; | ||
| 9 | import android.view.View; | ||
| 10 | |||
| 11 | import androidx.annotation.NonNull; | ||
| 12 | import androidx.recyclerview.widget.LinearLayoutManager; | ||
| 13 | import androidx.recyclerview.widget.RecyclerView; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Implementation from: | ||
| 17 | * https://gist.github.com/lapastillaroja/858caf1a82791b6c1a36 | ||
| 18 | */ | ||
| 19 | public class DividerItemDecoration extends RecyclerView.ItemDecoration { | ||
| 20 | |||
| 21 | private Drawable mDivider; | ||
| 22 | private boolean mShowFirstDivider = false; | ||
| 23 | private boolean mShowLastDivider = false; | ||
| 24 | |||
| 25 | public DividerItemDecoration(Context context, AttributeSet attrs) { | ||
| 26 | final TypedArray a = context | ||
| 27 | .obtainStyledAttributes(attrs, new int[]{android.R.attr.listDivider}); | ||
| 28 | mDivider = a.getDrawable(0); | ||
| 29 | a.recycle(); | ||
| 30 | } | ||
| 31 | |||
| 32 | public DividerItemDecoration(Context context, AttributeSet attrs, boolean showFirstDivider, | ||
| 33 | boolean showLastDivider) { | ||
| 34 | this(context, attrs); | ||
| 35 | mShowFirstDivider = showFirstDivider; | ||
| 36 | mShowLastDivider = showLastDivider; | ||
| 37 | } | ||
| 38 | |||
| 39 | public DividerItemDecoration(Drawable divider) { | ||
| 40 | mDivider = divider; | ||
| 41 | } | ||
| 42 | |||
| 43 | public DividerItemDecoration(Drawable divider, boolean showFirstDivider, | ||
| 44 | boolean showLastDivider) { | ||
| 45 | this(divider); | ||
| 46 | mShowFirstDivider = showFirstDivider; | ||
| 47 | mShowLastDivider = showLastDivider; | ||
| 48 | } | ||
| 49 | |||
| 50 | @Override | ||
| 51 | public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, | ||
| 52 | @NonNull RecyclerView.State state) { | ||
| 53 | super.getItemOffsets(outRect, view, parent, state); | ||
| 54 | if (mDivider == null) { | ||
| 55 | return; | ||
| 56 | } | ||
| 57 | if (parent.getChildAdapterPosition(view) < 1) { | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | |||
| 61 | if (getOrientation(parent) == LinearLayoutManager.VERTICAL) { | ||
| 62 | outRect.top = mDivider.getIntrinsicHeight(); | ||
| 63 | } else { | ||
| 64 | outRect.left = mDivider.getIntrinsicWidth(); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | @Override | ||
| 69 | public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { | ||
| 70 | if (mDivider == null) { | ||
| 71 | super.onDrawOver(c, parent, state); | ||
| 72 | return; | ||
| 73 | } | ||
| 74 | |||
| 75 | // Initialization needed to avoid compiler warning | ||
| 76 | int left = 0, right = 0, top = 0, bottom = 0, size; | ||
| 77 | int orientation = getOrientation(parent); | ||
| 78 | int childCount = parent.getChildCount(); | ||
| 79 | |||
| 80 | if (orientation == LinearLayoutManager.VERTICAL) { | ||
| 81 | size = mDivider.getIntrinsicHeight(); | ||
| 82 | left = parent.getPaddingLeft(); | ||
| 83 | right = parent.getWidth() - parent.getPaddingRight(); | ||
| 84 | } else { //horizontal | ||
| 85 | size = mDivider.getIntrinsicWidth(); | ||
| 86 | top = parent.getPaddingTop(); | ||
| 87 | bottom = parent.getHeight() - parent.getPaddingBottom(); | ||
| 88 | } | ||
| 89 | |||
| 90 | for (int i = mShowFirstDivider ? 0 : 1; i < childCount; i++) { | ||
| 91 | View child = parent.getChildAt(i); | ||
| 92 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); | ||
| 93 | |||
| 94 | if (orientation == LinearLayoutManager.VERTICAL) { | ||
| 95 | top = child.getTop() - params.topMargin; | ||
| 96 | bottom = top + size; | ||
| 97 | } else { //horizontal | ||
| 98 | left = child.getLeft() - params.leftMargin; | ||
| 99 | right = left + size; | ||
| 100 | } | ||
| 101 | mDivider.setBounds(left, top, right, bottom); | ||
| 102 | mDivider.draw(c); | ||
| 103 | } | ||
| 104 | |||
| 105 | // show last divider | ||
| 106 | if (mShowLastDivider && childCount > 0) { | ||
| 107 | View child = parent.getChildAt(childCount - 1); | ||
| 108 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); | ||
| 109 | if (orientation == LinearLayoutManager.VERTICAL) { | ||
| 110 | top = child.getBottom() + params.bottomMargin; | ||
| 111 | bottom = top + size; | ||
| 112 | } else { // horizontal | ||
| 113 | left = child.getRight() + params.rightMargin; | ||
| 114 | right = left + size; | ||
| 115 | } | ||
| 116 | mDivider.setBounds(left, top, right, bottom); | ||
| 117 | mDivider.draw(c); | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | private int getOrientation(RecyclerView parent) { | ||
| 122 | if (parent.getLayoutManager() instanceof LinearLayoutManager) { | ||
| 123 | LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager(); | ||
| 124 | return layoutManager.getOrientation(); | ||
| 125 | } else { | ||
| 126 | throw new IllegalStateException( | ||
| 127 | "DividerItemDecoration can only be used with a LinearLayoutManager."); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | } | ||