Search in sources :

Example 21 with NotFoundException

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

the class AnimatorInflater method loadStateListAnimator.

public static StateListAnimator loadStateListAnimator(Context context, int id) throws NotFoundException {
    final Resources resources = context.getResources();
    final ConfigurationBoundResourceCache<StateListAnimator> cache = resources.getStateListAnimatorCache();
    final Theme theme = context.getTheme();
    StateListAnimator animator = cache.getInstance(id, resources, theme);
    if (animator != null) {
        return animator;
    }
    XmlResourceParser parser = null;
    try {
        parser = resources.getAnimation(id);
        animator = createStateListAnimatorFromXml(context, parser, Xml.asAttributeSet(parser));
        if (animator != null) {
            animator.appendChangingConfigurations(getChangingConfigs(resources, id));
            final ConstantState<StateListAnimator> constantState = animator.createConstantState();
            if (constantState != null) {
                cache.put(id, theme, constantState);
                // return a clone so that the animator in constant state is never used.
                animator = constantState.newInstance(resources, theme);
            }
        }
        return animator;
    } catch (XmlPullParserException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load state list animator resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } catch (IOException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load state list animator resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) XmlResourceParser(android.content.res.XmlResourceParser) Theme(android.content.res.Resources.Theme) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Example 22 with NotFoundException

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

the class AnimatorInflater method loadAnimator.

/** @hide */
public static Animator loadAnimator(Resources resources, Theme theme, int id, float pathErrorScale) throws NotFoundException {
    final ConfigurationBoundResourceCache<Animator> animatorCache = resources.getAnimatorCache();
    Animator animator = animatorCache.getInstance(id, resources, theme);
    if (animator != null) {
        if (DBG_ANIMATOR_INFLATER) {
            Log.d(TAG, "loaded animator from cache, " + resources.getResourceName(id));
        }
        return animator;
    } else if (DBG_ANIMATOR_INFLATER) {
        Log.d(TAG, "cache miss for animator " + resources.getResourceName(id));
    }
    XmlResourceParser parser = null;
    try {
        parser = resources.getAnimation(id);
        animator = createAnimatorFromXml(resources, theme, parser, pathErrorScale);
        if (animator != null) {
            animator.appendChangingConfigurations(getChangingConfigs(resources, id));
            final ConstantState<Animator> constantState = animator.createConstantState();
            if (constantState != null) {
                if (DBG_ANIMATOR_INFLATER) {
                    Log.d(TAG, "caching animator for res " + resources.getResourceName(id));
                }
                animatorCache.put(id, theme, constantState);
                // create a new animator so that cached version is never used by the user
                animator = constantState.newInstance(resources, theme);
            }
        }
        return animator;
    } catch (XmlPullParserException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } catch (IOException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) XmlResourceParser(android.content.res.XmlResourceParser) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Example 23 with NotFoundException

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

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

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

the class MountServiceTests method copyRawToFile.

private void copyRawToFile(int rawResId, File outFile) {
    Resources res = mContext.getResources();
    InputStream is = null;
    try {
        is = res.openRawResource(rawResId);
    } catch (NotFoundException e) {
        fail("Failed to load resource with id: " + rawResId);
    }
    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 : InputStream(java.io.InputStream) NotFoundException(android.content.res.Resources.NotFoundException) Resources(android.content.res.Resources)

Example 25 with NotFoundException

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

the class WallpaperManager method openDefaultWallpaper.

/**
     * Open stream representing the default static image wallpaper.
     *
     * If the device defines no default wallpaper of the requested kind,
     * {@code null} is returned.
     *
     * @hide
     */
public static InputStream openDefaultWallpaper(Context context, @SetWallpaperFlags int which) {
    final String whichProp;
    final int defaultResId;
    if (which == FLAG_LOCK) {
        /* Factory-default lock wallpapers are not yet supported
            whichProp = PROP_LOCK_WALLPAPER;
            defaultResId = com.android.internal.R.drawable.default_lock_wallpaper;
            */
        return null;
    } else {
        whichProp = PROP_WALLPAPER;
        defaultResId = com.android.internal.R.drawable.default_wallpaper;
    }
    final String path = SystemProperties.get(whichProp);
    if (!TextUtils.isEmpty(path)) {
        final File file = new File(path);
        if (file.exists()) {
            try {
                return new FileInputStream(file);
            } catch (IOException e) {
            // Ignored, fall back to platform default below
            }
        }
    }
    try {
        return context.getResources().openRawResource(defaultResId);
    } catch (NotFoundException e) {
    // no default defined for this device; this is not a failure
    }
    return null;
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) IOException(java.io.IOException) File(java.io.File) Paint(android.graphics.Paint) FileInputStream(java.io.FileInputStream)

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