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);
}
typedArray.recycle();
return resourceIds;
}
java类android.support.annotation.ArrayRes的实例源码
ResUtil.java 文件源码
项目:Cable-Android
阅读 27
收藏 0
点赞 0
评论 0
GmFadeTextView.java 文件源码
项目:GmArchMvvm
阅读 22
收藏 0
点赞 0
评论 0
/**
* Sets the texts to be shuffled using a string array resource
*
* @param texts The string array resource to use for the texts
*/
public void setTexts(@ArrayRes int texts) {
isSingleText = false;
if (getResources().getStringArray(texts).length < 1)
throw new IllegalArgumentException("There must be at least one text");
else {
this.texts = getResources().getStringArray(texts);
stopAnimation();
position = 0;
startAnimation();
}
}
ResUtil.java 文件源码
项目:UIKit-ViewBlock
阅读 34
收藏 0
点赞 0
评论 0
public static int[] getResourcesIdArray(@ArrayRes int id) {
TypedArray typedArray = mApplication.getResources().obtainTypedArray(id);
int length = typedArray.length();
int[] resArray = new int[length];
for (int i = 0; i < length; i++) {
int resourceId = typedArray.getResourceId(i, 0);
resArray[i] = resourceId;
}
typedArray.recycle();
return resArray;
}
ResUtil.java 文件源码
项目:UIKit-ViewBlock
阅读 33
收藏 0
点赞 0
评论 0
public static Integer[] getResourcesIdIntegerArray(@ArrayRes int id) {
TypedArray typedArray = mApplication.getResources().obtainTypedArray(id);
int length = typedArray.length();
Integer[] resArray = new Integer[length];
for (int i = 0; i < length; i++) {
int resourceId = typedArray.getResourceId(i, 0);
resArray[i] = resourceId;
}
typedArray.recycle();
return resArray;
}
AndroidResource.java 文件源码
项目:android-util2
阅读 24
收藏 0
点赞 0
评论 0
/**
* load any object array from known resource.eg:
* @param context the context
* @param <T> the object type
* @return the object list
*/
public static <T> List<T> loadObjectArray(Context context, @ArrayRes int arrayId, ObjectFactory<T> factory){
// Get the array of objects from the `warm_up_descs` array
final TypedArray statuses = context.getResources().obtainTypedArray(arrayId);
final List<T> categoryList = new ArrayList<>();
TypedArray rawStatus = null;
try {
final int arrSize = statuses.length();
for (int i = 0; i < arrSize; i++) {
int statusId = statuses.getResourceId(i, EMPTY_RES_ID);
// Get the properties of one object
rawStatus = context.getResources().obtainTypedArray(statusId);
T[] ts = factory.create(rawStatus);
if(!Predicates.isEmpty(ts)){
for(T t: ts){
categoryList.add(t);
}
}
rawStatus.recycle();
rawStatus = null;
}
} finally {
statuses.recycle();
if (rawStatus != null) {
rawStatus.recycle();
}
}
return categoryList;
}
TimerGraphFragment.java 文件源码
项目:TwistyTimer
阅读 24
收藏 0
点赞 0
评论 0
private ArrayList<Stat> buildLabelList(@ArrayRes int stringArrayRes) {
ArrayList<Stat> statList = new ArrayList<>();
// Used to alternate background colors in foreach
int row = 0;
for (String label : getResources().getStringArray(stringArrayRes)) {
statList.add(new Stat(label, row));
row++;
}
return statList;
}
SuperSearch.java 文件源码
项目:intra42
阅读 24
收藏 0
点赞 0
评论 0
public static boolean searchOnArray(@ArrayRes int l, String elem, Context context) {
Resources res = context.getResources();
String[] array = res.getStringArray(l);
for (String s : array) {
if (s.equals(elem)) {
return true;
}
}
return false;
}
ColorUtils.java 文件源码
项目:PerfectShow
阅读 29
收藏 0
点赞 0
评论 0
public static int[] obtainColorArray(Resources res, @ArrayRes int resId)
{
TypedArray array = res.obtainTypedArray(resId);
final int length = array.length();
int[] resIds = new int[length];
for(int i = 0; i < length; ++i)
resIds[i] = array.getColor(i, Color.BLACK/* default color*/);
array.recycle();
return resIds;
}
ThemeHelper.java 文件源码
项目:NewsMe
阅读 28
收藏 0
点赞 0
评论 0
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);
ta.recycle();
return colors;
}
AlertDialogWrapper.java 文件源码
项目:talk-android
阅读 25
收藏 0
点赞 0
评论 0
/**
* Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
*
* @param itemsId the resource id of an array i.e. R.array.foo
* @param checkedItem specifies which item is checked. If -1 no items are checked.
* @param listener notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog.
* @return This
*/
public Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem, final DialogInterface.OnClickListener listener) {
builder.items(itemsId);
builder.itemsCallbackSingleChoice(checkedItem, new TalkDialog.ListCallbackSingleChoice() {
@Override
public boolean onSelection(TalkDialog dialog, View itemView, int which, CharSequence text) {
listener.onClick(dialog, which);
return true;
}
});
return this;
}