use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.
the class ApduServiceInfo method loadBanner.
public Drawable loadBanner(PackageManager pm) {
Resources res;
try {
res = pm.getResourcesForApplication(mService.serviceInfo.packageName);
Drawable banner = res.getDrawable(mBannerResourceId);
return banner;
} catch (NotFoundException e) {
Log.e(TAG, "Could not load banner.");
return null;
} catch (NameNotFoundException e) {
Log.e(TAG, "Could not load banner.");
return null;
}
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.
the class ResourcesImpl method loadXmlResourceParser.
/**
* Loads an XML parser for the specified file.
*
* @param file the path for the XML file to parse
* @param id the resource identifier for the file
* @param assetCookie the asset cookie for the file
* @param type the type of resource (used for logging)
* @return a parser for the specified XML file
* @throws NotFoundException if the file could not be loaded
*/
@NonNull
XmlResourceParser loadXmlResourceParser(@NonNull String file, @AnyRes int id, int assetCookie, @NonNull String type) throws NotFoundException {
if (id != 0) {
try {
synchronized (mCachedXmlBlocks) {
final int[] cachedXmlBlockCookies = mCachedXmlBlockCookies;
final String[] cachedXmlBlockFiles = mCachedXmlBlockFiles;
final XmlBlock[] cachedXmlBlocks = mCachedXmlBlocks;
// First see if this block is in our cache.
final int num = cachedXmlBlockFiles.length;
for (int i = 0; i < num; i++) {
if (cachedXmlBlockCookies[i] == assetCookie && cachedXmlBlockFiles[i] != null && cachedXmlBlockFiles[i].equals(file)) {
return cachedXmlBlocks[i].newParser();
}
}
// Not in the cache, create a new block and put it at
// the next slot in the cache.
final XmlBlock block = mAssets.openXmlBlockAsset(assetCookie, file);
if (block != null) {
final int pos = (mLastCachedXmlBlockIndex + 1) % num;
mLastCachedXmlBlockIndex = pos;
final XmlBlock oldBlock = cachedXmlBlocks[pos];
if (oldBlock != null) {
oldBlock.close();
}
cachedXmlBlockCookies[pos] = assetCookie;
cachedXmlBlockFiles[pos] = file;
cachedXmlBlocks[pos] = block;
return block.newParser();
}
}
} catch (Exception e) {
final NotFoundException rnf = new NotFoundException("File " + file + " from xml type " + type + " resource ID #0x" + Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
}
throw new NotFoundException("File " + file + " from xml type " + type + " resource ID #0x" + Integer.toHexString(id));
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.
the class ResourcesImpl method getQuantityText.
@NonNull
CharSequence getQuantityText(@PluralsRes int id, int quantity) throws NotFoundException {
PluralRules rule = getPluralRule();
CharSequence res = mAssets.getResourceBagText(id, attrForQuantityCode(rule.select(quantity)));
if (res != null) {
return res;
}
res = mAssets.getResourceBagText(id, ID_OTHER);
if (res != null) {
return res;
}
throw new NotFoundException("Plural resource ID #0x" + Integer.toHexString(id) + " quantity=" + quantity + " item=" + rule.select(quantity));
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_base by AOSPA.
the class ResourcesImpl method loadComplexColorForCookie.
/**
* Load a ComplexColor based on the XML file content. The result can be a GradientColor or
* ColorStateList. Note that pure color will be wrapped into a ColorStateList.
*
* We deferred the parser creation to this function b/c we need to differentiate b/t gradient
* and selector tag.
*
* @return a ComplexColor (GradientColor or ColorStateList) based on the XML file content.
*/
@Nullable
private ComplexColor loadComplexColorForCookie(Resources wrapper, TypedValue value, int id, Resources.Theme theme) {
if (value.string == null) {
throw new UnsupportedOperationException("Can't convert to ComplexColor: type=0x" + value.type);
}
final String file = value.string.toString();
if (TRACE_FOR_MISS_PRELOAD) {
// Log only framework resources
if ((id >>> 24) == 0x1) {
final String name = getResourceName(id);
if (name != null) {
Log.d(TAG, "Loading framework ComplexColor #" + Integer.toHexString(id) + ": " + name + " at " + file);
}
}
}
if (DEBUG_LOAD) {
Log.v(TAG, "Loading ComplexColor for cookie " + value.assetCookie + ": " + file);
}
ComplexColor complexColor = null;
Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, file);
if (file.endsWith(".xml")) {
try {
final XmlResourceParser parser = loadXmlResourceParser(file, id, value.assetCookie, "ComplexColor");
final AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Seek parser to start tag.
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
final String name = parser.getName();
if (name.equals("gradient")) {
complexColor = GradientColor.createFromXmlInner(wrapper, parser, attrs, theme);
} else if (name.equals("selector")) {
complexColor = ColorStateList.createFromXmlInner(wrapper, parser, attrs, theme);
}
parser.close();
} catch (Exception e) {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
final NotFoundException rnf = new NotFoundException("File " + file + " from ComplexColor resource ID #0x" + Integer.toHexString(id));
rnf.initCause(e);
throw rnf;
}
} else {
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
throw new NotFoundException("File " + file + " from drawable resource ID #0x" + Integer.toHexString(id) + ": .xml extension required");
}
Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
return complexColor;
}
use of android.content.res.Resources.NotFoundException in project todo-mvp-rxjava by albertizzy.
the class NavigationViewActions method navigateTo.
/**
* Returns a {@link ViewAction} that navigates to a menu item in {@link NavigationView} using a
* menu item resource id.
*
* <p>
* View constraints:
* <ul>
* <li>View must be a child of a {@link DrawerLayout}
* <li>View must be of type {@link NavigationView}
* <li>View must be visible on screen
* <li>View must be displayed on screen
* <ul>
*
* @param menuItemId the resource id of the menu item
* @return a {@link ViewAction} that navigates on a menu item
*/
public static ViewAction navigateTo(final int menuItemId) {
return new ViewAction() {
@Override
public void perform(UiController uiController, View view) {
NavigationView navigationView = (NavigationView) view;
Menu menu = navigationView.getMenu();
if (null == menu.findItem(menuItemId)) {
throw new PerformException.Builder().withActionDescription(this.getDescription()).withViewDescription(HumanReadables.describe(view)).withCause(new RuntimeException(getErrorMessage(menu, view))).build();
}
menu.performIdentifierAction(menuItemId, 0);
uiController.loopMainThreadUntilIdle();
}
private String getErrorMessage(Menu menu, View view) {
String NEW_LINE = System.getProperty("line.separator");
StringBuilder errorMessage = new StringBuilder("Menu item was not found, " + "available menu items:").append(NEW_LINE);
for (int position = 0; position < menu.size(); position++) {
errorMessage.append("[MenuItem] position=").append(position);
MenuItem menuItem = menu.getItem(position);
if (menuItem != null) {
CharSequence itemTitle = menuItem.getTitle();
if (itemTitle != null) {
errorMessage.append(", title=").append(itemTitle);
}
if (view.getResources() != null) {
int itemId = menuItem.getItemId();
try {
errorMessage.append(", id=");
String menuItemResourceName = view.getResources().getResourceName(itemId);
errorMessage.append(menuItemResourceName);
} catch (NotFoundException nfe) {
errorMessage.append("not found");
}
}
errorMessage.append(NEW_LINE);
}
}
return errorMessage.toString();
}
@Override
public String getDescription() {
return "click on menu item with id";
}
@Override
public Matcher<View> getConstraints() {
return allOf(isAssignableFrom(NavigationView.class), withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), isDisplayingAtLeast(90));
}
};
}
Aggregations