Example usage for android.content.res TypedArray length

List of usage examples for android.content.res TypedArray length

Introduction

In this page you can find the example usage for android.content.res TypedArray length.

Prototype

public int length() 

Source Link

Document

Returns the number of values in this array.

Usage

From source file:Main.java

public static String[] getItemStrings(Resources res, int iconsRes) {
    if (iconsRes == 0)
        return null;
    TypedArray array = res.obtainTypedArray(iconsRes);
    int n = array.length();
    String ids[] = new String[n];
    for (int i = 0; i < n; ++i) {
        ids[i] = res.getString(array.getResourceId(i, 0));
    }//from w ww . j av  a2  s.c om
    array.recycle();
    return ids;
}

From source file:Main.java

public static int[] getIdsArray(Context context, int idArray) {
    TypedArray ar = context.getResources().obtainTypedArray(idArray);
    int len = ar.length();
    int[] arrayIds = new int[len];
    for (int i = 0; i < len; i++)
        arrayIds[i] = ar.getResourceId(i, 0);
    ar.recycle();/*from w  ww. jav  a 2 s.c om*/
    return arrayIds;
}

From source file:Main.java

public static int[] getIdArray(Context context, int arrayId) {
    TypedArray typedArray = context.getResources().obtainTypedArray(arrayId);
    int length = typedArray.length();
    int[] ids = new int[length];
    for (int i = 0; i < length; i++) {
        ids[i] = typedArray.getResourceId(i, -1);
    }/*ww  w  . j ava 2  s . c  o m*/
    typedArray.recycle();
    return ids;
}

From source file:Main.java

public static int[] getEmojiArray(Context context, int arryId) {

    final TypedArray ar = context.getResources().obtainTypedArray(arryId);
    final int length = ar.length();
    final int[] array = new int[length];
    for (int i = 0; i < length; ++i) {
        array[i] = ar.getResourceId(i, 0);
    }/*from w  w  w  .jav a 2s  .co m*/
    return array;
}

From source file:Main.java

/**
 *//* w  ww.  jav a2  s . c  o  m*/
public static int[] getDrawableIdsArray(Context context, @ArrayRes int drawableArraysId) {
    TypedArray ta = context.getResources().obtainTypedArray(drawableArraysId);
    int count = ta.length();
    int[] ids = new int[count];
    for (int i = 0; i < count; i++) {
        ids[i] = ta.getResourceId(i, 0);
    }
    ta.recycle();
    return ids;
}

From source file:Main.java

public static ArrayList<String> loadTargetsDescriptions(Context ctxt, int resourceId) {
    TypedArray array = ctxt.getResources().obtainTypedArray(resourceId);
    final int count = array.length();
    ArrayList<String> targetContentDescriptions = new ArrayList<String>(count);
    for (int i = 0; i < count; i++) {
        String contentDescription = array.getString(i);
        targetContentDescriptions.add(contentDescription);
    }/*from w ww. j  ava  2 s .  c o m*/
    array.recycle();
    return targetContentDescriptions;
}

From source file:Main.java

public static int[] getIntArray(int resId, Resources mResources) {
    TypedArray array = mResources.obtainTypedArray(resId);
    int[] rc = new int[array.length()];
    TypedValue value = new TypedValue();
    for (int i = 0; i < array.length(); i++) {
        array.getValue(i, value);/*from   w w w  .  ja  v  a 2  s .  c  o  m*/
        rc[i] = value.resourceId;
    }
    return rc;
}

From source file:Main.java

public static int[] getColorArray(@NonNull Context context, @ArrayRes int array) {
    if (array == 0)
        return null;
    TypedArray ta = context.getResources().obtainTypedArray(array);
    int[] colors = new int[ta.length()];
    for (int i = 0; i < ta.length(); i++)
        colors[i] = ta.getColor(i, 0);//from w w  w. j  av a 2s.co  m
    ta.recycle();
    return colors;
}

From source file:Main.java

/**
 * chooses a random color from array.xml
 *//*w w w  . j  a va  2 s. c om*/
public static int getRandomMaterialColor(Context context, String typeColor) {
    int returnColor = Color.GRAY;
    int arrayId = context.getResources().getIdentifier("mdcolor_" + typeColor, "array",
            context.getPackageName());

    if (arrayId != 0) {
        TypedArray colors = context.getResources().obtainTypedArray(arrayId);
        int index = (int) (Math.random() * colors.length());
        returnColor = colors.getColor(index, Color.GRAY);
        colors.recycle();
    }
    return returnColor;
}

From source file:Main.java

public static int[] getResourceIds(Context c, @ArrayRes int array) {
    final TypedArray typedArray = c.getResources().obtainTypedArray(array);
    final int[] resourceIds = new int[typedArray.length()];
    for (int i = 0; i < typedArray.length(); i++) {
        resourceIds[i] = typedArray.getResourceId(i, 0);
    }/*from  w w  w .jav a  2 s.  com*/
    typedArray.recycle();
    return resourceIds;
}