Skip to content

Commit b5cb8d4

Browse files
committed
feat(effect): 优化圆角和箭头实现
1 parent dd49c59 commit b5cb8d4

12 files changed

Lines changed: 345 additions & 182 deletions

File tree

anylayer-effect/src/main/java/per/goweii/anylayer/effect/BackdropIgnoreView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import java.util.List;
1515

1616
public class BackdropIgnoreView extends FrameLayout {
17-
private List<WeakReference<BackdropBlurView>> mBackdropBlurViews = new LinkedList<>();
17+
private final List<WeakReference<BackdropBlurView>> mBackdropBlurViews = new LinkedList<>();
1818

1919
public BackdropIgnoreView(@NonNull Context context) {
2020
super(context);

anylayer-effect/src/main/java/per/goweii/anylayer/effect/PopupShadowLayout.java

Lines changed: 178 additions & 64 deletions
Large diffs are not rendered by default.

anylayer-effect/src/main/java/per/goweii/anylayer/effect/RoundedShadowLayout.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
public class RoundedShadowLayout extends ShadowLayout {
1212
private final RoundedShadowOutlineProvider mRoundedShadowOutlineProvider = new RoundedShadowOutlineProvider();
1313

14+
private boolean mRoundedCornerRadiusAdaptation = true;
15+
1416
public RoundedShadowLayout(Context context) {
1517
this(context, null);
1618
}
@@ -25,6 +27,7 @@ public RoundedShadowLayout(Context context, AttributeSet attrs, int defStyleAttr
2527
setClipToShadowOutline(true);
2628
setClipToPadding(false);
2729
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundedShadowLayout);
30+
mRoundedCornerRadiusAdaptation = typedArray.getBoolean(R.styleable.RoundedShadowLayout_roundedCornerRadiusAdaptation, mRoundedCornerRadiusAdaptation);
2831
float cornerRadius = typedArray.getDimension(R.styleable.RoundedShadowLayout_roundedCornerRadius, 0F);
2932
float cornerRadiusTopLeft = typedArray.getDimension(R.styleable.RoundedShadowLayout_roundedCornerRadiusTopLeft, cornerRadius);
3033
float cornerRadiusTopRight = typedArray.getDimension(R.styleable.RoundedShadowLayout_roundedCornerRadiusTopRight, cornerRadius);
@@ -36,13 +39,19 @@ public RoundedShadowLayout(Context context, AttributeSet attrs, int defStyleAttr
3639

3740
@Override
3841
protected int getSuggestedMinimumWidth() {
42+
if (mRoundedCornerRadiusAdaptation) {
43+
return super.getSuggestedMinimumWidth();
44+
}
3945
int radiusLeft = (int) Math.max(getTopLeftCornerRadius(), getBottomLeftCornerRadius());
4046
int radiusRight = (int) Math.max(getTopRightCornerRadius(), getBottomRightCornerRadius());
4147
return radiusLeft + radiusRight + super.getSuggestedMinimumWidth();
4248
}
4349

4450
@Override
4551
protected int getSuggestedMinimumHeight() {
52+
if (mRoundedCornerRadiusAdaptation) {
53+
return super.getSuggestedMinimumHeight();
54+
}
4655
int radiusTop = (int) Math.max(getTopLeftCornerRadius(), getTopRightCornerRadius());
4756
int radiusBottom = (int) Math.max(getBottomLeftCornerRadius(), getBottomRightCornerRadius());
4857
return radiusTop + radiusBottom + super.getSuggestedMinimumHeight();
@@ -76,6 +85,17 @@ public boolean areCornersRadiusSame() {
7685
return mRoundedShadowOutlineProvider.areCornersRadiusSame();
7786
}
7887

88+
public boolean isRoundedCornerRadiusAdaptation() {
89+
return mRoundedCornerRadiusAdaptation;
90+
}
91+
92+
public void setRoundedCornerRadiusAdaptation(boolean roundedCornerRadiusAdaptation) {
93+
if (mRoundedCornerRadiusAdaptation != roundedCornerRadiusAdaptation) {
94+
mRoundedCornerRadiusAdaptation = roundedCornerRadiusAdaptation;
95+
requestLayout();
96+
}
97+
}
98+
7999
public void setCornerRadius(float cornerRadius) {
80100
setCornerRadius(cornerRadius, cornerRadius, cornerRadius, cornerRadius);
81101
}

anylayer-effect/src/main/java/per/goweii/anylayer/effect/ShadowLayout.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ShadowLayout extends FrameLayout {
2525

2626
private int mSolidColor = Color.TRANSPARENT;
2727
private boolean mShadowSymmetry = true;
28-
private int mShadowColor = Color.argb(100, 0, 0, 0);
28+
private int mShadowColor = Color.argb(25, 0, 0, 0);
2929
private float mShadowRadius = 0F;
3030
private float mShadowOffsetX = 0F;
3131
private float mShadowOffsetY = 0F;

anylayer-effect/src/main/res/values/attrs.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<attr name="shadowOffsetY" format="dimension" />
1010
</declare-styleable>
1111
<declare-styleable name="RoundedShadowLayout">
12+
<attr name="roundedCornerRadiusAdaptation" format="boolean" />
1213
<attr name="roundedCornerRadius" format="dimension" />
1314
<attr name="roundedCornerRadiusTopLeft" format="dimension" />
1415
<attr name="roundedCornerRadiusTopRight" format="dimension" />
@@ -25,6 +26,11 @@
2526
<enum name="bottom" value="4" />
2627
</attr>
2728
<attr name="popupArrowCenter" format="boolean" />
29+
<attr name="popupArrowAlign" format="enum">
30+
<enum name="center" value="0" />
31+
<enum name="start" value="1" />
32+
<enum name="end" value="2" />
33+
</attr>
2834
<attr name="popupArrowOffset" format="dimension" />
2935
<attr name="popupArrowRadius" format="dimension" />
3036
<attr name="popupArrowWidth" format="dimension" />

anylayer/src/main/res/drawable/anylayer_notification_bg.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android">
33
<solid android:color="@color/anylayer_notification_bg" />
4+
<stroke
5+
android:width="@dimen/anylayer_notification_stroke_width"
6+
android:color="@color/anylayer_notification_stroke" />
47
<corners
58
android:bottomLeftRadius="@dimen/anylayer_notification_corner_radius"
69
android:bottomRightRadius="@dimen/anylayer_notification_corner_radius"

anylayer/src/main/res/values-night/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<color name="anylayer_text_color_fourth">#33FFFFFF</color>
88

99
<color name="anylayer_notification_bg">@color/anylayer_card_bg</color>
10+
<color name="anylayer_notification_stroke">#FF222222</color>
1011
<color name="anylayer_notification_title_text_color">@color/anylayer_text_color</color>
1112
<color name="anylayer_notification_label_text_color">@color/anylayer_text_color_second</color>
1213
<color name="anylayer_notification_time_text_color">@color/anylayer_text_color_third</color>

anylayer/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<color name="anylayer_text_color_fourth">#33000000</color>
88

99
<color name="anylayer_notification_bg">@color/anylayer_card_bg</color>
10+
<color name="anylayer_notification_stroke">#FFEEEEEE</color>
1011
<color name="anylayer_notification_title_text_color">@color/anylayer_text_color</color>
1112
<color name="anylayer_notification_label_text_color">@color/anylayer_text_color_second</color>
1213
<color name="anylayer_notification_time_text_color">@color/anylayer_text_color_third</color>

anylayer/src/main/res/values/dimens.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<dimen name="anylayer_margin_small">6dp</dimen>
55

66
<dimen name="anylayer_notification_corner_radius">8dp</dimen>
7+
<dimen name="anylayer_notification_stroke_width">0.5dp</dimen>
78
<dimen name="anylayer_notification_padding_left">16dp</dimen>
89
<dimen name="anylayer_notification_padding_right">16dp</dimen>
910
<dimen name="anylayer_notification_padding_top">16dp</dimen>

app/src/main/java/per/goweii/android/anylayer/FullScreenActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,20 +522,20 @@ public Animator createOutAnimator(@NonNull View content) {
522522
case R.id.tv_show_menu:
523523
if (anyLayer_show_menu == null) {
524524
anyLayer_show_menu = AnyLayer.popup(findViewById(R.id.tv_show_menu))
525-
.setAlign(Align.Direction.VERTICAL, Align.Horizontal.ALIGN_RIGHT, Align.Vertical.BELOW, false)
526-
.setOffsetYdp(15)
525+
.setAlign(Align.Direction.VERTICAL, Align.Horizontal.ALIGN_PARENT_RIGHT, Align.Vertical.BELOW, false)
526+
.setOffsetYdp(-15)
527527
.setOutsideTouchToDismiss(true)
528528
.setOutsideInterceptTouchEvent(false)
529529
.setContentView(R.layout.popup_meun)
530530
.setContentAnimator(new DialogLayer.AnimatorCreator() {
531531
@Override
532532
public Animator createInAnimator(@NonNull View content) {
533-
return AnimatorHelper.createDelayedZoomInAnim(content, 1F, 0F);
533+
return AnimatorHelper.createDelayedZoomInAnim(content, 0.8F, 0F);
534534
}
535535

536536
@Override
537537
public Animator createOutAnimator(@NonNull View content) {
538-
return AnimatorHelper.createDelayedZoomOutAnim(content, 1F, 0F);
538+
return AnimatorHelper.createDelayedZoomOutAnim(content, 0.8F, 0F);
539539
}
540540
});
541541
}

0 commit comments

Comments
 (0)