Skip to content

Commit 8a76b7e

Browse files
fix card view not rounded in blur windows
1 parent a7a64f0 commit 8a76b7e

3 files changed

Lines changed: 51 additions & 10 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.v2ray.ang.widget
2+
3+
import android.content.Context
4+
import android.graphics.Canvas
5+
import android.graphics.Path
6+
import android.graphics.RectF
7+
import android.util.AttributeSet
8+
import com.google.android.material.card.MaterialCardView
9+
10+
class ClipRoundedCardView @JvmOverloads constructor(
11+
context: Context,
12+
attrs: AttributeSet? = null,
13+
defStyleAttr: Int = com.google.android.material.R.attr.materialCardViewStyle
14+
) : MaterialCardView(context, attrs, defStyleAttr) {
15+
16+
private val clipPath = Path()
17+
private val clipRect = RectF()
18+
19+
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
20+
super.onSizeChanged(w, h, oldw, oldh)
21+
rebuildClipPath()
22+
}
23+
24+
override fun setRadius(radius: Float) {
25+
super.setRadius(radius)
26+
rebuildClipPath()
27+
}
28+
29+
private fun rebuildClipPath() {
30+
clipRect.set(0f, 0f, width.toFloat(), height.toFloat())
31+
clipPath.reset()
32+
clipPath.addRoundRect(clipRect, radius, radius, Path.Direction.CW)
33+
}
34+
35+
override fun dispatchDraw(canvas: Canvas) {
36+
val saveCount = canvas.save()
37+
canvas.clipPath(clipPath)
38+
super.dispatchDraw(canvas)
39+
canvas.restoreToCount(saveCount)
40+
}
41+
}

V2rayNG/app/src/main/res/layout/uwu_banner_settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<com.google.android.material.card.MaterialCardView
2+
<com.v2ray.ang.widget.ClipRoundedCardView
33
xmlns:android="http://schemas.android.com/apk/res/android"
44
xmlns:app="http://schemas.android.com/apk/res-auto"
55
android:layout_width="fill_parent"
@@ -58,4 +58,4 @@
5858

5959
</LinearLayout>
6060

61-
</com.google.android.material.card.MaterialCardView>
61+
</com.v2ray.ang.widget.ClipRoundedCardView>

V2rayNG/app/src/main/res/layout/uwu_banner_theme.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<com.google.android.material.card.MaterialCardView
2+
<com.v2ray.ang.widget.ClipRoundedCardView
33
android:orientation="vertical"
44
android:layout_width="fill_parent"
55
android:layout_height="wrap_content"
@@ -18,7 +18,7 @@
1818
android:orientation="vertical"
1919
android:layout_width="fill_parent"
2020
android:layout_height="wrap_content">
21-
<com.google.android.material.card.MaterialCardView
21+
<com.v2ray.ang.widget.ClipRoundedCardView
2222
android:clickable="false"
2323
android:clipToPadding="false"
2424
android:layout_width="fill_parent"
@@ -39,7 +39,7 @@
3939
android:layout_width="fill_parent"
4040
android:layout_height="wrap_content"
4141
android:baselineAligned="false">
42-
<com.google.android.material.card.MaterialCardView
42+
<com.v2ray.ang.widget.ClipRoundedCardView
4343
android:id="@+id/theme_banner_image_card"
4444
android:clickable="true"
4545
android:focusable="true"
@@ -91,7 +91,7 @@
9191
android:format24Hour="mm"
9292
android:fontFeatureSettings="tnum, cv03, cv04" />
9393
</LinearLayout>
94-
</com.google.android.material.card.MaterialCardView>
94+
</com.v2ray.ang.widget.ClipRoundedCardView>
9595
<RelativeLayout
9696
android:padding="16.0dip"
9797
android:layout_width="wrap_content"
@@ -260,8 +260,8 @@
260260
android:layout_alignStart="@+id/uwu_package_name" />
261261
</RelativeLayout>
262262
</LinearLayout>
263-
</com.google.android.material.card.MaterialCardView>
264-
<com.google.android.material.card.MaterialCardView
263+
</com.v2ray.ang.widget.ClipRoundedCardView>
264+
<com.v2ray.ang.widget.ClipRoundedCardView
265265
android:id="@+id/onClick"
266266
android:focusable="true"
267267
android:clickable="true"
@@ -386,6 +386,6 @@
386386
</LinearLayout>
387387
</LinearLayout>
388388
</LinearLayout>
389-
</com.google.android.material.card.MaterialCardView>
389+
</com.v2ray.ang.widget.ClipRoundedCardView>
390390
</LinearLayout>
391-
</com.google.android.material.card.MaterialCardView>
391+
</com.v2ray.ang.widget.ClipRoundedCardView>

0 commit comments

Comments
 (0)