| package com.dayu.qiheonlinelibrary.view; | 
|   | 
| import static android.view.Gravity.CENTER; | 
|   | 
| import android.app.Dialog; | 
| import android.content.DialogInterface; | 
| import android.text.TextUtils; | 
| import android.view.KeyEvent; | 
| import android.view.ViewGroup; | 
| import android.view.WindowManager; | 
| import android.widget.EditText; | 
| import android.widget.ImageView; | 
| import android.widget.TextView; | 
|   | 
| import com.dayu.baselibrary.utils.ToastUtil; | 
| import com.dayu.qiheonlinelibrary.R; | 
| import com.dayu.qiheonlinelibrary.activity.QHOlineBaseActivity; | 
|   | 
| /** | 
|  * author: zuo | 
|  * Date: 2024-08-07 | 
|  * Time: 18:27 | 
|  * 备注:搜索用户 | 
|  */ | 
| public class UserSearchDialog extends Dialog { | 
|     QHOlineBaseActivity mContext; | 
|     EditText etName, etCardId; | 
|   | 
|     public interface SearchCallBack { | 
|         void onBack(String name, String cardId); | 
|     } | 
|   | 
|     SearchCallBack searchCallBack; | 
|   | 
|     public UserSearchDialog(QHOlineBaseActivity context, SearchCallBack searchCallBack) { | 
|         super(context, com.dayu.baselibrary.R.style.ws_pay_showSelfDialog); | 
|         mContext = context; | 
|         this.searchCallBack = searchCallBack; | 
|         initView(); | 
|     } | 
|   | 
|     private void initView() { | 
|         getWindow().setGravity(CENTER); | 
|         setContentView(R.layout.dialog_search_user); | 
|         setCanceledOnTouchOutside(false); | 
|   | 
|         etName = findViewById(R.id.etName); | 
|         etCardId = findViewById(R.id.etCardId); | 
|         ImageView close = findViewById(R.id.closeDialog); | 
|         close.setOnClickListener(v -> UserSearchDialog.this.dismiss()); | 
|         TextView ok = findViewById(R.id.pw_ok); | 
|         ok.setOnClickListener(v -> { | 
|             String name = etName.getText().toString(); | 
|             String cardId = etCardId.getText().toString(); | 
|             if (!TextUtils.isEmpty(name) || !TextUtils.isEmpty(cardId)) { | 
|                 if (searchCallBack != null) { | 
|                     searchCallBack.onBack(name, cardId); | 
|                     UserSearchDialog.this.dismiss(); | 
|                 } | 
|             } else { | 
|                 ToastUtil.show("请输入姓名或身份证号"); | 
|             } | 
|         }); | 
|         // 设置 OnKeyListener 拦截返回键事件 | 
|         setOnKeyListener(new DialogInterface.OnKeyListener() { | 
|             @Override | 
|             public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { | 
|                 if (keyCode == KeyEvent.KEYCODE_BACK) { | 
|                     // 拦截返回键事件,返回 true | 
|                     return true; | 
|                 } | 
|                 return false; | 
|             } | 
|         }); | 
|     } | 
|   | 
|     public void show() { | 
|   | 
|         super.show(); | 
|         /** | 
|          * 设置宽度全屏,要设置在show的后面 | 
|          */ | 
|         WindowManager.LayoutParams layoutParams = getWindow().getAttributes(); | 
|         layoutParams.gravity = CENTER; | 
|         layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; | 
|         layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT; | 
|         getWindow().getDecorView().setPadding(0, 0, 0, 0); | 
|         getWindow().setAttributes(layoutParams); | 
|     } | 
| } |