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 File: ExternalResources.java    From external-resources with 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 #2
Source File: ExternalResources.java    From external-resources with 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 #3
Source File: Utils.java    From SelectionDialogs with 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 #4
Source File: Utils.java    From SelectionDialogs with 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 #5
Source File: SortListDialogFragment.java    From IslamicLibraryAndroid with 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 #6
Source File: ThemeHelper.java    From NewsMe with 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 #7
Source File: SettingsThemeFragment.java    From Slide with 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 #8
Source File: AlertDialogWrapper.java    From talk-android with 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 #9
Source File: LandingFragment.java    From android-showcase-template with 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 #10
Source File: LandingFragment.java    From android-showcase-template with 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 #11
Source File: GLAudioVisualizationView.java    From Android-AudioRecorder-App with 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 #12
Source File: HelpDialog.java    From EZScreenshot with 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 #13
Source File: TypedArrayHelper.java    From CameraButton with 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 #14
Source File: LogActivity.java    From Forage with 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 #15
Source File: ResUtil.java    From Silence with 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 #16
Source File: BottomSheet.java    From BottomSheet with 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 #17
Source File: StringUtils.java    From AndroidUtilCode with 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 #18
Source File: ThemeHelper.java    From AndroidTint with 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 File: BaseUtils.java    From orz with 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 File: BaseView.java    From Album with Apache License 2.0 4 votes vote down vote up
public final String[] getStringArray(@ArrayRes int id) {
    return getResources().getStringArray(id);
}
 
Example #21
Source File: BaseView.java    From Album with Apache License 2.0 4 votes vote down vote up
public final int[] getIntArray(@ArrayRes int id) {
    return getResources().getIntArray(id);
}
 
Example #22
Source File: ColorChooserDialog.java    From APlayer with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
public Builder customColors(@ArrayRes int topLevel, @Nullable int[][] subLevel) {
  mColorsTop = DialogUtils.getColorArray(mContext, topLevel);
  mColorsSub = subLevel;
  return this;
}
 
Example #23
Source File: ResourceUtils.java    From Mover with Apache License 2.0 4 votes vote down vote up
public static String[] getStringArray(@ArrayRes int id){
    return sResources.getStringArray(id);
}
 
Example #24
Source File: AlertDialog.java    From CompatAlertDialog with Apache License 2.0 4 votes vote down vote up
public Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem, final DialogInterface
        .OnClickListener listener) {
    builder.setSingleChoiceItems(itemsId, checkedItem, listener);
    return this;
}
 
Example #25
Source File: AlertDialog.java    From CompatAlertDialog with Apache License 2.0 4 votes vote down vote up
public Builder setMultiChoiceItems(@ArrayRes int itemsId, boolean[] checkedItems, final
DialogInterface.OnMultiChoiceClickListener listener) {
    builder.setMultiChoiceItems(itemsId, checkedItems, listener);
    return this;
}
 
Example #26
Source File: ResourceUtils.java    From Mover with Apache License 2.0 4 votes vote down vote up
public static CharSequence[] getTextArray(@ArrayRes int id){
    return sResources.getTextArray(id);
}
 
Example #27
Source File: AppUtils.java    From StatusBarUtil with Apache License 2.0 4 votes vote down vote up
public static String[] getStringArray(@ArrayRes int resId) {
    return mContext.getResources().getStringArray(resId);
}
 
Example #28
Source File: AlertDialog.java    From CompatAlertDialog with Apache License 2.0 4 votes vote down vote up
@Override
public Builder setItems(@ArrayRes int itemsId, final DialogInterface.OnClickListener listener) {
    builder.setItems(itemsId, listener);
    return this;
}
 
Example #29
Source File: AlertDialog.java    From CompatAlertDialog with Apache License 2.0 4 votes vote down vote up
Builder setSingleChoiceItems(@ArrayRes int itemsId, int checkedItem, final DialogInterface
.OnClickListener listener);
 
Example #30
Source File: AlertDialog.java    From CompatAlertDialog with Apache License 2.0 4 votes vote down vote up
@Override
public Builder setMultiChoiceItems(@ArrayRes int itemsId, boolean[] checkedItems, final
DialogInterface.OnMultiChoiceClickListener listener) {
    builder.setMultiChoiceItems(itemsId, checkedItems, listener);
    return this;
}