Skip to content

Commit

Permalink
Button Color
Browse files Browse the repository at this point in the history
  • Loading branch information
SlaVcE14 committed Jun 4, 2022
1 parent 3aef288 commit e54f769
Show file tree
Hide file tree
Showing 6 changed files with 280 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import android.app.Dialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
Expand All @@ -27,6 +29,8 @@ public class SetupDialog {

public static final String LONG_TYPE = "long";
public static final String SHORT_TYPE = "short";
public static final String DEFAULT_BUTTON = "DefaultBtn";
public static final String RED_BUTTON = "RedBtn";

public Dialog dialog;
private Button button1, button2;
Expand All @@ -50,7 +54,7 @@ public SetupDialog Short(Context context, String Title, String Btn2Txt){
return Short(context,Title,null,Btn2Txt);
}
public SetupDialog Delete(Context context,String Title){
return DialogBuilder(context,Title,null,null,null);
return DialogBuilder(context,Title,null,null,null).setRightButtonColor(RED_BUTTON);
}
public SetupDialog Delete(Context context){
return DialogBuilder(context,null,null,null,null);
Expand Down Expand Up @@ -80,7 +84,7 @@ public SetupDialog DialogBuilder(Context context, String dialogType){


public SetupDialog DialogBuilder(Context context,String Title,String Text, String Btn1Txt, String Btn2Txt){

this.context = context;
dialog = new Dialog(context);
if (Text == null){
dialog.setContentView(R.layout.popup_panel);
Expand Down Expand Up @@ -244,6 +248,71 @@ public SetupDialog setRightButtonColor(int color){
button2.getBackground().setTint(color);
return this;
}
/**
* Set text color for all buttons.
* @param color Color to use for tinting this drawable
* @return current class
* */
public SetupDialog setButtonsTextColor(int color){
button1.setTextColor(color);
button2.setTextColor(color);
return this;
}
/**
* Set text color for left button.
* @param color Color to use for tinting this drawable
* @return current class
* */
public SetupDialog setLeftButtonTextColor(int color){
button1.setTextColor(color);
// button1.setTextAppearance(R.style.ButtonColor);
return this;
}
/**
* Set text color for right button.
* @param color Color to use for tinting this drawable
* @return current class
* */
public SetupDialog setRightButtonTextColor(int color){
button2.setTextColor(color);
return this;
}


public SetupDialog setLeftButtonColor(String color){
switch (color){
case RED_BUTTON:
setLeftButtonBackgroundResource(R.drawable.ripple_button_red);
setLeftButtonTextColor(context.getResources().getColor(R.color.md_theme_onErrorContainer,context.getTheme()));
break;
default:
setLeftButtonBackgroundResource(R.drawable.ripple_button);
setLeftButtonTextColor(context.getResources().getColor(R.color.md_theme_onPrimaryContainer,context.getTheme()));
}
return this;
}

public SetupDialog setRightButtonColor(String color){
switch (color){
case RED_BUTTON:
setRightButtonBackgroundResource(R.drawable.ripple_button_red);
setRightButtonTextColor(context.getResources().getColor(R.color.md_theme_onErrorContainer,context.getTheme()));
break;
default:
setRightButtonBackgroundResource(R.drawable.ripple_button);
setRightButtonTextColor(context.getResources().getColor(R.color.md_theme_onPrimaryContainer,context.getTheme()));
}
return this;
}



public SetupDialog setButtonsColor(String color){
setLeftButtonColor(color);
setRightButtonColor(color);
return this;
}


/**
* Set onClick listener for both buttons
Expand Down
14 changes: 14 additions & 0 deletions SJDialog/src/main/res/drawable/ripple_button_red.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffffff">
<item android:id="@+id/mask">

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="?colorErrorContainer"/>
<corners android:radius="60dp"/>

</shape>
</item>


</ripple>
39 changes: 39 additions & 0 deletions SJDialog/src/main/res/values-night/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<resources>
<color name="md_theme_primary">#B2C5FF</color>
<color name="md_theme_onPrimary">#002A79</color>
<color name="md_theme_primaryContainer">#003EA9</color>
<color name="md_theme_onPrimaryContainer">#DAE2FF</color>
<color name="md_theme_secondary">#C1C6DD</color>
<color name="md_theme_onSecondary">#2A3042</color>
<color name="md_theme_secondaryContainer">#414659</color>
<color name="md_theme_onSecondaryContainer">#DCE1F9</color>
<color name="md_theme_tertiary">#C0C1FF</color>
<color name="md_theme_onTertiary">#1200AA</color>
<color name="md_theme_tertiaryContainer">#2510E1</color>
<color name="md_theme_onTertiaryContainer">#E1E0FF</color>
<color name="md_theme_error">#FFB4A9</color>
<color name="md_theme_errorContainer">#930006</color>
<color name="md_theme_onError">#680003</color>
<color name="md_theme_onErrorContainer">#FFDAD4</color>
<color name="md_theme_background">#1B1B1F</color>
<color name="md_theme_onBackground">#E3E1E6</color>
<color name="md_theme_surface">#1B1B1F</color>
<color name="md_theme_onSurface">#E3E1E6</color>
<color name="md_theme_surfaceVariant">#44464E</color>
<color name="md_theme_onSurfaceVariant">#C6C6D0</color>
<color name="md_theme_outline">#8F909A</color>
<color name="md_theme_inverseOnSurface">#1B1B1F</color>
<color name="md_theme_inverseSurface">#E3E1E6</color>
<color name="md_theme_inversePrimary">#0053DC</color>
<color name="md_theme_shadow">#000000</color>
<color name="md_theme_primaryInverse">#0053DC</color>
<color name="seed">#0060F4</color>
<color name="error">#BA1B1B</color>
<color name="Custom0">#625FCD</color>


<color name="overlay_light_primary">#9C4146</color>
<color name="overlay_light_onPrimary">#FFFFFF</color>
<color name= "overlay_light_primaryContainer">#FFDADB</color>
<color name="overlay_light_onPrimaryContainer">#400008</color>
</resources>
68 changes: 34 additions & 34 deletions SJDialog/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<resources>

<style name="Theme.sjlibrary" parent="Theme.Material3.DynamicColors.Dark">
<item name="colorPrimary">@color/md_theme_dark_primary</item>
<item name="colorOnPrimary">@color/md_theme_dark_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_dark_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/md_theme_dark_onPrimaryContainer</item>
<item name="colorSecondary">@color/md_theme_dark_secondary</item>
<item name="colorOnSecondary">@color/md_theme_dark_onSecondary</item>
<item name="colorSecondaryContainer">@color/md_theme_dark_secondaryContainer</item>
<item name="colorOnSecondaryContainer">@color/md_theme_dark_onSecondaryContainer</item>
<item name="colorTertiary">@color/md_theme_dark_tertiary</item>
<item name="colorOnTertiary">@color/md_theme_dark_onTertiary</item>
<item name="colorTertiaryContainer">@color/md_theme_dark_tertiaryContainer</item>
<item name="colorOnTertiaryContainer">@color/md_theme_dark_onTertiaryContainer</item>
<item name="colorError">@color/md_theme_dark_error</item>
<item name="colorErrorContainer">@color/md_theme_dark_errorContainer</item>
<item name="colorOnError">@color/md_theme_dark_onError</item>
<item name="colorOnErrorContainer">@color/md_theme_dark_onErrorContainer</item>
<item name="android:colorBackground">@color/md_theme_dark_background</item>
<item name="colorOnBackground">@color/md_theme_dark_onBackground</item>
<item name="colorSurface">@color/md_theme_dark_surface</item>
<item name="colorOnSurface">@color/md_theme_dark_onSurface</item>
<item name="colorSurfaceVariant">@color/md_theme_dark_surfaceVariant</item>
<item name="colorOnSurfaceVariant">@color/md_theme_dark_onSurfaceVariant</item>
<item name="colorOutline">@color/md_theme_dark_outline</item>
<item name="colorOnSurfaceInverse">@color/md_theme_dark_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_dark_inverseSurface</item>
<!-- <item name="colorInversePrimary">@color/md_theme_dark_inversePrimary</item>-->
<!-- <item name="colorShadow">@color/md_theme_dark_shadow</item>-->
<item name="colorPrimaryInverse">@color/md_theme_dark_primaryInverse</item>
<item name="colorPrimary">@color/md_theme_primary</item>
<item name="colorOnPrimary">@color/md_theme_onPrimary</item>
<item name="colorPrimaryContainer">@color/md_theme_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/md_theme_onPrimaryContainer</item>
<item name="colorSecondary">@color/md_theme_secondary</item>
<item name="colorOnSecondary">@color/md_theme_onSecondary</item>
<item name="colorSecondaryContainer">@color/md_theme_secondaryContainer</item>
<item name="colorOnSecondaryContainer">@color/md_theme_onSecondaryContainer</item>
<item name="colorTertiary">@color/md_theme_tertiary</item>
<item name="colorOnTertiary">@color/md_theme_onTertiary</item>
<item name="colorTertiaryContainer">@color/md_theme_tertiaryContainer</item>
<item name="colorOnTertiaryContainer">@color/md_theme_onTertiaryContainer</item>
<item name="colorError">@color/md_theme_error</item>
<item name="colorErrorContainer">@color/md_theme_errorContainer</item>
<item name="colorOnError">@color/md_theme_onError</item>
<item name="colorOnErrorContainer">@color/md_theme_onErrorContainer</item>
<item name="android:colorBackground">@color/md_theme_background</item>
<item name="colorOnBackground">@color/md_theme_onBackground</item>
<item name="colorSurface">@color/md_theme_surface</item>
<item name="colorOnSurface">@color/md_theme_onSurface</item>
<item name="colorSurfaceVariant">@color/md_theme_surfaceVariant</item>
<item name="colorOnSurfaceVariant">@color/md_theme_onSurfaceVariant</item>
<item name="colorOutline">@color/md_theme_outline</item>
<item name="colorOnSurfaceInverse">@color/md_theme_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_inverseSurface</item>
<!-- <item name="colorInversePrimary">@color/md_theme_inversePrimary</item>-->
<!-- <item name="colorShadow">@color/md_theme_shadow</item>-->
<item name="colorPrimaryInverse">@color/md_theme_primaryInverse</item>

<item name="materialButtonStyle">@style/ButtonColor</item>
</style>
Expand All @@ -43,15 +43,15 @@
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:textAppearance">?android:attr/textAppearanceSmallInverse</item>
<item name="android:textColor">@color/md_theme_dark_onPrimaryContainer</item>
<item name="android:textColor">@color/md_theme_onPrimaryContainer</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>

<style name="AppTheme.Overlay" parent="ThemeOverlay.Material3.DynamicColors.Dark">
<item name="colorPrimary">@color/overlay_light_primary</item>
<item name="colorOnPrimary">@color/overlay_light_onPrimary</item>
<item name="colorPrimaryContainer">@color/overlay_light_primaryContainer</item>
<item name="colorOnPrimaryContainer">@color/overlay_light_onPrimaryContainer</item>
<style name="ButtonColor.Red" parent="@style/ButtonColor">
<item name="android:background">@drawable/ripple_button_red</item>
<item name="android:textColor">@color/md_theme_onErrorContainer</item>
</style>



</resources>
Loading

0 comments on commit e54f769

Please sign in to comment.