use of greendroid.widget.item.SubtitleItem in project GreenDroid by cyrilmottier.
the class ItemAdapter method createFromXml.
/**
* Creates an ItemAdapter from a given XML document. Called on a parser
* positioned at a tag in an XML document, tries to create an ItemAdapter
* from that tag.
*
* @param context The Context in which the ItemAdapter will be used in
* @param parser The XmlPullParser
* @return a new ItemAdapter constructed with the content of the file
* pointed by <em>xmlId</em>
* @throws XmlPullParserException
* @throws IOException
*/
public static ItemAdapter createFromXml(Context context, XmlPullParser parser) throws XmlPullParserException, IOException {
AttributeSet attrs = Xml.asAttributeSet(parser);
int type;
while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
// Empty loop
}
if (type != XmlPullParser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
if (!parser.getName().equals("item-array")) {
throw new XmlPullParserException("Unknown start tag. Should be 'item-array'");
}
final List<Item> items = new ArrayList<Item>();
final int innerDepth = parser.getDepth() + 1;
final Resources r = context.getResources();
int depth;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
if (depth > innerDepth) {
continue;
}
String name = parser.getName();
Item item;
if (name.equals("text-item")) {
item = new TextItem();
} else if (name.equals("longtext-item")) {
item = new LongTextItem();
} else if (name.equals("description-item")) {
item = new DescriptionItem();
} else if (name.equals("separator-item")) {
item = new SeparatorItem();
} else if (name.equals("progress-item")) {
item = new ProgressItem();
} else if (name.equals("drawable-item")) {
item = new DrawableItem();
} else if (name.equals("subtitle-item")) {
item = new SubtitleItem();
} else if (name.equals("subtext-item")) {
item = new SubtextItem();
} else if (name.equals("thumbnail-item")) {
item = new ThumbnailItem();
} else {
// ItemAdapter and creates our own items via XML?
throw new XmlPullParserException(parser.getPositionDescription() + ": invalid item tag " + name);
}
if (item != null) {
item.inflate(r, parser, attrs);
items.add(item);
}
}
return new ItemAdapter(context, items);
}
use of greendroid.widget.item.SubtitleItem in project GreenDroid by cyrilmottier.
the class SubtitleItemView method setObject.
public void setObject(Item object) {
final SubtitleItem item = (SubtitleItem) object;
mTextView.setText(item.text);
mSubtitleView.setText(item.subtitle);
}
Aggregations