Welcome to mirror list, hosted at ThFree Co, Russian Federation.

BrandedAlertDialogBuilder.java « branding « notes « owncloud « niedermann « it « java « main « src « app - github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c48e62981a9db4917d08911a2b1cd3fe7d8d2f96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package it.niedermann.owncloud.notes.branding;

import android.content.Context;
import android.content.DialogInterface;
import android.widget.Button;

import androidx.annotation.CallSuper;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;

import static it.niedermann.owncloud.notes.branding.BrandingUtil.getSecondaryForegroundColorDependingOnTheme;

public class BrandedAlertDialogBuilder extends AlertDialog.Builder implements Branded {

    protected AlertDialog dialog;

    public BrandedAlertDialogBuilder(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public AlertDialog create() {
        this.dialog = super.create();

        @NonNull final var context = getContext();
        @ColorInt final int mainColor = BrandingUtil.readBrandMainColor(context);
        @ColorInt final int textColor = BrandingUtil.readBrandTextColor(context);
        applyBrand(mainColor, textColor);
        dialog.setOnShowListener(dialog -> applyBrand(mainColor, textColor));
        return dialog;
    }

    @CallSuper
    @Override
    public void applyBrand(int mainColor, int textColor) {
        final var buttons = new Button[3];
        buttons[0] = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
        buttons[1] = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
        buttons[2] = dialog.getButton(DialogInterface.BUTTON_NEUTRAL);
        for (final var button : buttons) {
            if (button != null) {
                button.setTextColor(getSecondaryForegroundColorDependingOnTheme(button.getContext(), mainColor));
            }
        }
    }
}