package com.app.baselibrary.commonUtil;

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

import java.util.ArrayList;

/**
 * Desc: 访问本地res的工具类；
 * Author: pl
 * Date: 2017-04-18 14:32
 */

public class ResUtils {


    public static int[] getDrawableArray(Context context, int resId) {
        TypedArray resArray = context.getResources().obtainTypedArray(resId);

        int len = resArray.length();
        int[] resIds = new int[len];
        for (int i = 0; i < len; i++)
            resIds[i] = resArray.getResourceId(i, 0);

        resArray.recycle();

        return resIds;
    }

    /**
     * 拿到String的资源；
     * @param context
     * @param resId
     * @return
     */
    public static ArrayList<String> getStringArray(Context context, int resId){

        ArrayList<String> result =new ArrayList<>();
        String[] arrays = context.getResources().getStringArray(resId);
        for (String string :
                arrays) {
            result.add(string);
        }

        return result;
    }
}
