From fa6f5a7cb28a3637c1af43fd93cecfb295f69843 Mon Sep 17 00:00:00 2001 From: hss01248 Date: Sat, 24 Mar 2018 10:51:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=87=A0=E4=B8=AA=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E9=85=8D=E7=BD=AE=E9=A1=B9,=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E6=8C=89=E9=92=AE=E5=9B=9E=E8=B0=83=E5=90=8E?= =?UTF-8?q?=E6=98=AF=E5=90=A6dismiss=E7=9A=84=E5=88=A4=E5=AE=9A=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hss01248/dialogutildemo/MainActivity.java | 2 +- .../main/java/com/hss01248/dialog/Tool.java | 34 ++++++++++++------- .../dialog/bottomsheet/BottomSheetHolder.java | 2 +- .../bottomsheet/BottomSheetPagerHolder.java | 2 +- .../dialog/building/DialogViewBuilder.java | 6 ++-- .../dialog/building/MyDialogBuilder.java | 6 ++-- .../hss01248/dialog/config/ConfigBean.java | 14 ++++---- .../hss01248/dialog/config/DefaultConfig.java | 17 ++++++++++ .../dialog/ios/IosActionSheetHolder.java | 2 +- .../dialog/ios/IosAlertDialogHolder.java | 4 +-- .../dialog/ios/IosCenterItemHolder.java | 2 +- .../dialog/material/MaterialDialogHolder.java | 2 +- 12 files changed, 60 insertions(+), 33 deletions(-) diff --git a/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java b/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java index 9d50aaf..acf254d 100644 --- a/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java +++ b/app/src/main/java/com/hss01248/dialogutildemo/MainActivity.java @@ -554,7 +554,7 @@ public void onGetChoose(boolean[] states) { public void onItemClick(CharSequence text, int position) { showToast(text + "--" + position); } - }).show(); + }).setDismissAfterResultCallback(false).show(); break; case R.id.btn_md_bs: diff --git a/dialog/src/main/java/com/hss01248/dialog/Tool.java b/dialog/src/main/java/com/hss01248/dialog/Tool.java index 1fa638b..28cf141 100644 --- a/dialog/src/main/java/com/hss01248/dialog/Tool.java +++ b/dialog/src/main/java/com/hss01248/dialog/Tool.java @@ -49,11 +49,12 @@ */ public class Tool { - public static void dismiss(ConfigBean bean){ + public static void dismiss(ConfigBean bean,boolean isAfterResult){ - if(!bean.dismissAfterButtonClick){ + if(isAfterResult && !bean.dismissAfterResultCallback){ return; } + //先隐藏keyboard hideKeyBorad(bean); if(bean.showAsActivity){ @@ -77,6 +78,11 @@ public static void dismiss(ConfigBean bean){ } } + public static void dismiss(ConfigBean bean){ + dismiss(bean,false); + } + + public static Handler getMainHandler() { if(mainHandler ==null){ mainHandler = new Handler(Looper.getMainLooper()); @@ -257,18 +263,22 @@ public void onClick(View v) { return; } bean.listener.onGetInput(holder.getTxt1(),holder.getTxt2()); - } - bean.listener.onGetChoose(bean.checkedItems); - List selectedIndex = new ArrayList(); - List selectedStrs = new ArrayList(); - for(int j=0;j selectedIndex = new ArrayList(); + List selectedStrs = new ArrayList(); + for(int j=0;j parent, View view, int position, long id) { BottomSheetBean sheetBean = bean.lvDatas.get(position); bean.itemListener.onItemClick(sheetBean.text,position); - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }); diff --git a/dialog/src/main/java/com/hss01248/dialog/bottomsheet/BottomSheetPagerHolder.java b/dialog/src/main/java/com/hss01248/dialog/bottomsheet/BottomSheetPagerHolder.java index 766f028..f1675f3 100644 --- a/dialog/src/main/java/com/hss01248/dialog/bottomsheet/BottomSheetPagerHolder.java +++ b/dialog/src/main/java/com/hss01248/dialog/bottomsheet/BottomSheetPagerHolder.java @@ -74,7 +74,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) int actualPosition = pageNum * bean.gridColumns * 2 +position; bean.itemListener.onItemClick(bean.lvDatas.get(actualPosition).text,actualPosition); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }); diff --git a/dialog/src/main/java/com/hss01248/dialog/building/DialogViewBuilder.java b/dialog/src/main/java/com/hss01248/dialog/building/DialogViewBuilder.java index f1b880b..035b450 100644 --- a/dialog/src/main/java/com/hss01248/dialog/building/DialogViewBuilder.java +++ b/dialog/src/main/java/com/hss01248/dialog/building/DialogViewBuilder.java @@ -291,7 +291,7 @@ public void onClick(DialogInterface dialogInterface, int i) { bean.listener.onFirst(); bean.listener.onGetChoose(singleChosen,bean.wordsMd[singleChosen]); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }) .setNegativeButton(bean.text2, new DialogInterface.OnClickListener() { @@ -310,7 +310,7 @@ public void onClick(DialogInterface dialogInterface, int i) { if (bean.itemListener != null){ bean.itemListener.onItemClick(bean.wordsMd[i],i); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }); @@ -346,7 +346,7 @@ public void onClick(DialogInterface dialogInterface, int i) { } bean.listener.onChoosen(selectedIndex,selectedStrs,bean.checkedItems); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }) .setNegativeButton(bean.text2, new DialogInterface.OnClickListener() { diff --git a/dialog/src/main/java/com/hss01248/dialog/building/MyDialogBuilder.java b/dialog/src/main/java/com/hss01248/dialog/building/MyDialogBuilder.java index 4d3674f..cd86d22 100644 --- a/dialog/src/main/java/com/hss01248/dialog/building/MyDialogBuilder.java +++ b/dialog/src/main/java/com/hss01248/dialog/building/MyDialogBuilder.java @@ -292,7 +292,7 @@ public void onClick(DialogInterface dialogInterface, int i) { bean.listener.onFirst(); bean.listener.onGetChoose(singleChosen,bean.wordsMd[singleChosen]); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }) .setNegativeButton(bean.text2, new DialogInterface.OnClickListener() { @@ -311,7 +311,7 @@ public void onClick(DialogInterface dialogInterface, int i) { if (bean.itemListener != null){ bean.itemListener.onItemClick(bean.wordsMd[i],i); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }); @@ -347,7 +347,7 @@ public void onClick(DialogInterface dialogInterface, int i) { } bean.listener.onChoosen(selectedIndex,selectedStrs,bean.checkedItems); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); } }) .setNegativeButton(bean.text2, new DialogInterface.OnClickListener() { diff --git a/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java b/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java index 7de6fd1..06e57c6 100644 --- a/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java +++ b/dialog/src/main/java/com/hss01248/dialog/config/ConfigBean.java @@ -82,15 +82,15 @@ public class ConfigBean extends MyDialogBuilder implements Styleable { public boolean isTransparentBehind; public MyDialogListener listener; public MyItemDialogListener itemListener; - public boolean cancelable = true;//默认可以点击后退键来dismiss对话框 - public boolean outsideTouchable = true;//默认外部半透明处点击消失 - public boolean dismissAfterButtonClick = true; + public boolean cancelable = DefaultConfig.cancelable;//默认可以点击后退键来dismiss对话框 + public boolean outsideTouchable = DefaultConfig.outsideTouchable;//默认外部半透明处点击消失 + public boolean dismissAfterResultCallback = DefaultConfig.dismissAfterResultCallback; public Dialog dialog; public AlertDialog alertDialog; - public boolean dimBehind = true; + public boolean dimBehind = DefaultConfig.dimBehind; public @DrawableRes int bgRes; - public boolean useTheShadowBg = true; + public boolean useTheShadowBg = DefaultConfig.useTheShadowBg; public int viewHeight; //各类对话框特有的参数 public CharSequence[] wordsMd; @@ -253,8 +253,8 @@ public ConfigBean setBottomSheetDialogMaxHeightPercent(float bottomSheetDialogMa return this; } - public ConfigBean setDismissAfterButtonClicked(boolean dismissAfterButtonClick) { - this.dismissAfterButtonClick = dismissAfterButtonClick; + public ConfigBean setDismissAfterResultCallback(boolean dismissAfterResultCallback) { + this.dismissAfterResultCallback = dismissAfterResultCallback; return this; } diff --git a/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java b/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java index ce1d2f0..48b401e 100644 --- a/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java +++ b/dialog/src/main/java/com/hss01248/dialog/config/DefaultConfig.java @@ -24,6 +24,23 @@ public class DefaultConfig { public static @ColorRes int inputTxtColor = R.color.dialogutil_text_input_44; + public static boolean cancelable = true;//默认可以点击后退键来dismiss对话框 + public static boolean outsideTouchable = false;//默认外部半透明处点击消失 + + /** + * 是否在点击按钮后自动消失 + * 针对有的情况下点击按钮/item拿到回调后,需要dialog不消失 + */ + public static boolean dismissAfterResultCallback = false; + /** + * 半透明遮罩 + */ + public static boolean dimBehind = true; + /** + * 是否使用带阴影的背景(以防有的手机无法显示后面的半透明遮罩,而与下方界面黏连) + */ + public static boolean useTheShadowBg = true; + /* 14sp 17sp 14sp diff --git a/dialog/src/main/java/com/hss01248/dialog/ios/IosActionSheetHolder.java b/dialog/src/main/java/com/hss01248/dialog/ios/IosActionSheetHolder.java index fdabc3b..11bc548 100644 --- a/dialog/src/main/java/com/hss01248/dialog/ios/IosActionSheetHolder.java +++ b/dialog/src/main/java/com/hss01248/dialog/ios/IosActionSheetHolder.java @@ -120,7 +120,7 @@ public View getView(final int position, View convertView, ViewGroup parent) { @Override public void onClick(View v) { //StyledDialog.dismiss(bean.dialog,bean.alertDialog); - Tool.dismiss(bean); + Tool.dismiss(bean,true); bean.itemListener.onItemClick(bean.wordsIos.get(position),position); } diff --git a/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java b/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java index 9d4239e..c04a1f3 100644 --- a/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java +++ b/dialog/src/main/java/com/hss01248/dialog/ios/IosAlertDialogHolder.java @@ -138,7 +138,7 @@ public void onClick(View view) { } bean.listener.onGetInput(et1.getText().toString().trim(),et2.getText().toString().trim()); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); bean.listener.onFirst(); } @@ -174,7 +174,7 @@ public void onClick(View view) { } bean.listener.onGetInput(et1.getText().toString().trim(),et2.getText().toString().trim()); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); bean.listener.onFirst(); } }); diff --git a/dialog/src/main/java/com/hss01248/dialog/ios/IosCenterItemHolder.java b/dialog/src/main/java/com/hss01248/dialog/ios/IosCenterItemHolder.java index bcc8c1a..2915b0b 100644 --- a/dialog/src/main/java/com/hss01248/dialog/ios/IosCenterItemHolder.java +++ b/dialog/src/main/java/com/hss01248/dialog/ios/IosCenterItemHolder.java @@ -96,8 +96,8 @@ public View getView(final int position, View convertView, ViewGroup parent) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Tool.dismiss(bean); bean.itemListener.onItemClick(bean.wordsIos.get(position),position); + Tool.dismiss(bean,true); } }); diff --git a/dialog/src/main/java/com/hss01248/dialog/material/MaterialDialogHolder.java b/dialog/src/main/java/com/hss01248/dialog/material/MaterialDialogHolder.java index ea83f77..06f43a2 100644 --- a/dialog/src/main/java/com/hss01248/dialog/material/MaterialDialogHolder.java +++ b/dialog/src/main/java/com/hss01248/dialog/material/MaterialDialogHolder.java @@ -117,7 +117,7 @@ public void onClick(View v) { } bean.listener.onGetInput(mdInputHolder.getTxt1(),mdInputHolder.getTxt2()); } - Tool.dismiss(bean); + Tool.dismiss(bean,true); if(bean.listener!=null){ bean.listener.onFirst(); }