Skip to content

Commit

Permalink
Version 2.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscgdev committed Oct 13, 2019
1 parent 1a74528 commit dd55939
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 9 deletions.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.marcoscg.dialogsheetsample"
minSdkVersion 14
targetSdkVersion 28
versionCode 207
versionName "2.0.7"
versionCode 208
versionName "2.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private void createAndShowDialog() {
.setMessage(R.string.lorem)
.setSingleLineTitle(true)
.setColoredNavigationBar(true)
//.setButtonsColorRes(R.color.colorAccent) // You can use dialogSheetAccent style attribute instead
.setPositiveButton(android.R.string.ok, new DialogSheet.OnPositiveClickListener() {
@Override
public void onClick(View view) {
Expand Down
4 changes: 2 additions & 2 deletions dialogsheet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 207
versionName "2.0.7"
versionCode 208
versionName "2.0.8"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.marcoscg.dialogsheet;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand All @@ -14,8 +16,8 @@
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.StringRes;
import android.support.design.button.MaterialButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatButton;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.text.TextUtils;
Expand All @@ -24,6 +26,7 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import static com.marcoscg.dialogsheet.Utils.adjustAlpha;
import static com.marcoscg.dialogsheet.Utils.dpToPx;
import static com.marcoscg.dialogsheet.Utils.isColorLight;

Expand All @@ -40,7 +43,7 @@ public class DialogSheet {

private AppCompatTextView titleTextView, messageTextView;
private AppCompatImageView iconImageView;
private AppCompatButton positiveButton, negativeButton, neutralButton;
private MaterialButton positiveButton, negativeButton, neutralButton;
private RelativeLayout textContainer;
private LinearLayout messageContainer;

Expand Down Expand Up @@ -276,13 +279,34 @@ public DialogSheet setButtonsTextAllCaps(boolean textAllCaps) {
return this;
}

@Deprecated
@SuppressLint("RestrictedApi")
public DialogSheet setButtonsColor(@ColorInt int buttonsColor) {
int rippleColor = adjustAlpha(buttonsColor, 0.2f);
ColorStateList secondaryButtonColor = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},
new int[]{android.R.attr.state_focused},
new int[]{android.R.attr.state_activated},
new int[]{}
},
new int[]{
rippleColor,
rippleColor,
rippleColor,
Color.TRANSPARENT
});

positiveButton.setSupportBackgroundTintList(ColorStateList.valueOf(buttonsColor));

negativeButton.setTextColor(buttonsColor);
negativeButton.setRippleColor(secondaryButtonColor);
neutralButton.setTextColor(buttonsColor);
neutralButton.setRippleColor(secondaryButtonColor);
return this;
}

@Deprecated
public DialogSheet setButtonsColorRes(@ColorRes int buttonsColorRes) {
setButtonsColor(ContextCompat.getColor(context, buttonsColorRes));
return this;
}

Expand Down
14 changes: 13 additions & 1 deletion dialogsheet/src/main/java/com/marcoscg/dialogsheet/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@ static boolean isColorLight(@ColorInt int color) {
return darkness < 0.4;
}

@ColorInt
static int adjustAlpha(@ColorInt int color, float factor) {
int alpha = Math.round(Color.alpha(color) * factor);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha, red, green, blue);
}

@ColorInt
static int getTextColor(int color) {
return isColorLight(color) ? Color.parseColor("#DE000000") : Color.parseColor("#FFFFFFFF");
}

@ColorInt
static int getTextColorSec(int color) {
return isColorLight(color) ? Color.parseColor("#8A000000") : Color.parseColor("#B3FFFFFF");
}

@ColorInt
static int getAttrColor(Context context, int attr) {
TypedValue typedValue = new TypedValue();

TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[]{attr});
int color = a.getColor(0, 0);
int color = a.getColor(0, -1);
a.recycle();

return color;
Expand Down

0 comments on commit dd55939

Please sign in to comment.