Java Code Examples for android.support.annotation.AnyRes

The following are top voted examples for showing how to use android.support.annotation.AnyRes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: AndroidBlueprints   File: ResourcesHelper.java   View source code 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
Project: android-52Kit   File: Utils.java   View source code 6 votes vote down vote up
/**
 * 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));
}
 
Example 3
Project: SkinFramework   File: ComposedResources.java   View source code 5 votes vote down vote up
@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);
}
 
Example 4
Project: SkinFramework   File: ComposedResources.java   View source code 5 votes vote down vote up
@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);
}
 
Example 5
Project: SciChart.Android.Examples   File: ZipAndShareTask.java   View source code 5 votes vote down vote up
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;
}
 
Example 6
Project: Android-skin-support   File: SkinCompatResources.java   View source code 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 7
Project: AlexaAndroid   File: NotificationBuilder.java   View source code 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 8
Project: Chemistry   File: ViewTypes.java   View source code 5 votes vote down vote up
@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;
}
 
Example 9
Project: android-wheels   File: CommonUtils.java   View source code 5 votes vote down vote up
/**
 * 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));
}
 
Example 10
Project: luxunPro   File: EMResourceUtil.java   View source code 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 11
Project: external-resources   File: ExternalResources.java   View source code 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 12
Project: external-resources   File: Utils.java   View source code 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 13
Project: ExoMedia   File: ResourceUtil.java   View source code 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 14
Project: ThemeEngine   File: Theme.java   View source code 5 votes vote down vote up
@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));
}
 
Example 15
Project: penn-mobile-android   File: BusRoute.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 16
Project: apps-android-wikipedia   File: ResourceUtil.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 17
Project: apps-android-wikipedia   File: ResourceUtil.java   View source code 5 votes vote down vote up
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();
}
 
Example 18
Project: letv   File: TypedArrayUtils.java   View source code 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 19
Project: boohee_v5.6   File: TypedArrayUtils.java   View source code 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 20
Project: Android-skin-support   File: SkinCompatResources.java   View source code 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 21
Project: jigsaw-android   File: ResUtils.java   View source code 4 votes vote down vote up
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));
}
 
Example 22
Project: Android-Data-Binding-Recycler   File: BindingViewModel.java   View source code 4 votes vote down vote up
@AnyRes
int getVariableId();
 
Example 23
Project: Chemistry   File: BasicChemistry.java   View source code 4 votes vote down vote up
@ViewType
@AnyRes
public abstract int getViewType();
 
Example 24
Project: Chemistry   File: BasicChemistry.java   View source code 4 votes vote down vote up
public final <RI extends Item> Boiler<RI, VH> wrap(@ViewType @AnyRes int viewType) {
	return compose(viewType, this);
}
 
Example 25
Project: Chemistry   File: BasicChemistry.java   View source code 4 votes vote down vote up
public final Boiler<Item, VH> useViewType(@ViewType @AnyRes int viewType) {
	return compose(this).useViewType(viewType);
}
 
Example 26
Project: Chemistry   File: BasicChemistry.java   View source code 4 votes vote down vote up
public Boiler<Item, VH> useViewType(@ViewType @AnyRes int viewType) {
	ViewTypes.validateArgument(viewType);
	this.viewType = viewType;
	return this;
}
 
Example 27
Project: Chemistry   File: BasicChemistry.java   View source code 4 votes vote down vote up
public Preperator<Item> useViewType(@ViewType @AnyRes int viewType) {
	ViewTypes.validateArgument(viewType);
	this.viewType = viewType;
	return this;
}
 
Example 28
Project: Chemistry   File: Chemistry.java   View source code 4 votes vote down vote up
@ViewType
@AnyRes
public abstract int getItemViewType(Item item);
 
Example 29
Project: Chemistry   File: Chemistry.java   View source code 4 votes vote down vote up
public static <Item> BasicChemistry.Preperator<Item> compose(@ViewType @AnyRes int viewType) {
	return new BasicChemistry.Preperator<Item>().useViewType(viewType);
}
 
Example 30
Project: Chemistry   File: Chemistry.java   View source code 4 votes vote down vote up
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);
}
 
Example 31
Project: Chemistry   File: TypeSelector.java   View source code 4 votes vote down vote up
@ViewType
@AnyRes
int getItemViewType(Item item);
 
Example 32
Project: Chemistry   File: ViewTypes.java   View source code 4 votes vote down vote up
@SuppressWarnings("Range")
@ViewType
@AnyRes
private static int invalid() {
	return RecyclerView.INVALID_TYPE;
}
 
Example 33
Project: Android-App-Template   File: ResourcesUtil.java   View source code 4 votes vote down vote up
public static String getResourceEntryName(@AnyRes int anyRes) {
    return ContextUtil.getResources().getResourceEntryName(anyRes);
}
 
Example 34
Project: Android-App-Template   File: ResourcesUtil.java   View source code 4 votes vote down vote up
public static String getResourceName(@AnyRes int anyRes) {
    return ContextUtil.getResources().getResourceName(anyRes);
}
 
Example 35
Project: Android-App-Template   File: ResourcesUtil.java   View source code 4 votes vote down vote up
public static String getResourcePackageName(@AnyRes int anyRes) {
    return ContextUtil.getResources().getResourcePackageName(anyRes);
}
 
Example 36
Project: Android-App-Template   File: ResourcesUtil.java   View source code 4 votes vote down vote up
public static String getResourceTypeName(@AnyRes int anyRes) {
    return ContextUtil.getResources().getResourceTypeName(anyRes);
}
 
Example 37
Project: Android-App-Template   File: ResourcesUtil.java   View source code 4 votes vote down vote up
public static void getValue(@AnyRes int anyRes, TypedValue outValue, boolean resolveRefs) {
    ContextUtil.getResources().getValue(anyRes, outValue, resolveRefs);
}
 
Example 38
Project: Android-App-Template   File: ResourcesUtil.java   View source code 4 votes vote down vote up
public static void getValueForDensity(@AnyRes int anyRes, int density, TypedValue outValue, boolean resolveRefs) {
    if (APILevel.require(15))
        ContextUtil.getResources().getValueForDensity(anyRes, density, outValue, resolveRefs);
    else
        ContextUtil.getResources().getValue(anyRes, outValue, resolveRefs);
}
 
Example 39
Project: ThemeEngine   File: Theme.java   View source code 4 votes vote down vote up
/**
 * Gets id from theme apk
 */
