@Nonnull private ResName getResName(int id) { ResName resName = resourceTable.getResName(id); if (resName == null) { throw new Resources.NotFoundException("Resource ID #0x" + Integer.toHexString(id)); } return resName; }
@UiThread // Implicit synchronization for use of shared resource VALUE. public static float getFloat(Context context, @DimenRes int id) { TypedValue value = VALUE; context.getResources().getValue(id, value, true); if (value.type == TypedValue.TYPE_FLOAT) { return value.getFloat(); } throw new Resources.NotFoundException("Resource ID #0x" + Integer.toHexString(id) + " type #0x" + Integer.toHexString(value.type) + " is not valid"); }
private static Drawable loadDrawableForCookie(TypedValue value, int id, Resources res, Resources.Theme theme) { if (value.string == null) { throw new Resources.NotFoundException("Resource \"" + res.getResourceName(id) + "\" (" + Integer.toHexString(id) + ") is not a Drawable (color or path): " + value); } String file = value.string.toString(); final Drawable dr; if (file.endsWith(".xml")) { try { XmlResourceParser rp = res.getAssets().openXmlResourceParser(value.assetCookie, file); dr = LollipopDrawablesCompat.createFromXml(res, rp, theme); rp.close(); } catch (Exception e) { Log.w(LollipopDrawablesCompat.class.getSimpleName(), "Failed to load drawable resource, " + "using a fallback...", e); return res.getDrawable(value.resourceId); } } else { try { InputStream is = res.getAssets().openNonAssetFd(value.assetCookie, file).createInputStream(); dr = LollipopDrawablesCompat.createFromResourceStream(res, value, is, file, null); is.close(); } catch (Exception e) { Log.w(LollipopDrawablesCompat.class.getSimpleName(), "Failed to load drawable resource, " + "using a fallback...", e); return res.getDrawable(value.resourceId); } } return dr; }
private Drawable loadDrawableForCookie(TypedValue value, int id, Resources.Theme theme) { if (value.string == null) throw new Resources.NotFoundException("Resource \"" + getResourceName(id) + "\" (" + Integer.toHexString(id) + ") is not a Drawable (color or path): " + value);
/** * Loads an {@link Animator} object from a resource * * @param context Application context used to access resources * @param id The resource id of the animation to load * @return The animator object reference by the specified id * @throws android.content.res.Resources.NotFoundException when the animation cannot be loaded */ public static Animator loadAnimator(Context context, int id) throws NotFoundException { XmlResourceParser parser = null; try { parser = context.getResources().getAnimation(id); return createAnimatorFromXml(context, parser); } catch (XmlPullParserException ex) { Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } catch (IOException ex) { Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id)); rnf.initCause(ex); throw rnf; } finally { if (parser != null) parser.close(); } }
/** * 添加一个导航按钮 * * @param drawableRes 图标资源 * @param checkedDrawableRes 选中时的图标资源 * @param title 显示文字内容.尽量简短 * @param chekedColor 选中的颜色 * @return {@link MaterialBuilder} * @throws Resources.NotFoundException drawable 资源获取异常 */ public MaterialBuilder addItem(@DrawableRes int drawableRes, @DrawableRes int checkedDrawableRes, @NonNull String title, @ColorInt int chekedColor) { Drawable defaultDrawable = ContextCompat.getDrawable(getContext(), drawableRes); Drawable checkDrawable = ContextCompat.getDrawable(getContext(), checkedDrawableRes); if (defaultDrawable == null) { throw new Resources.NotFoundException("Resource ID " + Integer.toHexString(drawableRes)); } if (checkDrawable == null) { throw new Resources.NotFoundException("Resource ID " + Integer.toHexString(checkedDrawableRes)); } addItem(defaultDrawable, checkDrawable, title, chekedColor); return MaterialBuilder.this; }
protected void addView(T resolverOld, T resolverNew, boolean after) throws Resources.NotFoundException { int position = -1; for (ViewBinder viewBinder : mViewBinderList) { if (viewBinder.getResolver() == resolverOld) { position = mViewBinderList.indexOf(viewBinder); break; } } if (position != -1) { if (after) position++; mViewBinderList.add(position, Binding.bindViewResolver(resolverNew)); notifyItemInserted(position); } else { throw new Resources.NotFoundException("Old view don't Exists in the list"); } }
protected void toggle(int position, boolean isToExpand) throws Resources.NotFoundException { ExpandableViewBinder<Object, View> binder = ((ExpandableViewAdapter<Object>) getViewAdapter()) .getParentBinderAtPosition(position); if (binder == null) { throw new Resources.NotFoundException( "Parent view don't exists in the ExpandablePlaceHolderView"); } if (isToExpand) { binder.expand(); } else { binder.collapse(); } } }
private int getResourceId(String possiblyQualifiedResourceName, String defaultPackageName, String defaultType) { if (AttributeResource.isNull(possiblyQualifiedResourceName)) return 0; if (AttributeResource.isStyleReference(possiblyQualifiedResourceName)) { ResName styleReference = AttributeResource.getStyleReference(possiblyQualifiedResourceName, defaultPackageName, "attr"); Integer resourceId = resourceTable.getResourceId(styleReference); if (resourceId == null) { throw new Resources.NotFoundException(styleReference.getFullyQualifiedName()); } return resourceId; } if (AttributeResource.isResourceReference(possiblyQualifiedResourceName)) { ResName resourceReference = AttributeResource.getResourceReference(possiblyQualifiedResourceName, defaultPackageName, defaultType); Integer resourceId = resourceTable.getResourceId(resourceReference); if (resourceId == null) { throw new Resources.NotFoundException(resourceReference.getFullyQualifiedName()); } return resourceId; } possiblyQualifiedResourceName = removeLeadingSpecialCharsIfAny(possiblyQualifiedResourceName); ResName resName = ResName.qualifyResName(possiblyQualifiedResourceName, defaultPackageName, defaultType); Integer resourceId = resourceTable.getResourceId(resName); return resourceId == null ? 0 : resourceId; }
protected <T> void toggle(T resolver, boolean isToExpand) throws Resources.NotFoundException { ExpandableViewBinder<T, View> binder = ((ExpandableViewAdapter<T>) getViewAdapter()) .getBinderForResolver(resolver); if (resolver == null) { throw new Resources.NotFoundException( "Parent view don't exists in the ExpandablePlaceHolderView"); } if (isToExpand) { binder.expand(); } else { binder.collapse(); } }
public static int getPreferencePosition(PreferenceGroupAdapter adapter, Class<? extends Preference> clazz) { for (int i = 0; i < adapter.getItemCount(); i++) { if (clazz.isInstance(adapter.getItem(i))) { return i; } } throw new Resources.NotFoundException(); } }
private void injectResourceStuffForLegacy(ApkLoader apkLoader, AndroidManifest appManifest, SdkEnvironment sdkEnvironment) { PackageResourceTable systemResourceTable = apkLoader.getSystemResourceTable(sdkEnvironment); PackageResourceTable appResourceTable = apkLoader.getAppResourceTable(appManifest); RoutingResourceTable combinedAppResourceTable = new RoutingResourceTable(appResourceTable, systemResourceTable); PackageResourceTable compileTimeSdkResourceTable = apkLoader.getCompileTimeSdkResourceTable(); ResourceTable combinedCompileTimeResourceTable = new RoutingResourceTable(appResourceTable, compileTimeSdkResourceTable); RuntimeEnvironment.setCompileTimeResourceTable(combinedCompileTimeResourceTable); RuntimeEnvironment.setAppResourceTable(combinedAppResourceTable); RuntimeEnvironment.setSystemResourceTable(new RoutingResourceTable(systemResourceTable)); try { appManifest.initMetaData(combinedAppResourceTable); } catch (RoboNotFoundException e1) { throw new Resources.NotFoundException(e1.getMessage()); } }
protected int findValueFor(String key) { key = (key == null) ? null : key.trim(); String valueFor = attrData.getValueFor(key); if (valueFor == null) { // Maybe they have passed in the value directly, rather than the name. if (attrData.isValue(key)) { valueFor = key; } else { throw new Resources.NotFoundException("no value found for " + key); } } return Util.parseInt(valueFor); } }
protected XmlResourceParser loadXmlResourceParser(int resId, String type) throws Resources.NotFoundException { ResName resName = getResName(resId); ResName resolvedResName = resolveResName(resName, config); if (resolvedResName == null) { throw new RuntimeException("couldn't resolve " + resName.getFullyQualifiedName()); } resName = resolvedResName; XmlBlock block = resourceTable.getXml(resName, config); if (block == null) { throw new Resources.NotFoundException(resName.getFullyQualifiedName()); } ResourceTable resourceProvider = ResourceIds.isFrameworkResource(resId) ? RuntimeEnvironment.getSystemResourceTable() : RuntimeEnvironment.getCompileTimeResourceTable(); return getXmlResourceParser(resourceProvider, block, resName.packageName); }
public Resources getResources(String pkg) throws Resources.NotFoundException { InstalledAppInfo installedAppInfo = getInstalledAppInfo(pkg, 0); if (installedAppInfo != null) { AssetManager assets = mirror.android.content.res.AssetManager.ctor.newInstance(); mirror.android.content.res.AssetManager.addAssetPath.call(assets, installedAppInfo.apkPath); Resources hostRes = context.getResources(); return new Resources(assets, hostRes.getDisplayMetrics(), hostRes.getConfiguration()); } throw new Resources.NotFoundException(pkg); }
@Implementation protected final XmlResourceParser openXmlResourceParser(int cookie, String fileName) throws IOException { XmlBlock xmlBlock = XmlBlock.create(Fs.fromUrl(fileName), resourceTable.getPackageName()); if (xmlBlock == null) { throw new Resources.NotFoundException(fileName); } return getXmlResourceParser(resourceTable, xmlBlock, resourceTable.getPackageName()); }
private Resources.NotFoundException newNotFoundException(int id) { ResourceTable resourceTable = legacyShadowOf(realResourcesImpl.getAssets()).getResourceTable(); ResName resName = resourceTable.getResName(id); if (resName == null) { return new Resources.NotFoundException("resource ID #0x" + Integer.toHexString(id)); } else { return new Resources.NotFoundException(resName.getFullyQualifiedName()); } }
private Resources.NotFoundException newNotFoundException(int id) { ResourceTable resourceTable = legacyShadowOf(realResources.getAssets()).getResourceTable(); ResName resName = resourceTable.getResName(id); if (resName == null) { return new Resources.NotFoundException("resource ID #0x" + Integer.toHexString(id)); } else { return new Resources.NotFoundException(resName.getFullyQualifiedName()); } }
private Resources.NotFoundException newNotFoundException(int id) { ResourceTable resourceTable = legacyShadowOf(realResourcesImpl.getAssets()).getResourceTable(); ResName resName = resourceTable.getResName(id); if (resName == null) { return new Resources.NotFoundException("resource ID #0x" + Integer.toHexString(id)); } else { return new Resources.NotFoundException(resName.getFullyQualifiedName()); } }
@UiThread // Implicit synchronization for use of shared resource VALUE. public static Drawable getTintedDrawable(Context context, @DrawableRes int id, @AttrRes int tintAttrId) { boolean attributeFound = context.getTheme().resolveAttribute(tintAttrId, VALUE, true); if (!attributeFound) { throw new Resources.NotFoundException("Required tint color attribute with name " + context.getResources().getResourceEntryName(tintAttrId) + " and attribute ID " + tintAttrId + " was not found."); } Drawable drawable = ContextCompat.getDrawable(context, id); drawable = DrawableCompat.wrap(drawable.mutate()); int color = ContextCompat.getColor(context, VALUE.resourceId); DrawableCompat.setTint(drawable, color); return drawable; }