コード例 #1
0
ファイル: RssActivity.java プロジェクト: hungnguyen2/NSV
 private String writeXml() {
   XmlSerializer serializer = Xml.newSerializer();
   StringWriter writer = new StringWriter();
   try {
     serializer.setOutput(writer);
     serializer.startDocument("UTF-8", true);
     serializer.startTag("", "messages");
     serializer.attribute("", "number", String.valueOf(messages.size()));
     for (Message msg : messages) {
       serializer.startTag("", "message");
       serializer.attribute("", "date", msg.getDate());
       serializer.startTag("", "title");
       serializer.text(msg.getTitle());
       serializer.endTag("", "title");
       serializer.startTag("", "url");
       serializer.text(msg.getLink().toExternalForm());
       serializer.endTag("", "url");
       serializer.startTag("", "body");
       serializer.text(msg.getDescription());
       serializer.endTag("", "body");
       serializer.endTag("", "message");
     }
     serializer.endTag("", "messages");
     serializer.endDocument();
     return writer.toString();
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
 }
コード例 #2
0
  protected void updateFeeds() {

    Log.d("swiggins", "In updateFeeds()");

    lastUpdate = new java.util.Date().getTime();
    AndroidSaxFeedParser feed = null;

    try {
      while (!feedqueue.isEmpty()) {
        Log.d("swiggins", "Clearing queue");
        feedqueue.remove();
      }

      for (String link : links) {
        feed = new AndroidSaxFeedParser(link);
        if (feed != null)
          for (Message m : feed.parse()) {
            Log.d("swiggins", "Adding message " + m.getTitle());
            feedqueue.add(m);
          }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // Collections.sort(feedqueue);

  }
コード例 #3
0
ファイル: RssActivity.java プロジェクト: hungnguyen2/NSV
 private void loadFeed(ParserType type, String feedUrl) {
   try {
     FeedParser parser = FeedParserFactory.getParser(type, feedUrl);
     long start = System.currentTimeMillis();
     messages = parser.parse();
     long duration = System.currentTimeMillis() - start;
     Log.i("AndroidNews", "Parser duration=" + duration);
     String xml = writeXml();
     Log.i("AndroidNews", xml);
     List<String> titles = new ArrayList<String>(messages.size());
     String html =
         "<html><head><meta charset=\"utf-8\" />"
             + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head>"
             + "<body style=\"text-align:justify;color:#222;margin:0;padding:10px;line-height:normal\">"
             + "<style type=\"text/css\">"
             + "a {color: #333;text-decoration:underline;} h2 a {color: #005074;text-decoration:none;} h2 {margin: 15px 0 0 0;font-size: 1.4em;font-weight:normal} "
             + "ul, li {list-style:none;margin: 5px 0;padding:0;clear:both} "
             + "em {color: #666;font-style:normal;font-size:0.9em;} img {float:left; margin: 0 5px 0 0;}"
             + "</style>"
             + "<ul>";
     for (Message msg : messages) {
       titles.add(msg.getTitle());
       html +=
           "<li>"
               + "<h2><a href=\""
               + msg.getLink()
               + "\">"
               + msg.getTitle()
               + "</a></h2>"
               + "<div style=\"padding:3px 0;\"><em>"
               + msg.getDate()
               + "</em></div>"
               + msg.getDescription()
               + "</li>";
     }
     html += "</ul></body></html>";
     wvContent.loadData(html, "text/html;charset=utf-8", "utf-8");
   } catch (Throwable t) {
     Log.e("AndroidNews", t.getMessage(), t);
   }
 }