summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2015-02-04 23:24:23 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-02-04 23:24:24 +0000
commite8d05b5bab49f2becb1762b70275d3914de23be2 (patch)
treed9070ad0a7e280b3bb7e92234217d7eb83bb238c
parent3f5175fccd39c341064e8bd86cb03dba4bc6881c (diff)
parente8489cd5f578d8f60f0f48bf6d40785488f4092c (diff)
downloadframeworks_base-e8d05b5bab49f2becb1762b70275d3914de23be2.zip
frameworks_base-e8d05b5bab49f2becb1762b70275d3914de23be2.tar.gz
frameworks_base-e8d05b5bab49f2becb1762b70275d3914de23be2.tar.bz2
Merge "Avoid unnecessary exception handling for <include> tag"
-rw-r--r--core/java/android/view/LayoutInflater.java47
-rw-r--r--core/res/res/values/attrs.xml2
2 files changed, 27 insertions, 22 deletions
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index ac32430..a5225cb 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -16,24 +16,25 @@
package android.view;
-import android.annotation.Nullable;
-import android.graphics.Canvas;
-import android.os.Handler;
-import android.os.Message;
-import android.os.Trace;
-import android.util.TypedValue;
-import android.widget.FrameLayout;
+import com.android.internal.R;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
+import android.graphics.Canvas;
+import android.os.Handler;
+import android.os.Message;
+import android.os.Trace;
import android.util.AttributeSet;
import android.util.Log;
+import android.util.TypedValue;
import android.util.Xml;
+import android.widget.FrameLayout;
import java.io.IOException;
import java.lang.reflect.Constructor;
@@ -925,6 +926,14 @@ public abstract class LayoutInflater {
inheritContext);
final ViewGroup group = (ViewGroup) parent;
+ final TypedArray a = context.obtainStyledAttributes(
+ attrs, R.styleable.Include);
+ final int id = a.getResourceId(R.styleable.Include_id, View.NO_ID);
+ final int visibility = a.getInt(R.styleable.Include_visibility, -1);
+ final boolean hasWidth = a.hasValue(R.styleable.Include_layout_width);
+ final boolean hasHeight = a.hasValue(R.styleable.Include_layout_height);
+ a.recycle();
+
// We try to load the layout params set in the <include /> tag. If
// they don't exist, we will rely on the layout params set in the
// included XML file.
@@ -934,27 +943,21 @@ public abstract class LayoutInflater {
// successfully loaded layout params from the <include /> tag,
// false means we need to rely on the included layout params.
ViewGroup.LayoutParams params = null;
- try {
- params = group.generateLayoutParams(attrs);
- } catch (RuntimeException e) {
- params = group.generateLayoutParams(childAttrs);
- } finally {
- if (params != null) {
- view.setLayoutParams(params);
+ if (hasWidth && hasHeight) {
+ try {
+ params = group.generateLayoutParams(attrs);
+ } catch (RuntimeException e) {
+ // Ignore, just fail over to child attrs.
}
}
+ if (params == null) {
+ params = group.generateLayoutParams(childAttrs);
+ }
+ view.setLayoutParams(params);
// Inflate all children.
rInflate(childParser, view, childAttrs, true, true);
- final TypedArray a = context.obtainStyledAttributes(
- attrs, com.android.internal.R.styleable.Include);
- final int id = a.getResourceId(
- com.android.internal.R.styleable.Include_id, View.NO_ID);
- final int visibility = a.getInt(
- com.android.internal.R.styleable.Include_visibility, -1);
- a.recycle();
-
if (id != View.NO_ID) {
view.setId(id);
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 3a15b9d..ceb7b63 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -2641,6 +2641,8 @@
<declare-styleable name="Include">
<attr name="id" />
<attr name="visibility" />
+ <attr name="layout_width" />
+ <attr name="layout_height" />
</declare-styleable>
<!-- Attributes that can be used with a {@link android.view.ViewGroup} or any