本文整理汇总了Java中android.content.res.TypedArray.length方法的典型用法代码示例。如果您正苦于以下问题:Java TypedArray.length方法的具体用法?Java TypedArray.length怎么用?Java TypedArray.length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.res.TypedArray
的用法示例。
在下文中一共展示了TypedArray.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResIdArray
import android.content.res.TypedArray; //导入方法依赖的package包/类
public static int[] getResIdArray(Context context, int id) {
final TypedArray idsarr = context.getResources().obtainTypedArray(id);
int[] ids = new int[idsarr.length()];
for (int i = 0; i < idsarr.length(); i++) {
ids[i] = idsarr.getResourceId(i, 0);
}
idsarr.recycle();
return ids;
}
示例2: ContentAdapter
import android.content.res.TypedArray; //导入方法依赖的package包/类
public ContentAdapter(Context context) {
Resources resources = context.getResources();
mPlaces = resources.getStringArray(R.array.places);
mPlaceDesc = resources.getStringArray(R.array.place_desc);
TypedArray a = resources.obtainTypedArray(R.array.place_avator);
mPlaceAvators = new Drawable[a.length()];
for (int i = 0; i < mPlaceAvators.length; i++) {
mPlaceAvators[i] = a.getDrawable(i);
}
a.recycle();
}
示例3: getResourceIdArray
import android.content.res.TypedArray; //导入方法依赖的package包/类
private int[] getResourceIdArray(Context context, int arrayResId) {
TypedArray ar = context.getResources().obtainTypedArray(arrayResId);
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;
}
示例4: getResourcesIdArray
import android.content.res.TypedArray; //导入方法依赖的package包/类
public static int[] getResourcesIdArray(@ArrayRes int id) {
TypedArray typedArray = mApplication.getResources().obtainTypedArray(id);
int length = typedArray.length();
int[] resArray = new int[length];
for (int i = 0; i < length; i++) {
int resourceId = typedArray.getResourceId(i, 0);
resArray[i] = resourceId;
}
typedArray.recycle();
return resArray;
}
示例5: internalSetTargetResources
import android.content.res.TypedArray; //导入方法依赖的package包/类
private void internalSetTargetResources(int resourceId) {
Resources res = getContext().getResources();
TypedArray array = res.obtainTypedArray(resourceId);
int count = array.length();
ArrayList<TargetDrawable> targetDrawables = new ArrayList<TargetDrawable>(count);
for (int i = 0; i < count; i++) {
Drawable drawable = array.getDrawable(i);
targetDrawables.add(new TargetDrawable(res, drawable));
}
array.recycle();
mTargetResourceId = resourceId;
mTargetDrawables = targetDrawables;
updateTargetPositions();
}
示例6: loadDescriptions
import android.content.res.TypedArray; //导入方法依赖的package包/类
private ArrayList<String> loadDescriptions(int resourceId) {
TypedArray array = getContext().getResources().obtainTypedArray(resourceId);
final int count = array.length();
ArrayList<String> targetContentDescriptions = new ArrayList<String>(count);
for (int i = 0; i < count; i++) {
String contentDescription = array.getString(i);
targetContentDescriptions.add(contentDescription);
}
array.recycle();
return targetContentDescriptions;
}
示例7: getData
import android.content.res.TypedArray; //导入方法依赖的package包/类
private ArrayList<Image> getData() {
final ArrayList<Image> imageItems = new ArrayList<>();
TypedArray imgs = getResources().obtainTypedArray(R.array.image_ids);
for (int i = imageStartId; i < imgs.length(); i++) {
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), imgs.getResourceId(i, -1));
Image image = new Image(0l, null, null, 0, null, null);
image.setTitle(Integer.toString(i));
image.setImage(bitmap);
imageItems.add(image);
}
return imageItems;
}
示例8: setLayerColors
import android.content.res.TypedArray; //导入方法依赖的package包/类
/**
* 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);
}
示例9: ContentAdapter
import android.content.res.TypedArray; //导入方法依赖的package包/类
public ContentAdapter(Context context) {
Resources resources = context.getResources();
mPlaces = resources.getStringArray(R.array.places);
mPlaceDesc = resources.getStringArray(R.array.place_desc);
TypedArray a = resources.obtainTypedArray(R.array.places_picture);
mPlacePictures = new Drawable[a.length()];
for (int i = 0; i < mPlacePictures.length; i++) {
mPlacePictures[i] = a.getDrawable(i);
}
a.recycle();
}
示例10: loadTargetsDescriptions
import android.content.res.TypedArray; //导入方法依赖的package包/类
public static ArrayList<String> loadTargetsDescriptions(Context ctxt, int resourceId) {
TypedArray array = ctxt.getResources().obtainTypedArray(resourceId);
final int count = array.length();
ArrayList<String> targetContentDescriptions = new ArrayList<String>(count);
for (int i = 0; i < count; i++) {
String contentDescription = array.getString(i);
targetContentDescriptions.add(contentDescription);
}
array.recycle();
return targetContentDescriptions;
}
示例11: CheckableRelativeLayout
import android.content.res.TypedArray; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param context
* The context to operate in.
* @param attrs
* The attributes defined in XML for this element.
*/
public CheckableRelativeLayout(final Context context, final AttributeSet attrs)
{
super(context, attrs);
TypedArray typedArray = null;
// Cache the check box drawable.
typedArray = context.getTheme()
.obtainStyledAttributes(new int[] { android.R.attr.listChoiceIndicatorMultiple });
if (typedArray != null && typedArray.length() > 0)
mCheckDrawable = typedArray.getDrawable(0);
else
// Fallback if the target theme doesn't define a check box drawable.
// Perhaps an application specific drawable should be used instead
// of null.
mCheckDrawable = null;
// Careful with resources like this, we don't need any memory leaks.
typedArray.recycle();
// Cache the radio button drawable.
typedArray = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.listChoiceIndicatorSingle });
if (typedArray != null && typedArray.length() > 0)
mRadioDrawable = typedArray.getDrawable(0);
else
// Fallback if the target theme doesn't define a radio button
// drawable.
// Perhaps an application specific drawable should be used instead
// of null
mRadioDrawable = null;
// Careful with resources like this, we don't need any memory leaks.
typedArray.recycle();
mIsChecked = false;
}
示例12: getRandomMaterialColor
import android.content.res.TypedArray; //导入方法依赖的package包/类
/**
* @param typeColor the type of color as String
* @return random color as an integer value
*/
private int getRandomMaterialColor(String typeColor) {
int returnColor = Color.GRAY;
int arrayId = context.getResources().getIdentifier("mdcolor_" + typeColor, "array", context.getPackageName());
if (arrayId != 0) {
TypedArray colors = context.getResources().obtainTypedArray(arrayId);
int index = (int) (Math.random() * colors.length());
returnColor = colors.getColor(index, Color.GRAY);
colors.recycle();
}
return returnColor;
}
示例13: loadScreenIcons
import android.content.res.TypedArray; //导入方法依赖的package包/类
private Drawable[] loadScreenIcons() {
TypedArray ta = getResources().obtainTypedArray(R.array.ld_activityScreenIcons);
Drawable[] icons = new Drawable[ta.length()];
for (int i = 0; i < ta.length(); i++) {
int id = ta.getResourceId(i, 0);
if (id != 0) {
icons[i] = ContextCompat.getDrawable(this, id);
}
}
ta.recycle();
return icons;
}
示例14: getResourceIds
import android.content.res.TypedArray; //导入方法依赖的package包/类
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;
}
示例15: onCreate
import android.content.res.TypedArray; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
photoEditorActivity = (PhotoEditorActivity) getActivity();
TypedArray images = getResources().obtainTypedArray(R.array.photo_editor_photos);
stickerBitmaps = new ArrayList<>();
for (int i = 0; i < images.length(); i++) {
stickerBitmaps.add(decodeSampledBitmapFromResource(photoEditorActivity.getResources(), images.getResourceId(i, -1), 120, 120));
}
}