From 95122e00b07d684eaafcd7c44030a62c73319d69 Mon Sep 17 00:00:00 2001 From: iGio90 Date: Mon, 26 Feb 2018 09:58:04 +0100 Subject: [PATCH 1/5] update dependencies, use sdk27 --- app/build.gradle | 12 ++++++------ build.gradle | 4 +++- library/build.gradle | 8 ++++---- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6095d87..f64618d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 27 + buildToolsVersion '26.0.2' defaultConfig { applicationId "com.github.javiersantos.bottomdialogs.demo" - minSdkVersion 11 - targetSdkVersion 24 + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -21,8 +21,8 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:24.2.0' - compile 'com.android.support:design:24.2.0' + compile 'com.android.support:appcompat-v7:27.0.2' + compile 'com.android.support:design:27.0.2' compile 'com.mikepenz:iconics-core:2.6.5@aar' compile 'com.mikepenz:material-design-iconic-typeface:2.2.0.1@aar' compile('com.mikepenz:aboutlibraries:5.6.7@aar') { transitive = true; } diff --git a/build.gradle b/build.gradle index a3330d4..7e01a0a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.0' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +16,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/library/build.gradle b/library/build.gradle index dee189d..e7a8c0f 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 24 + compileSdkVersion 27 buildToolsVersion "24.0.2" defaultConfig { - minSdkVersion 11 - targetSdkVersion 24 + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.2.1" } @@ -20,5 +20,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:24.2.0' + compile 'com.android.support:appcompat-v7:27.0.2' } From f9a8d587d38c6f6864ff68805def193dc1fce6de Mon Sep 17 00:00:00 2001 From: iGio90 Date: Mon, 26 Feb 2018 09:58:27 +0100 Subject: [PATCH 2/5] added onDismiss listener --- .../com/github/javiersantos/bottomdialogs/BottomDialog.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java index 1aedb97..365ce38 100644 --- a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java +++ b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java @@ -2,6 +2,7 @@ import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.ColorRes; @@ -73,6 +74,11 @@ public void dismiss() { mBuilder.bottomDialog.dismiss(); } + public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) { + if (mBuilder != null && mBuilder.bottomDialog != null) + mBuilder.bottomDialog.setOnDismissListener(onDismissListener); + } + @UiThread private Dialog initBottomDialog(final Builder builder) { final Dialog bottomDialog = new Dialog(builder.context, R.style.BottomDialogs); From 961fb0406928676b419920085970d93b8b917684 Mon Sep 17 00:00:00 2001 From: iGio90 Date: Mon, 26 Feb 2018 10:09:16 +0100 Subject: [PATCH 3/5] customizable background color --- gradle/wrapper/gradle-wrapper.properties | 4 +- .../bottomdialogs/BottomDialog.java | 40 ++++++++++++------- .../main/res/layout/library_bottom_dialog.xml | 2 +- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 5070481..dff6091 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Aug 29 18:12:35 CEST 2016 +#Mon Feb 26 08:59:43 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip diff --git a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java index 365ce38..92dd5c1 100644 --- a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java +++ b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java @@ -3,6 +3,7 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.ColorRes; @@ -25,13 +26,13 @@ public class BottomDialog { - protected final Builder mBuilder; - protected ImageView vIcon ; - protected TextView vTitle ; - protected TextView vContent; - protected FrameLayout vCustomView; - protected Button vNegative ; - protected Button vPositive; + private final Builder mBuilder; + private ImageView vIcon ; + private TextView vTitle ; + private TextView vContent; + private FrameLayout vCustomView; + private Button vNegative ; + private Button vPositive; public final Builder getBuilder() { return mBuilder; @@ -57,7 +58,7 @@ public final Button getPositiveButton() { return vPositive; } - protected BottomDialog(Builder builder) { + BottomDialog(Builder builder) { mBuilder = builder; mBuilder.bottomDialog = initBottomDialog(builder); } @@ -84,12 +85,15 @@ private Dialog initBottomDialog(final Builder builder) { final Dialog bottomDialog = new Dialog(builder.context, R.style.BottomDialogs); View view = LayoutInflater.from(builder.context).inflate(R.layout.library_bottom_dialog, null); - vIcon = (ImageView) view.findViewById(R.id.bottomDialog_icon); - vTitle = (TextView) view.findViewById(R.id.bottomDialog_title); - vContent = (TextView) view.findViewById(R.id.bottomDialog_content); - vCustomView = (FrameLayout) view.findViewById(R.id.bottomDialog_custom_view); - vNegative = (Button) view.findViewById(R.id.bottomDialog_cancel); - vPositive = (Button) view.findViewById(R.id.bottomDialog_ok); + View container = view.findViewById(R.id.bottomDialog_container); + vIcon = view.findViewById(R.id.bottomDialog_icon); + vTitle = view.findViewById(R.id.bottomDialog_title); + vContent = view.findViewById(R.id.bottomDialog_content); + vCustomView = view.findViewById(R.id.bottomDialog_custom_view); + vNegative = view.findViewById(R.id.bottomDialog_cancel); + vPositive = view.findViewById(R.id.bottomDialog_ok); + + container.setBackgroundColor(builder.backgroundColor); if (builder.icon != null) { vIcon.setVisibility(View.VISIBLE); @@ -180,6 +184,9 @@ public static class Builder { protected Drawable icon; protected CharSequence title, content; + // Content style + protected int backgroundColor = Color.WHITE; + // Buttons protected CharSequence btn_negative, btn_positive; protected ButtonCallback btn_negative_callback, btn_positive_callback; @@ -234,6 +241,11 @@ public Builder setIcon(@DrawableRes int iconRes) { return this; } + public Builder setBackgroundColor(int colorRes) { + this.backgroundColor = context.getResources().getColor(colorRes); + return this; + } + public Builder setPositiveBackgroundColorResource(@ColorRes int buttonColorRes) { this.btn_colorPositiveBackground = ResourcesCompat.getColor(context.getResources(), buttonColorRes, null); return this; diff --git a/library/src/main/res/layout/library_bottom_dialog.xml b/library/src/main/res/layout/library_bottom_dialog.xml index e44c003..48a6e93 100644 --- a/library/src/main/res/layout/library_bottom_dialog.xml +++ b/library/src/main/res/layout/library_bottom_dialog.xml @@ -11,9 +11,9 @@ android:background="@drawable/shadow" /> Date: Mon, 26 Feb 2018 10:14:33 +0100 Subject: [PATCH 4/5] hide title and content if they are not set --- .../com/github/javiersantos/bottomdialogs/BottomDialog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java index 92dd5c1..dcf4c7f 100644 --- a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java +++ b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java @@ -102,10 +102,14 @@ private Dialog initBottomDialog(final Builder builder) { if (builder.title != null) { vTitle.setText(builder.title); + } else { + vTitle.setVisibility(View.GONE); } if (builder.content != null) { vContent.setText(builder.content); + } else { + vContent.setVisibility(View.GONE); } if (builder.customView != null) { From 95b945247becde26b2c1b361c718f05062b17857 Mon Sep 17 00:00:00 2001 From: iGio90 Date: Mon, 26 Feb 2018 10:22:05 +0100 Subject: [PATCH 5/5] added customizable shadow height, expose custom view, cleanups --- .../bottomdialogs/BottomDialog.java | 66 ++++++++++++------- .../main/res/layout/library_bottom_dialog.xml | 2 +- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java index dcf4c7f..21a8195 100644 --- a/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java +++ b/library/src/main/java/com/github/javiersantos/bottomdialogs/BottomDialog.java @@ -25,6 +25,7 @@ import android.widget.TextView; public class BottomDialog { + private static final int DEFAULT_SHADOW_HEIGHT = 3; private final Builder mBuilder; private ImageView vIcon ; @@ -34,30 +35,32 @@ public class BottomDialog { private Button vNegative ; private Button vPositive; - public final Builder getBuilder() { + public Builder getBuilder() { return mBuilder; } - public final ImageView getIconImageView() { + public ImageView getIconImageView() { return vIcon; } - public final TextView getTitleTextView() { + public TextView getTitleTextView() { return vTitle; } - public final TextView getContentTextView() { + public TextView getContentTextView() { return vContent; } - public final Button getNegativeButton() { + public Button getNegativeButton() { return vNegative; } - public final Button getPositiveButton() { + public Button getPositiveButton() { return vPositive; } + public View getCustomView() { return vCustomView; } + BottomDialog(Builder builder) { mBuilder = builder; mBuilder.bottomDialog = initBottomDialog(builder); @@ -86,6 +89,8 @@ private Dialog initBottomDialog(final Builder builder) { View view = LayoutInflater.from(builder.context).inflate(R.layout.library_bottom_dialog, null); View container = view.findViewById(R.id.bottomDialog_container); + View shadow = view.findViewById(R.id.bottomDialog_shadow); + vIcon = view.findViewById(R.id.bottomDialog_icon); vTitle = view.findViewById(R.id.bottomDialog_title); vContent = view.findViewById(R.id.bottomDialog_content); @@ -93,7 +98,15 @@ private Dialog initBottomDialog(final Builder builder) { vNegative = view.findViewById(R.id.bottomDialog_cancel); vPositive = view.findViewById(R.id.bottomDialog_ok); + // Apply style changes container.setBackgroundColor(builder.backgroundColor); + if (builder.shadowHeight != DEFAULT_SHADOW_HEIGHT) { + LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) + shadow.getLayoutParams(); + params.height = UtilsLibrary.dpToPixels(builder.context, + builder.shadowHeight); + shadow.setLayoutParams(params); + } if (builder.icon != null) { vIcon.setVisibility(View.VISIBLE); @@ -172,42 +185,46 @@ public void onClick(View view) { bottomDialog.setContentView(view); bottomDialog.setCancelable(builder.isCancelable); - bottomDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - bottomDialog.getWindow().setGravity(Gravity.BOTTOM); + + if (bottomDialog.getWindow() != null) { + bottomDialog.getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); + bottomDialog.getWindow().setGravity(Gravity.BOTTOM); + } return bottomDialog; } public static class Builder { - protected Context context; + Context context; // Bottom Dialog - protected Dialog bottomDialog; + Dialog bottomDialog; // Icon, Title and Content - protected Drawable icon; - protected CharSequence title, content; + Drawable icon; + CharSequence title, content; // Content style - protected int backgroundColor = Color.WHITE; + int backgroundColor = Color.WHITE; + int shadowHeight = DEFAULT_SHADOW_HEIGHT; // Buttons - protected CharSequence btn_negative, btn_positive; - protected ButtonCallback btn_negative_callback, btn_positive_callback; - protected boolean isAutoDismiss; + CharSequence btn_negative, btn_positive; + ButtonCallback btn_negative_callback, btn_positive_callback; + boolean isAutoDismiss; // Button text colors - protected int btn_colorNegative, btn_colorPositive; + int btn_colorNegative, btn_colorPositive; // Button background colors - protected int btn_colorPositiveBackground; + int btn_colorPositiveBackground; // Custom View - protected View customView; - protected int customViewPaddingLeft, customViewPaddingTop, customViewPaddingRight, customViewPaddingBottom; + View customView; + int customViewPaddingLeft, customViewPaddingTop, customViewPaddingRight, customViewPaddingBottom; // Other options - protected boolean isCancelable; + boolean isCancelable; public Builder(@NonNull Context context) { this.context = context; @@ -250,6 +267,11 @@ public Builder setBackgroundColor(int colorRes) { return this; } + public Builder setShadowHeight(int heightDp) { + this.shadowHeight = heightDp; + return this; + } + public Builder setPositiveBackgroundColorResource(@ColorRes int buttonColorRes) { this.btn_colorPositiveBackground = ResourcesCompat.getColor(context.getResources(), buttonColorRes, null); return this; @@ -353,8 +375,6 @@ public BottomDialog show() { } public interface ButtonCallback { - void onClick(@NonNull BottomDialog dialog); } - } diff --git a/library/src/main/res/layout/library_bottom_dialog.xml b/library/src/main/res/layout/library_bottom_dialog.xml index 48a6e93..db9b0cf 100644 --- a/library/src/main/res/layout/library_bottom_dialog.xml +++ b/library/src/main/res/layout/library_bottom_dialog.xml @@ -5,7 +5,7 @@ android:orientation="vertical">