Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.content.res.TypedArray;

public class Main {
    public static int getColorFromAttribute(Context context, int attr) {
        int[] colors = getColorsFromAttributes(context, attr);
        if (colors.length >= 1)
            return colors[0];
        else
            return 0;
    }

    public static int[] getColorsFromAttributes(Context context, int... attr) {
        final TypedArray a = context.obtainStyledAttributes(attr);
        int[] colors = new int[a.getIndexCount()];
        for (int i = 0; i < a.getIndexCount(); i++) {
            colors[i] = a.getColor(i, 0);
        }
        a.recycle();
        return colors;
    }
}