| New file |
| | |
| | | |
| | | package com.hdl.photovoltaic.widget; |
| | | |
| | | import android.content.Context; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.os.Bundle; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.BaseDialog; |
| | | import com.hdl.photovoltaic.databinding.DialogFlashingIconBoxBinding; |
| | | |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | | /** |
| | | * 自定义自动关闭dialog |
| | | */ |
| | | public class FlashingIconBoxDialog extends BaseDialog { |
| | | |
| | | private DialogFlashingIconBoxBinding viewBinding; |
| | | |
| | | private Drawable mDrawable; |
| | | private String mContentStr; |
| | | |
| | | private boolean mIsShow = true; |
| | | |
| | | //默认1500毫秒 |
| | | private int mMillisecond = 1500; |
| | | |
| | | public FlashingIconBoxDialog(@NonNull Context context) { |
| | | super(context, R.style.Custom_List_Dialog); |
| | | } |
| | | |
| | | /** |
| | | * @param context 上下文 |
| | | * @param millisecond 设置延时时间关闭弹窗(单位ms) |
| | | */ |
| | | public FlashingIconBoxDialog(@NonNull Context context, int millisecond) { |
| | | this(context); |
| | | this.mMillisecond = millisecond; |
| | | } |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | viewBinding = DialogFlashingIconBoxBinding.inflate(getLayoutInflater()); |
| | | setContentView(viewBinding.getRoot()); |
| | | if (mIsShow) { |
| | | viewBinding.tipImageTv.setVisibility(View.VISIBLE); |
| | | } else { |
| | | viewBinding.tipImageTv.setVisibility(View.GONE); |
| | | } |
| | | if (this.mDrawable != null) { |
| | | viewBinding.tipImageTv.setBackground(this.mDrawable); |
| | | } |
| | | if (!TextUtils.isEmpty(this.mContentStr)) { |
| | | viewBinding.tipContentTv.setText(this.mContentStr); |
| | | } |
| | | flashing(); |
| | | } |
| | | |
| | | /** |
| | | * 设置图标 |
| | | * |
| | | * @param drawable 成功或者失败,提示图标 |
| | | */ |
| | | public void setImage(Drawable drawable) { |
| | | this.mDrawable = drawable; |
| | | if (viewBinding != null && this.mDrawable != null) { |
| | | viewBinding.tipImageTv.setBackground(drawable); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置图标是否显示 |
| | | * |
| | | * @param isShow (true=图标,否则不显示) |
| | | */ |
| | | public void isShowImage(boolean isShow) { |
| | | this.mIsShow = isShow; |
| | | if (isShow) { |
| | | viewBinding.tipImageTv.setVisibility(View.VISIBLE); |
| | | } else { |
| | | viewBinding.tipImageTv.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置提示文本 |
| | | * |
| | | * @param content 文本 |
| | | */ |
| | | public void setContent(String content) { |
| | | this.mContentStr = content; |
| | | if (viewBinding != null && !TextUtils.isEmpty(content)) { |
| | | viewBinding.tipContentTv.setText(content); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置延时时间关闭弹窗 |
| | | * |
| | | * @param millisecond 时间(单位ms) |
| | | */ |
| | | public void setDelayTime(int millisecond) { |
| | | this.mMillisecond = millisecond; |
| | | } |
| | | |
| | | /** |
| | | * 三秒后自动关闭dialog |
| | | */ |
| | | private void flashing() { |
| | | //三秒后自动关闭dialog |
| | | final Timer timer = new Timer(); |
| | | timer.schedule(new TimerTask() { |
| | | public void run() { |
| | | timer.cancel(); |
| | | dismiss(); |
| | | } |
| | | }, this.mMillisecond); |
| | | |
| | | } |
| | | |
| | | |
| | | } |