| | |
| | | package com.hdl.photovoltaic.widget; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | |
| | | this.mContext = context; |
| | | } |
| | | |
| | | @Override |
| | | protected void onStart() { |
| | | super.onStart(); |
| | | // 获取窗口对象 |
| | | Window dialogWindow = this.getWindow(); |
| | | if (dialogWindow != null) { |
| | | // 获取对话框当前的参数值 |
| | | WindowManager.LayoutParams p = dialogWindow.getAttributes(); |
| | | p.width = LinearLayout.LayoutParams.MATCH_PARENT; |
| | | p.height = LinearLayout.LayoutParams.WRAP_CONTENT; |
| | | p.gravity = Gravity.TOP; |
| | | // 设置到属性配置中 |
| | | dialogWindow.setAttributes(p); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | viewBinding = DialogListBinding.inflate(getLayoutInflater()); |
| | | setContentView(viewBinding.getRoot()); |
| | | this.setCanceledOnTouchOutside(true); |
| | | // setDialogTouchOutsideCloseable(this); |
| | | setDialogTouchOutsideCloseable(this); |
| | | initData(); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(mContext); |
| | | listDialogAdapter = new ListDialogAdapter(this.list, mContext); |
| | |
| | | } |
| | | |
| | | |
| | | @SuppressLint("ClickableViewAccessibility") |
| | | public void setDialogTouchOutsideCloseable(Dialog dialog) { |
| | | viewBinding.getRoot().setOnTouchListener(new View.OnTouchListener() { |
| | | // viewBinding.getRoot().setOnTouchListener(new View.OnTouchListener() { |
| | | // |
| | | // @Override |
| | | // public boolean onTouch(View v, MotionEvent event) { |
| | | // int top = viewBinding.dialogParent.getTop(); |
| | | // int left = viewBinding.dialogParent.getLeft(); |
| | | // int bottom = viewBinding.dialogParent.getBottom(); |
| | | // int right = viewBinding.dialogParent.getRight(); |
| | | // int y = (int) event.getY(); |
| | | // int x = (int) event.getX(); |
| | | // if (event.getAction() == MotionEvent.ACTION_UP) { |
| | | // if (top < y && y < bottom) { |
| | | // |
| | | // } else { |
| | | // dismiss(); |
| | | // } |
| | | // |
| | | // if (left < x && x < right) { |
| | | // |
| | | // } else { |
| | | // dismiss(); |
| | | // } |
| | | // |
| | | // |
| | | // } |
| | | // return true; |
| | | // } |
| | | // }); |
| | | viewBinding.getRoot().setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public boolean onTouch(View v, MotionEvent event) { |
| | | public void onClick(View v) { |
| | | int top = viewBinding.dialogParent.getTop(); |
| | | int left = viewBinding.dialogParent.getLeft(); |
| | | int bottom = viewBinding.dialogParent.getBottom(); |
| | | int right = viewBinding.dialogParent.getRight(); |
| | | int y = (int) event.getY(); |
| | | int x = (int) event.getX(); |
| | | if (event.getAction() == MotionEvent.ACTION_UP) { |
| | | int y = (int) v.getY(); |
| | | int x = (int) v.getX(); |
| | | if (top < y && y < bottom) { |
| | | |
| | | } else { |
| | | dismiss(); |
| | | } |
| | | |
| | | if (left < x && x < right) { |
| | | |
| | | } else { |
| | | dismiss(); |
| | | } |
| | | |
| | | |
| | | } |
| | | return true; |
| | | } |
| | | }); |
| | | // Window window = dialog.getWindow(); |
| | | // WindowManager.LayoutParams params = window.getAttributes(); |
| | | // params.width = ViewGroup.LayoutParams.MATCH_PARENT; |
| | | // params.height = ViewGroup.LayoutParams.MATCH_PARENT; |
| | | // window.setAttributes(params); |
| | | // //空白处不能取消动画 |
| | | // setCanceledOnTouchOutside(true); |
| | | } |
| | | } |