Commit fa8f5a64 authored by mengcuiguang's avatar mengcuiguang

添加加载框

parent 75a7604c
...@@ -24,6 +24,13 @@ public interface BaseView { ...@@ -24,6 +24,13 @@ public interface BaseView {
*/ */
void showLoading(String msg); void showLoading(String msg);
/**
* show loading message
*
* @param msg
*/
void showLoading(String msg, boolean isShowLoadingImg);
/** /**
* hide loading * hide loading
*/ */
......
...@@ -163,6 +163,26 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base ...@@ -163,6 +163,26 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Base
} }
} }
/**
* 显示加载进度条(自定义message)
*
* @param message _
*/
@Override
public void showLoading(String message, boolean isShowLoadingImg) {
if (!this.isFinishing() && this.getWindow() != null) {
if (progressDialog == null) {
progressDialog = new LoadingDialog(this);
progressDialog.setLoadText(message);
}
progressDialog.setShowLoadingImg(isShowLoadingImg);
progressDialog.show();
setProgressOnTouchOutside(false);
setProgressNoDismiss();
}
}
/** /**
* 设置Progress是否手触消失 * 设置Progress是否手触消失
* *
......
...@@ -279,18 +279,22 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener { ...@@ -279,18 +279,22 @@ class MyFragment : LazyLoadBaseFragment(), MyView, View.OnClickListener {
override fun adFail() { override fun adFail() {
if (canFail) return if (canFail) return
showLoading("正在获取视频", false)
NoPreAdManager.loadVideoAd( NoPreAdManager.loadVideoAd(
requireActivity(), requireActivity(),
carrierType, object : AdStatusListener { carrierType, object : AdStatusListener {
override fun adFail() { override fun adFail() {
carrierType = Constant.CARRIERTYPE_NINE carrierType = Constant.CARRIERTYPE_NINE
hideLoading()
showToast("广告太火爆了,请稍候再试") showToast("广告太火爆了,请稍候再试")
} }
override fun adSuccess() { override fun adSuccess() {
hideLoading()
} }
override fun adClose(vo: HashMap<String, Any>?) { override fun adClose(vo: HashMap<String, Any>?) {
hideLoading()
vo?.let { vo?.let {
myPresenter.unlock(vo) myPresenter.unlock(vo)
} }
......
...@@ -91,6 +91,26 @@ public abstract class BaseFragment extends BaseAppFragment { ...@@ -91,6 +91,26 @@ public abstract class BaseFragment extends BaseAppFragment {
} }
} }
/**
* 显示加载进度条(自定义message)
*
* @param message _
*/
public void showLoading(String message, boolean isShowLoadingImg) {
// ExtKt.showLoadingExt(this, message);
if (getActivity() != null && !getActivity().isFinishing() &&
getActivity().getWindow() != null && !getActivity().isFinishing()) {
if (progressDialog == null) {
progressDialog = new LoadingDialog(getActivity());
progressDialog.setLoadText(message);
}
progressDialog.setShowLoadingImg(isShowLoadingImg);
progressDialog.show();
setProgressOnTouchOutside(false);
setProgressNoDismiss();
}
}
/** /**
* 消失加载进度条 * 消失加载进度条
*/ */
......
package com.mints.helivideo.ui.widgets; package com.mints.helivideo.ui.widgets;
import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.mints.helivideo.R; import com.mints.helivideo.R;
import com.mints.helivideo.utils.BubbleUtils;
import com.mints.library.utils.GlideUtils;
/** /**
* 描述:加载中dialog * 描述:加载中dialog
...@@ -20,29 +27,30 @@ import com.mints.helivideo.R; ...@@ -20,29 +27,30 @@ import com.mints.helivideo.R;
* 时间:2017/10/10 17:51 * 时间:2017/10/10 17:51
* 邮箱:mengcuiguang@cashbang.cn * 邮箱:mengcuiguang@cashbang.cn
*/ */
public class LoadingDialog extends BaseDialog { public class LoadingDialog extends Dialog {
private Context mContext; private final ImageView img;
private LayoutInflater inflater; private final LinearLayout container;
private LayoutParams lp; private final TextView tv;
private TextView loadtext; private final TextView tv2;
private LinearLayout loading_ll; private final ImageView ivDot;
private final LinearLayout ll;
public LoadingDialog(Context context) { public LoadingDialog(Context context) {
super(context, R.style.dialog); super(context, R.style.dialog);
this.mContext = context; LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); container = (LinearLayout) inflater.inflate(R.layout.layout_custom_progress_dialog_view, null);
View layout = inflater.inflate(R.layout.loadingdialog, null); img = container.findViewById(R.id.ivProgress);
if (android.os.Build.VERSION.SDK_INT > 22) {//android 6.0替换clip的加载动画 tv = container.findViewById(R.id.loading_tips);
final Drawable drawable = ContextCompat.getDrawable(mContext, R.drawable.ufo_loading_refresh); tv2 = container.findViewById(R.id.loading_waiting);
ProgressBar loading_bar = (ProgressBar) layout.findViewById(R.id.loading_bar); ivDot = container.findViewById(R.id.iv_dot);
loading_bar.setIndeterminateDrawable(drawable); ll = container.findViewById(R.id.ll_container);
}
loadtext = (TextView) layout.findViewById(R.id.loading_text); GlideUtils.INSTANCE.loadImageViewGif(context, R.drawable.ic_loading, img);
loading_ll = (LinearLayout) layout.findViewById(R.id.loading_ll);
setContentView(layout); setContentView(container);
// 设置window属性 // 设置window属性
lp = getWindow().getAttributes(); LayoutParams lp = getWindow().getAttributes();
lp.gravity = Gravity.CENTER; lp.gravity = Gravity.CENTER;
lp.dimAmount = 0; // 去背景遮盖 lp.dimAmount = 0; // 去背景遮盖
// lp.alpha = 1.0f;//透明效果 // lp.alpha = 1.0f;//透明效果
...@@ -56,10 +64,40 @@ public class LoadingDialog extends BaseDialog { ...@@ -56,10 +64,40 @@ public class LoadingDialog extends BaseDialog {
*/ */
public void setLoadText(String content) { public void setLoadText(String content) {
if (TextUtils.isEmpty(content)) { if (TextUtils.isEmpty(content)) {
loading_ll.setVisibility(View.GONE); tv.setVisibility(View.GONE);
} else {
tv.setVisibility(View.VISIBLE);
tv.setText(content);
}
}
/**
* 是否显示图片
*/
public void setShowLoadingImg(boolean showLoadingImg) {
if (showLoadingImg) {
img.setVisibility(View.VISIBLE);
ll.setVisibility(View.GONE);
tv.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
int dimen = getContext().getResources().getDimensionPixelSize(R.dimen.font_size_14);
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimen);
container.setBackgroundColor(Color.TRANSPARENT);
} else { } else {
loading_ll.setVisibility(View.VISIBLE); img.setVisibility(View.GONE);
loadtext.setText(content); ll.setVisibility(View.VISIBLE);
GlideUtils.INSTANCE.loadImageViewGif(getContext(), R.drawable.ic_loading_dot, ivDot);
int paddingTB = BubbleUtils.dp2px(30);
int paddingSE = BubbleUtils.dp2px(10);
tv.setPadding(paddingSE, paddingTB, paddingSE, 0);
tv.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
int dimen = getContext().getResources().getDimensionPixelSize(R.dimen.font_size_30);
tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimen);
tv2.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
tv2.setTextSize(TypedValue.COMPLEX_UNIT_PX, dimen);
container.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.shape_bg_transparent));
} }
} }
......
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp" />
<solid android:color="#B0000000" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="10dp">
<ImageView
android:id="@+id/ivProgress"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="center"
android:scaleType="fitXY"
android:src="@drawable/ic_loading" />
<TextView
android:id="@+id/loading_tips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="加载中..."
android:textColor="@color/white"
android:textSize="14sp" />
<LinearLayout
android:id="@+id/ll_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/loading_waiting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="请稍候"
android:textColor="@color/white"
android:textSize="14sp" />
<ImageView
android:id="@+id/iv_dot"
android:layout_width="wrap_content"
android:layout_height="12dp"
android:layout_marginTop="2dp" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
...@@ -24,5 +24,9 @@ ...@@ -24,5 +24,9 @@
<!--inner category--> <!--inner category-->
<!--inner category--> <!--inner category-->
<!--inner category--> <!--inner category-->
<!-- 字体 -->
<dimen name="font_size_14">14sp</dimen>
<dimen name="font_size_16">16sp</dimen>
<dimen name="font_size_30">30sp</dimen>
</resources> </resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment