本文整理汇总了Java中android.support.annotation.ArrayRes类的典型用法代码示例。如果您正苦于以下问题:Java ArrayRes类的具体用法?Java ArrayRes怎么用?Java ArrayRes使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArrayRes类属于android.support.annotation包,在下文中一共展示了ArrayRes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: obtainBadgeMap
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@SuppressLint("UseSparseArrays")
@SuppressWarnings("ResourceType")
public static Map<Integer, Pair<String, String>> obtainBadgeMap(Context context, @ArrayRes int id) {
TypedArray badgeArray = context.getResources().obtainTypedArray(id);
Map<Integer, Pair<String, String>> badgeMap = new HashMap<>();
for (int i = 0; i < badgeArray.length(); i++) {
int resId = badgeArray.getResourceId(i, -1);
if (resId != -1) {
TypedArray array = context.getResources().obtainTypedArray(resId);
badgeMap.put(resId, new Pair<>(array.getString(0), array.getString(1)));
array.recycle();
}
}
badgeArray.recycle();
return badgeMap;
}
示例2: getEmoji
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@NonNull
private static String[] getEmoji(Context ctx, @ArrayRes int res) {
String[] rawStrings = ctx.getResources().getStringArray(res);
String[] emoji = new String[rawStrings.length];
int i = 0;
for (String codePoint : rawStrings) {
String[] bytes = codePoint.split(",");
int[] codePoints = new int[bytes.length];
int j = 0;
for (String b : bytes) {
codePoints[j] = Integer.valueOf(b, 16);
}
emoji[i] = new String(codePoints, 0, codePoints.length);
i++;
}
return emoji;
}
示例3: getStringArray
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@NonNull
public String[] getStringArray(@ArrayRes int id) throws NotFoundException {
Map<Integer, String> idNameMap = getArrayIdTable();
Map<String, List<String>> stringArrayMap = getResourceStringArrayMap();
if (idNameMap.containsKey(id)) {
String name = idNameMap.get(id);
if (stringArrayMap.containsKey(name)) {
List<String> stringList = stringArrayMap.get(name);
return stringList.toArray(new String[0]);
}
}
throw new Resources.NotFoundException("String array resource ID #0x" + Integer.toHexString(id));
}
示例4: getIntArray
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@NonNull
public int[] getIntArray(@ArrayRes int id) throws NotFoundException {
Map<Integer, String> idNameMap = getArrayIdTable();
Map<String, List<Integer>> intArrayMap = getResourceIntArrayMap();
if (idNameMap.containsKey(id)) {
String name = idNameMap.get(id);
if (intArrayMap.containsKey(name)) {
List<Integer> intList = intArrayMap.get(name);
int[] intArray = new int[intList.size()];
for (int i = 0; i < intList.size(); i++) {
intArray[i] = intList.get(i);
}
return intArray;
}
}
return new int[0];
}
示例5: showColorPicker
import android.support.annotation.ArrayRes; //导入依赖的package包/类
public void showColorPicker(View view){
@ArrayRes int pallet = new int[]{
SimpleColorDialog.MATERIAL_COLOR_PALLET, // default if no pallet explicitly set
SimpleColorDialog.MATERIAL_COLOR_PALLET_DARK,
SimpleColorDialog.MATERIAL_COLOR_PALLET_LIGHT,
SimpleColorDialog.BEIGE_COLOR_PALLET,
SimpleColorDialog.COLORFUL_COLOR_PALLET
}[counter++ % 5];
SimpleColorDialog.build()
.title(R.string.pick_a_color)
.colors(this, pallet)
.colorPreset(color)
.allowCustom(true)
.show(this, COLOR_DIALOG);
/** Results: {@link MainActivity#onResult} **/
}
示例6: convertResourceArraysToColorsArrayList
import android.support.annotation.ArrayRes; //导入依赖的package包/类
/**
* Converts 3 resource arrays to ArrayList<SelectableColor> of colors. Colors can be sorted by name at runtime, note that colors will be sorted in language displays to user.
* Note: all arrays must have equal lengths.
*
* @param context current context
* @param sortByName if true colors will be sorted by name, otherwise colors will be left as they are
* @param idsArray array resource id to use as colors ids
* @param namesArray array resource id to use as colors names
* @param colorsArray array resource id to use as colors, well color values
* @return colors ArrayList
*/
public static ArrayList<SelectableColor> convertResourceArraysToColorsArrayList(Context context, boolean sortByName, @ArrayRes int idsArray, @ArrayRes int namesArray, @ArrayRes int colorsArray) {
//get and check arrays
String[] ids = context.getResources().getStringArray(idsArray);
int[] colors = context.getResources().getIntArray(colorsArray);
String[] names = context.getResources().getStringArray(namesArray);
if (ids.length != colors.length && ids.length != names.length) {
Log.e(LOG_TAG, "convertResourceArraysToColorsArrayList(): Arrays must have equals lengths!");
return null;
}
//create ArrayList
ArrayList<SelectableColor> result = new ArrayList<>();
for (int i = 0; i < ids.length; i++) {
result.add(new SelectableColor(ids[i], names[i], colors[i]));
}
//sort by names
if (sortByName) {
Collections.sort(result, new SelectableItemNameComparator<SelectableColor>());
}
return result;
}
示例7: convertResourceArraysToIconsArrayList
import android.support.annotation.ArrayRes; //导入依赖的package包/类
/**
* Converts 3 resource arrays to ArrayList<SelectableIcons> of icons. Icons can be sorted by name at runtime, note that icons will be sorted in language displays to user.
* Note: all arrays must have equal lengths.
*
* @param context current context
* @param sortByName if true colors will be sorted by name, otherwise colors will be left as they are
* @param idsArray array resource id to use as icons ids
* @param namesArray array resource id to use as icons names
* @param drawablesArray array resource id to use as icons drawables
* @return icons ArrayList
*/
public static ArrayList<SelectableIcon> convertResourceArraysToIconsArrayList(Context context, boolean sortByName, @ArrayRes int idsArray, @ArrayRes int namesArray, @ArrayRes int drawablesArray) {
//get and check arrays
String[] ids = context.getResources().getStringArray(idsArray);
int[] drawables = context.getResources().getIntArray(drawablesArray);
String[] names = context.getResources().getStringArray(namesArray);
if (ids.length != drawables.length && ids.length != names.length) {
Log.e(LOG_TAG, "convertResourceArraysToIconsArrayList(): Arrays must have equals lengths!");
return null;
}
//create ArrayList
ArrayList<SelectableIcon> result = new ArrayList<>();
for (int i = 0; i < ids.length; i++) {
result.add(new SelectableIcon(ids[i], names[i], drawables[i]));
}
//sort by names
if (sortByName) {
Collections.sort(result, new SelectableItemNameComparator<SelectableIcon>());
}
return result;
}
示例8: show
import android.support.annotation.ArrayRes; //导入依赖的package包/类
public static void show(@NonNull Context context, @StringRes int title, @ArrayRes int names, @NonNull final OnSelection callback) {
final WeakReference<OnSelection> callbackRef = new WeakReference<>(callback);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(title);
builder.setItems(names, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
OnSelection callbackSafe = callbackRef.get();
if (callbackSafe != null) {
callback.onSelection(which);
}
}
});
builder.setNegativeButton(android.R.string.cancel, null);
builder.create().show();
}
示例9: extractColorArray
import android.support.annotation.ArrayRes; //导入依赖的package包/类
public static int[] extractColorArray(@ArrayRes int arrayId, Context context) {
String[] choicesString = context.getResources().getStringArray(arrayId);
int[] choicesInt = context.getResources().getIntArray(arrayId);
// If user uses color reference(i.e. @color/color_choice) in the array,
// the choicesString contains null values. We use the choicesInt in such case.
boolean isStringArray = choicesString[0] != null;
int length = isStringArray ? choicesString.length : choicesInt.length;
int[] colorChoices = new int[length];
for (int i = 0; i < length; i++) {
colorChoices[i] = isStringArray ? Color.parseColor(choicesString[i]) : choicesInt[i];
}
return colorChoices;
}
示例10: setSpinnerContents
import android.support.annotation.ArrayRes; //导入依赖的package包/类
private void setSpinnerContents(Spinner spinner, @ArrayRes int spinnerContents, int selectedIndex, int offset,
@ArrayRes int spinnerIcons) {
List<EventTypeItem> items = new ArrayList<>();
final String[] arrTexts = getResources().getStringArray(spinnerContents);
final TypedArray arrIcons = spinnerIcons > 0 ? getResources().obtainTypedArray(spinnerIcons) : null;
if (offset >= arrTexts.length) {
throw new IllegalArgumentException("Offset >= Array.length");
} else if (offset < 0) {
throw new IllegalArgumentException("Offset < 0");
}
for (int i = offset; i < arrTexts.length; i++) {
//noinspection ResourceType
items.add(new EventTypeItem(i, arrTexts[i], (null != arrIcons) ? arrIcons.getResourceId(i, 0) : 0));
}
if (null != arrIcons) {
arrIcons.recycle();
}
final EventTypeArrayAdapter arrayAdapter = new EventTypeArrayAdapter(CreateEditEventActivity.this, items);
spinner.setAdapter(arrayAdapter);
spinner.setSelection(selectedIndex - offset);
}
示例11: setSummary
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@Override
public void setSummary(@ArrayRes int summaryResId) {
try {
setSummary(getContext().getResources().getStringArray(summaryResId));
} catch (Exception e) {
super.setSummary(summaryResId);
}
}
示例12: getColorArray
import android.support.annotation.ArrayRes; //导入依赖的package包/类
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;
}
示例13: LocalResourceSimpleAdapter
import android.support.annotation.ArrayRes; //导入依赖的package包/类
private LocalResourceSimpleAdapter(final Context context, @ArrayRes int arrayId, boolean lazy) {
mSrcArray = context.getResources().getStringArray(arrayId);
mLazy = lazy;
mUris = new Uri[mSrcArray.length];
if (!lazy) {
for (int i = 0; i < mSrcArray.length; i++) {
mUris[i] = Uri.parse(mSrcArray[i]);
}
}
}
示例14: getTextArray
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@NonNull
@Override
public CharSequence[] getTextArray(@ArrayRes int id) throws NotFoundException {
int realId = getCorrespondResId(id);
if (realId > 0) {
return mSkinResources.getTextArray(id);
}
return super.getTextArray(id);
}
示例15: getStringArray
import android.support.annotation.ArrayRes; //导入依赖的package包/类
@NonNull
@Override
public String[] getStringArray(@ArrayRes int id) throws NotFoundException {
int realId = getCorrespondResId(id);
if (realId > 0) {
return mSkinResources.getStringArray(realId);
}
return super.getStringArray(id);
}