|
@@ -0,0 +1,166 @@
|
|
|
|
+package com.compdfkit.tools.dialog;
|
|
|
|
+
|
|
|
|
+import android.content.Context;
|
|
|
|
+import android.text.TextUtils;
|
|
|
|
+import android.view.Display;
|
|
|
|
+import android.view.View;
|
|
|
|
+import android.view.Window;
|
|
|
|
+import android.view.WindowManager;
|
|
|
|
+import android.widget.Button;
|
|
|
|
+import android.widget.EditText;
|
|
|
|
+import android.widget.TextView;
|
|
|
|
+import androidx.appcompat.app.AppCompatDialog;
|
|
|
|
+
|
|
|
|
+import com.compdfkit.tools.R;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author luozhipeng
|
|
|
|
+ * @classname CommonInputDialog
|
|
|
|
+ * @date 2020-02-21 11:42
|
|
|
|
+ * @description
|
|
|
|
+ */
|
|
|
|
+public class CCommonInputDialog extends AppCompatDialog {
|
|
|
|
+
|
|
|
|
+ private Context context;
|
|
|
|
+
|
|
|
|
+ private String title;
|
|
|
|
+ private String message;
|
|
|
|
+ private String cancelStr;
|
|
|
|
+ private String okStr;
|
|
|
|
+ private Runnable cancelCallback;
|
|
|
|
+ private OnInputConpleteListener onInputConpleteListener;
|
|
|
|
+
|
|
|
|
+ private View mView;
|
|
|
|
+
|
|
|
|
+ private TextView titleTv;
|
|
|
|
+ private View gap_1;
|
|
|
|
+
|
|
|
|
+ private TextView messageTv;
|
|
|
|
+ private String messageStrTv;
|
|
|
|
+ private View gap_3;
|
|
|
|
+
|
|
|
|
+ private EditText messageEt;
|
|
|
|
+ private View gap_2;
|
|
|
|
+ private Button cancelBt;
|
|
|
|
+ private Button okBt;
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog(Context context) {
|
|
|
|
+ super(context);
|
|
|
|
+ initView(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog(Context context, int theme) {
|
|
|
|
+ super(context, theme);
|
|
|
|
+ initView(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected CCommonInputDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
|
|
|
|
+ super(context, cancelable, cancelListener);
|
|
|
|
+ initView(context);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initView(Context context) {
|
|
|
|
+ this.context = context;
|
|
|
|
+
|
|
|
|
+ mView = View.inflate(context, R.layout.common_input_dialog_layout, null);
|
|
|
|
+
|
|
|
|
+ titleTv = mView.findViewById(R.id.common_input_dialog_title);
|
|
|
|
+ gap_1 = mView.findViewById(R.id.common_input_dialog_gap_1);
|
|
|
|
+
|
|
|
|
+ messageTv = mView.findViewById(R.id.common_input_dialog_message);
|
|
|
|
+ gap_3 = mView.findViewById(R.id.common_input_dialog_gap_3);
|
|
|
|
+
|
|
|
|
+ messageEt = mView.findViewById(R.id.common_input_dialog_et);
|
|
|
|
+ gap_2 = mView.findViewById(R.id.common_input_dialog_gap_2);
|
|
|
|
+ cancelBt = mView.findViewById(R.id.common_input_dialog_cancel);
|
|
|
|
+ okBt = mView.findViewById(R.id.common_input_dialog_ok);
|
|
|
|
+ cancelBt.setOnClickListener(v -> {
|
|
|
|
+ if (cancelCallback != null) {
|
|
|
|
+ cancelCallback.run();
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ okBt.setOnClickListener(v -> {
|
|
|
|
+ if (onInputConpleteListener != null) {
|
|
|
|
+ onInputConpleteListener.getInputText(messageEt.getText().toString());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ setContentView(mView);
|
|
|
|
+
|
|
|
|
+ Window window = getWindow();
|
|
|
|
+ WindowManager m = window.getWindowManager();
|
|
|
|
+ Display display = m.getDefaultDisplay();
|
|
|
|
+ WindowManager.LayoutParams p = window.getAttributes();
|
|
|
|
+ p.width = (int) (display.getWidth() * 0.7);
|
|
|
|
+ window.setAttributes(p);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void initVisibility() {
|
|
|
|
+ if (TextUtils.isEmpty(title)) {
|
|
|
|
+ titleTv.setVisibility(View.GONE);
|
|
|
|
+ gap_1.setVisibility(View.GONE);
|
|
|
|
+ } else {
|
|
|
|
+ titleTv.setVisibility(View.VISIBLE);
|
|
|
|
+ gap_1.setVisibility(View.VISIBLE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (TextUtils.isEmpty(messageStrTv)) {
|
|
|
|
+ messageTv.setVisibility(View.GONE);
|
|
|
|
+ gap_3.setVisibility(View.GONE);
|
|
|
|
+ } else {
|
|
|
|
+ messageTv.setVisibility(View.VISIBLE);
|
|
|
|
+ gap_3.setVisibility(View.VISIBLE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (cancelCallback != null) {
|
|
|
|
+ cancelBt.setVisibility(View.VISIBLE);
|
|
|
|
+ } else {
|
|
|
|
+ cancelBt.setVisibility(View.GONE);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void setInputType(int type) {
|
|
|
|
+ messageEt.setInputType(type);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog setTitle(String title) {
|
|
|
|
+ this.title = title;
|
|
|
|
+ titleTv.setText(title);
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog setMessage(String message) {
|
|
|
|
+ this.messageStrTv = message;
|
|
|
|
+ messageTv.setText(message);
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog setHintInputText(String message) {
|
|
|
|
+ this.message = message;
|
|
|
|
+ messageEt.setHint(message);
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog setCancelCallback(String cancelStr, Runnable cancelCallback) {
|
|
|
|
+ this.cancelStr = cancelStr;
|
|
|
|
+ this.cancelCallback = cancelCallback;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public CCommonInputDialog setOkCallback(String okStr, OnInputConpleteListener onInputConpleteListener) {
|
|
|
|
+ this.okStr = okStr;
|
|
|
|
+ this.onInputConpleteListener = onInputConpleteListener;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void show() {
|
|
|
|
+ initVisibility();
|
|
|
|
+ super.show();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public interface OnInputConpleteListener {
|
|
|
|
+ void getInputText(String text);
|
|
|
|
+ }
|
|
|
|
+}
|