类android.support.annotation.AnyRes源码实例Demo

下面列出了怎么用android.support.annotation.AnyRes的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: AndroidBlueprints   文件: ResourcesHelper.java
/**
 * 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;
}
 
源代码2 项目: BehaviorCollect   文件: ViewUtils.java
/**
 * 根据资源id获取资源文件名字 --- 带包名的全路径。
 *
 * @param context 上下文
 * @param resid   资源id
 * @return
 */
public static String getResourceName(@NonNull Context context, @AnyRes int resid) {
    String res = "";
    if (-1 == resid) return res;
    try {
        res = context.getResources().getResourceName(resid);
    } catch (Resources.NotFoundException e) {
        // e.printStackTrace();
        //LogUtils.d("out", "未获取到ResourceName ---id="+resid);
    }
    return res;
}
 
源代码3 项目: BehaviorCollect   文件: ViewUtils.java
/**
 * 根据资源id获取资源文件名字   --- 简单名称。
 *
 * @param context 上下文
 * @param resid   资源id
 * @return
 */
public static String getSimpleResourceName(@NonNull Context context, @AnyRes int resid) {
    String res = "";
    if (-1 == resid) return res;
    try {
        res = context.getResources().getResourceName(resid);
        res = res.substring(res.indexOf("/") + 1);
    } catch (Resources.NotFoundException e) {
        // e.printStackTrace();
        //LogUtils.d("out", "未获取到ResourceName ---id="+resid);
    }
    return res;
}
 
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);
}
 
源代码5 项目: AlexaAndroid   文件: NotificationBuilder.java
/**
 * 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;
}
 
源代码6 项目: external-resources   文件: ExternalResources.java
@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);
}
 
源代码7 项目: external-resources   文件: Utils.java
@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;
  }
}
 
源代码8 项目: ExoMedia   文件: ResourceUtil.java
/**
 * 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;
}
 
源代码9 项目: PowerFileExplorer   文件: ResourcesUtil.java
public static String getResourceEntryName(@AnyRes int anyRes) {
    return Base.getResources().getResourceEntryName(anyRes);
}
 
源代码10 项目: PowerFileExplorer   文件: ResourcesUtil.java
public static String getResourceName(@AnyRes int anyRes) {
    return Base.getResources().getResourceName(anyRes);
}
 
源代码11 项目: PowerFileExplorer   文件: ResourcesUtil.java
public static String getResourcePackageName(@AnyRes int anyRes) {
    return Base.getResources().getResourcePackageName(anyRes);
}
 
源代码12 项目: PowerFileExplorer   文件: ResourcesUtil.java
public static String getResourceTypeName(@AnyRes int anyRes) {
    return Base.getResources().getResourceTypeName(anyRes);
}
 
源代码13 项目: PowerFileExplorer   文件: ResourcesUtil.java
public static void getValue(@AnyRes int anyRes, TypedValue outValue, boolean resolveRefs) {
    Base.getResources().getValue(anyRes, outValue, resolveRefs);
}
 
源代码14 项目: PowerFileExplorer   文件: ResourcesUtil.java
public static void getValueForDensity(@AnyRes int anyRes, int density, TypedValue outValue, boolean resolveRefs) {
    if (APILevel.require(15))
        Base.getResources().getValueForDensity(anyRes, density, outValue, resolveRefs);
    else
        Base.getResources().getValue(anyRes, outValue, resolveRefs);
}
 
源代码15 项目: weMessage   文件: IOUtils.java
public static Uri getUriFromResource(@NonNull Context context, @AnyRes int resId) throws Resources.NotFoundException {
    Resources res = context.getResources();
    Uri resUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + res.getResourcePackageName(resId) + '/' + res.getResourceTypeName(resId) + '/' + res.getResourceEntryName(resId));

    return resUri;
}
 
源代码16 项目: letv   文件: TypedArrayUtils.java
@AnyRes
public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
    return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue));
}
 
源代码17 项目: Android-skin-support   文件: SkinCompatResources.java
public static void getValue(Context context, @AnyRes int resId, TypedValue outValue, boolean resolveRefs) {
    getInstance().getSkinValue(context, resId, outValue, resolveRefs);
}
 
源代码18 项目: Graywater   文件: GraywaterAdapter.java
/**
 * @param model
 * 		the model that will be bound.
 * @return the type of the viewholder.
 */
@AnyRes
int getViewType(U model);
 
 类方法
 同包方法