| | |
| | | package com.hdl.photovoltaic.widget; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.os.Bundle; |
| | | import android.view.View; |
| | | import android.view.Gravity; |
| | | import android.view.ViewGroup; |
| | | import android.view.Window; |
| | | import android.view.WindowManager; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.BaseDialog; |
| | | import com.hdl.photovoltaic.databinding.DialogTypeTitleListBBinding; |
| | | import com.hdl.photovoltaic.utils.UnitConversionUtils; |
| | | import com.hdl.photovoltaic.widget.adapter.TypeListDialogAdapter; |
| | | |
| | | import java.util.List; |
| | |
| | | |
| | | private List<String> mList; |
| | | |
| | | public BTypeTitleListDialog(@NonNull Context context, List<String> list,String selectType) { |
| | | public BTypeTitleListDialog(@NonNull Context context, List<String> list, String selectType) { |
| | | super(context, R.style.Custom_Dialog); |
| | | this.mContext = context; |
| | | this.mList = list; |
| | | this.mSelectType=selectType; |
| | | this.mSelectType = selectType; |
| | | } |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | | Window window = getWindow(); |
| | | if (window != null) { |
| | | window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); |
| | | WindowManager.LayoutParams layoutParams = window.getAttributes(); |
| | | layoutParams.gravity = Gravity.START | Gravity.TOP; |
| | | layoutParams.width = (int) UnitConversionUtils.dpToPx(mContext, 375 - 32); |
| | | layoutParams.x = (int) UnitConversionUtils.dpToPx(mContext, 16); |
| | | layoutParams.y = (int) UnitConversionUtils.dpToPx(mContext, 200); |
| | | window.setAttributes(layoutParams); |
| | | } |
| | | viewBinding = DialogTypeTitleListBBinding.inflate(getLayoutInflater()); |
| | | setContentView(viewBinding.getRoot()); |
| | | setDialogTouchOutsideCloseable(this); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(mContext); |
| | | typeListDialogAdapter = new TypeListDialogAdapter(this.mList, mContext,this.mSelectType); |
| | | typeListDialogAdapter = new TypeListDialogAdapter(this.mList, mContext, this.mSelectType); |
| | | viewBinding.typeListRl.setLayoutManager(linearLayout); |
| | | viewBinding.typeListRl.setAdapter(typeListDialogAdapter); |
| | | typeListDialogAdapter.setItemOnclickListener(new TypeListDialogAdapter.OnclickListener() { |
| | |
| | | @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.dimAmount = 0.6f; |
| | | // dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| | | // p.gravity = Gravity.BOTTOM; |
| | | // p.y = DensityUtils.dip2px(mContext, 352); |
| | | //// //这里设置的宽高优先级高于XML中的布局设置 |
| | | //// if (this.enumBoxType == BoxType.PhotoAlbumBox) { |
| | | //// p.gravity = Gravity.BOTTOM; |
| | | //// } else if (this.enumBoxType == BoxType.FlashingBox) { |
| | | //// p.dimAmount = 0f; |
| | | //// } |
| | | // // 设置到属性配置中 |
| | | // dialogWindow.setAttributes(p); |
| | | // } |
| | | // setDialogTouchOutsideCloseable(this); |
| | | |
| | | } |
| | | |
| | | @SuppressLint("ClickableViewAccessibility") |
| | | public void setDialogTouchOutsideCloseable(Dialog dialog) { |
| | | viewBinding.typeParentCl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | int top = viewBinding.dialogParentCl.getTop(); |
| | | int left = viewBinding.dialogParentCl.getLeft(); |
| | | int bottom = viewBinding.dialogParentCl.getBottom(); |
| | | int right = viewBinding.dialogParentCl.getRight(); |
| | | int y = (int) v.getY(); |
| | | int x = (int) v.getX(); |
| | | if (top < y && y < bottom) { |
| | | } else { |
| | | dismiss(); |
| | | } |
| | | if (left < x && x < right) { |
| | | |
| | | } else { |
| | | dismiss(); |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public void setOnListener(OnClickListener onClickListener) { |
| | | this.mOnClickListener = onClickListener; |