android.support.annotation.ArrayRes Java Examples

The following examples show how to use android.support.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 Project: SelectionDialogs   Author: coreORB   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source Project: SelectionDialogs   Author: coreORB   File: Utils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source Project: external-resources   Author: prcaen   File: ExternalResources.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the string array associated with a particular resource key.
 * This resource can come from resources you provided via the URL or via default resources.
 *
 * @param key The desired resource identifier, as generated by the aapt
 * tool. This integer encodes the package, type, and resource
 * entry. The value 0 is an invalid identifier.
 * @return The string array associated with the resource.
 * @throws NotFoundException Throws NotFoundException if the given key does not exist.
 */
public String[] getStringArray(@NonNull String key) throws NotFoundException {
  Resource resource = resources.get(key);
  if (null != resource) {
    return resource.getAsStringArray();
  }

  @ArrayRes int resId = getApplicationResourceIdentifier(key, "array");

  if (0 != resId) {
    String[] values = context.getResources().getStringArray(resId);
    Resource[] stringResources = new Resource[values.length];

    for (int i = 0; i < values.length; i++) {
      stringResources[i] = new Resource(values[i]);
    }

    resources.add(key, new Resource(stringResources));

    return values;
  }

  throw new NotFoundException("String array resource with key: " + key);
}
 
Example #4
Source Project: external-resources   Author: prcaen   File: ExternalResources.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Return the int array associated with a particular resource key.
 * * This resource can come from resources you provided via the URL or via default resources.
 *
 * @param key The desired resource identifier.
 * @return The int array associated with the resource.
 * @throws NotFoundException Throws NotFoundException if the given key does not exist.
 */
public int[] getIntArray(@NonNull String key) throws NotFoundException {
  Resource resource = resources.get(key);
  if (null != resource && null != resource.getAsIntegerArray()) {
    return resource.getAsIntegerArray();
  }

  @ArrayRes int resId = getApplicationResourceIdentifier(key, "array");

  if (0 != resId) {
    int[] values = context.getResources().getIntArray(resId);

    Resource[] intResources = new Resource[values.length];

    for (int i = 0; i < values.length; i++) {
      intResources[i] = new Resource(values[i]);
    }

    resources.add(key, new Resource(intResources));

    return values;
  }

  throw new NotFoundException("Int array resource with key: " + key);
}
 
Example #5
Source Project: android-showcase-template   Author: aerogear   File: LandingFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    
    @StringRes int titleResId = getArguments().getInt(TITLE);
    mTitle.setText(getString(titleResId));
    
    @ArrayRes int descriptionResId = getArguments().getInt(DESCRIPTION);
    String[] descriptionArray = getResources().getStringArray(descriptionResId);
    description.addAll(Arrays.asList(descriptionArray));
}
 
Example #6
Source Project: android-showcase-template   Author: aerogear   File: LandingFragment.java    License: Apache License 2.0 5 votes vote down vote up
public static LandingFragment newInstance(@StringRes int titleResId, 
                                          @ArrayRes int descriptionResId) {
    LandingFragment fragment = new LandingFragment();

    Bundle args = new Bundle();
    args.putInt(TITLE, titleResId);
    args.putInt(DESCRIPTION, descriptionResId);

    fragment.setArguments(args);

    return fragment;
}
 
Example #7
Source Project: IslamicLibraryAndroid   Author: fekracomputers   File: SortListDialogFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@NonNull
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;
}
 
Example #8
Source Project: Android-AudioRecorder-App   Author: Arjun-sna   File: GLAudioVisualizationView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #9
Source Project: CameraButton   Author: hluhovskyi   File: TypedArrayHelper.java    License: Apache License 2.0 5 votes vote down vote up
@ColorInt
static int[] getColors(Context context,
                       TypedArray array,
                       @StyleableRes int attr,
                       @ArrayRes int defaultColorsRes) {

    return context.getResources().getIntArray(
            array.getResourceId(attr, defaultColorsRes));
}
 
Example #10
Source Project: AndroidUtilCode   Author: Blankj   File: StringUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the string array associated with a particular resource ID.
 *
 * @param id The desired resource identifier.
 * @return The string array associated with the resource.
 */
public static String[] getStringArray(@ArrayRes int id) {
    try {
        return Utils.getApp().getResources().getStringArray(id);
    } catch (Resources.NotFoundException ignore) {
        return new String[0];
    }
}
 
Example #11
Source Project: Slide   Author: ccrama   File: SettingsThemeFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static ArrayAdapter<? extends CharSequence> createFromResource(@NonNull Context context, @ArrayRes int textArrayResId, @LayoutRes int layoutTypeResId) {
    CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
    if (!Reddit.canUseNightModeAuto) {
        strings = ArrayUtils.remove(strings, SettingValues.NightModeState.AUTOMATIC.ordinal());
    }
    return new ArrayAdapter<>(context, layoutTypeResId, Arrays.asList(strings));
}
 
