androidx.annotation.ArrayRes Java Examples
The following examples show how to use
androidx.annotation.ArrayRes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamicResourceUtils.java From dynamic-support with Apache License 2.0 | 6 votes |
/** * Get drawable resource array from its resource id. * * @param context The context to retrieve resources. * @param arrayRes The resource id of the drawable array. * * @return The drawable resource array from its resource id. */ public static @Nullable @DrawableRes int[] convertToDrawableResArray( @NonNull Context context, @ArrayRes int arrayRes) { @DrawableRes int[] resources = null; if (arrayRes != ADS_DEFAULT_RESOURCE_ID) { TypedArray drawableArray = context.getResources().obtainTypedArray(arrayRes); resources = new int[drawableArray.length()]; for (int i = 0; i < drawableArray.length(); i++) { try { resources[i] = drawableArray.getResourceId(i, ADS_DEFAULT_RESOURCE_VALUE); } catch (Exception e) { resources[i] = ADS_DEFAULT_RESOURCE_VALUE; } } drawableArray.recycle(); } return resources; }
Example #2
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したDimension arrayをfloat配列へ読み込む * @param res * @param arrayId * @param defaultValue * @return */ @NonNull public static float[] readDimensionArray(@NonNull final Resources res, @ArrayRes final int arrayId, final float defaultValue) { float[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new float[n]; for (int i = 0; i < n; i++) { result[i] = a.getDimension(i, defaultValue); } } finally { a.recycle(); } return result; }
Example #3
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したfloat arrayを読み込む * @param res * @param arrayId * @param defaultValue * @return */ @NonNull public static float[] readArray(@NonNull final Resources res, @ArrayRes final int arrayId, final float defaultValue) { float[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new float[n]; for (int i = 0; i < n; i++) { result[i] = a.getFloat(i, defaultValue); } } finally { a.recycle(); } return result; }
Example #4
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したdrawable arrayを読み込む * @param res * @param arrayId * @return */ @NonNull public static Drawable[] readDrawableArray(@NonNull final Resources res, @ArrayRes final int arrayId) { Drawable[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new Drawable[n]; for (int i = 0; i < n; i++) { result[i] = a.getDrawable(i); } } finally { a.recycle(); } return result; }
Example #5
Source File: MainActivity.java From SimpleDialogFragments with Apache License 2.0 | 6 votes |
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]; int outline = pallet == SimpleColorDialog.MATERIAL_COLOR_PALLET_LIGHT ? Color.BLACK : pallet == SimpleColorDialog.BEIGE_COLOR_PALLET ? SimpleColorDialog.AUTO : SimpleColorDialog.NONE; SimpleColorDialog.build() .title(R.string.pick_a_color) .colors(this, pallet) .colorPreset(color) .allowCustom(true) .showOutline(outline) .show(this, COLOR_DIALOG); /** Results: {@link MainActivity#onResult} **/ }
Example #6
Source File: DialogService.java From Twire with GNU General Public License v3.0 | 6 votes |
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((dialog, which) -> dialog.dismiss()) .build(); }
Example #7
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したint arrayを読み込む * xmlで定義している値がintとして扱えないときはUnsupportedOperationExceptionを投げる * @param res * @param arrayId * @param defaultValue * @return * @throws UnsupportedOperationException */ @NonNull public static int[] readArrayWithException(@NonNull final Resources res, @ArrayRes final int arrayId, final int defaultValue) throws UnsupportedOperationException { int[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new int[n]; for (int i = 0; i < n; i++) { result[i] = a.getInteger(i, defaultValue); } } finally { a.recycle(); } return result; }
Example #8
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したint arrayを読み込む * @param res * @param arrayId * @param defaultValue * @return */ @NonNull public static int[] readArray(@NonNull final Resources res, @ArrayRes final int arrayId, final int defaultValue) { int[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new int[n]; for (int i = 0; i < n; i++) { result[i] = a.getInt(i, defaultValue); } } finally { a.recycle(); } return result; }
Example #9
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したstring arrayを読み込む * @param res * @param arrayId * @param defaultValue * @return */ @NonNull public static String[] readArray(@NonNull final Resources res, @ArrayRes final int arrayId, final String defaultValue) { String[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new String[n]; for (int i = 0; i < n; i++) { result[i] = a.getString(i); if (result[i] == null) { result[i] = defaultValue; } } } finally { a.recycle(); } return result; }
Example #10
Source File: TypedArrayUtils.java From libcommon with Apache License 2.0 | 6 votes |
/** * xmlで定義したboolean arrayを読み込む * @param res * @param arrayId * @param defaultValue * @return */ @NonNull public static boolean[] readArray(@NonNull final Resources res, @ArrayRes final int arrayId, final boolean defaultValue) { boolean[] result; final TypedArray a = res.obtainTypedArray(arrayId); try { final int n = a.length(); result = new boolean[n]; for (int i = 0; i < n; i++) { result[i] = a.getBoolean(i, defaultValue); } } finally { a.recycle(); } return result; }
Example #11
Source File: ResourceResolver.java From litho with Apache License 2.0 | 6 votes |
@Nullable public final int[] resolveIntArrayRes(@ArrayRes int resId) { if (resId != 0) { int[] cached = mResourceCache.get(resId); if (cached != null) { return cached; } int[] result = mResources.getIntArray(resId); mResourceCache.put(resId, result); return result; } return null; }
Example #12
Source File: DynamicResourceUtils.java From dynamic-support with Apache License 2.0 | 6 votes |
/** * Get color array from its resource id. * * @param context The context to retrieve resources. * @param arrayRes The resource id of the color array. * * @return The color array from its resource id. */ public static @Nullable @ColorInt Integer[] convertToColorArray( @NonNull Context context, @ArrayRes int arrayRes) { Integer[] colors = null; if (arrayRes != ADS_DEFAULT_RESOURCE_ID) { TypedArray colorArray = context.getResources().obtainTypedArray(arrayRes); colors = new Integer[colorArray.length()]; for (int i = 0; i < colorArray.length(); i++) { try { if (colorArray.getInteger(i, Theme.AUTO) != Theme.AUTO) { colors[i] = colorArray.getColor(i, ADS_DEFAULT_RESOURCE_VALUE); } else { colors[i] = Theme.AUTO; } } catch (Exception e) { colors[i] = ADS_DEFAULT_RESOURCE_VALUE; } } colorArray.recycle(); } return colors; }
Example #13
Source File: ArrayAdapter.java From Status with Apache License 2.0 | 5 votes |
public ArrayAdapter(Context context, @ArrayRes int stringArray) { this.context = context; originalItems = new ArrayList<>(); originalItems.addAll(Arrays.asList(context.getResources().getTextArray(stringArray))); items = new ArrayList<>(originalItems); }
Example #14
Source File: ValueUtils.java From Mysplash with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable public static String getNameByValue(Context context, String value, @ArrayRes int nameArrayId, @ArrayRes int valueArrayId) { String[] names = context.getResources().getStringArray(nameArrayId); String[] values = context.getResources().getStringArray(valueArrayId); for (int i = 0; i < values.length; i ++) { if (values[i].equals(value)) { return names[i]; } } return null; }
Example #15
Source File: S.java From BaldPhone with Apache License 2.0 | 5 votes |
public static int[] typedArrayToResArray(@NonNull Resources resources, @ArrayRes int resId) { final TypedArray ar = resources.obtainTypedArray(resId); final int len = ar.length(); int[] resIds = new int[len]; for (int i = 0; i < len; i++) resIds[i] = ar.getResourceId(i, 0); ar.recycle(); return resIds; }
Example #16
Source File: OptionMapper.java From GeometricWeather with GNU Lesser General Public License v3.0 | 5 votes |
@Nullable public static String getNameByValue(Context context, String value, @ArrayRes int nameArrayId, @ArrayRes int valueArrayId) { String[] names = context.getResources().getStringArray(nameArrayId); String[] values = context.getResources().getStringArray(valueArrayId); for (int i = 0; i < values.length; i ++) { if (values[i].equals(value)) { return names[i]; } } return null; }
Example #17
Source File: DialogService.java From Twire with GNU General Public License v3.0 | 5 votes |
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(); }
Example #18
Source File: SingleChoiceListDialogFragment.java From SAI with GNU General Public License v3.0 | 5 votes |
/** * Create a SingleChoiceListDialogFragment without item checking * * @param title * @param items * @return */ public static SingleChoiceListDialogFragment newInstance(CharSequence title, @ArrayRes int items) { SingleChoiceListDialogFragment fragment = new SingleChoiceListDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_PARAMS, new DialogParams(title, items)); fragment.setArguments(args); return fragment; }
Example #19
Source File: ResourceUtils.java From DevUtils with Apache License 2.0 | 5 votes |
/** * 获取 String[] * @param id resource identifier * @return String[] */ public static String[] getStringArray(@ArrayRes final int id) { try { return DevUtils.getContext().getResources().getStringArray(id); } catch (Exception e) { LogPrintUtils.eTag(TAG, e, "getStringArray"); } return null; }
Example #20
Source File: LoadMoviesUseCase.java From SectionedRecyclerViewAdapter with MIT License | 5 votes |
List<Movie> execute(@NonNull final Context context, @ArrayRes final int stringArray) { final List<String> arrayList = new ArrayList<>(Arrays.asList( context.getResources().getStringArray(stringArray))); final List<Movie> movieList = new ArrayList<>(); for (String str : arrayList) { String[] array = str.split("\\|"); movieList.add(new Movie(array[0], array[1])); } return movieList; }
Example #21
Source File: SuperSearch.java From intra42 with Apache License 2.0 | 5 votes |
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; }
Example #22
Source File: TimerGraphFragment.java From TwistyTimer with GNU General Public License v3.0 | 5 votes |
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; }
Example #23
Source File: EditEntryActivity.java From Aegis with GNU General Public License v3.0 | 5 votes |
private int getStringResourceIndex(@ArrayRes int id, String string) { String[] res = getResources().getStringArray(id); for (int i = 0; i < res.length; i++) { if (res[i].equalsIgnoreCase(string)) { return i; } } return -1; }
Example #24
Source File: SingleChoiceListDialogFragment.java From SAI with GNU General Public License v3.0 | 5 votes |
/** * Create a SingleChoiceListDialogFragment with item checking * * @param title * @param items * @param checkedItem * @return */ public static SingleChoiceListDialogFragment newInstance(CharSequence title, @ArrayRes int items, int checkedItem) { SingleChoiceListDialogFragment fragment = new SingleChoiceListDialogFragment(); Bundle args = new Bundle(); args.putParcelable(ARG_PARAMS, new DialogParams(title, items, checkedItem)); fragment.setArguments(args); return fragment; }
Example #25
Source File: DialogService.java From Pocket-Plays-for-Twitch with GNU General Public License v3.0 | 5 votes |
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(); }
Example #26
Source File: ResUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
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; }
Example #27
Source File: ResourceResolver.java From litho with Apache License 2.0 | 5 votes |
@Nullable public String[] resolveStringArrayAttr(@AttrRes int attrResId, @ArrayRes int defResId) { TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return resolveStringArrayRes(a.getResourceId(0, defResId)); } finally { a.recycle(); } }
Example #28
Source File: ResourceResolver.java From litho with Apache License 2.0 | 5 votes |
@Nullable public int[] resolveIntArrayAttr(@AttrRes int attrResId, @ArrayRes int defResId) { TypedArray a = mTheme.obtainStyledAttributes(new int[] {attrResId}); try { return resolveIntArrayRes(a.getResourceId(0, defResId)); } finally { a.recycle(); } }
Example #29
Source File: SpinnerHelper.java From Aegis with GNU General Public License v3.0 | 4 votes |
public static void fillSpinner(Context context, Spinner spinner, @ArrayRes int textArrayResId) { ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(context, textArrayResId, android.R.layout.simple_spinner_item); initSpinner(spinner, adapter); }
Example #30
Source File: ThemeSwitcherResourceProvider.java From material-components-android with Apache License 2.0 | 4 votes |
@ArrayRes public int getSecondaryColors() { return R.array.mtrl_secondary_palettes; }