Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more customizations #37

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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; }
Expand Down
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -331,8 +375,6 @@ public BottomDialog show() {
}

public interface ButtonCallback {

void onClick(@NonNull BottomDialog dialog);
}

}
4 changes: 2 additions & 2 deletions library/src/main/res/layout/library_bottom_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
android:orientation="vertical">

<View
android:id="@+id/shadow"
android:id="@+id/bottomDialog_shadow"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@drawable/shadow" />

<LinearLayout
android:id="@+id/bottomDialog_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
android:padding="20dp"
android:paddingBottom="16dp"
android:paddingStart="26dp"
Expand Down