Search in sources :

Example 6 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by ParanoidAndroid.

the class StorageManagerBaseTest method copyRawToFile.

/**
     * Helper to copy a raw resource file to an actual specified file
     *
     * @param rawResId The raw resource ID of the OBB resource file
     * @param outFile A File representing the file we want to copy the OBB to
     * @throws NotFoundException If the resource file could not be found
     */
private void copyRawToFile(int rawResId, File outFile) throws NotFoundException {
    Resources res = mContext.getResources();
    InputStream is = null;
    try {
        is = res.openRawResource(rawResId);
    } catch (NotFoundException e) {
        Log.i(LOG_TAG, "Failed to load resource with id: " + rawResId);
        throw e;
    }
    FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
    assertTrue(FileUtils.copyToFile(is, outFile));
    FileUtils.setPermissions(outFile.getPath(), FileUtils.S_IRWXU | FileUtils.S_IRWXG | FileUtils.S_IRWXO, -1, -1);
}
Also used : DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

Example 7 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by ResurrectionRemix.

the class BridgeTypedArray method getTextArray.

/**
     * Retrieve the CharSequence[] for the attribute at <var>index</var>.
     * This gets the resource ID of the selected attribute, and uses
     * {@link Resources#getTextArray Resources.getTextArray} of the owning
     * Resources object to retrieve its String[].
     *
     * @param index Index of attribute to retrieve.
     *
     * @return CharSequence[] for the attribute, or null if not defined.
     */
@Override
public CharSequence[] getTextArray(int index) {
    if (!hasValue(index)) {
        return null;
    }
    ResourceValue resVal = mResourceData[index];
    if (resVal instanceof ArrayResourceValue) {
        ArrayResourceValue array = (ArrayResourceValue) resVal;
        int count = array.getElementCount();
        return count >= 0 ? Resources_Delegate.fillValues(mBridgeResources, array, new CharSequence[count]) : null;
    }
    int id = getResourceId(index, 0);
    String resIdMessage = id > 0 ? " (resource id 0x" + Integer.toHexString(id) + ')' : "";
    throw new NotFoundException(String.format("%1$s in %2$s%3$s is not a valid array resource.", resVal.getValue(), mNames[index], resIdMessage));
}
Also used : StyleResourceValue(com.android.ide.common.rendering.api.StyleResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AttrResourceValue(com.android.ide.common.rendering.api.AttrResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) NotFoundException(android.content.res.Resources.NotFoundException) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue)

Example 8 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by ResurrectionRemix.

the class Resources_Delegate method openRawResource.

@LayoutlibDelegate
static InputStream openRawResource(Resources resources, int id, TypedValue value) throws NotFoundException {
    getValue(resources, id, value, true);
    String path = value.string.toString();
    File f = new File(path);
    if (f.isFile()) {
        try {
            // and actually load it as a 9-patch instead of a normal bitmap
            if (path.toLowerCase().endsWith(NinePatch.EXTENSION_9PATCH)) {
                return new NinePatchInputStream(f);
            }
            return new FileInputStream(f);
        } catch (FileNotFoundException e) {
            NotFoundException exception = new NotFoundException();
            exception.initCause(e);
            throw exception;
        }
    }
    throw new NotFoundException();
}
Also used : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) File(java.io.File) FileInputStream(java.io.FileInputStream) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 9 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by ResurrectionRemix.

the class Resources_Delegate method getXml.

@LayoutlibDelegate
static XmlResourceParser getXml(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        String v = value.getSecond().getValue();
        if (v != null) {
            // check this is a file
            File f = new File(v);
            if (f.isFile()) {
                try {
                    XmlPullParser parser = ParserFactory.create(f);
                    return new BridgeXmlBlockParser(parser, resources.mContext, mPlatformResourceFlag[0]);
                } catch (XmlPullParserException e) {
                    NotFoundException newE = new NotFoundException();
                    newE.initCause(e);
                    throw newE;
                } catch (FileNotFoundException e) {
                    NotFoundException newE = new NotFoundException();
                    newE.initCause(e);
                    throw newE;
                }
            }
        }
    }
    // id was not found or not resolved. Throw a NotFoundException.
    throwException(resources, id);
    // this is not used since the method above always throws
    return null;
}
Also used : DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) XmlPullParser(org.xmlpull.v1.XmlPullParser) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) File(java.io.File) BridgeXmlBlockParser(com.android.layoutlib.bridge.android.BridgeXmlBlockParser) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 10 with NotFoundException

use of android.content.res.Resources.NotFoundException in project android_frameworks_base by ResurrectionRemix.

the class WallpaperInfo method loadDescription.

/**
     * Return a brief summary of this wallpaper's behavior.
     */
public CharSequence loadDescription(PackageManager pm) throws NotFoundException {
    String packageName = mService.resolvePackageName;
    ApplicationInfo applicationInfo = null;
    if (packageName == null) {
        packageName = mService.serviceInfo.packageName;
        applicationInfo = mService.serviceInfo.applicationInfo;
    }
    if (mService.serviceInfo.descriptionRes != 0) {
        return pm.getText(packageName, mService.serviceInfo.descriptionRes, applicationInfo);
    }
    if (mDescriptionResource <= 0)
        throw new NotFoundException();
    return pm.getText(packageName, mDescriptionResource, mService.serviceInfo.applicationInfo);
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

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