This commit is contained in:
parent
5bf2bc9687
commit
d6ae19f331
|
|
@ -38,202 +38,6 @@ import androidx.core.content.ContextCompat;
|
|||
*/
|
||||
public class SlideDownView extends LinearLayout {
|
||||
|
||||
// ==================== Builder 模式支持 ====================
|
||||
/**
|
||||
* Builder类用于以链式调用方式构建SlideDownView实例
|
||||
*/
|
||||
public static class Builder {
|
||||
private final Context context;
|
||||
|
||||
// 可选参数(都有默认值)
|
||||
private String title = "";
|
||||
private float titleSize = 15f;
|
||||
private String content = "";
|
||||
private float contentSize = 12f;
|
||||
private int imageRes = 0;
|
||||
private int type = 0;
|
||||
private String backgroundColor = null;
|
||||
private int hideDuration = 300;
|
||||
private boolean viewCenter = true;
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param context 上下文
|
||||
*/
|
||||
public Builder(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题文本
|
||||
* @param title 标题
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置标题字号
|
||||
* @param titleSize 字号(sp)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setTitleSize(float titleSize) {
|
||||
this.titleSize = titleSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内容文本
|
||||
* @param content 内容
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setContent(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内容字号
|
||||
* @param contentSize 字号(sp)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setContentSize(float contentSize) {
|
||||
this.contentSize = contentSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置图标资源
|
||||
* @param imageRes 资源ID
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setImage(int imageRes) {
|
||||
this.imageRes = imageRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置类型(0=成功绿色,1=错误红色)
|
||||
* @param type 类型
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setType(int type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色(字符串格式,如#FF0000)
|
||||
* @param color 颜色字符串
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setBackgroundColor(String color) {
|
||||
this.backgroundColor = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色(ColorInt)
|
||||
* @param color 颜色值
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setBackgroundColor(int color) {
|
||||
this.backgroundColor = "#" + Integer.toHexString(color).substring(2);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置隐藏动画时长
|
||||
* @param duration 时长(毫秒)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setHideDuration(int duration) {
|
||||
this.hideDuration = duration;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置内容是否居中
|
||||
* @param center 是否居中
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setViewCenter(boolean center) {
|
||||
this.viewCenter = center;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置成功样式(绿色背景)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setSuccessStyle() {
|
||||
this.type = 0;
|
||||
this.backgroundColor = "#4CB050";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置错误样式(红色背景)
|
||||
* @return Builder实例
|
||||
*/
|
||||
public Builder setErrorStyle() {
|
||||
this.type = 1;
|
||||
this.backgroundColor = "#FF4443";
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建SlideDownView实例
|
||||
* @return SlideDownView实例
|
||||
*/
|
||||
public SlideDownView build() {
|
||||
SlideDownView view = new SlideDownView(context);
|
||||
view.setTextTitle(this.title);
|
||||
view.setTextTitleSize((int) this.titleSize);
|
||||
view.setTextContent(this.content);
|
||||
view.setTextContentSize((int) this.contentSize);
|
||||
view.setCustomImage(this.imageRes);
|
||||
view.setType(this.type);
|
||||
if (this.backgroundColor != null) {
|
||||
view.setBackgroundColor(this.backgroundColor);
|
||||
}
|
||||
view.setHide_milliseconds(this.hideDuration);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 便捷静态方法 ====================
|
||||
/**
|
||||
* 创建成功提示视图
|
||||
* @param context 上下文
|
||||
* @param message 消息内容
|
||||
* @return SlideDownView实例
|
||||
*/
|
||||
public static SlideDownView createSuccess(Context context, String message) {
|
||||
return new Builder(context)
|
||||
.setTitle("成功")
|
||||
.setContent(message)
|
||||
.setType(0)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建错误提示视图
|
||||
* @param context 上下文
|
||||
* @param message 消息内容
|
||||
* @return SlideDownView实例
|
||||
*/
|
||||
public static SlideDownView createError(Context context, String message) {
|
||||
return new Builder(context)
|
||||
.setTitle("错误")
|
||||
.setContent(message)
|
||||
.setType(1)
|
||||
.build();
|
||||
}
|
||||
|
||||
// ==================== 原有代码 ====================
|
||||
// 动画相关属性
|
||||
private final boolean isExpanded = false;
|
||||
private float mTextTitleSize = 15f;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
android:layout_gravity="center"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="13dp"
|
||||
android:text="AD测试"
|
||||
android:textColor="#464545"
|
||||
android:textSize="14sp"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,6 @@
|
|||
<version>1.0.1</version>
|
||||
<version>1.1.0</version>
|
||||
</versions>
|
||||
<lastUpdated>20260106080444</lastUpdated>
|
||||
<lastUpdated>20260106082556</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
f2298a4dbfbde71af7355caa9b559c98
|
||||
7322f6253155e0b096d8b33718a6214f
|
||||
|
|
@ -1 +1 @@
|
|||
462dd14aeadd7bf2272453e77e5b89d63d4a810e
|
||||
3ce6eb1b9c955d66beb3c120ea21904fa64bd08a
|
||||
|
|
@ -1 +1 @@
|
|||
5659a424a210627ed787d9d14780537f6b391d8874a58237ffc97a5a13153f9d
|
||||
fdb034f958a1e3439c328e16e9475fd56941a11a941443cfb11b47755d48e13e
|
||||
|
|
@ -1 +1 @@
|
|||
2f94512db1150b949af704251fb009e6636b6ab84b0c38998f6e6f4b93da018d65952655c8c29d4ad2a20e7049158038d4a2219298c0024d9a8e3268fec401ad
|
||||
51616e90722ab613ae8cc42f4b69f9f38b143b23b6ca05f66b17d6e83617d7a6e39ad485fdee67b04cf0406bf2424b2d497a0678fc21e45e655317c783ac030e
|
||||
Loading…
Reference in New Issue