package com.cooleshow.base.widgets; import android.app.Dialog; import android.content.Context; import android.graphics.drawable.AnimationDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.airbnb.lottie.LottieAnimationView; import com.cooleshow.base.R; import com.cooleshow.base.widgets.dialog.BaseFullDialog; import androidx.annotation.NonNull; /** * Author by pq, Date on 2022/12/19. */ public class ProgressLoading2 extends BaseFullDialog { private ImageView mImageView; private TextView mTvLoadingText; private LottieAnimationView mViewLoadingAnim; private TextView mTvCancel; private LinearLayout mLlContent; private View.OnClickListener mClickListener; public ProgressLoading2(@NonNull Context context) { super(context, R.style.LightProgressDialog); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.progress_dialog); setCancelable(true); setCanceledOnTouchOutside(false); WindowManager.LayoutParams attributes = getWindow().getAttributes(); attributes.gravity = Gravity.CENTER; attributes.dimAmount = 0.2f; getWindow().setAttributes(attributes); mImageView = findViewById(R.id.iv_loading); mTvLoadingText = findViewById(R.id.tv_loading_text); mViewLoadingAnim = findViewById(R.id.view_loading_anim); mTvCancel = findViewById(R.id.tv_cancel_loading); mLlContent = findViewById(R.id.ll_content); mViewLoadingAnim.setImageAssetsFolder("lottie/refresh/images/"); mViewLoadingAnim.setAnimation("lottie/refresh_anim.json"); mViewLoadingAnim.loop(true); if (mClickListener != null) { mTvCancel.setOnClickListener(mClickListener); } } public void showLoading() { super.show(); if (mViewLoadingAnim != null) { mViewLoadingAnim.playAnimation(); } if (mTvLoadingText != null) { mTvLoadingText.setText("加载中"); mTvLoadingText.setVisibility(View.VISIBLE); } } public void showLoading(String text) { super.show(); if (mViewLoadingAnim != null) { mViewLoadingAnim.playAnimation(); } if (mTvLoadingText != null) { mTvLoadingText.setText(text); mTvLoadingText.setVisibility(View.VISIBLE); } } public void showLoadingAndCancel(String text) { showLoading(text); if (mTvCancel != null) { mTvCancel.setVisibility(View.VISIBLE); } } public void setClickListener(View.OnClickListener clickListener) { mClickListener = clickListener; } public void updateLoadingText(String text) { if (mTvLoadingText != null) { mTvLoadingText.setText(text); mTvLoadingText.setVisibility(View.VISIBLE); } } public void hideLoading() { super.dismiss(); stopAnim(); } public void stopAnim() { if (mViewLoadingAnim != null) { mViewLoadingAnim.cancelAnimation(); } } public void setLoadingStyle(Drawable drawable, int contentTestSize, int textColor) { if (mLlContent != null) { mLlContent.setBackground(drawable); } if (mTvLoadingText != null) { mTvLoadingText.setTextSize(contentTestSize); mTvLoadingText.setTextColor(textColor); } } public void updateDimAmount(float dimAmount) { Window window = getWindow(); if (window != null) { WindowManager.LayoutParams attributes = window.getAttributes(); attributes.gravity = Gravity.CENTER; attributes.dimAmount = dimAmount; window.setAttributes(attributes); } } }