Skip to content

Commit

Permalink
用drawable实现阴影,适配所有dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
huangshuisheng committed Apr 25, 2017
1 parent 7d6a654 commit 1a76270
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ dependencies {
//compile 'com.jakewharton:butterknife:8.4.0'
compile 'com.android.support:design:25.0.0'
//compile 'com.github.wangjiegulu:ShadowViewhelper:1.0.4'
compile 'com.github.wangjiegulu:ShadowViewHelper:1.0.2'
//compile 'com.github.wangjiegulu:ShadowViewHelper:1.0.2'
}
71 changes: 51 additions & 20 deletions lib/src/main/java/com/hss01248/dialog/Tool.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import com.hss01248.dialog.config.ConfigBean;
import com.hss01248.dialog.config.DefaultConfig;
import com.wangjie.shadowviewhelper.ShadowProperty;
import com.wangjie.shadowviewhelper.ShadowViewHelper;

/**
* Created by Administrator on 2016/10/9 0009.
Expand Down Expand Up @@ -184,33 +182,61 @@ public static void setDialogStyle(ConfigBean bean) {
if (bean.alertDialog!= null){
setMdBtnStytle(bean);
setListItemsStyle(bean);


}else {
setDialogStyle(bean.context,bean.dialog,bean.viewHeight,bean);
}
setBg(bean);
setDim(bean);

//fixNoDim(bean);
addShaow(bean);
// addShaow(bean);





}

/**
* 在有的平板上背部半透明消失
* @param bean
*/
private static void fixNoDim(ConfigBean bean) {
if (bean.alertDialog != null){
bean.alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DIM_BEHIND);
bean.alertDialog.getWindow().setDimAmount(0.5f);
}else if (bean.dialog != null){
bean.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DIM_BEHIND);
bean.dialog.getWindow().setDimAmount(0.5f);
private static void setDim(ConfigBean bean) {
if(bean.type == DefaultConfig.TYPE_IOS_LOADING){//转菊花,则让背景透明
bean.isTransparentBehind = true;
}
if (bean.alertDialog!= null){
if(bean.isTransparentBehind){
bean.alertDialog.getWindow().setDimAmount(0);
}
bean.alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED );
}else {
if(bean.isTransparentBehind){
bean.dialog.getWindow().setDimAmount(0);
}
bean.dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED );
}
}

private static void setBg(ConfigBean bean) {
if (bean.alertDialog!= null){
bean.alertDialog.getWindow().setBackgroundDrawableResource(R.drawable.shadow);
}else {
if(bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_GRID
|| bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_LIST
|| bean.type == DefaultConfig.TYPE_BOTTOM_SHEET_CUSTOM
|| bean.type == DefaultConfig.TYPE_PROGRESS){


}else if(bean.type == DefaultConfig.TYPE_IOS_LOADING){
bean.dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}else {
bean.dialog.getWindow().setBackgroundDrawableResource(R.drawable.shadow);
}

}
}



