Ejemplo n.º 1
0
  private static Item parseItem(XmlPullParser parser) throws XmlPullParserException, IOException {
    Item item = new Item();

    while (parser.next() != XmlPullParser.END_TAG) {
      if (parser.getEventType() != XmlPullParser.START_TAG) {
        continue;
      }

      switch (parser.getName()) {
        case "title":
          item.title = cleanString(parseNextText(parser));
          break;
        case "source":
          String sourceUrl = parser.getAttributeValue(null, "url");
          parseNextText(parser); // ignore "empty" element
          item.sourceUrl = sourceUrl;
          break;
        case "link":
          item.link = parseNextText(parser);
          break;
        case "pubDate":
          item.pubDate = parseNextText(parser);
          break;
        case "description":
          item.description = parseNextText(parser);
          break;

        default:
          skipElement(parser);
          break;
      }
    }

    return item;
  }
Ejemplo n.º 2
0
 /**
  * 加载默认项
  *
  * @param context
  * @param index
  */
 public CatGridAdapter(Context context, int index) {
   this.context = context;
   this.list = new ArrayList<CatGridAdapter.Item>();
   String[] str = this.context.getResources().getStringArray(strId[index]);
   for (int i = 0; i < NUM; i++) {
     Item o = new Item();
     o.resid = img[index][i];
     o.title = str[i];
     o.url = "";
     this.list.add(o);
   }
 }
Ejemplo n.º 3
0
  // this function creates a copy of the item passed to it, correct constructor based on the
  // itemtype
  public static Item deepCopyItem(Item copythis) {
    Item temp = null; // new Item is declared and set to null
    if (copythis.itemtype.equals("Book")) { // if the item is a Book
      temp = new Book(); // call the book constructor
      temp.price = copythis.price; // set the price of the book to the price of the new book
      temp.itemtype =
          copythis.itemtype; // set the itemtype of the book to the itemtype of the new book
      temp.sNo =
          copythis.sNo; // set the serial number of the book to the serial number of the new book
      temp.title = copythis.title; // set the title of the book to the title of the new book
    }
    if (copythis.itemtype.equals("eBook")) { // if the item is an eBook
      temp = new eBook(); // call the ebook constructor
      temp.price = copythis.price; // set the price of the eBook to the price of the new ebook
      temp.itemtype =
          copythis.itemtype; // set the itemtype of the ebook to the itemtype of the new ebook
      temp.sNo =
          copythis.sNo; // set the serial number of the ebook to the serial number of the new ebook
      temp.title = copythis.title; // set the title of the ebook to the title of the new ebook
    }
    if (copythis.itemtype.equals("CD")) { // if the item is a CD
      temp = new CD(); // call the CD constructor
      temp.price = copythis.price; // set the price of the CD to the price of the new CD
      temp.itemtype = copythis.itemtype; // set the itemtype of the CD to the itemtype of the new CD
      temp.sNo = copythis.sNo; // set the serial number of the CD to the serial number of the new CD
      temp.title = copythis.title; // set the title of the CD to the title of the new CD
    }
    if (copythis.itemtype.equals("MP3")) { // if the item is an MP3
      temp = new MP3(); // call the MP3 constructor
      temp.price = copythis.price; // set the price of the MP3 to the price of the new MP3
      temp.itemtype =
          copythis.itemtype; // set the itemtype of the MP3 to the itemtype of the new MP3
      temp.sNo =
          copythis.sNo; // set the serial number of the MP3 to the serial number of the new MP3
      temp.title = copythis.title; // set the title of the Mp3 to the title of the new MP3
    }

    return temp; // return the new item
  }
  public void reloadAdapter() {
    Map<String, String> mapData = loadMap("dates");

    data = new ArrayList<>();

    Iterator it = mapData.entrySet().iterator();
    while (it.hasNext()) {
      Map.Entry pairs = (Map.Entry) it.next();
      Item item = new Item();
      item.title = pairs.getValue().toString();
      item.id = pairs.getKey().toString();
      data.add(item);
    }

    SimpleAdapter adapter = new SimpleAdapter();

    setListAdapter(adapter);
  }
Ejemplo n.º 5
0
  @Override
  protected List<Item> buildItems() {
    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String[] projection =
        new String[] {
          ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
          ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
          ContactsContract.CommonDataKinds.Phone.NUMBER
        };

    Cursor people =
        context
            .getContentResolver()
            .query(
                uri, projection, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);

    int indexId = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.CONTACT_ID);
    int indexName = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME);
    int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

    if (contactId == null) {
      contactId = new HashMap<Item, String>();
    } else {
      contactId.clear();
    }
    List<Item> contacts = new ArrayList<Item>();
    people.moveToFirst();
    while (people.moveToNext()) {
      Item i = new Item();
      i.data = people.getString(indexNumber);
      i.title = String.format(FORMAT_TITLE, people.getString(indexName), i.data);
      i.source = this;

      contactId.put(i, people.getString(indexId));
      contacts.add(i);
    }
    people.close();

    return contacts;
  }
 public void addCircleMenu(int id, String title) {
   Item i = new Item();
   i.id = id;
   i.title = title;
   itemList.add(i);
 }