use of android.view.InflateException in project android_frameworks_base by DirtyUnicorns.
the class GenericInflater method inflate.
/**
* Inflate a new hierarchy from the specified XML node. Throws
* InflaterException if there is an error.
* <p>
* <em><strong>Important</strong></em> For performance
* reasons, inflation relies heavily on pre-processing of XML files
* that is done at build time. Therefore, it is not currently possible to
* use inflater with an XmlPullParser over a plain XML file at runtime.
*
* @param parser XML dom node containing the description of the
* hierarchy.
* @param root Optional to be the parent of the generated hierarchy (if
* <em>attachToRoot</em> is true), or else simply an object that
* provides a set of values for root of the returned
* hierarchy (if <em>attachToRoot</em> is false.)
* @param attachToRoot Whether the inflated hierarchy should be attached to
* the root parameter?
* @return The root of the inflated hierarchy. If root was supplied and
* attachToRoot is true, this is root; otherwise it is the root of
* the inflated XML file.
*/
public T inflate(XmlPullParser parser, P root, boolean attachToRoot) {
synchronized (mConstructorArgs) {
final AttributeSet attrs = Xml.asAttributeSet(parser);
mConstructorArgs[0] = mContext;
T result = (T) root;
try {
// Look for the root node.
int type;
while ((type = parser.next()) != parser.START_TAG && type != parser.END_DOCUMENT) {
;
}
if (type != parser.START_TAG) {
throw new InflateException(parser.getPositionDescription() + ": No start tag found!");
}
if (DEBUG) {
System.out.println("**************************");
System.out.println("Creating root: " + parser.getName());
System.out.println("**************************");
}
// Temp is the root that was found in the xml
T xmlRoot = createItemFromTag(parser, parser.getName(), attrs);
result = (T) onMergeRoots(root, attachToRoot, (P) xmlRoot);
if (DEBUG) {
System.out.println("-----> start inflating children");
}
// Inflate all children under temp
rInflate(parser, result, attrs);
if (DEBUG) {
System.out.println("-----> done inflating children");
}
} catch (InflateException e) {
throw e;
} 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;
}
return result;
}
}
use of android.view.InflateException in project android_frameworks_base by DirtyUnicorns.
the class GenericInflater method createItem.
/**
* Low-level function for instantiating by name. This attempts to
* instantiate class of the given <var>name</var> found in this
* inflater's ClassLoader.
*
* <p>
* There are two things that can happen in an error case: either the
* exception describing the error will be thrown, or a null will be
* returned. You must deal with both possibilities -- the former will happen
* the first time createItem() is called for a class of a particular name,
* the latter every time there-after for that class name.
*
* @param name The full name of the class to be instantiated.
* @param attrs The XML attributes supplied for this instance.
*
* @return The newly instantied item, or null.
*/
public final T createItem(String name, String prefix, AttributeSet attrs) throws ClassNotFoundException, InflateException {
Constructor constructor = (Constructor) sConstructorMap.get(name);
try {
if (null == constructor) {
// Class not found in the cache, see if it's real,
// and try to add it
Class clazz = mContext.getClassLoader().loadClass(prefix != null ? (prefix + name) : name);
constructor = clazz.getConstructor(mConstructorSignature);
constructor.setAccessible(true);
sConstructorMap.put(name, constructor);
}
Object[] args = mConstructorArgs;
args[1] = attrs;
return (T) constructor.newInstance(args);
} catch (NoSuchMethodException e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + (prefix != null ? (prefix + name) : name));
ie.initCause(e);
throw ie;
} catch (ClassNotFoundException e) {
// If loadClass fails, we should propagate the exception.
throw e;
} catch (Exception e) {
InflateException ie = new InflateException(attrs.getPositionDescription() + ": Error inflating class " + constructor.getClass().getName());
ie.initCause(e);
throw ie;
}
}
use of android.view.InflateException in project Auto.js by hyb1996.
the class DynamicLayoutInflater method createViewForName.
private View createViewForName(String name, HashMap<String, String> attrs) {
try {
if (name.equals("View")) {
return new View(mContext);
}
if (!name.contains(".")) {
name = "android.widget." + name;
}
ViewCreator<?> creator = mViewCreators.get(name);
if (creator != null) {
return creator.create(mContext, attrs);
}
Class<?> clazz = Class.forName(name);
String style = attrs.get("style");
if (style == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return (View) clazz.getConstructor(Context.class).newInstance(mContext);
} else {
int styleRes = Res.parseStyle(mContext, style);
return (View) clazz.getConstructor(Context.class, AttributeSet.class, int.class, int.class).newInstance(mContext, null, 0, styleRes);
}
} catch (Exception e) {
throw new InflateException(e);
}
}
use of android.view.InflateException in project android_packages_apps_Snap by LineageOS.
the class PreferenceInflater method newPreference.
private CameraPreference newPreference(String tagName, Object[] args) {
String name = PACKAGE_NAME + "." + tagName;
Constructor<?> constructor = sConstructorMap.get(name);
try {
if (constructor == null) {
// Class not found in the cache, see if it's real, and try to
// add it
Class<?> clazz = mContext.getClassLoader().loadClass(name);
constructor = clazz.getConstructor(CTOR_SIGNATURE);
sConstructorMap.put(name, constructor);
}
return (CameraPreference) constructor.newInstance(args);
} catch (NoSuchMethodException e) {
throw new InflateException("Error inflating class " + name, e);
} catch (ClassNotFoundException e) {
throw new InflateException("No such class: " + name, e);
} catch (Exception e) {
throw new InflateException("While create instance of" + name, e);
}
}
use of android.view.InflateException in project Awful.apk by Awful.
the class ThreadDisplayFragment method onCreateView.
// --------------------------------
@Override
public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedState) {
View result;
try {
result = inflateView(R.layout.thread_display, aContainer, aInflater);
} catch (InflateException e) {
if (webViewIsMissing(e)) {
return null;
} else {
throw e;
}
}
pageBar = (PageBar) result.findViewById(R.id.page_bar);
pageBar.setListener(new PageBar.PageBarCallbacks() {
@Override
public void onPageNavigation(boolean nextPage) {
turnPage(nextPage);
}
@Override
public void onRefreshClicked() {
refresh();
}
@Override
public void onPageNumberClicked() {
displayPagePicker();
}
});
getAwfulActivity().setPreferredFont(pageBar.getTextView());
mThreadView = (AwfulWebView) result.findViewById(R.id.thread);
initThreadViewProperties();
mUserPostNotice = (TextView) result.findViewById(R.id.thread_userpost_notice);
refreshProbationBar();
// FAB
mFAB = (FloatingActionButton) result.findViewById(R.id.just_post);
mFAB.setOnClickListener(onButtonClick);
mFAB.setVisibility(View.GONE);
return result;
}
Aggregations