302 lines
12 KiB
Java
302 lines
12 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.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubtech.utils.DisplayUtil;
|
|
import com.ubtech.view.dialog.SimpleDialog;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class PermissionHintDialog extends Dialog implements View.OnClickListener {
|
|
public Button btnCancel;
|
|
public Button btnOk;
|
|
public String cancel;
|
|
public String content;
|
|
private ImageView imgLogo;
|
|
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 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 PermissionHintDialog build() {
|
|
int i;
|
|
double d;
|
|
int a;
|
|
int a2;
|
|
PermissionHintDialog permissionHintDialog = new PermissionHintDialog(this.context);
|
|
permissionHintDialog.requestWindowFeature(1);
|
|
permissionHintDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
|
|
permissionHintDialog.content = this.content;
|
|
permissionHintDialog.ok = this.ok;
|
|
permissionHintDialog.cancel = this.cancel;
|
|
permissionHintDialog.onOkListener = this.onOkListener;
|
|
permissionHintDialog.onCancelListener = this.onCancelListener;
|
|
View inflate = LayoutInflater.from(this.context).inflate(R.layout.dialog_permission_hint, (ViewGroup) null, false);
|
|
permissionHintDialog.intView(inflate, this);
|
|
permissionHintDialog.setContentView(inflate);
|
|
permissionHintDialog.setCanceledOnTouchOutside(this.canceledOnTouchOutside);
|
|
Window window = permissionHintDialog.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 permissionHintDialog;
|
|
}
|
|
|
|
public Builder cancel(String str) {
|
|
this.cancel = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder canceledOnTouchOutside(boolean z) {
|
|
this.canceledOnTouchOutside = z;
|
|
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 PermissionHintDialog(Context context) {
|
|
super(context);
|
|
}
|
|
|
|
public static PermissionHintDialog 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 showBluetoothEnableFailedHint(Context context) {
|
|
new SimpleDialog.Builder(context).d(R.string.permission_button_text_permission_denied_warning_dialog).a((CharSequence) context.getResources().getString(R.string.permission_waring_text_bluetooth_enable_failed)).b(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.PermissionHintDialog.4
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
dialogInterface.dismiss();
|
|
}
|
|
}).a().show();
|
|
return true;
|
|
}
|
|
|
|
public static boolean showLocationPermissionDeniedHint(Context context) {
|
|
new Builder(context).ok(R.string.permission_button_text_permission_denied_warning_dialog).content(String.format(context.getResources().getString(R.string.permission_prompt_open_permission_by_settings), context.getResources().getString(R.string.permission_location))).onOk(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.PermissionHintDialog.2
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
}
|
|
}).build().show();
|
|
return true;
|
|
}
|
|
|
|
public static boolean showPermissionDeniedHint(Context context, String str) {
|
|
new Builder(context).ok(R.string.permission_button_text_permission_denied_warning_dialog).content(str).onOk(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.PermissionHintDialog.1
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
}
|
|
}).build().show();
|
|
return true;
|
|
}
|
|
|
|
public static boolean showStoragePermissionDeniedHint(Context context) {
|
|
new Builder(context).ok(R.string.permission_button_text_permission_denied_warning_dialog).content(String.format(context.getResources().getString(R.string.permission_prompt_open_permission_by_settings), context.getResources().getString(R.string.permission_storage))).onOk(new DialogInterface.OnClickListener() { // from class: com.ubt.jimu.base.dialog.PermissionHintDialog.3
|
|
@Override // android.content.DialogInterface.OnClickListener
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
}
|
|
}).build().show();
|
|
return true;
|
|
}
|
|
|
|
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);
|
|
} else if (JimuApplication.l().i()) {
|
|
this.btnCancel.setBackgroundResource(R.drawable.negative_btn_bg_pad);
|
|
} else {
|
|
this.btnCancel.setBackgroundResource(R.drawable.negative_btn_bg);
|
|
}
|
|
if (this.onOkListener == null) {
|
|
this.btnOk.setVisibility(8);
|
|
} else if (JimuApplication.l().i()) {
|
|
this.btnOk.setBackgroundResource(R.drawable.positive_btn_bg_pad);
|
|
} else {
|
|
this.btnOk.setBackgroundResource(R.drawable.positive_btn_bg);
|
|
}
|
|
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);
|
|
}
|
|
}
|
|
|
|
@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) {
|
|
dismiss();
|
|
} else {
|
|
onClickListener2.onClick(this, 0);
|
|
dismiss();
|
|
}
|
|
}
|
|
|
|
public PermissionHintDialog(Context context, int i) {
|
|
super(context, i);
|
|
}
|
|
|
|
protected PermissionHintDialog(Context context, boolean z, DialogInterface.OnCancelListener onCancelListener) {
|
|
super(context, z, onCancelListener);
|
|
}
|
|
}
|