Skip to content

Commit

Permalink
feat(effect): 优化圆角和箭头实现
Browse files Browse the repository at this point in the history
  • Loading branch information
goweii committed Oct 31, 2021
1 parent dd49c59 commit b5cb8d4
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.List;

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

public BackdropIgnoreView(@NonNull Context context) {
super(context);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
public class RoundedShadowLayout extends ShadowLayout {
private final RoundedShadowOutlineProvider mRoundedShadowOutlineProvider = new RoundedShadowOutlineProvider();

private boolean mRoundedCornerRadiusAdaptation = true;

public RoundedShadowLayout(Context context) {
this(context, null);
}
Expand All @@ -25,6 +27,7 @@ public RoundedShadowLayout(Context context, AttributeSet attrs, int defStyleAttr
setClipToShadowOutline(true);
setClipToPadding(false);
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RoundedShadowLayout);
mRoundedCornerRadiusAdaptation = typedArray.getBoolean(R.styleable.RoundedShadowLayout_roundedCornerRadiusAdaptation, mRoundedCornerRadiusAdaptation);
float cornerRadius = typedArray.getDimension(R.styleable.RoundedShadowLayout_roundedCornerRadius, 0F);
float cornerRadiusTopLeft = typedArray.getDimension(R.styleable.RoundedShadowLayout_roundedCornerRadiusTopLeft, cornerRadius);
float cornerRadiusTopRight = typedArray.getDimension(R.styleable.RoundedShadowLayout_roundedCornerRadiusTopRight, cornerRadius);
Expand All @@ -36,13 +39,19 @@ public RoundedShadowLayout(Context context, AttributeSet attrs, int defStyleAttr

@Override
protected int getSuggestedMinimumWidth() {
if (mRoundedCornerRadiusAdaptation) {
return super.getSuggestedMinimumWidth();
}
int radiusLeft = (int) Math.max(getTopLeftCornerRadius(), getBottomLeftCornerRadius());
int radiusRight = (int) Math.max(getTopRightCornerRadius(), getBottomRightCornerRadius());
return radiusLeft + radiusRight + super.getSuggestedMinimumWidth();
}

@Override
protected int getSuggestedMinimumHeight() {
if (mRoundedCornerRadiusAdaptation) {
return super.getSuggestedMinimumHeight();
}
int radiusTop = (int) Math.max(getTopLeftCornerRadius(), getTopRightCornerRadius());
int radiusBottom = (int) Math.max(getBottomLeftCornerRadius(), getBottomRightCornerRadius());
return radiusTop + radiusBottom + super.getSuggestedMinimumHeight();
Expand Down Expand Up @@ -76,6 +85,17 @@ public boolean areCornersRadiusSame() {
return mRoundedShadowOutlineProvider.areCornersRadiusSame();
}

public boolean isRoundedCornerRadiusAdaptation() {
return mRoundedCornerRadiusAdaptation;
}

public void setRoundedCornerRadiusAdaptation(boolean roundedCornerRadiusAdaptation) {
if (mRoundedCornerRadiusAdaptation != roundedCornerRadiusAdaptation) {
mRoundedCornerRadiusAdaptation = roundedCornerRadiusAdaptation;
requestLayout();
}
}

public void setCornerRadius(float cornerRadius) {
setCornerRadius(cornerRadius, cornerRadius, cornerRadius, cornerRadius);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ShadowLayout extends FrameLayout {

private int mSolidColor = Color.TRANSPARENT;
private boolean mShadowSymmetry = true;
private int mShadowColor = Color.argb(100, 0, 0, 0);
private int mShadowColor = Color.argb(25, 0, 0, 0);
private float mShadowRadius = 0F;
private float mShadowOffsetX = 0F;
private float mShadowOffsetY = 0F;
Expand Down
6 changes: 6 additions & 0 deletions anylayer-effect/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<attr name="shadowOffsetY" format="dimension" />
</declare-styleable>
<declare-styleable name="RoundedShadowLayout">
<attr name="roundedCornerRadiusAdaptation" format="boolean" />
<attr name="roundedCornerRadius" format="dimension" />
<attr name="roundedCornerRadiusTopLeft" format="dimension" />
<attr name="roundedCornerRadiusTopRight" format="dimension" />
Expand All @@ -25,6 +26,11 @@
<enum name="bottom" value="4" />
</attr>
<attr name="popupArrowCenter" format="boolean" />
<attr name="popupArrowAlign" format="enum">
<enum name="center" value="0" />
<enum name="start" value="1" />
<enum name="end" value="2" />
</attr>
<attr name="popupArrowOffset" format="dimension" />
<attr name="popupArrowRadius" format="dimension" />
<attr name="popupArrowWidth" format="dimension" />
Expand Down
3 changes: 3 additions & 0 deletions anylayer/src/main/res/drawable/anylayer_notification_bg.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/anylayer_notification_bg" />
<stroke
android:width="@dimen/anylayer_notification_stroke_width"
android:color="@color/anylayer_notification_stroke" />
<corners
android:bottomLeftRadius="@dimen/anylayer_notification_corner_radius"
android:bottomRightRadius="@dimen/anylayer_notification_corner_radius"
Expand Down
1 change: 1 addition & 0 deletions anylayer/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<color name="anylayer_text_color_fourth">#33FFFFFF</color>

<color name="anylayer_notification_bg">@color/anylayer_card_bg</color>
<color name="anylayer_notification_stroke">#FF222222</color>
<color name="anylayer_notification_title_text_color">@color/anylayer_text_color</color>
<color name="anylayer_notification_label_text_color">@color/anylayer_text_color_second</color>
<color name="anylayer_notification_time_text_color">@color/anylayer_text_color_third</color>
Expand Down
1 change: 1 addition & 0 deletions anylayer/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<color name="anylayer_text_color_fourth">#33000000</color>

<color name="anylayer_notification_bg">@color/anylayer_card_bg</color>
<color name="anylayer_notification_stroke">#FFEEEEEE</color>
<color name="anylayer_notification_title_text_color">@color/anylayer_text_color</color>
<color name="anylayer_notification_label_text_color">@color/anylayer_text_color_second</color>
<color name="anylayer_notification_time_text_color">@color/anylayer_text_color_third</color>
Expand Down
1 change: 1 addition & 0 deletions anylayer/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<dimen name="anylayer_margin_small">6dp</dimen>

<dimen name="anylayer_notification_corner_radius">8dp</dimen>
<dimen name="anylayer_notification_stroke_width">0.5dp</dimen>
<dimen name="anylayer_notification_padding_left">16dp</dimen>
<dimen name="anylayer_notification_padding_right">16dp</dimen>
<dimen name="anylayer_notification_padding_top">16dp</dimen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,20 +522,20 @@ public Animator createOutAnimator(@NonNull View content) {
case R.id.tv_show_menu:
if (anyLayer_show_menu == null) {
anyLayer_show_menu = AnyLayer.popup(findViewById(R.id.tv_show_menu))
.setAlign(Align.Direction.VERTICAL, Align.Horizontal.ALIGN_RIGHT, Align.Vertical.BELOW, false)
.setOffsetYdp(15)
.setAlign(Align.Direction.VERTICAL, Align.Horizontal.ALIGN_PARENT_RIGHT, Align.Vertical.BELOW, false)
.setOffsetYdp(-15)
.setOutsideTouchToDismiss(true)
.setOutsideInterceptTouchEvent(false)
.setContentView(R.layout.popup_meun)
.setContentAnimator(new DialogLayer.AnimatorCreator() {
@Override
public Animator createInAnimator(@NonNull View content) {
return AnimatorHelper.createDelayedZoomInAnim(content, 1F, 0F);
return AnimatorHelper.createDelayedZoomInAnim(content, 0.8F, 0F);
}

@Override
public Animator createOutAnimator(@NonNull View content) {
return AnimatorHelper.createDelayedZoomOutAnim(content, 1F, 0F);
return AnimatorHelper.createDelayedZoomOutAnim(content, 0.8F, 0F);
}
});
}
Expand Down
42 changes: 21 additions & 21 deletions app/src/main/res/layout/dialog_normal.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<per.goweii.anylayer.effect.RoundedShadowLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="320dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:cardBackgroundColor="#ffffff"
app:cardCornerRadius="6dp"
app:cardUseCompatPadding="false"
app:cardElevation="0dp">
app:roundedCornerRadius="12dp"
app:roundedCornerRadiusAdaptation="true"
app:shadowRadius="32dp"
app:shadowSolidColor="#ffffff">

<LinearLayout
android:layout_width="match_parent"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:orientation="vertical">

Expand All @@ -19,9 +19,9 @@
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="说明"
android:textColor="#232323"
android:textSize="16sp"
android:text="说明" />
android:textSize="16sp" />

<TextView
android:id="@+id/tv_dialog_content"
Expand All @@ -32,9 +32,9 @@
android:paddingTop="28dp"
android:paddingRight="20dp"
android:paddingBottom="25dp"
android:text="@string/dialog_msg"
android:textColor="#232323"
android:textSize="17sp"
android:text="@string/dialog_msg" />
android:textSize="17sp" />

<LinearLayout
android:layout_width="match_parent"
Expand All @@ -47,49 +47,49 @@
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:clickable="true"
android:background="?android:attr/selectableItemBackground">
android:background="?android:attr/selectableItemBackground"
android:clickable="true">

<TextView
android:id="@+id/tv_dialog_no"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="关闭"
android:textColor="#232323"
android:textSize="16sp"
android:text="关闭" />
android:textSize="16sp" />

</FrameLayout>

<View
android:id="@+id/view_line"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#f3f3f3" />

<FrameLayout
android:id="@+id/fl_dialog_yes"
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground">
android:background="?android:attr/selectableItemBackground"
android:clickable="true">

<TextView
android:id="@+id/tv_dialog_yes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="确定"
android:textColor="#232323"
android:textSize="16sp"
android:text="确定" />
android:textSize="16sp" />

</FrameLayout>

</LinearLayout>

</LinearLayout>

</androidx.cardview.widget.CardView>
</per.goweii.anylayer.effect.RoundedShadowLayout>
Loading

0 comments on commit b5cb8d4

Please sign in to comment.