ProgressLoading2.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.cooleshow.base.widgets;
  2. import android.app.Dialog;
  3. import android.content.Context;
  4. import android.graphics.drawable.AnimationDrawable;
  5. import android.graphics.drawable.Drawable;
  6. import android.os.Bundle;
  7. import android.view.Gravity;
  8. import android.view.View;
  9. import android.view.Window;
  10. import android.view.WindowManager;
  11. import android.widget.ImageView;
  12. import android.widget.LinearLayout;
  13. import android.widget.TextView;
  14. import com.airbnb.lottie.LottieAnimationView;
  15. import com.cooleshow.base.R;
  16. import com.cooleshow.base.widgets.dialog.BaseFullDialog;
  17. import androidx.annotation.NonNull;
  18. /**
  19. * Author by pq, Date on 2022/12/19.
  20. */
  21. public class ProgressLoading2 extends BaseFullDialog {
  22. private ImageView mImageView;
  23. private TextView mTvLoadingText;
  24. private LottieAnimationView mViewLoadingAnim;
  25. private TextView mTvCancel;
  26. private LinearLayout mLlContent;
  27. private View.OnClickListener mClickListener;
  28. public ProgressLoading2(@NonNull Context context) {
  29. super(context, R.style.LightProgressDialog);
  30. }
  31. @Override
  32. protected void onCreate(Bundle savedInstanceState) {
  33. super.onCreate(savedInstanceState);
  34. setContentView(R.layout.progress_dialog);
  35. setCancelable(true);
  36. setCanceledOnTouchOutside(false);
  37. WindowManager.LayoutParams attributes = getWindow().getAttributes();
  38. attributes.gravity = Gravity.CENTER;
  39. attributes.dimAmount = 0.2f;
  40. getWindow().setAttributes(attributes);
  41. mImageView = findViewById(R.id.iv_loading);
  42. mTvLoadingText = findViewById(R.id.tv_loading_text);
  43. mViewLoadingAnim = findViewById(R.id.view_loading_anim);
  44. mTvCancel = findViewById(R.id.tv_cancel_loading);
  45. mLlContent = findViewById(R.id.ll_content);
  46. mViewLoadingAnim.setImageAssetsFolder("lottie/refresh/images/");
  47. mViewLoadingAnim.setAnimation("lottie/refresh_anim.json");
  48. mViewLoadingAnim.loop(true);
  49. if (mClickListener != null) {
  50. mTvCancel.setOnClickListener(mClickListener);
  51. }
  52. }
  53. public void showLoading() {
  54. super.show();
  55. if (mViewLoadingAnim != null) {
  56. mViewLoadingAnim.playAnimation();
  57. }
  58. if (mTvLoadingText != null) {
  59. mTvLoadingText.setText("加载中");
  60. mTvLoadingText.setVisibility(View.VISIBLE);
  61. }
  62. }
  63. public void showLoading(String text) {
  64. super.show();
  65. if (mViewLoadingAnim != null) {
  66. mViewLoadingAnim.playAnimation();
  67. }
  68. if (mTvLoadingText != null) {
  69. mTvLoadingText.setText(text);
  70. mTvLoadingText.setVisibility(View.VISIBLE);
  71. }
  72. }
  73. public void showLoadingAndCancel(String text) {
  74. showLoading(text);
  75. if (mTvCancel != null) {
  76. mTvCancel.setVisibility(View.VISIBLE);
  77. }
  78. }
  79. public void setClickListener(View.OnClickListener clickListener) {
  80. mClickListener = clickListener;
  81. }
  82. public void updateLoadingText(String text) {
  83. if (mTvLoadingText != null) {
  84. mTvLoadingText.setText(text);
  85. mTvLoadingText.setVisibility(View.VISIBLE);
  86. }
  87. }
  88. public void hideLoading() {
  89. super.dismiss();
  90. stopAnim();
  91. }
  92. public void stopAnim() {
  93. if (mViewLoadingAnim != null) {
  94. mViewLoadingAnim.cancelAnimation();
  95. }
  96. }
  97. public void setLoadingStyle(Drawable drawable, int contentTestSize, int textColor) {
  98. if (mLlContent != null) {
  99. mLlContent.setBackground(drawable);
  100. }
  101. if (mTvLoadingText != null) {
  102. mTvLoadingText.setTextSize(contentTestSize);
  103. mTvLoadingText.setTextColor(textColor);
  104. }
  105. }
  106. public void updateDimAmount(float dimAmount) {
  107. Window window = getWindow();
  108. if (window != null) {
  109. WindowManager.LayoutParams attributes = window.getAttributes();
  110. attributes.gravity = Gravity.CENTER;
  111. attributes.dimAmount = dimAmount;
  112. window.setAttributes(attributes);
  113. }
  114. }
  115. }