Search in sources :

Example 56 with NotFoundException

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

the class Resources_Delegate method loadXmlResourceParser.

@LayoutlibDelegate
static XmlResourceParser loadXmlResourceParser(Resources resources, String file, int id, int assetCookie, String type) throws NotFoundException {
    // even though we know the XML file to load directly, we still need to resolve the
    // id so that we can know if it's a platform or project resource.
    // (mPlatformResouceFlag will get the result and will be used later).
    getResourceValue(resources, id, mPlatformResourceFlag);
    File f = new File(file);
    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;
    }
}
Also used : 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 57 with NotFoundException

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

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 58 with NotFoundException

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

the class Resources_Delegate method openRawResource.

@LayoutlibDelegate
static InputStream openRawResource(Resources resources, int id) throws NotFoundException {
    Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
    if (value != null) {
        String path = value.getSecond().getValue();
        if (path != null) {
            // check this is a file
            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 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 : NinePatchInputStream(com.android.layoutlib.bridge.util.NinePatchInputStream) DensityBasedResourceValue(com.android.ide.common.rendering.api.DensityBasedResourceValue) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) ArrayResourceValue(com.android.ide.common.rendering.api.ArrayResourceValue) 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 59 with NotFoundException

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

the class WallpaperInfo method loadContextDescription.

/**
     * Retrieves a title of the URI that specifies a link for further context about this wallpaper.
     *
     * @param pm An instance of {@link PackageManager} to retrieve the title.
     * @return The title.
     */
public CharSequence loadContextDescription(PackageManager pm) throws NotFoundException {
    if (mContextDescriptionResource <= 0)
        throw new NotFoundException();
    String packageName = mService.resolvePackageName;
    ApplicationInfo applicationInfo = null;
    if (packageName == null) {
        packageName = mService.serviceInfo.packageName;
        applicationInfo = mService.serviceInfo.applicationInfo;
    }
    return pm.getText(packageName, mContextDescriptionResource, applicationInfo).toString();
}
Also used : ApplicationInfo(android.content.pm.ApplicationInfo) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) NotFoundException(android.content.res.Resources.NotFoundException)

Example 60 with NotFoundException

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

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