diff options
| -rw-r--r-- | core/java/android/view/animation/AnimationUtils.java | 89 | ||||
| -rw-r--r-- | core/java/com/android/internal/policy/TransitionAnimation.java | 3 |
2 files changed, 36 insertions, 56 deletions
diff --git a/core/java/android/view/animation/AnimationUtils.java b/core/java/android/view/animation/AnimationUtils.java index 7d1dc7660871..84ef22637cb0 100644 --- a/core/java/android/view/animation/AnimationUtils.java +++ b/core/java/android/view/animation/AnimationUtils.java @@ -28,6 +28,7 @@ import android.content.res.XmlResourceParser; import android.os.SystemClock; import android.util.AttributeSet; import android.util.Xml; +import android.view.InflateException; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; @@ -137,16 +138,9 @@ public class AnimationUtils { try { parser = context.getResources().getAnimation(id); return createAnimationFromXml(context, parser); - } catch (XmlPullParserException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; - } catch (IOException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; + } catch (XmlPullParserException | IOException ex) { + throw new NotFoundException( + "Can't load animation resource ID #0x" + Integer.toHexString(id), ex); } finally { if (parser != null) parser.close(); } @@ -159,8 +153,9 @@ public class AnimationUtils { } @UnsupportedAppUsage - private static Animation createAnimationFromXml(Context c, XmlPullParser parser, - AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException { + private static Animation createAnimationFromXml( + Context c, XmlPullParser parser, AnimationSet parent, AttributeSet attrs) + throws XmlPullParserException, IOException, InflateException { Animation anim = null; @@ -168,8 +163,8 @@ public class AnimationUtils { int type; int depth = parser.getDepth(); - while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) - && type != XmlPullParser.END_DOCUMENT) { + while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) + && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; @@ -193,7 +188,7 @@ public class AnimationUtils { } else if (name.equals("extend")) { anim = new ExtendAnimation(c, attrs); } else { - throw new RuntimeException("Unknown animation name: " + parser.getName()); + throw new InflateException("Unknown animation name: " + parser.getName()); } if (parent != null) { @@ -220,29 +215,24 @@ public class AnimationUtils { try { parser = context.getResources().getAnimation(id); return createLayoutAnimationFromXml(context, parser); - } catch (XmlPullParserException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; - } catch (IOException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; + } catch (XmlPullParserException | IOException | InflateException ex) { + throw new NotFoundException( + "Can't load animation resource ID #0x" + Integer.toHexString(id), ex); } finally { if (parser != null) parser.close(); } } - private static LayoutAnimationController createLayoutAnimationFromXml(Context c, - XmlPullParser parser) throws XmlPullParserException, IOException { + private static LayoutAnimationController createLayoutAnimationFromXml( + Context c, XmlPullParser parser) + throws XmlPullParserException, IOException, InflateException { return createLayoutAnimationFromXml(c, parser, Xml.asAttributeSet(parser)); } - private static LayoutAnimationController createLayoutAnimationFromXml(Context c, - XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { + private static LayoutAnimationController createLayoutAnimationFromXml( + Context c, XmlPullParser parser, AttributeSet attrs) + throws XmlPullParserException, IOException, InflateException { LayoutAnimationController controller = null; @@ -263,7 +253,7 @@ public class AnimationUtils { } else if ("gridLayoutAnimation".equals(name)) { controller = new GridLayoutAnimationController(c, attrs); } else { - throw new RuntimeException("Unknown layout animation name: " + name); + throw new InflateException("Unknown layout animation name: " + name); } } @@ -342,16 +332,9 @@ public class AnimationUtils { try { parser = context.getResources().getAnimation(id); return createInterpolatorFromXml(context.getResources(), context.getTheme(), parser); - } catch (XmlPullParserException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; - } catch (IOException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; + } catch (XmlPullParserException | IOException | InflateException ex) { + throw new NotFoundException( + "Can't load animation resource ID #0x" + Integer.toHexString(id), ex); } finally { if (parser != null) parser.close(); } @@ -367,30 +350,26 @@ public class AnimationUtils { * @throws NotFoundException * @hide */ - public static Interpolator loadInterpolator(Resources res, Theme theme, int id) throws NotFoundException { + public static Interpolator loadInterpolator(Resources res, Theme theme, int id) + throws NotFoundException { XmlResourceParser parser = null; try { parser = res.getAnimation(id); return createInterpolatorFromXml(res, theme, parser); - } catch (XmlPullParserException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; - } catch (IOException ex) { - NotFoundException rnf = new NotFoundException("Can't load animation resource ID #0x" + - Integer.toHexString(id)); - rnf.initCause(ex); - throw rnf; + } catch (XmlPullParserException | IOException | InflateException ex) { + throw new NotFoundException( + "Can't load animation resource ID #0x" + Integer.toHexString(id), ex); } finally { - if (parser != null) + if (parser != null) { parser.close(); + } } } - private static Interpolator createInterpolatorFromXml(Resources res, Theme theme, XmlPullParser parser) - throws XmlPullParserException, IOException { + private static Interpolator createInterpolatorFromXml( + Resources res, Theme theme, XmlPullParser parser) + throws XmlPullParserException, IOException, InflateException { BaseInterpolator interpolator = null; @@ -430,7 +409,7 @@ public class AnimationUtils { } else if (name.equals("pathInterpolator")) { interpolator = new PathInterpolator(res, theme, attrs); } else { - throw new RuntimeException("Unknown interpolator name: " + parser.getName()); + throw new InflateException("Unknown interpolator name: " + parser.getName()); } } return interpolator; diff --git a/core/java/com/android/internal/policy/TransitionAnimation.java b/core/java/com/android/internal/policy/TransitionAnimation.java index 1172f7ba447a..aa2318d219f8 100644 --- a/core/java/com/android/internal/policy/TransitionAnimation.java +++ b/core/java/com/android/internal/policy/TransitionAnimation.java @@ -50,6 +50,7 @@ import android.media.Image; import android.media.ImageReader; import android.os.SystemProperties; import android.util.Slog; +import android.view.InflateException; import android.view.SurfaceControl; import android.view.WindowManager.LayoutParams; import android.view.WindowManager.TransitionOldType; @@ -1264,7 +1265,7 @@ public class TransitionAnimation { public static Animation loadAnimationSafely(Context context, int resId, String tag) { try { return AnimationUtils.loadAnimation(context, resId); - } catch (Resources.NotFoundException e) { + } catch (Resources.NotFoundException | InflateException e) { Slog.w(tag, "Unable to load animation resource", e); return null; } |