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/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/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' } 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..21a8195 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,8 @@ 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; @@ -23,40 +25,43 @@ import android.widget.TextView; public class BottomDialog { + private static final int DEFAULT_SHADOW_HEIGHT = 3; - 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() { + 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; } - protected BottomDialog(Builder builder) { + public View getCustomView() { return vCustomView; } + + BottomDialog(Builder builder) { mBuilder = builder; mBuilder.bottomDialog = initBottomDialog(builder); } @@ -73,17 +78,35 @@ 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); 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); + 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); + vCustomView = view.findViewById(R.id.bottomDialog_custom_view); + 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); @@ -92,10 +115,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) { @@ -158,39 +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 + 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; @@ -228,6 +262,16 @@ public Builder setIcon(@DrawableRes int iconRes) { return this; } + public Builder setBackgroundColor(int colorRes) { + this.backgroundColor = context.getResources().getColor(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; @@ -331,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 e44c003..db9b0cf 100644 --- a/library/src/main/res/layout/library_bottom_dialog.xml +++ b/library/src/main/res/layout/library_bottom_dialog.xml @@ -5,15 +5,15 @@ android:orientation="vertical">