|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.preference.GenericInflater<T,P>
abstract class GenericInflater<T,P extends GenericInflater.Parent>
Generic XML inflater. This has been adapted from LayoutInflater and
quickly passed over to use generics.
| Nested Class Summary | |
|---|---|
static interface |
GenericInflater.Factory<T>
|
static interface |
GenericInflater.Parent<T>
|
| Field Summary | |
|---|---|
protected Context |
mContext
|
| Constructor Summary | |
|---|---|
protected |
GenericInflater(Context context)
Create a new inflater instance associated with a particular Context. |
protected |
GenericInflater(GenericInflater<T,P> original,
Context newContext)
Create a new inflater instance that is a copy of an existing inflater, optionally with its Context changed. |
| Method Summary | |
|---|---|
abstract GenericInflater |
cloneInContext(Context newContext)
Create a copy of the existing inflater object, with the copy pointing to a different Context than the original. |
T |
createItem(String name,
String prefix,
AttributeSet attrs)
Low-level function for instantiating by name. |
Context |
getContext()
Return the context we are running in, for access to resources, class loader, etc. |
String |
getDefaultPackage()
Returns the default package, or null if it is not set. |
GenericInflater.Factory<T> |
getFactory()
Return the current factory (or null). |
T |
inflate(int resource,
P root)
Inflate a new item hierarchy from the specified xml resource. |
T |
inflate(int resource,
P root,
boolean attachToRoot)
Inflate a new hierarchy from the specified xml resource. |
T |
inflate(XmlPullParser parser,
P root)
Inflate a new hierarchy from the specified xml node. |
T |
inflate(XmlPullParser parser,
P root,
boolean attachToRoot)
Inflate a new hierarchy from the specified XML node. |
protected boolean |
onCreateCustomFromTag(XmlPullParser parser,
T parent,
AttributeSet attrs)
Before this inflater tries to create an item from the tag, this method will be called. |
protected T |
onCreateItem(String name,
AttributeSet attrs)
This routine is responsible for creating the correct subclass of item given the xml element name. |
protected P |
onMergeRoots(P givenRoot,
boolean attachToGivenRoot,
P xmlRoot)
|
void |
setDefaultPackage(String defaultPackage)
Sets the default package that will be searched for classes to construct for tag names that have no explicit package. |
void |
setFactory(GenericInflater.Factory<T> factory)
Attach a custom Factory interface for creating items while using this inflater. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected final Context mContext
| Constructor Detail |
|---|
protected GenericInflater(Context context)
context - The Context in which this inflater will
create its items; most importantly, this supplies the theme
from which the default values for their attributes are
retrieved.
protected GenericInflater(GenericInflater<T,P> original,
Context newContext)
cloneInContext(android.content.Context).
original - The original inflater to copy.newContext - The new Context to use.| Method Detail |
|---|
public abstract GenericInflater cloneInContext(Context newContext)
ContextThemeWrapper to create a new inflater to go along
with the new Context theme.
newContext - The new Context to associate with the new inflater.
May be the same as the original Context if desired.
public void setDefaultPackage(String defaultPackage)
defaultPackage - The default package. This will be prepended to the
tag name, so it should end with a period.public String getDefaultPackage()
setDefaultPackage(String)public Context getContext()
public final GenericInflater.Factory<T> getFactory()
public void setFactory(GenericInflater.Factory<T> factory)
onCreateItem(java.lang.String, android.util.AttributeSet) method is called.
If you have an existing inflater and want to add your
own factory to it, use cloneInContext(android.content.Context) to clone the existing
instance and then you can use this function (once) on the returned new
instance. This will merge your own factory with whatever factory the
original instance is using.
public T inflate(int resource,
P root)
resource - ID for an XML resource to load (e.g.,
R.layout.main_page)root - Optional parent of the generated hierarchy.
public T inflate(XmlPullParser parser,
P root)
Important 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.
parser - XML dom node containing the description of the
hierarchy.root - Optional parent of the generated hierarchy.
public T inflate(int resource,
P root,
boolean attachToRoot)
resource - ID for an XML resource to load (e.g.,
R.layout.main_page)root - Optional root to be the parent of the generated hierarchy (if
attachToRoot is true), or else simply an object that
provides a set of values for root of the returned
hierarchy (if attachToRoot is false.)attachToRoot - Whether the inflated hierarchy should be attached to
the root parameter?
public T inflate(XmlPullParser parser,
P root,
boolean attachToRoot)
Important 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.
parser - XML dom node containing the description of the
hierarchy.root - Optional to be the parent of the generated hierarchy (if
attachToRoot is true), or else simply an object that
provides a set of values for root of the returned
hierarchy (if attachToRoot is false.)attachToRoot - Whether the inflated hierarchy should be attached to
the root parameter?
public final T createItem(String name,
String prefix,
AttributeSet attrs)
throws ClassNotFoundException,
InflateException
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.
name - The full name of the class to be instantiated.attrs - The XML attributes supplied for this instance.
ClassNotFoundException
InflateException
protected T onCreateItem(String name,
AttributeSet attrs)
throws ClassNotFoundException
name - The fully qualified class name of the item to be create.attrs - An AttributeSet of attributes to apply to the item.
ClassNotFoundException
protected boolean onCreateCustomFromTag(XmlPullParser parser,
T parent,
AttributeSet attrs)
throws XmlPullParserException
parser - XML dom node containing the description of the hierarchy.parent - The item that should be the parent of whatever you create.attrs - An AttributeSet of attributes to apply to the item.
XmlPullParserException
protected P onMergeRoots(P givenRoot,
boolean attachToGivenRoot,
P xmlRoot)
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||