android.support.annotation.AnyRes Java Examples

The following examples show how to use android.support.annotation.AnyRes. 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: AndroidBlueprints   Author: davideas   File: ResourcesHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source Project: BehaviorCollect   Author: hellozhixue   File: ViewUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 根据资源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;
}
 
Example #3
Source Project: BehaviorCollect   Author: hellozhixue   File: ViewUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 根据资源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;
}
 
Example #4
Source Project: Android-skin-support   Author: ximsfei   File: SkinCompatResources.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example #5
Source Project: AlexaAndroid   Author: willblaschko   File: NotificationBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source Project: external-resources   Author: prcaen   File: ExternalResources.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #7
Source Project: external-resources   Author: prcaen   File: Utils.java    License: Apache License 2.0 5 votes vote down vote up
@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;
  }
}
 
Example #8
Source Project: ExoMedia   Author: brianwernick   File: ResourceUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #9
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String getResourceEntryName(@AnyRes int anyRes) {
    return Base.getResources().getResourceEntryName(anyRes);
}
 
Example #10
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String getResourceName(@AnyRes int anyRes) {
    return Base.getResources().getResourceName(anyRes);
}
 
Example #11
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String getResourcePackageName(@AnyRes int anyRes) {
    return Base.getResources().getResourcePackageName(anyRes);
}
 
Example #12
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static String getResourceTypeName(@AnyRes int anyRes) {
    return Base.getResources().getResourceTypeName(anyRes);
}
 
Example #13
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
public static void getValue(@AnyRes int anyRes, TypedValue outValue, boolean resolveRefs) {
    Base.getResources().getValue(anyRes, outValue, resolveRefs);
}
 
Example #14
Source Project: PowerFileExplorer   Author: PowerExplorer   File: ResourcesUtil.java    License: GNU General Public License v3.0 4 votes vote down vote up
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);
}
 
Example #15
Source Project: weMessage   Author: RomanScott   File: IOUtils.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
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;
}
 
Example #16
Source Project: letv   Author: JackChan1999   File: TypedArrayUtils.java    License: Apache License 2.0 4 votes vote down vote up
@AnyRes
public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) {
    return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue));
}
 
Example #17
Source Project: Android-skin-support   Author: ximsfei   File: SkinCompatResources.java    License: MIT License 4 votes vote down vote up
public static void getValue(Context context, @AnyRes int resId, TypedValue outValue, boolean resolveRefs) {
    getInstance().getSkinValue(context, resId, outValue, resolveRefs);
}
 
Example #18
Source Project: Graywater   Author: tumblr   File: GraywaterAdapter.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @param model
 * 		the model that will be bound.
 * @return the type of the viewholder.
 */
@AnyRes
int getViewType(U model);