private static void addShaow(ConfigBean bean) {
/**/
if(bean.type == DefaultConfig.TYPE_IOS_LOADING
Expand Down Expand Up @@ -238,12 +264,12 @@ private static void addShaow(ConfigBean bean) {
ViewCompat.setBackground(dialog.getWindow().getDecorView(), sd);
ViewCompat.setLayerType(dialog.getWindow().getDecorView(), ViewCompat.LAYER_TYPE_SOFTWARE, null);*/

ShadowViewHelper.bindShadowHelper(
/* ShadowViewHelper.bindShadowHelper(
new ShadowProperty()
.setShadowColor(0x77000000)
.setShadowDy(3)
.setShadowRadius(3)
, dialog.getWindow().getDecorView());
, dialog.getWindow().getDecorView());*/

}

Expand Down Expand Up @@ -275,16 +301,21 @@ public static void setDialogStyle(Context activity, Dialog dialog, int measuredH
Window window = dialog.getWindow();

//window.setWindowAnimations(R.style.dialog_center);
if(bean.type != DefaultConfig.TYPE_PROGRESS){
/*if(bean.type == DefaultConfig.TYPE_IOS_LOADING){
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//todo keycode to show round corner
}
}else if(bean.type == DefaultConfig.TYPE_MD_MULTI_CHOOSE
|| bean.type == DefaultConfig.TYPE_MD_ALERT
|| bean.type == DefaultConfig.TYPE_MD_SINGLE_CHOOSE){
window.setBackgroundDrawableResource(R.drawable.shadow);
}*/



WindowManager.LayoutParams wl = window.getAttributes();
if(bean.type == DefaultConfig.TYPE_IOS_LOADING){//转菊花,则让背景透明
/* if(bean.type == DefaultConfig.TYPE_IOS_LOADING){//转菊花,则让背景透明
wl.dimAmount = 0;
}
}*/

/* wl.x = 0;
wl.y = getWindowManager().getDefaultDisplay().getHeight();*/
// 以下这两句是为了保证按钮可以水平满屏
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class ConfigBean extends MyDialogBuilder implements Styleable {

public CharSequence hint1;
public CharSequence hint2;
public boolean isTransparentBehind;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ private void buildBottomSheet(ConfigBean bean) {
dialog.setContentView(bean.customView);
dialog.setCancelable(bean.cancelable);
dialog.setCanceledOnTouchOutside(bean.outsideTouchable);

bean.dialog = dialog;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/res/drawable/bg_ios_roundcorner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="10dp"/>
<corners android:radius="@dimen/round_corner"/>
<solid android:color="@android:color/white"/>

</shape>
103 changes: 103 additions & 0 deletions lib/src/main/res/drawable/shadow.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_1" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_2" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_3" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_4" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_5" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_6" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_7" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/cardShadowColor_8" />
<corners android:radius="@dimen/cardRadius" />
<padding
android:bottom="@dimen/cardPadding"
android:left="@dimen/cardPadding"
android:top="@dimen/cardPadding"
android:right="@dimen/cardPadding" />
</shape>
</item>
<item>
<shape android:shape="rectangle">
<corners android:radius="@dimen/round_corner" />
<solid android:color="@color/cardBodyColor" />
<!--<padding android:bottom="@dimen/cardRadius"
android:top="@dimen/cardRadius"
android:left="@dimen/cardRadius"
android:right="@dimen/cardRadius"
/>-->
</shape>
</item>
</layer-list>

4 changes: 1 addition & 3 deletions lib/src/main/res/layout/dialog_ios_alert_bottom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:layout_height="wrap_content">


Expand All @@ -15,7 +14,6 @@
android:scrollbars="none"
android:overScrollMode="never"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:overScrollFooter="@android:color/transparent"
android:overScrollHeader="@android:color/transparent"
android:layout_height="0dp"
Expand Down Expand Up @@ -48,7 +46,7 @@
<Button
android:id="@+id/btn_bottom"
android:background="@drawable/selector_btn_press_all"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="cancle"
android:textSize="@dimen/btn_txt_size"
android:textColor="@color/ios_btntext_blue"
Expand Down
7 changes: 3 additions & 4 deletions lib/src/main/res/layout/dialog_ios_center_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
android:orientation="vertical"
android:background="@android:color/transparent"
android:layout_width="match_parent"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_height="wrap_content">

android:layout_height="wrap_content">
<!--android:paddingTop="10dp"
android:paddingBottom="10dp"-->
<ListView
android:background="@drawable/bg_ios_roundcorner"
android:id="@+id/lv"
android:scrollbars="none"
android:overScrollMode="never"
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:overScrollFooter="@android:color/transparent"
android:overScrollHeader="@android:color/transparent"
android:layout_height="0dp"
Expand Down
2 changes: 1 addition & 1 deletion lib/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<dimen name="round_corner">8dp</dimen>
<dimen name="round_corner">5dp</dimen>
<dimen name="line_1px">1px</dimen>

<dimen name="btn_txt_size">14sp</dimen>
Expand Down
15 changes: 15 additions & 0 deletions lib/src/main/res/values/shadowre.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="cardBodyColor">#FFFFFF</color>
<color name="cardShadowColor_1">#0a8c8c8c</color>
<color name="cardShadowColor_2">#0f898989</color>
<color name="cardShadowColor_3">#14898989</color>
<color name="cardShadowColor_4">#19898989</color>
<color name="cardShadowColor_5">#1e898989</color>
<color name="cardShadowColor_6">#23898989</color>
<color name="cardShadowColor_7">#28898989</color>
<color name="cardShadowColor_8">#2d898989</color>
<dimen name="cardPadding">1px</dimen>
<dimen name="cardRadius">@dimen/round_corner</dimen>

</resources>

0 comments on commit 1a76270

Please sign in to comment.