@AnyRes
public static int getId(Context context, String type, String name) {
    return getResources(context).getIdentifier(name, type, getPackageName());
}
 
Example 40
Project: penn-mobile-android   File: MainActivity.java   View source code 4 votes vote down vote up
private void navigateLayout(@AnyRes int id) {
        Fragment fragment = null;
        switch (id) {
            case R.id.nav_home:
                if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
                    fragment = new MainFragment();
                }
                break;
            case R.id.nav_registrar:
            case R.id.registrar_cont:
                fragment = new RegistrarFragment();
                break;
            case R.id.nav_directory:
                fragment = new DirectoryFragment();
                break;
            case R.id.nav_gsr:
            case R.id.gsr_cont:
                fragment = new GsrFragment();
                break;
            case R.id.nav_dining:
            case R.id.dining_cont:
                fragment = new DiningFragment();
                break;
            case R.id.nav_news:
            case R.id.news_cont:
                fragment = new NewsFragment();
                break;
            case R.id.nav_map:
            case R.id.map_cont:
                getPermission();
                return;
            case R.id.nav_laundry:
            case R.id.laundry_cont:

                /*
                fragment = new LaundryFragment();
                if (from_alarm) {
                    from_alarm = false;
                    Bundle arg = new Bundle();
                    arg.putInt(getString(R.string.laundry_hall_no), getIntent().getIntExtra(getString(R.string.laundry_hall_no), -1));
                    fragment.setArguments(arg);
                }
                */

                Intent intent = new Intent(this, LaundryActivity.class);
                startActivity(intent);

                break;
//            case R.id.nav_nso:
//            case R.id.nso_cont:
//                fragment = new NsoFragment();
//                break;
            case R.id.nav_support:
                fragment = new SupportFragment();
                break;
            case R.id.nav_about:
                fragment = new AboutFragment();
                break;
            case R.id.nav_pref:
                fragment = new PreferenceFragment();
                break;
        }

        fragmentTransact(fragment);
    }