350 lines
13 KiB
Java
350 lines
13 KiB
Java
package com.ubt.jimu.base.dialog;
|
|
|
|
import android.app.Activity;
|
|
import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.text.TextUtils;
|
|
import android.text.method.ScrollingMovementMethod;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.Window;
|
|
import android.view.WindowManager;
|
|
import android.widget.Button;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
|
import com.ubt.jimu.Channel;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubt.jimu.base.cache.Cache;
|
|
import com.ubt.jimu.update.UpdateManager;
|
|
import com.ubt.jimu.utils.NetWorkUtil;
|
|
import com.ubt.jimu.utils.SystemUtils;
|
|
import com.ubtech.utils.DisplayUtil;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class JimuSimpleDialog extends Dialog implements View.OnClickListener {
|
|
public Button btnCancel;
|
|
public Button btnOk;
|
|
public String cancel;
|
|
public int cancleBtnBg;
|
|
public String content;
|
|
private ImageView imgLogo;
|
|
private OnDismissListener mOnDismissListener;
|
|
public String ok;
|
|
private DialogInterface.OnClickListener onCancelListener;
|
|
private DialogInterface.OnClickListener onOkListener;
|
|
private TextView tvDialogTitle;
|
|
private TextView tvTips;
|
|
|
|
public static class Builder {
|
|
private String cancel;
|
|
private int cancleBtnBg;
|
|
private String content;
|
|
private Context context;
|
|
private String logoUrl;
|
|
private String ok;
|
|
private DialogInterface.OnClickListener onCancelListener;
|
|
private DialogInterface.OnClickListener onOkListener;
|
|
private String title;
|
|
private int logoResId = 0;
|
|
private boolean canceledOnTouchOutside = true;
|
|
private int gravity = 17;
|
|
|
|
public Builder(Context context) {
|
|
this.context = context;
|
|
}
|
|
|
|
public JimuSimpleDialog build() {
|
|
int i;
|
|
double d;
|
|
int a;
|
|
int a2;
|
|
JimuSimpleDialog jimuSimpleDialog = new JimuSimpleDialog(this.context);
|
|
jimuSimpleDialog.requestWindowFeature(1);
|
|
jimuSimpleDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
|
|
jimuSimpleDialog.content = this.content;
|
|
jimuSimpleDialog.ok = this.ok;
|
|
jimuSimpleDialog.cancel = this.cancel;
|
|
jimuSimpleDialog.onOkListener = this.onOkListener;
|
|
jimuSimpleDialog.onCancelListener = this.onCancelListener;
|
|
jimuSimpleDialog.cancleBtnBg = this.cancleBtnBg;
|
|
View inflate = LayoutInflater.from(this.context).inflate(R.layout.dialog_jimu_simple, (ViewGroup) null, false);
|
|
jimuSimpleDialog.intView(inflate, this);
|
|
jimuSimpleDialog.setContentView(inflate);
|
|
jimuSimpleDialog.setCanceledOnTouchOutside(this.canceledOnTouchOutside);
|
|
Window window = jimuSimpleDialog.getWindow();
|
|
WindowManager.LayoutParams attributes = window.getAttributes();
|
|
window.setBackgroundDrawableResource(R.color.translucent);
|
|
window.setWindowAnimations(R.style.dialogWindowAlphaIn);
|
|
int max = Math.max(DisplayUtil.b(JimuApplication.l()), DisplayUtil.a(JimuApplication.l()));
|
|
if (JimuApplication.l().i()) {
|
|
i = (int) (max * 0.5039d);
|
|
d = 0.624d;
|
|
} else {
|
|
i = (int) (max * 0.5165d);
|
|
d = 0.6088d;
|
|
}
|
|
int i2 = (int) (i * d);
|
|
if (JimuApplication.l().i()) {
|
|
a = DisplayUtil.a(this.context, 516.0f);
|
|
a2 = DisplayUtil.a(this.context, 322.0f);
|
|
} else {
|
|
a = DisplayUtil.a(this.context, 344.55f);
|
|
a2 = DisplayUtil.a(this.context, 209.75f);
|
|
}
|
|
if (a > i || a2 > i2) {
|
|
i = a;
|
|
i2 = a2;
|
|
}
|
|
attributes.width = i;
|
|
attributes.height = i2;
|
|
attributes.gravity = 17;
|
|
window.setAttributes(attributes);
|
|
return jimuSimpleDialog;
|
|
}
|
|
|
|
public Builder cancel(String str) {
|
|
this.cancel = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder canceledOnTouchOutside(boolean z) {
|
|
this.canceledOnTouchOutside = z;
|
|
return this;
|
|
}
|
|
|
|
public Builder cancleBtnBg(int i) {
|
|
this.cancleBtnBg = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder content(String str) {
|
|
this.content = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder gravity(int i) {
|
|
this.gravity = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder logoResId(int i) {
|
|
this.logoResId = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder logoUrl(String str) {
|
|
this.logoUrl = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder ok(String str) {
|
|
this.ok = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder onCancel(DialogInterface.OnClickListener onClickListener) {
|
|
this.onCancelListener = onClickListener;
|
|
return this;
|
|
}
|
|
|
|
public Builder onOk(DialogInterface.OnClickListener onClickListener) {
|
|
this.onOkListener = onClickListener;
|
|
return this;
|
|
}
|
|
|
|
public Builder title(String str) {
|
|
this.title = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder cancel(int i) {
|
|
this.cancel = this.context.getString(i);
|
|
return this;
|
|
}
|
|
|
|
public Builder content(int i) {
|
|
this.content = this.context.getString(i);
|
|
return this;
|
|
}
|
|
|
|
public Builder ok(int i) {
|
|
this.ok = this.context.getString(i);
|
|
return this;
|
|
}
|
|
|
|
public Builder title(int i) {
|
|
this.title = this.context.getString(i);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public interface OnDismissListener {
|
|
void onDismiss(Dialog dialog);
|
|
}
|
|
|
|
public JimuSimpleDialog(Context context) {
|
|
super(context);
|
|
}
|
|
|
|
public static JimuSimpleDialog buildSimpleDialog(Activity activity, String str, String str2, String str3, String str4, int i, DialogInterface.OnClickListener onClickListener, DialogInterface.OnClickListener onClickListener2) {
|
|
return new Builder(activity).title(str3).cancel(str2).ok(str).content(str4).gravity(i).onCancel(onClickListener).onOk(onClickListener2).build();
|
|
}
|
|
|
|
public static boolean shouldShowWifiOnlyDialog(Context context) {
|
|
return NetWorkUtil.a(context) == NetWorkUtil.NetworkType.MOBILE && Cache.getInstance().isWifiOnly() && !Cache.getInstance().isShowMobileDataTips();
|
|
}
|
|
|
|
public static boolean showWifiOnlyDialog(Context context, final DialogInterface.OnClickListener onClickListener, final DialogInterface.OnClickListener onClickListener2, boolean z) {
|
|
if (context != null && !z && shouldShowWifiOnlyDialog(context)) {
|
|
new Builder(context).title(R.string.mobile_data_tips).cancel(R.string.cancel).ok(R.string.key_continue).content(R.string.tips_using_mobile_data).onCancel(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.JimuSimpleDialog.4
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
DialogInterface.OnClickListener onClickListener3 = onClickListener;
|
|
if (onClickListener3 != null) {
|
|
onClickListener3.onClick(dialogInterface, i);
|
|
}
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).onOk(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.JimuSimpleDialog.3
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
DialogInterface.OnClickListener onClickListener3 = onClickListener2;
|
|
if (onClickListener3 != null) {
|
|
onClickListener3.onClick(dialogInterface, i);
|
|
Cache.getInstance().setShowMobileDataTips(true);
|
|
}
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).build().show();
|
|
return true;
|
|
}
|
|
if (onClickListener2 == null) {
|
|
return false;
|
|
}
|
|
onClickListener2.onClick(null, -1);
|
|
return false;
|
|
}
|
|
|
|
public static Dialog versionUpdateDialog(final Activity activity, boolean z, String str) {
|
|
Builder builder = new Builder(activity);
|
|
builder.title(R.string.update_title).ok(R.string.update_sure).content(str).gravity(3).onOk(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.JimuSimpleDialog.1
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
if (Channel.GOOGLE_PLAY.getChannelName().equals("google_play")) {
|
|
SystemUtils.a(activity);
|
|
dialogInterface.dismiss();
|
|
} else {
|
|
UpdateManager.c().a(activity);
|
|
dialogInterface.dismiss();
|
|
}
|
|
}
|
|
}).build();
|
|
if (!z) {
|
|
builder.cancel(R.string.cancel).canceledOnTouchOutside(true).onCancel(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.JimuSimpleDialog.2
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
});
|
|
}
|
|
return builder.build();
|
|
}
|
|
|
|
@Override // android.app.Dialog, android.content.DialogInterface
|
|
public void dismiss() {
|
|
super.dismiss();
|
|
OnDismissListener onDismissListener = this.mOnDismissListener;
|
|
if (onDismissListener != null) {
|
|
onDismissListener.onDismiss(this);
|
|
}
|
|
}
|
|
|
|
public void intView(View view, Builder builder) {
|
|
this.tvDialogTitle = (TextView) view.findViewById(R.id.tvDialogTitle);
|
|
this.tvTips = (TextView) view.findViewById(R.id.tvTips);
|
|
this.imgLogo = (ImageView) view.findViewById(R.id.imgLogo);
|
|
this.btnCancel = (Button) view.findViewById(R.id.btnCancel);
|
|
this.btnOk = (Button) view.findViewById(R.id.btnOk);
|
|
this.btnCancel.setOnClickListener(this);
|
|
this.btnOk.setOnClickListener(this);
|
|
if (!TextUtils.isEmpty(this.content)) {
|
|
this.tvTips.setText(this.content);
|
|
this.tvTips.setMovementMethod(ScrollingMovementMethod.getInstance());
|
|
}
|
|
if (this.onCancelListener == null) {
|
|
this.btnCancel.setVisibility(8);
|
|
}
|
|
if (this.onOkListener == null) {
|
|
this.btnOk.setVisibility(8);
|
|
}
|
|
if (!TextUtils.isEmpty(this.ok)) {
|
|
this.btnOk.setText(this.ok);
|
|
}
|
|
if (!TextUtils.isEmpty(this.cancel)) {
|
|
this.btnCancel.setText(this.cancel);
|
|
}
|
|
if (TextUtils.isEmpty(builder.title)) {
|
|
this.tvDialogTitle.setVisibility(8);
|
|
} else {
|
|
this.tvDialogTitle.setVisibility(0);
|
|
this.tvDialogTitle.setText(builder.title);
|
|
}
|
|
if (!TextUtils.isEmpty(builder.logoUrl)) {
|
|
Glide.e(getContext()).a(builder.logoUrl).a(this.imgLogo);
|
|
} else if (builder.logoResId != 0) {
|
|
this.imgLogo.setImageResource(builder.logoResId);
|
|
} else {
|
|
this.imgLogo.setVisibility(8);
|
|
}
|
|
if (17 != builder.gravity) {
|
|
this.tvTips.setGravity(builder.gravity);
|
|
}
|
|
int i = this.cancleBtnBg;
|
|
if (i != 0) {
|
|
this.btnCancel.setBackgroundResource(i);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
int id = view.getId();
|
|
if (id == R.id.btnCancel) {
|
|
DialogInterface.OnClickListener onClickListener = this.onCancelListener;
|
|
if (onClickListener != null) {
|
|
onClickListener.onClick(this, 0);
|
|
return;
|
|
} else {
|
|
dismiss();
|
|
return;
|
|
}
|
|
}
|
|
if (id != R.id.btnOk) {
|
|
dismiss();
|
|
return;
|
|
}
|
|
DialogInterface.OnClickListener onClickListener2 = this.onOkListener;
|
|
if (onClickListener2 != null) {
|
|
onClickListener2.onClick(this, 0);
|
|
} else {
|
|
dismiss();
|
|
}
|
|
}
|
|
|
|
public void setOnDismissListener(OnDismissListener onDismissListener) {
|
|
this.mOnDismissListener = onDismissListener;
|
|
}
|
|
|
|
public JimuSimpleDialog(Context context, int i) {
|
|
super(context, i);
|
|
}
|
|
|
|
protected JimuSimpleDialog(Context context, boolean z, DialogInterface.OnCancelListener onCancelListener) {
|
|
super(context, z, onCancelListener);
|
|
}
|
|
}
|