All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.afollestad.materialdialogs.DialogUtils Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
package com.afollestad.materialdialogs;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.drawable.Drawable;

/**
 * @author Aidan Follestad (afollestad)
 */
public class DialogUtils {

    public static int adjustAlpha(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);
    }

    public static int resolveColor(Context context, int attr) {
        return resolveColor(context, attr, 0);
    }

    public static int resolveColor(Context context, int attr, int fallback) {
        TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
        try {
            return a.getColor(0, fallback);
        } finally {
            a.recycle();
        }
    }

    public static Drawable resolveDrawable(Context context, int attr) {
        return resolveDrawable(context, attr, null);
    }

    public static Drawable resolveDrawable(Context context, int attr, Drawable fallback) {
        TypedArray a = context.getTheme().obtainStyledAttributes(new int[]{attr});
        try {
            Drawable d = a.getDrawable(0);
            if (d == null && fallback != null)
                d = fallback;
            return d;
        } finally {
            a.recycle();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy