@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;
}
java类android.support.annotation.ArrayRes的实例源码
AchievementsUtils.java 文件源码
项目:CodeWatch
阅读 35
收藏 0
点赞 0
评论 0
StaticEmojiPageModel.java 文件源码
项目:Nird2
阅读 36
收藏 0
点赞 0
评论 0
@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;
}
StaticEmojiPageModel.java 文件源码
项目:Nird2
阅读 41
收藏 0
点赞 0
评论 0
@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;
}
ShadowResources.java 文件源码
项目:YuiHatano
阅读 34
收藏 0
点赞 0
评论 0
@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));
}
ShadowResources.java 文件源码
项目:YuiHatano
阅读 38
收藏 0
点赞 0
评论 0
@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];
}
MainActivity.java 文件源码
项目:SimpleDialogFragments
阅读 32
收藏 0
点赞 0
评论 0
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} **/
}
ShadowResources.java 文件源码
项目:KBUnitTest
阅读 30
收藏 0
点赞 0
评论 0
@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));
}
ShadowResources.java 文件源码
项目:KBUnitTest
阅读 42
收藏 0
点赞 0
评论 0
@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];
}
Utils.java 文件源码
项目:SelectionDialogs
阅读 39
收藏 0
点赞 0
评论 0
/**
* 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;
}
Utils.java 文件源码
项目:SelectionDialogs
阅读 34
收藏 0
点赞 0
评论 0
/**
* 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;
}
PreferenceSelectionDialog.java 文件源码
项目:android-sql-logging
阅读 38
收藏 0
点赞 0
评论 0
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();
}
MainActivity.java 文件源码
项目:SimpleDialogFragments
阅读 39
收藏 0
点赞 0
评论 0
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} **/
}
ColorUtils.java 文件源码
项目:colorpreference
阅读 33
收藏 0
点赞 0
评论 0
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;
}
CreateEditEventActivity.java 文件源码
项目:DietDiaryApp
阅读 35
收藏 0
点赞 0
评论 0
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);
}
SliderPreference.java 文件源码
项目:q-mail
阅读 35
收藏 0
点赞 0
评论 0
@Override
public void setSummary(@ArrayRes int summaryResId) {
try {
setSummary(getContext().getResources().getStringArray(summaryResId));
} catch (Exception e) {
super.setSummary(summaryResId);
}
}
DialogUtils.java 文件源码
项目:GitHub
阅读 38
收藏 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;
}
LocalResourceSimpleAdapter.java 文件源码
项目:GitHub
阅读 34
收藏 0
点赞 0
评论 0
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]);
}
}
}
ComposedResources.java 文件源码
项目:SkinFramework
阅读 46
收藏 0
点赞 0
评论 0
@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);
}
ComposedResources.java 文件源码
项目:SkinFramework
阅读 40
收藏 0
点赞 0
评论 0
@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);
}
ComposedResources.java 文件源码
项目:SkinFramework
阅读 38
收藏 0
点赞 0
评论 0
@NonNull
@Override
public int[] getIntArray(@ArrayRes int id) throws NotFoundException {
int realId = getCorrespondResId(id);
if (realId > 0) {
return mSkinResources.getIntArray(realId);
}
return super.getIntArray(id);
}
ComposedResources.java 文件源码
项目:SkinFramework
阅读 38
收藏 0
点赞 0
评论 0
@NonNull
@Override
public TypedArray obtainTypedArray(@ArrayRes int id) throws NotFoundException {
int realId = getCorrespondResId(id);
if (realId > 0) {
return mSkinResources.obtainTypedArray(realId);
}
return super.obtainTypedArray(id);
}
ResourcesUtils.java 文件源码
项目:androidtools
阅读 31
收藏 0
点赞 0
评论 0
/**
* Gets the string array resource based on the string array resource ID(List)
*
* @param context context
* @param resId resId
* @return string array resource
*/
public static List<String> getStringList(Context context, @ArrayRes int resId) {
List<String> strings = new ArrayList<String>();
String[] strs = getStringArray(context, resId);
for (String string : strs) {
strings.add(string);
}
return strings;
}
ResUtil.java 文件源码
项目:PeSanKita-android
阅读 44
收藏 0
点赞 0
评论 0
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;
}
SortListDialogFragment.java 文件源码
项目:IslamicLibraryAndroid
阅读 36
收藏 0
点赞 0
评论 0
public static SortListDialogFragment newInstance(@ArrayRes int sortingChoices, int currentSortIndex) {
SortListDialogFragment frag = new SortListDialogFragment();
Bundle args = new Bundle();
args.putInt(KEY_SORT_ARRAY_RES_ID, sortingChoices);
args.putInt(KEY_CURRENT_SORT_INDEX, currentSortIndex);
frag.setArguments(args);
return frag;
}
TypedArrayHelper.java 文件源码
项目:CameraButton
阅读 41
收藏 0
点赞 0
评论 0
@ColorInt
static int[] getColors(Context context,
TypedArray array,
@StyleableRes int attr,
@ArrayRes int defaultColorsRes) {
return context.getResources().getIntArray(
array.getResourceId(attr, defaultColorsRes));
}
GLAudioVisualizationView.java 文件源码
项目:Android-AudioRecorder-App
阅读 36
收藏 0
点赞 0
评论 0
/**
* Set layer colors from array resource
*
* @param arrayId array resource
*/
public T setLayerColors(@ArrayRes int arrayId) {
TypedArray colorsArray = context.getResources().obtainTypedArray(arrayId);
int[] colors = new int[colorsArray.length()];
for (int i = 0; i < colorsArray.length(); i++) {
colors[i] = colorsArray.getColor(i, Color.TRANSPARENT);
}
colorsArray.recycle();
return setLayerColors(colors);
}
DialogService.java 文件源码
项目:Pocket-Plays-for-Twitch
阅读 44
收藏 0
点赞 0
评论 0
public static MaterialDialog getChooseStartUpPageDialog(Activity activity, String currentlySelectedPageTitle, MaterialDialog.ListCallbackSingleChoice listCallbackSingleChoice) {
final Settings settings = new Settings(activity);
@ArrayRes int arrayRessource = settings.isLoggedIn() ? R.array.StartupPages : R.array.StartupPagesNoLogin;
int indexOfPage = 0;
String[] androidStrings = activity.getResources().getStringArray(arrayRessource);
for (int i = 0; i < androidStrings.length; i++) {
if (androidStrings[i].equals(currentlySelectedPageTitle)) {
indexOfPage = i;
break;
}
}
return getBaseThemedDialog(activity)
.title(R.string.gen_start_page)
.items(arrayRessource)
.itemsCallbackSingleChoice(indexOfPage, listCallbackSingleChoice)
.positiveText(R.string.ok)
.negativeText(R.string.cancel)
.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
})
.build();
}
DialogService.java 文件源码
项目:Pocket-Plays-for-Twitch
阅读 36
收藏 0
点赞 0
评论 0
public static MaterialDialog getChooseChatSizeDialog(Activity activity, @StringRes int dialogTitle, @ArrayRes int array, int currentSize, MaterialDialog.ListCallbackSingleChoice callbackSingleChoice) {
int indexOfPage = currentSize - 1;
String[] sizeTitles = activity.getResources().getStringArray(array);
return getBaseThemedDialog(activity)
.title(dialogTitle)
.itemsCallbackSingleChoice(indexOfPage, callbackSingleChoice)
.items(sizeTitles)
.positiveText(R.string.done)
.build();
}
ResTool.java 文件源码
项目:EasyAndroid
阅读 33
收藏 0
点赞 0
评论 0
/**
* 获取返回Drawable Array,解决直接使用getIntArray获取Drawable数组时,所有item都为0的问题.
*
* @param id resource id
* @return Drawable Array
*/
public static Drawable[] getDrawableArray(@ArrayRes int id)
{
TypedArray typedArray = getTypedArray(id);
//获取数量需要用这样的方法, TypedArray.getIndexCount() 获取的一直是0.
int count = getTextArray(id).length;
Drawable[] drawables = new Drawable[count];
for(int i = 0; i < drawables.length; i++)
{
drawables[i] = typedArray.getDrawable(i);
}
typedArray.recycle();
return drawables;
}
ResTool.java 文件源码
项目:EasyAndroid
阅读 28
收藏 0
点赞 0
评论 0
/**
* 获取返回Drawable Id Array,因为主要原因是使用 {@link #getDrawableArray(int)} 时,用Glide直接加载
* Drawable会报异常,这里提供一个获取drawable id array的方法解决这个问题.
*
* @param id Array id
* @return Drawable id Array
*/
public static int[] getDrawableIdArray(@ArrayRes int id)
{
TypedArray typedArray = getTypedArray(id);
int length = getTextArray(id).length;
int[] ids = new int[length];
for(int i = 0; i < ids.length; i++)
{
ids[i] = typedArray.getResourceId(i, 0);
}
typedArray.recycle();
return ids;
}