use of android.view.InflateException in project HoloEverywhere by Prototik.
the class LayoutInflater method inflate.
@Override
public View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot) {
synchronized (mConstructorArgs) {
final AttributeSet attrs = Xml.asAttributeSet(parser);
mConstructorArgs[0] = mContext;
View result = root;
try {
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
;
}
if (type != XmlPullParser.START_TAG) {
throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
}
final String name = parser.getName();
if (TAG_MERGE.equals(name)) {
if (root == null || !attachToRoot) {
throw new InflateException("<merge /> can be used only with a valid " + "ViewGroup root and attachToRoot=true");
}
rInflate(parser, root, attrs, false);
} else {
View temp;
if (TAG_1995.equals(name)) {
temp = new BlinkLayout(mContext, attrs);
} else {
temp = createViewFromTag(root, name, attrs);
}
ViewGroup.LayoutParams params = null;
if (root != null) {
params = root.generateLayoutParams(attrs);
if (!attachToRoot) {
temp.setLayoutParams(params);
}
}
rInflate(parser, temp, attrs, true);
if (root != null && attachToRoot) {
root.addView(temp, params);
}
if (root == null || !attachToRoot) {
result = temp;
}
}
} catch (XmlPullParserException e) {
InflateException ex = new InflateException(e.getMessage());
ex.initCause(e);
throw ex;
} catch (IOException e) {
InflateException ex = new InflateException(parser.getPositionDescription() + ": " + e.getMessage());
ex.initCause(e);
throw ex;
} finally {
mConstructorArgs[1] = null;
}
return result;
}
}
use of android.view.InflateException in project HoloEverywhere by Prototik.
the class LayoutInflater method parseInclude.
private void parseInclude(XmlPullParser parser, View parent, AttributeSet attrs) throws XmlPullParserException, IOException {
int type;
if (parent instanceof ViewGroup) {
final int layout = attrs.getAttributeResourceValue(null, "layout", 0);
if (layout == 0) {
final String value = attrs.getAttributeValue(null, "layout");
if (value == null) {
throw new InflateException("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
} else {
throw new InflateException("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid.");
}
} else {
final XmlResourceParser childParser = getContext().getResources().getLayout(layout);
try {
final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
;
}
if (type != XmlPullParser.START_TAG) {
throw new InflateException(childParser.getPositionDescription() + ": No start tag found!");
}
final String childName = childParser.getName();
if (TAG_MERGE.equals(childName)) {
rInflate(childParser, parent, childAttrs, false);
} else {
final View view = createViewFromTag(parent, childName, childAttrs);
final ViewGroup group = (ViewGroup) parent;
ViewGroup.LayoutParams params = null;
try {
params = group.generateLayoutParams(attrs);
} catch (RuntimeException e) {
params = group.generateLayoutParams(childAttrs);
} finally {
if (params != null) {
view.setLayoutParams(params);
}
}
rInflate(childParser, view, childAttrs, true);
TypedArray a = mContext.obtainStyledAttributes(attrs, new int[] { android.R.attr.id, android.R.attr.visibility }, 0, 0);
int id = a.getResourceId(0, View.NO_ID);
int visibility = a.getInt(1, -1);
a.recycle();
if (id != View.NO_ID) {
view.setId(id);
}
switch(visibility) {
case 0:
view.setVisibility(View.VISIBLE);
break;
case 1:
view.setVisibility(View.INVISIBLE);
break;
case 2:
view.setVisibility(View.GONE);
break;
}
group.addView(view);
}
} finally {
childParser.close();
}
}
} else {
throw new InflateException("<include /> can only be used inside of a ViewGroup");
}
final int currentDepth = parser.getDepth();
while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > currentDepth) && type != XmlPullParser.END_DOCUMENT) {
;
}
}
use of android.view.InflateException in project HoloEverywhere by Prototik.
the class GenericInflater method createItem.
@SuppressWarnings("unchecked")
public final T createItem(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException {
if (prefix != null) {
name = prefix + name;
}
Constructor<?> constructor = GenericInflater.sConstructorMap.get(name);
try {
if (constructor == null) {
if (mClassLoader == null) {
mClassLoader = getClassLoader();
if (mClassLoader == null) {
mClassLoader = mContext.getClassLoader();
}
}
Class<?> clazz = mClassLoader.loadClass(name);
constructor = findConstructor(clazz);
GenericInflater.sConstructorMap.put(clazz, constructor);
}
return (T) constructor.newInstance(obtainConstructorArgs(name, attrs, constructor));
} catch (NoSuchMethodException e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + name);
ie.initCause(e);
throw ie;
} catch (Exception e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + constructor.toString());
ie.initCause(e);
throw ie;
}
}
use of android.view.InflateException in project android_frameworks_base by crdroidandroid.
the class Transition method parseMatchOrder.
private static int[] parseMatchOrder(String matchOrderString) {
StringTokenizer st = new StringTokenizer(matchOrderString, ",");
int[] matches = new int[st.countTokens()];
int index = 0;
while (st.hasMoreTokens()) {
String token = st.nextToken().trim();
if (MATCH_ID_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_ID;
} else if (MATCH_INSTANCE_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_INSTANCE;
} else if (MATCH_NAME_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_NAME;
} else if (MATCH_VIEW_NAME_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_NAME;
} else if (MATCH_ITEM_ID_STR.equalsIgnoreCase(token)) {
matches[index] = Transition.MATCH_ITEM_ID;
} else if (token.isEmpty()) {
int[] smallerMatches = new int[matches.length - 1];
System.arraycopy(matches, 0, smallerMatches, 0, index);
matches = smallerMatches;
index--;
} else {
throw new InflateException("Unknown match type in matchOrder: '" + token + "'");
}
index++;
}
return matches;
}
use of android.view.InflateException in project android_frameworks_base by crdroidandroid.
the class TransitionInflater method createCustom.
private Object createCustom(AttributeSet attrs, Class expectedType, String tag) {
String className = attrs.getAttributeValue(null, "class");
if (className == null) {
throw new InflateException(tag + " tag must have a 'class' attribute");
}
try {
synchronized (sConstructors) {
Constructor constructor = sConstructors.get(className);
if (constructor == null) {
Class c = mContext.getClassLoader().loadClass(className).asSubclass(expectedType);
if (c != null) {
constructor = c.getConstructor(sConstructorSignature);
constructor.setAccessible(true);
sConstructors.put(className, constructor);
}
}
return constructor.newInstance(mContext, attrs);
}
} catch (InstantiationException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (ClassNotFoundException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (InvocationTargetException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (NoSuchMethodException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
} catch (IllegalAccessException e) {
throw new InflateException("Could not instantiate " + expectedType + " class " + className, e);
}
}
Aggregations