Search in sources :

Example 1 with ProgressItem

use of greendroid.widget.item.ProgressItem 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);
}
Also used : SubtitleItem(greendroid.widget.item.SubtitleItem) LongTextItem(greendroid.widget.item.LongTextItem) TextItem(greendroid.widget.item.TextItem) ArrayList(java.util.ArrayList) ProgressItem(greendroid.widget.item.ProgressItem) DrawableItem(greendroid.widget.item.DrawableItem) Item(greendroid.widget.item.Item) LongTextItem(greendroid.widget.item.LongTextItem) TextItem(greendroid.widget.item.TextItem) DescriptionItem(greendroid.widget.item.DescriptionItem) ThumbnailItem(greendroid.widget.item.ThumbnailItem) SeparatorItem(greendroid.widget.item.SeparatorItem) SubtitleItem(greendroid.widget.item.SubtitleItem) SubtextItem(greendroid.widget.item.SubtextItem) DrawableItem(greendroid.widget.item.DrawableItem) ProgressItem(greendroid.widget.item.ProgressItem) SubtextItem(greendroid.widget.item.SubtextItem) AttributeSet(android.util.AttributeSet) ThumbnailItem(greendroid.widget.item.ThumbnailItem) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) LongTextItem(greendroid.widget.item.LongTextItem) SeparatorItem(greendroid.widget.item.SeparatorItem) DescriptionItem(greendroid.widget.item.DescriptionItem)

Example 2 with ProgressItem

use of greendroid.widget.item.ProgressItem in project GreenDroid by cyrilmottier.

the class BasicItemActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    List<Item> items = new ArrayList<Item>();
    items.add(new SeparatorItem("Class 1"));
    items.add(new ThumbnailItem("Powered paragliding", "aka paramotoring", R.drawable.class1));
    items.add(new DescriptionItem("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus consequat leo, et tincidunt justo tristique in."));
    items.add(new SeparatorItem("Class 2"));
    items.add(new DrawableItem("Trikes", R.drawable.class2));
    items.add(new DescriptionItem("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus consequat leo, et tincidunt justo tristique in."));
    items.add(new SeparatorItem("Class 3"));
    items.add(new ThumbnailItem("Multi-axis", "Looks like a tiny plane", R.drawable.class3));
    items.add(new DescriptionItem("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus consequat leo, et tincidunt justo tristique in."));
    items.add(new SeparatorItem("Class 4"));
    items.add(new ThumbnailItem("Auto-gyro", "A scary helicopter", R.drawable.class4));
    items.add(new DescriptionItem("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus consequat leo, et tincidunt justo tristique in."));
    items.add(new SeparatorItem("Class 5"));
    items.add(new DrawableItem("Hot air baloon", R.drawable.class5));
    items.add(new DescriptionItem("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus consequat leo, et tincidunt justo tristique in."));
    final Item item1 = new SeparatorItem("Class 6");
    final Item item2 = new TextItem("Airbus/Boeing planes");
    final Item item3 = new DescriptionItem("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed tempus consequat leo, et tincidunt justo tristique in.");
    items.add(item1);
    items.add(item2);
    items.add(item3);
    final ProgressItem progressItem = new ProgressItem("Removing intruders", true);
    items.add(progressItem);
    final ItemAdapter adapter = new ItemAdapter(this, items);
    setListAdapter(adapter);
    mHandler.postDelayed(new Runnable() {

        public void run() {
            adapter.remove(item1);
            adapter.remove(item2);
            adapter.remove(item3);
            adapter.remove(progressItem);
            adapter.insert(new ThumbnailItem("Ultralight aviation", "List of French 'ULM' classes", R.drawable.ic_gdcatalog), 0);
            adapter.notifyDataSetChanged();
        }
    }, 8000);
}
Also used : ThumbnailItem(greendroid.widget.item.ThumbnailItem) SeparatorItem(greendroid.widget.item.SeparatorItem) Item(greendroid.widget.item.Item) TextItem(greendroid.widget.item.TextItem) DescriptionItem(greendroid.widget.item.DescriptionItem) DrawableItem(greendroid.widget.item.DrawableItem) ProgressItem(greendroid.widget.item.ProgressItem) TextItem(greendroid.widget.item.TextItem) ArrayList(java.util.ArrayList) ThumbnailItem(greendroid.widget.item.ThumbnailItem) DrawableItem(greendroid.widget.item.DrawableItem) ProgressItem(greendroid.widget.item.ProgressItem) SeparatorItem(greendroid.widget.item.SeparatorItem) DescriptionItem(greendroid.widget.item.DescriptionItem) ItemAdapter(greendroid.widget.ItemAdapter)

Example 3 with ProgressItem

use of greendroid.widget.item.ProgressItem in project GreenDroid by cyrilmottier.

the class ProgressItemView method setObject.

public void setObject(Item object) {
    final ProgressItem item = (ProgressItem) object;
    mProgressBar.setVisibility(item.isInProgress ? View.VISIBLE : View.GONE);
    mTextView.setText(item.text);
}
Also used : ProgressItem(greendroid.widget.item.ProgressItem)

Aggregations

ProgressItem (greendroid.widget.item.ProgressItem)3 DescriptionItem (greendroid.widget.item.DescriptionItem)2 DrawableItem (greendroid.widget.item.DrawableItem)2 Item (greendroid.widget.item.Item)2 SeparatorItem (greendroid.widget.item.SeparatorItem)2 TextItem (greendroid.widget.item.TextItem)2 ThumbnailItem (greendroid.widget.item.ThumbnailItem)2 ArrayList (java.util.ArrayList)2 Resources (android.content.res.Resources)1 AttributeSet (android.util.AttributeSet)1 ItemAdapter (greendroid.widget.ItemAdapter)1 LongTextItem (greendroid.widget.item.LongTextItem)1 SubtextItem (greendroid.widget.item.SubtextItem)1 SubtitleItem (greendroid.widget.item.SubtitleItem)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1