/**
* get uri to any resource type
*
* @param resId - resource id
* @return - Uri to resource by given id
*/
public static Uri getUriToResource(@NonNull Activity activity, @AnyRes int resId) {
Uri resUri = null;
try {
/** Return a Resources instance for your application's package. */
Resources res = activity.getResources();
/**
* Creates a Uri which parses the given encoded URI string.
* @param uriString an RFC 2396-compliant, encoded URI
* @throws NullPointerException if uriString is null
* @return Uri for this given uri string
*/
resUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + res.getResourcePackageName(resId) + '/' + res
.getResourceTypeName(resId) + '/' + res.getResourceEntryName(resId));
/** return uri */
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
return resUri;
}
java类android.support.annotation.AnyRes的实例源码
ResourcesHelper.java 文件源码
项目:AndroidBlueprints
阅读 36
收藏 0
点赞 0
评论 0
Utils.java 文件源码
项目:android-52Kit
阅读 49
收藏 0
点赞 0
评论 0
/**
* Get uri to any resource type
* @param context - context
* @param resId - resource id
* @throws Resources.NotFoundException if the given ID does not exist.
* @return - Uri to resource by given id
*/
public static Uri getUriFromResource(@NonNull Context context, @AnyRes int resId) throws Resources.NotFoundException {
/** Return a Resources instance for your application's package. */
Resources res = context.getResources();
/**
* Creates a Uri which parses the given encoded URI string.
* @param uriString an RFC 2396-compliant, encoded URI
* @throws NullPointerException if uriString is null
* @return Uri for this given uri string
*/
/** return uri */
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + res.getResourcePackageName(resId)
+ '/' + res.getResourceTypeName(resId)
+ '/' + res.getResourceEntryName(resId));
}
ComposedResources.java 文件源码
项目:SkinFramework
阅读 36
收藏 0
点赞 0
评论 0
@Override
public void getValue(@AnyRes int id, TypedValue outValue, boolean resolveRefs) throws NotFoundException {
int realId = getCorrespondResId(id);
if (realId > 0) {
mSkinResources.getValue(realId, outValue, resolveRefs);
return;
}
super.getValue(id, outValue, resolveRefs);
}
ComposedResources.java 文件源码
项目:SkinFramework
阅读 47
收藏 0
点赞 0
评论 0
@Override
public void getValueForDensity(@AnyRes int id, int density, TypedValue outValue, boolean resolveRefs) throws NotFoundException {
int realId = getCorrespondResId(id);
if (realId > 0) {
mSkinResources.getValueForDensity(realId, density, outValue, resolveRefs);
return;
}
super.getValueForDensity(id, density, outValue, resolveRefs);
}
ZipAndShareTask.java 文件源码
项目:SciChart.Android.Examples
阅读 32
收藏 0
点赞 0
评论 0
private static String[] getAssetsNamesFromLayoutIds(Context context, String resLayoutAssets, @AnyRes int... ids){
final Resources resources = context.getResources();
final int size = ids.length;
final String[] assetNames = new String[size];
for (int i = 0; i < size; i++) {
final int id = ids[i];
final String resourceEntryName = resources.getResourceEntryName(id);
assetNames[i] = resLayoutAssets + "/" + resourceEntryName + ".xml.txt";
}
return assetNames;
}
SkinCompatResources.java 文件源码
项目:Android-skin-support
阅读 31
收藏 0
点赞 0
评论 0
private void getSkinValue(Context context, @AnyRes int resId, TypedValue outValue, boolean resolveRefs) {
if (!isDefaultSkin) {
int targetResId = getTargetResId(context, resId);
if (targetResId != 0) {
mResources.getValue(targetResId, outValue, resolveRefs);
return;
}
}
context.getResources().getValue(resId, outValue, resolveRefs);
}
NotificationBuilder.java 文件源码
项目:AlexaAndroid
阅读 42
收藏 0
点赞 0
评论 0
/**
* get uri to drawable or any other resource type if u wish
* @param context - context
* @param drawableId - drawable res id
* @return - uri
*/
public static String getUriToDrawable(@NonNull Context context, @AnyRes int drawableId) {
String imageUri = ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + context.getResources().getResourcePackageName(drawableId)
+ '/' + context.getResources().getResourceTypeName(drawableId)
+ '/' + context.getResources().getResourceEntryName(drawableId);
return imageUri;
}
ViewTypes.java 文件源码
项目:Chemistry
阅读 47
收藏 0
点赞 0
评论 0
@ViewType
@AnyRes
public static int generate() {
int result;
for (; ; ) {
result = sNextGeneratedId.get();
// aapt-generated IDs have the high byte nonzero; clamp to the range under that.
final int newValue = (result + 1) & 0x00FFFFFF;
if (sNextGeneratedId.compareAndSet(result, newValue)) {
break;
}
}
return CUSTOM_PACKAGE_NAMESPACE_RES | result;
}
CommonUtils.java 文件源码
项目:android-wheels
阅读 42
收藏 0
点赞 0
评论 0
/**
* Get {@link Uri} representing given resource
*
* @param context Context
* @param resourceId Resource identifier
* @return Resource uri
*/
@NonNull
public static Uri getResourceUri(@NonNull Context context, @AnyRes int resourceId) {
Resources resources = context.getResources();
return Uri
.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(resourceId) +
"/" + resources.getResourceTypeName(resourceId) + "/" +
resources.getResourceEntryName(resourceId));
}
EMResourceUtil.java 文件源码
项目:luxunPro
阅读 38
收藏 0
点赞 0
评论 0
/**
* Resolves the reference to an attribute, returning the root resource id.
*
* @param context The context to use when determining the root id
* @param attr The attribute to resolve
* @return The resource id pointing to the de-referenced attribute
*/
@AnyRes
public static int getResolvedResourceId(Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(attr, typedValue, true);
if (typedValue.type == TypedValue.TYPE_REFERENCE) {
return typedValue.data;
}
return typedValue.resourceId;
}
ExternalResources.java 文件源码
项目:external-resources
阅读 36
收藏 0
点赞 0
评论 0
@Nullable private String getApplicationResourceEntryName(@AnyRes int resId)
throws IllegalStateException {
if (!useApplicationResources) {
throw new IllegalStateException(
"You have set the useApplicationResources to false, using application resource is an error.");
}
return Utils.getAndroidResourceEntryName(context, resId);
}
Utils.java 文件源码
项目:external-resources
阅读 43
收藏 0
点赞 0
评论 0
@Nullable public static String getAndroidResourceEntryName(Context context, @AnyRes int resId) {
try {
return context.getResources().getResourceEntryName(resId);
} catch (android.content.res.Resources.NotFoundException e) {
return null;
}
}
ResourceUtil.java 文件源码
项目:ExoMedia
阅读 38
收藏 0
点赞 0
评论 0
/**
* Resolves the reference to an attribute, returning the root resource id.
*
* @param context The context to use when determining the root id
* @param attr The attribute to resolve
* @return The resource id pointing to the de-referenced attribute
*/
@AnyRes
public static int getResolvedResourceId(Context context, @AttrRes int attr) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(attr, typedValue, true);
if (typedValue.type == TypedValue.TYPE_REFERENCE) {
return typedValue.data;
}
return typedValue.resourceId;
}
Theme.java 文件源码
项目:ThemeEngine
阅读 36
收藏 0
点赞 0
评论 0
@Nullable
public static Res get(Context context, @AnyRes int resId) {
if (resId == 0) {
return null;
}
return new Res(context.getResources().getResourceTypeName(resId), context.getResources().getResourceEntryName(resId));
}
BusRoute.java 文件源码
项目:penn-mobile-android
阅读 38
收藏 0
点赞 0
评论 0
/**
* Provide appropriate colors for each bus route.
* @return Color as an int, output of `Color.rgb`
*/
@AnyRes
public int getColor() {
switch (route_name) {
case "Campus Loop":
return Color.rgb(76, 175, 80);
case "PennBUS West":
return Color.rgb(244, 67, 54);
case "PennBUS East":
return Color.rgb(63, 81, 181);
}
return Color.GRAY;
}
ResourceUtil.java 文件源码
项目:apps-android-wikipedia
阅读 51
收藏 0
点赞 0
评论 0
/**
* Resolves the resource ID of a theme-dependent attribute (for example, a color value
* that changes based on the selected theme)
* @param context The context whose theme contains the attribute.
* @param id Theme-dependent attribute ID to be resolved.
* @return The actual resource ID of the requested theme-dependent attribute.
*/
@AnyRes public static int getThemedAttributeId(@NonNull Context context, @AttrRes int id) {
TypedValue typedValue = getThemedAttribute(context, id);
if (typedValue == null) {
throw new IllegalArgumentException("Attribute not found; ID=" + id);
}
return typedValue.resourceId;
}
ResourceUtil.java 文件源码
项目:apps-android-wikipedia
阅读 45
收藏 0
点赞 0
评论 0
public static Uri uri(@NonNull Context context, @AnyRes int id) throws Resources.NotFoundException {
Resources res = context.getResources();
return new Uri.Builder()
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
.authority(res.getResourcePackageName(id))
.appendPath(res.getResourceTypeName(id))
.appendPath(res.getResourceEntryName(id))
.build();
}
TypedArrayUtils.java 文件源码
项目:letv
阅读 40
收藏 0
点赞 0
评论 0
@AnyRes
public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue));
}
TypedArrayUtils.java 文件源码
项目:boohee_v5.6
阅读 31
收藏 0
点赞 0
评论 0
@AnyRes
public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue));
}
SkinCompatResources.java 文件源码
项目:Android-skin-support
阅读 41
收藏 0
点赞 0
评论 0
public static void getValue(Context context, @AnyRes int resId, TypedValue outValue, boolean resolveRefs) {
getInstance().getSkinValue(context, resId, outValue, resolveRefs);
}
ResUtils.java 文件源码
项目:jigsaw-android
阅读 38
收藏 0
点赞 0
评论 0
public static Uri getUriOfResource(@NonNull Context context, @AnyRes int resId) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + context.getResources().getResourcePackageName(resId)
+ '/' + context.getResources().getResourceTypeName(resId)
+ '/' + context.getResources().getResourceEntryName(resId));
}
BindingViewModel.java 文件源码
项目:Android-Data-Binding-Recycler
阅读 42
收藏 0
点赞 0
评论 0
@AnyRes
int getVariableId();
BasicChemistry.java 文件源码
项目:Chemistry
阅读 37
收藏 0
点赞 0
评论 0
@ViewType
@AnyRes
public abstract int getViewType();
BasicChemistry.java 文件源码
项目:Chemistry
阅读 37
收藏 0
点赞 0
评论 0
public final <RI extends Item> Boiler<RI, VH> wrap(@ViewType @AnyRes int viewType) {
return compose(viewType, this);
}
BasicChemistry.java 文件源码
项目:Chemistry
阅读 35
收藏 0
点赞 0
评论 0
public final Boiler<Item, VH> useViewType(@ViewType @AnyRes int viewType) {
return compose(this).useViewType(viewType);
}
BasicChemistry.java 文件源码
项目:Chemistry
阅读 41
收藏 0
点赞 0
评论 0
public Boiler<Item, VH> useViewType(@ViewType @AnyRes int viewType) {
ViewTypes.validateArgument(viewType);
this.viewType = viewType;
return this;
}
BasicChemistry.java 文件源码
项目:Chemistry
阅读 33
收藏 0
点赞 0
评论 0
public Preperator<Item> useViewType(@ViewType @AnyRes int viewType) {
ViewTypes.validateArgument(viewType);
this.viewType = viewType;
return this;
}
Chemistry.java 文件源码
项目:Chemistry
阅读 39
收藏 0
点赞 0
评论 0
@ViewType
@AnyRes
public abstract int getItemViewType(Item item);
Chemistry.java 文件源码
项目:Chemistry
阅读 35
收藏 0
点赞 0
评论 0
public static <Item> BasicChemistry.Preperator<Item> compose(@ViewType @AnyRes int viewType) {
return new BasicChemistry.Preperator<Item>().useViewType(viewType);
}
Chemistry.java 文件源码
项目:Chemistry
阅读 37
收藏 0
点赞 0
评论 0
public static <Item, VH extends ViewHolder> BasicChemistry.Boiler<Item, VH> compose(@ViewType @AnyRes int viewType, @NonNull BasicChemistry<? super Item, VH> base) {
return new BasicChemistry.Boiler<>(base).useViewType(viewType);
}