| | |
| | | import android.annotation.SuppressLint; |
| | | import android.app.Dialog; |
| | | import android.content.Context; |
| | | import android.graphics.Color; |
| | | import android.graphics.PixelFormat; |
| | | import android.graphics.drawable.ColorDrawable; |
| | | import android.os.Bundle; |
| | | import android.view.Gravity; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.view.Window; |
| | | import android.view.WindowManager; |
| | | import android.widget.LinearLayout; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | |
| | | |
| | | import java.util.List; |
| | | |
| | | import io.dcloud.common.util.DensityUtils; |
| | | |
| | | public class TypeTitleListDialog extends BaseDialog { |
| | | |
| | | private OnClickListener mOnClickListener; |
| | |
| | | private TypeListDialogAdapter typeListDialogAdapter; |
| | | |
| | | private Context mContext; |
| | | String mSelectType; |
| | | |
| | | private List<String> mList; |
| | | |
| | | public TypeTitleListDialog(@NonNull Context context, List<String> list) { |
| | | public TypeTitleListDialog(@NonNull Context context, List<String> list, String selectType) { |
| | | super(context, R.style.Custom_Dialog); |
| | | this.mContext = context; |
| | | this.mList = list; |
| | | this.mSelectType = selectType; |
| | | } |
| | | |
| | | @Override |
| | |
| | | setContentView(viewBinding.getRoot()); |
| | | setDialogTouchOutsideCloseable(this); |
| | | LinearLayoutManager linearLayout = new LinearLayoutManager(mContext); |
| | | typeListDialogAdapter = new TypeListDialogAdapter(this.mList, mContext); |
| | | 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.getRoot().setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.typeParentCl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | int top = viewBinding.typeParentCl.getTop(); |
| | | int left = viewBinding.typeParentCl.getLeft(); |
| | | int bottom = viewBinding.typeParentCl.getBottom(); |
| | | int right = viewBinding.typeParentCl.getRight(); |
| | | 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) { |