266 lines
8.3 KiB
Java
266 lines
8.3 KiB
Java
package com.ubt.jimu.base.dialog;
|
|
|
|
import android.app.Dialog;
|
|
import android.content.Context;
|
|
import android.content.DialogInterface;
|
|
import android.graphics.drawable.ColorDrawable;
|
|
import android.os.Bundle;
|
|
import android.text.TextUtils;
|
|
import android.text.method.ScrollingMovementMethod;
|
|
import android.view.KeyEvent;
|
|
import android.view.View;
|
|
import android.view.Window;
|
|
import android.view.WindowManager;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
import com.ubt.jimu.JimuApplication;
|
|
import com.ubt.jimu.R;
|
|
import com.ubtech.utils.DisplayUtil;
|
|
import com.ubtech.view.widget.UButton;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class UpdateDialog extends Dialog implements View.OnClickListener {
|
|
private boolean backAble;
|
|
private UButton btnCancel;
|
|
private UButton btnOk;
|
|
private String cancel;
|
|
private boolean canceledOnTouchOutside;
|
|
private String content;
|
|
private ImageView imgLeft;
|
|
private ImageView imgRight;
|
|
private boolean isLeft;
|
|
private boolean isRight;
|
|
private int leftResId;
|
|
private InteractionListner mInteractionListener;
|
|
private String ok;
|
|
private int rightResId;
|
|
private String title;
|
|
private TextView tvContent;
|
|
private TextView tvDialogTitle;
|
|
|
|
public static class Builder {
|
|
private String cancel;
|
|
private String content;
|
|
private int leftResId;
|
|
private InteractionListner mInteractionListner;
|
|
private String ok;
|
|
private int rightResId;
|
|
private String title;
|
|
private boolean canceledOnTouchOutside = true;
|
|
private boolean backAble = true;
|
|
private boolean isLeft = false;
|
|
private boolean isRight = false;
|
|
|
|
public Builder backAble(boolean z) {
|
|
this.backAble = z;
|
|
return this;
|
|
}
|
|
|
|
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 interactionListener(InteractionListner interactionListner) {
|
|
this.mInteractionListner = interactionListner;
|
|
return this;
|
|
}
|
|
|
|
public Builder isLeft(boolean z) {
|
|
this.isLeft = z;
|
|
return this;
|
|
}
|
|
|
|
public Builder isRight(boolean z) {
|
|
this.isRight = z;
|
|
return this;
|
|
}
|
|
|
|
public Builder leftResId(int i) {
|
|
this.leftResId = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder ok(String str) {
|
|
this.ok = str;
|
|
return this;
|
|
}
|
|
|
|
public Builder rightResId(int i) {
|
|
this.rightResId = i;
|
|
return this;
|
|
}
|
|
|
|
public Builder title(String str) {
|
|
this.title = str;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
public interface InteractionListner {
|
|
void onCancelClick(UpdateDialog updateDialog);
|
|
|
|
void onLeftImgClick(UpdateDialog updateDialog);
|
|
|
|
void onOkClick(UpdateDialog updateDialog);
|
|
|
|
void onRightImgClick(UpdateDialog updateDialog);
|
|
}
|
|
|
|
public UpdateDialog(Context context, Builder builder) {
|
|
super(context);
|
|
this.canceledOnTouchOutside = builder.canceledOnTouchOutside;
|
|
this.backAble = builder.backAble;
|
|
this.isLeft = builder.isLeft;
|
|
this.isRight = builder.isRight;
|
|
this.leftResId = builder.leftResId;
|
|
this.rightResId = builder.rightResId;
|
|
this.title = builder.title;
|
|
this.content = builder.content;
|
|
this.cancel = builder.cancel;
|
|
this.ok = builder.ok;
|
|
this.mInteractionListener = builder.mInteractionListner;
|
|
}
|
|
|
|
private void initView() {
|
|
this.imgLeft = (ImageView) findViewById(R.id.imgLeft);
|
|
this.imgRight = (ImageView) findViewById(R.id.imgRight);
|
|
this.tvDialogTitle = (TextView) findViewById(R.id.tvDialogTitle);
|
|
this.tvContent = (TextView) findViewById(R.id.tvContent);
|
|
this.btnCancel = (UButton) findViewById(R.id.btnCancel);
|
|
this.btnOk = (UButton) findViewById(R.id.btnOk);
|
|
this.imgLeft.setOnClickListener(this);
|
|
this.imgRight.setOnClickListener(this);
|
|
this.btnCancel.setOnClickListener(this);
|
|
this.btnOk.setOnClickListener(this);
|
|
if (this.isLeft) {
|
|
this.imgLeft.setVisibility(0);
|
|
this.imgLeft.setImageResource(this.leftResId);
|
|
} else {
|
|
this.imgLeft.setVisibility(8);
|
|
}
|
|
if (this.isRight) {
|
|
this.imgRight.setVisibility(0);
|
|
this.imgRight.setImageResource(this.rightResId);
|
|
} else {
|
|
this.imgRight.setVisibility(8);
|
|
}
|
|
if (TextUtils.isEmpty(this.cancel)) {
|
|
this.btnCancel.setVisibility(8);
|
|
} else {
|
|
this.btnCancel.setVisibility(0);
|
|
this.btnCancel.setText(this.cancel);
|
|
}
|
|
if (TextUtils.isEmpty(this.ok)) {
|
|
this.btnOk.setVisibility(8);
|
|
} else {
|
|
this.btnOk.setVisibility(0);
|
|
this.btnOk.setText(this.ok);
|
|
}
|
|
if (TextUtils.isEmpty(this.title)) {
|
|
this.tvDialogTitle.setVisibility(4);
|
|
} else {
|
|
this.tvDialogTitle.setVisibility(0);
|
|
this.tvDialogTitle.setText(this.title);
|
|
}
|
|
if (TextUtils.isEmpty(this.content)) {
|
|
this.tvContent.setVisibility(4);
|
|
return;
|
|
}
|
|
this.tvContent.setVisibility(0);
|
|
this.tvContent.setText(this.content);
|
|
this.tvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
|
|
}
|
|
|
|
private void setupWindow() {
|
|
int i;
|
|
double d;
|
|
int a;
|
|
int a2;
|
|
requestWindowFeature(1);
|
|
setContentView(R.layout.firmware_update_dialog);
|
|
Window window = getWindow();
|
|
window.setBackgroundDrawable(new ColorDrawable(0));
|
|
window.setWindowAnimations(R.style.dialogWindowAlphaIn);
|
|
WindowManager.LayoutParams attributes = window.getAttributes();
|
|
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(getContext(), 516.0f);
|
|
a2 = DisplayUtil.a(getContext(), 322.0f);
|
|
} else {
|
|
a = DisplayUtil.a(getContext(), 344.0f);
|
|
a2 = DisplayUtil.a(getContext(), 222.5f);
|
|
}
|
|
if (a > i || a2 > i2) {
|
|
i = a;
|
|
i2 = a2;
|
|
}
|
|
attributes.width = i;
|
|
attributes.height = i2;
|
|
attributes.gravity = 17;
|
|
window.setAttributes(attributes);
|
|
setCanceledOnTouchOutside(this.canceledOnTouchOutside);
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
if (this.mInteractionListener == null) {
|
|
}
|
|
switch (view.getId()) {
|
|
case R.id.btnCancel /* 2131296362 */:
|
|
this.mInteractionListener.onCancelClick(this);
|
|
break;
|
|
case R.id.btnOk /* 2131296369 */:
|
|
this.mInteractionListener.onOkClick(this);
|
|
break;
|
|
case R.id.imgLeft /* 2131296847 */:
|
|
this.mInteractionListener.onLeftImgClick(this);
|
|
break;
|
|
case R.id.imgRight /* 2131296875 */:
|
|
this.mInteractionListener.onRightImgClick(this);
|
|
break;
|
|
}
|
|
}
|
|
|
|
@Override // android.app.Dialog
|
|
protected void onCreate(Bundle bundle) {
|
|
super.onCreate(bundle);
|
|
setupWindow();
|
|
initView();
|
|
}
|
|
|
|
@Override // android.app.Dialog, android.view.KeyEvent.Callback
|
|
public boolean onKeyDown(int i, KeyEvent keyEvent) {
|
|
if (this.backAble) {
|
|
return super.onKeyDown(i, keyEvent);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public UpdateDialog(Context context, int i) {
|
|
super(context, i);
|
|
}
|
|
|
|
protected UpdateDialog(Context context, boolean z, DialogInterface.OnCancelListener onCancelListener) {
|
|
super(context, z, onCancelListener);
|
|
}
|
|
}
|