/** * 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; }
/** * 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)); }
@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); }
@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); }
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; }
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); }
/** * 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; }
@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; }
/** * 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)); }
/** * 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; }
@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); }
@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; } }
@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)); }
/** * 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; }
/** * 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; }
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(); }
@AnyRes public static int getResourceId(TypedArray a, @StyleableRes int index, @StyleableRes int fallbackIndex, @AnyRes int defaultValue) { return a.getResourceId(index, a.getResourceId(fallbackIndex, defaultValue)); }
public static void getValue(Context context, @AnyRes int resId, TypedValue outValue, boolean resolveRefs) { getInstance().getSkinValue(context, resId, outValue, resolveRefs); }
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)); }
@AnyRes int getVariableId();
@ViewType @AnyRes public abstract int getViewType();
public final <RI extends Item> Boiler<RI, VH> wrap(@ViewType @AnyRes int viewType) { return compose(viewType, this); }
public final Boiler<Item, VH> useViewType(@ViewType @AnyRes int viewType) { return compose(this).useViewType(viewType); }
public Boiler<Item, VH> useViewType(@ViewType @AnyRes int viewType) { ViewTypes.validateArgument(viewType); this.viewType = viewType; return this; }
public Preperator<Item> useViewType(@ViewType @AnyRes int viewType) { ViewTypes.validateArgument(viewType); this.viewType = viewType; return this; }
@ViewType @AnyRes public abstract int getItemViewType(Item item);
public static <Item> BasicChemistry.Preperator<Item> compose(@ViewType @AnyRes int viewType) { return new BasicChemistry.Preperator<Item>().useViewType(viewType); }
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); }
@ViewType @AnyRes int getItemViewType(Item item);
@SuppressWarnings("Range") @ViewType @AnyRes private static int invalid() { return RecyclerView.INVALID_TYPE; }
public static String getResourceEntryName(@AnyRes int anyRes) { return ContextUtil.getResources().getResourceEntryName(anyRes); }
public static String getResourceName(@AnyRes int anyRes) { return ContextUtil.getResources().getResourceName(anyRes); }
public static String getResourcePackageName(@AnyRes int anyRes) { return ContextUtil.getResources().getResourcePackageName(anyRes); }
public static String getResourceTypeName(@AnyRes int anyRes) { return ContextUtil.getResources().getResourceTypeName(anyRes); }
public static void getValue(@AnyRes int anyRes, TypedValue outValue, boolean resolveRefs) { ContextUtil.getResources().getValue(anyRes, outValue, resolveRefs); }
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); }
/** * Gets id from theme apk */ @AnyRes public static int getId(Context context, String type, String name) { return getResources(context).getIdentifier(name, type, getPackageName()); }
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); }