Search in sources :

Example 76 with NotFoundException

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);
}
Also used : Drawable(android.graphics.drawable.Drawable) NotFoundException(android.content.res.Resources.NotFoundException) Method(java.lang.reflect.Method) NotFoundException(android.content.res.Resources.NotFoundException)

Example 77 with NotFoundException

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);
    }
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

Example 78 with NotFoundException

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());
    }
}
Also used : Context(android.content.Context) NotFoundException(android.content.res.Resources.NotFoundException) BraintreeException(com.braintreepayments.api.exceptions.BraintreeException) Resources(android.content.res.Resources) Test(org.junit.Test)

Example 79 with NotFoundException

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;
}
Also used : Typeface(android.graphics.Typeface) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) NotFoundException(android.content.res.Resources.NotFoundException) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 80 with NotFoundException

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;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) Typeface(android.graphics.Typeface) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) FamilyResourceEntry(androidx.core.content.res.FontResourcesParserCompat.FamilyResourceEntry) IOException(java.io.IOException)

Aggregations

NotFoundException (android.content.res.Resources.NotFoundException)165 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)49 Resources (android.content.res.Resources)47 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)45 FileNotFoundException (java.io.FileNotFoundException)34 IOException (java.io.IOException)34 ApplicationInfo (android.content.pm.ApplicationInfo)31 File (java.io.File)30 InputStream (java.io.InputStream)28 FileInputStream (java.io.FileInputStream)20 Drawable (android.graphics.drawable.Drawable)19 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)16 Nullable (android.annotation.Nullable)15 XmlResourceParser (android.content.res.XmlResourceParser)12 SettingNotFoundException (android.provider.Settings.SettingNotFoundException)12 ArrayResourceValue (com.android.ide.common.rendering.api.ArrayResourceValue)12 ResourceValue (com.android.ide.common.rendering.api.ResourceValue)12 NonNull (android.annotation.NonNull)10 ColorDrawable (android.graphics.drawable.ColorDrawable)10 DensityBasedResourceValue (com.android.ide.common.rendering.api.DensityBasedResourceValue)8