DialogUtil.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.cooleshow.base.widgets;
  2. import android.view.Gravity;
  3. import android.view.View;
  4. import android.widget.ImageView;
  5. import android.widget.TextView;
  6. import androidx.fragment.app.FragmentManager;
  7. import com.cooleshow.base.R;
  8. import com.cooleshow.base.utils.PopupUtil;
  9. /**
  10. * 创建日期:2022/6/1 15:31
  11. *
  12. * @author Ryan
  13. * 类说明:
  14. */
  15. public class DialogUtil {
  16. public interface ShowListener {
  17. void onShow(ViewHolder holder, BaseDialog dialog);
  18. }
  19. public interface OnDialogButtonClickListener {
  20. void onCancel(View v);
  21. void onCommit(View v);
  22. }
  23. /*居中显示*/
  24. public static void showInCenter(FragmentManager fragmentmanager, int resourcesId, ShowListener showListener) {
  25. CommonDialog.init().setLayoutId(resourcesId)
  26. .setConvertListener(new ViewConvertListener() {
  27. @Override
  28. public void convertView(ViewHolder holder, BaseDialog dialog) {
  29. showListener.onShow(holder, dialog);
  30. }
  31. })
  32. .setDimAmount(0.5f)
  33. .setGravity(Gravity.CENTER)
  34. .show(fragmentmanager);
  35. }
  36. public static void showInCenterNoCancel(FragmentManager fragmentmanager, int resourcesId, ShowListener showListener) {
  37. CommonDialog.init().setLayoutId(resourcesId)
  38. .setConvertListener(new ViewConvertListener() {
  39. @Override
  40. public void convertView(ViewHolder holder, BaseDialog dialog) {
  41. showListener.onShow(holder, dialog);
  42. }
  43. })
  44. .setDimAmount(0.7f)
  45. .setGravity(Gravity.CENTER)
  46. .setOutCancel(false)
  47. .show(fragmentmanager);
  48. }
  49. public static void showInCenterWithClose(FragmentManager fragmentmanager, int resourcesId, String title, String content, OnDialogButtonClickListener onDialogButtonClickListener) {
  50. if (fragmentmanager == null) {
  51. return;
  52. }
  53. CommonDialog.init().setLayoutId(resourcesId)
  54. .setConvertListener(new ViewConvertListener() {
  55. @Override
  56. public void convertView(ViewHolder holder, BaseDialog dialog) {
  57. TextView tvTitle = holder.getView(R.id.tv_title);
  58. TextView tvContent = holder.getView(R.id.tv_content);
  59. TextView btncancel = holder.getView(R.id.btn_cancel);
  60. TextView btnCommit = holder.getView(R.id.btn_commit);
  61. ImageView iv_live_common_popu_close = holder.getView(R.id.iv_close);
  62. tvTitle.setText(title);
  63. tvContent.setText(content);
  64. iv_live_common_popu_close.setOnClickListener(v -> dialog.dismiss());
  65. btncancel.setOnClickListener(view -> {
  66. onDialogButtonClickListener.onCancel(view);
  67. dialog.dismiss();
  68. });
  69. btnCommit.setOnClickListener(view -> {
  70. onDialogButtonClickListener.onCommit(view);
  71. dialog.dismiss();
  72. });
  73. }
  74. })
  75. .setDimAmount(0.2f)
  76. .setOutCancel(false)
  77. .setGravity(Gravity.CENTER)
  78. .show(fragmentmanager);
  79. }
  80. /*居中显示*/
  81. public static void showInCenter(FragmentManager fragmentmanager, int resourcesId, String title, String content, OnDialogButtonClickListener onDialogButtonClickListener) {
  82. if (fragmentmanager == null) {
  83. return;
  84. }
  85. CommonDialog.init().setLayoutId(resourcesId)
  86. .setConvertListener(new ViewConvertListener() {
  87. @Override
  88. public void convertView(ViewHolder holder, BaseDialog dialog) {
  89. TextView tvTitle = holder.getView(R.id.tv_title);
  90. TextView tvContent = holder.getView(R.id.tv_content);
  91. TextView btncancel = holder.getView(R.id.btn_cancel);
  92. TextView btnCommit = holder.getView(R.id.btn_commit);
  93. tvTitle.setText(title);
  94. tvContent.setText(content);
  95. btncancel.setOnClickListener(view -> {
  96. onDialogButtonClickListener.onCancel(view);
  97. dialog.dismiss();
  98. });
  99. btnCommit.setOnClickListener(view -> {
  100. onDialogButtonClickListener.onCommit(view);
  101. dialog.dismiss();
  102. });
  103. }
  104. })
  105. .setDimAmount(0.2f)
  106. .setOutCancel(false)
  107. .setGravity(Gravity.CENTER)
  108. .show(fragmentmanager);
  109. }
  110. }