use of android.content.res.Resources.NotFoundException in project devbricks by dailystudio.
the class AndroidObject method getFullResIcon.
public Drawable getFullResIcon(Resources resources, int iconId) {
if (resources == null || iconId <= 0) {
return null;
}
if (Build.VERSION.SDK_INT < 11) {
// Android v3.0+
return null;
}
Object object = null;
try {
Method method = Resources.class.getMethod("getDrawableForDensity", int.class, int.class);
object = method.invoke(resources, iconId, mIconDpi);
} catch (Exception e) {
Logger.warn("getDrawableForDensity() failure: %s [resId: %d]", e.toString(), iconId);
object = null;
}
if (object == null) {
try {
object = resources.getDrawable(iconId);
} catch (NotFoundException e) {
Logger.warn("getDrawable() failure: %s [resId: %d]", e.toString(), iconId);
object = null;
}
}
if (object instanceof Drawable == false) {
return resources.getDrawable(iconId);
}
return ((Drawable) object);
}
use of android.content.res.Resources.NotFoundException in project android_frameworks_opt_telephony by LineageOS.
the class ValueParser method retrieveAlphaId.
/**
* Retrieves alpha identifier from an Alpha Identifier COMPREHENSION-TLV
* object.
*
* @param ctlv An Alpha Identifier COMPREHENSION-TLV object
* @return String corresponding to the alpha identifier
* @throws ResultException
*/
static String retrieveAlphaId(ComprehensionTlv ctlv) throws ResultException {
if (ctlv != null) {
byte[] rawValue = ctlv.getRawValue();
int valueIndex = ctlv.getValueIndex();
int length = ctlv.getLength();
if (length != 0) {
try {
return IccUtils.adnStringFieldToString(rawValue, valueIndex, length);
} catch (IndexOutOfBoundsException e) {
throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD);
}
} else {
CatLog.d("ValueParser", "Alpha Id length=" + length);
return null;
}
} else {
/* Per 3GPP specification 102.223,
* if the alpha identifier is not provided by the UICC,
* the terminal MAY give information to the user
* noAlphaUsrCnf defines if you need to show user confirmation or not
*/
boolean noAlphaUsrCnf = false;
Resources resource = Resources.getSystem();
try {
noAlphaUsrCnf = resource.getBoolean(com.android.internal.R.bool.config_stkNoAlphaUsrCnf);
} catch (NotFoundException e) {
noAlphaUsrCnf = false;
}
return (noAlphaUsrCnf ? null : CatService.STK_DEFAULT);
}
}
use of android.content.res.Resources.NotFoundException in project braintree_android by braintree.
the class CardBuilderUnitTest method buildGraphQL_throwsAnExceptionWhenTheQueryCannotBeRead.
@Test
public void buildGraphQL_throwsAnExceptionWhenTheQueryCannotBeRead() throws InvalidArgumentException {
Resources resources = mock(Resources.class);
doThrow(new NotFoundException("Not found")).when(resources).openRawResource(anyInt());
Context context = mock(Context.class);
when(context.getResources()).thenReturn(resources);
try {
new CardBuilder().buildGraphQL(context, Authorization.fromString(TOKENIZATION_KEY));
fail("Expected exception");
} catch (BraintreeException e) {
assertEquals("Unable to read GraphQL query", e.getMessage());
assertEquals("Not found", e.getCause().getMessage());
}
}
use of android.content.res.Resources.NotFoundException in project RobotoViews by eeVoskos.
the class Roboto method getFontFromRes.
private Typeface getFontFromRes(int resource) {
Typeface tf = null;
InputStream is;
try {
is = mContext.getResources().openRawResource(resource);
} catch (NotFoundException e) {
if (DEBUG) {
e.printStackTrace();
}
return Typeface.DEFAULT;
}
String outPath = mContext.getCacheDir() + "/tmp.raw";
try {
byte[] buffer = new byte[is.available()];
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outPath));
int l = 0;
while ((l = is.read(buffer)) > 0) bos.write(buffer, 0, l);
bos.close();
tf = Typeface.createFromFile(outPath);
// clean up
new File(outPath).delete();
} catch (IOException e) {
if (DEBUG) {
e.printStackTrace();
}
// Fallback to default font
return Typeface.DEFAULT;
}
return tf;
}
use of android.content.res.Resources.NotFoundException in project Carbon by ZieIony.
the class ResourcesCompat method loadFont.
/**
* Load the given font. This method will always return null for asynchronous requests, which
* provide a fontCallback, as there is no immediate result. When the callback is not provided,
* the request is treated as synchronous and fails if async loading is required.
*/
private static Typeface loadFont(@NonNull Context context, Resources wrapper, TypedValue value, int id, int style, int weight, @Nullable androidx.core.content.res.ResourcesCompat.FontCallback fontCallback, @Nullable Handler handler, boolean isRequestFromLayoutInflator) {
if (value.string == null) {
throw new NotFoundException("Resource \"" + wrapper.getResourceName(id) + "\" (" + Integer.toHexString(id) + ") is not a Font: " + value);
}
final String file = value.string.toString();
if (!file.startsWith("res/")) {
// Early exit if the specified string is unlikely to be a resource path.
if (fontCallback != null) {
fontCallback.callbackFailAsync(FontRequestCallback.FAIL_REASON_FONT_LOAD_ERROR, handler);
}
return null;
}
Typeface typeface = TypefaceCompat.findFromCache(wrapper, id, (style & Typeface.ITALIC) != 0, weight);
if (typeface != null) {
if (fontCallback != null) {
fontCallback.callbackSuccessAsync(typeface, handler);
}
return typeface;
}
try {
if (file.toLowerCase().endsWith(".xml")) {
final XmlResourceParser rp = wrapper.getXml(id);
final FamilyResourceEntry familyEntry = FontResourcesParserCompat.parse(rp, wrapper);
if (familyEntry == null) {
Log.e(TAG, "Failed to find font-family tag");
if (fontCallback != null) {
fontCallback.callbackFailAsync(FontRequestCallback.FAIL_REASON_FONT_LOAD_ERROR, handler);
}
return null;
}
return TypefaceCompat.createFromResourcesFamilyXml(context, familyEntry, wrapper, id, style, weight, fontCallback, handler, isRequestFromLayoutInflator);
}
typeface = TypefaceCompat.createFromResourcesFontFile(context, wrapper, id, file, (style & Typeface.ITALIC) != 0, weight);
if (fontCallback != null) {
if (typeface != null) {
fontCallback.callbackSuccessAsync(typeface, handler);
} else {
fontCallback.callbackFailAsync(FontRequestCallback.FAIL_REASON_FONT_LOAD_ERROR, handler);
}
}
return typeface;
} catch (XmlPullParserException e) {
Log.e(TAG, "Failed to parse xml resource " + file, e);
} catch (IOException e) {
Log.e(TAG, "Failed to read xml resource " + file, e);
}
if (fontCallback != null) {
fontCallback.callbackFailAsync(FontRequestCallback.FAIL_REASON_FONT_LOAD_ERROR, handler);
}
return null;
}
Aggregations