1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-12-22 19:08:03 +01:00

Added ThemedAlertDialogBuilder and a corresponding method in ThemeHelper

This commit is contained in:
vanitasvitae 2016-11-06 15:48:54 +01:00
parent 58c61a0d05
commit 76d58cb100
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
2 changed files with 54 additions and 0 deletions

View file

@ -19,6 +19,7 @@
*/
package com.github.dfa.diaspora_android.ui.theme;
import android.content.DialogInterface;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
@ -26,9 +27,11 @@ import android.os.Build;
import android.support.design.widget.TabLayout;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.CompoundButtonCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.ActionMenuView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ProgressBar;
@ -153,4 +156,15 @@ public class ThemeHelper {
public static int getNeutralGreyColor() {
return ContextCompat.getColor(getInstance().appSettings.getApplicationContext(), R.color.md_grey_800);
}
public static void updateAlertDialogColor(AlertDialog alertDialog) {
if(alertDialog != null) {
for(int i : new int[]{DialogInterface.BUTTON_POSITIVE, DialogInterface.BUTTON_NEGATIVE, DialogInterface.BUTTON_NEUTRAL}) {
Button b = alertDialog.getButton(i);
if(b != null) {
b.setTextColor(getAccentColor());
}
}
}
}
}

View file

@ -0,0 +1,40 @@
package com.github.dfa.diaspora_android.ui.theme;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.support.v7.app.AlertDialog;
import com.github.dfa.diaspora_android.util.AppSettings;
/**
* AlertDialog Builder that colors its buttons
* Created by vanitas on 06.11.16.
*/
public class ThemedAlertDialogBuilder extends AlertDialog.Builder {
protected AppSettings appSettings;
public ThemedAlertDialogBuilder(@NonNull Context context, AppSettings appSettings) {
super(context);
this.appSettings = appSettings;
}
public ThemedAlertDialogBuilder(@NonNull Context context, @StyleRes int themeResId, AppSettings appSettings) {
super(context, themeResId);
this.appSettings = appSettings;
}
@Override
public AlertDialog create() {
AlertDialog dialog = super.create();
applyColors(dialog);
return dialog;
}
private void applyColors(AlertDialog alertDialog) {
ThemeHelper.getInstance(appSettings);
ThemeHelper.updateAlertDialogColor(alertDialog);
}
}