Skip to content

Commit dd55939

Browse files
committed
Version 2.0.8
1 parent 1a74528 commit dd55939

File tree

6 files changed

+46
-9
lines changed

6 files changed

+46
-9
lines changed

.idea/caches/gradle_models.ser

2.23 KB
Binary file not shown.

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.marcoscg.dialogsheetsample"
77
minSdkVersion 14
88
targetSdkVersion 28
9-
versionCode 207
10-
versionName "2.0.7"
9+
versionCode 208
10+
versionName "2.0.8"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
}
1313
buildTypes {

app/src/main/java/com/marcoscg/dialogsheetsample/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ private void createAndShowDialog() {
3434
.setMessage(R.string.lorem)
3535
.setSingleLineTitle(true)
3636
.setColoredNavigationBar(true)
37+
//.setButtonsColorRes(R.color.colorAccent) // You can use dialogSheetAccent style attribute instead
3738
.setPositiveButton(android.R.string.ok, new DialogSheet.OnPositiveClickListener() {
3839
@Override
3940
public void onClick(View view) {

dialogsheet/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ android {
55
defaultConfig {
66
minSdkVersion 14
77
targetSdkVersion 28
8-
versionCode 207
9-
versionName "2.0.7"
8+
versionCode 208
9+
versionName "2.0.8"
1010
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1111

1212
}

dialogsheet/src/main/java/com/marcoscg/dialogsheet/DialogSheet.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.marcoscg.dialogsheet;
22

3+
import android.annotation.SuppressLint;
34
import android.content.Context;
45
import android.content.DialogInterface;
6+
import android.content.res.ColorStateList;
57
import android.content.res.Configuration;
68
import android.graphics.Bitmap;
79
import android.graphics.Color;
@@ -14,8 +16,8 @@
1416
import android.support.annotation.DrawableRes;
1517
import android.support.annotation.LayoutRes;
1618
import android.support.annotation.StringRes;
19+
import android.support.design.button.MaterialButton;
1720
import android.support.v4.content.ContextCompat;
18-
import android.support.v7.widget.AppCompatButton;
1921
import android.support.v7.widget.AppCompatImageView;
2022
import android.support.v7.widget.AppCompatTextView;
2123
import android.text.TextUtils;
@@ -24,6 +26,7 @@
2426
import android.widget.LinearLayout;
2527
import android.widget.RelativeLayout;
2628

29+
import static com.marcoscg.dialogsheet.Utils.adjustAlpha;
2730
import static com.marcoscg.dialogsheet.Utils.dpToPx;
2831
import static com.marcoscg.dialogsheet.Utils.isColorLight;
2932

@@ -40,7 +43,7 @@ public class DialogSheet {
4043

4144
private AppCompatTextView titleTextView, messageTextView;
4245
private AppCompatImageView iconImageView;
43-
private AppCompatButton positiveButton, negativeButton, neutralButton;
46+
private MaterialButton positiveButton, negativeButton, neutralButton;
4447
private RelativeLayout textContainer;
4548
private LinearLayout messageContainer;
4649

@@ -276,13 +279,34 @@ public DialogSheet setButtonsTextAllCaps(boolean textAllCaps) {
276279
return this;
277280
}
278281

279-
@Deprecated
282+
@SuppressLint("RestrictedApi")
280283
public DialogSheet setButtonsColor(@ColorInt int buttonsColor) {
284+
int rippleColor = adjustAlpha(buttonsColor, 0.2f);
285+
ColorStateList secondaryButtonColor = new ColorStateList(
286+
new int[][]{
287+
new int[]{android.R.attr.state_pressed},
288+
new int[]{android.R.attr.state_focused},
289+
new int[]{android.R.attr.state_activated},
290+
new int[]{}
291+
},
292+
new int[]{
293+
rippleColor,
294+
rippleColor,
295+
rippleColor,
296+
Color.TRANSPARENT
297+
});
298+
299+
positiveButton.setSupportBackgroundTintList(ColorStateList.valueOf(buttonsColor));
300+
301+
negativeButton.setTextColor(buttonsColor);
302+
negativeButton.setRippleColor(secondaryButtonColor);
303+
neutralButton.setTextColor(buttonsColor);
304+
neutralButton.setRippleColor(secondaryButtonColor);
281305
return this;
282306
}
283307

284-
@Deprecated
285308
public DialogSheet setButtonsColorRes(@ColorRes int buttonsColorRes) {
309+
setButtonsColor(ContextCompat.getColor(context, buttonsColorRes));
286310
return this;
287311
}
288312

dialogsheet/src/main/java/com/marcoscg/dialogsheet/Utils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ static boolean isColorLight(@ColorInt int color) {
2020
return darkness < 0.4;
2121
}
2222

23+
@ColorInt
24+
static int adjustAlpha(@ColorInt int color, float factor) {
25+
int alpha = Math.round(Color.alpha(color) * factor);
26+
int red = Color.red(color);
27+
int green = Color.green(color);
28+
int blue = Color.blue(color);
29+
return Color.argb(alpha, red, green, blue);
30+
}
31+
32+
@ColorInt
2333
static int getTextColor(int color) {
2434
return isColorLight(color) ? Color.parseColor("#DE000000") : Color.parseColor("#FFFFFFFF");
2535
}
2636

37+
@ColorInt
2738
static int getTextColorSec(int color) {
2839
return isColorLight(color) ? Color.parseColor("#8A000000") : Color.parseColor("#B3FFFFFF");
2940
}
3041

42+
@ColorInt
3143
static int getAttrColor(Context context, int attr) {
3244
TypedValue typedValue = new TypedValue();
3345

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

3850
return color;

0 commit comments

Comments
 (0)