Example #12
Source Project: NewsMe   Author: iQuick   File: ThemeHelper.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #13
Source Project: talk-android   Author: jianliaoim   File: AlertDialogWrapper.java    License: MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source Project: EZScreenshot   Author: zty5678   File: HelpDialog.java    License: Apache License 2.0 5 votes vote down vote up
public String getHtmlContent(@ArrayRes int arrayResId) {
    String array[] = getContext().getResources().getStringArray(arrayResId);
    List<Pair<String, String>> arrays = new ArrayList<>();
    for (int i = 0; i < array.length; i += 2) {
        int j = i + 1;
        if (j < array.length) {
            String first = array[i];
            String second = array[j];
            arrays.add(new Pair<String, String>(first, second));
        }
    }


    final StringBuilder changelogBuilder = new StringBuilder();
    changelogBuilder
            .append("<!DOCTYPE html><html><head>")
            .append(getStyle())
            .append("</head><body>");

    for (Pair<String, String> pair : arrays) {
        changelogBuilder.append("<span class='title' >" + pair.first + "</span>");
        changelogBuilder.append("<span class='content' >" + pair.second + "</span>");
    }

    changelogBuilder.append("</body></html>");

    return changelogBuilder.toString();

}
 
Example #15
Source Project: Forage   Author: Plastix   File: LogActivity.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void setLogTypes(@ArrayRes int options) {
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, options,
            android.R.layout.simple_spinner_item);

    adapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);

    logType.setAdapter(adapter);
}
 
Example #16
Source Project: Silence   Author: SilenceIM   File: ResUtil.java    License: GNU General Public License v3.0 5 votes vote down vote up
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 #17
Source Project: BottomSheet   Author: michaelbel   File: BottomSheet.java    License: Apache License 2.0 5 votes vote down vote up
public Builder setItems(@ArrayRes int itemsId, int[] icons, final OnClickListener listener) {
    bottomSheet.ITEMS.addAll(Arrays.asList(context.getResources().getTextArray(itemsId)));
    for (int i: icons) {
        bottomSheet.ICONS.add(ContextCompat.getDrawable(context, i));
    }
    bottomSheet.onClickListener = listener;
    return this;
}
 
Example #18
Source Project: AndroidTint   Author: iQuick   File: ThemeHelper.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #19
Source Project: orz   Author: vsona   File: BaseUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 */
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;
}
 
Example #20
Source Project: StatusBarUtil   Author: Ye-Miao   File: AppUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String[] getStringArray(@ArrayRes int resId) {
    return mContext.getResources().getStringArray(resId);
}
 
Example #21
Source Project: Android-utils   Author: Shouheng88   File: StringUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static CharSequence[] getTextArray(@ArrayRes int id) {
    return UtilsApp.getApp().getResources().getTextArray(id);
}
 
Example #22
Source Project: Android-utils   Author: Shouheng88   File: StringUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String[] getStringArray(@ArrayRes int id) {
    return UtilsApp.getApp().getResources().getStringArray(id);
}
 
Example #23
Source Project: Android-utils   Author: Shouheng88   File: ResUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static int[] getIntArray(@ArrayRes int id) {
    return UtilsApp.getApp().getResources().getIntArray(id);
}
 
Example #24
Source Project: Android-utils   Author: Shouheng88   File: ResUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static CharSequence[] getTextArray(@ArrayRes int id) {
    return UtilsApp.getApp().getResources().getTextArray(id);
}
 
Example #25
Source Project: Android-utils   Author: Shouheng88   File: ResUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static String[] getStringArray(@ArrayRes int id) {
    return UtilsApp.getApp().getResources().getStringArray(id);
}
 
Example #26
Source Project: Kalle   Author: yanzhenjie   File: BaseView.java    License: Apache License 2.0 4 votes vote down vote up
public final String[] getStringArray(@ArrayRes int id) {
    return getResources().getStringArray(id);
}
 
Example #27
Source Project: Kalle   Author: yanzhenjie   File: BaseView.java    License: Apache License 2.0 4 votes vote down vote up
public final int[] getIntArray(@ArrayRes int id) {
    return getResources().getIntArray(id);
}
 
Example #28
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static int[] getIntArray(@ArrayRes int arrayRes) {
    return Base.getResources().getIntArray(arrayRes);
}
 
Example #29
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String[] getStringArray(@ArrayRes int arrayRes) {
    return Base.getResources().getStringArray(arrayRes);
}
 
Example #30
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static CharSequence[] getTextArray(@ArrayRes int arrayRes) {
    return Base.getResources().getTextArray(arrayRes);
}