/** rss item 문자열 생성 */ private static String rssItemStr(RssItem item) { StringBuilder buffer = new StringBuilder(); buffer.append(" "); // 들여쓰기용 buffer.append("<item>"); if (item.getTitle() != null && !"".equals(item.getTitle())) buffer.append("<title>" + "<![CDATA[" + item.getTitle() + "]]>" + "</title>"); if (item.getLink() != null && !"".equals(item.getLink())) buffer.append("<link>" + item.getLink() + "</link>"); if (item.getDescription() != null && !"".equals(item.getDescription())) buffer.append( "<description>" + "<![CDATA[" + item.getDescription().replaceAll(BR, "") + "]]>" + "</description>"); if (item.getAuthor() != null && !"".equals(item.getAuthor())) buffer.append("<author>" + item.getAuthor() + "</author>"); if (item.getCategory() != null && !"".equals(item.getCategory())) buffer.append("<category>" + "<![CDATA[" + item.getCategory() + "]]>" + "</category>"); if (item.getLink() != null && !"".equals(item.getLink())) buffer.append("<guid>" + item.getLink() + "</guid>"); if (item.getPubDate() != null) buffer.append("<pubDate>" + toRfc822DateFormat(item.getPubDate()) + "</pubDate>"); buffer.append("</item>"); return buffer.toString(); }
/* (non-Javadoc) * @see javax.microedition.lcdui.ItemCommandListener#commandAction(javax.microedition.lcdui.Command, javax.microedition.lcdui.Item) */ public void commandAction(Command command, Item item) { // System.out.println("DefaultRssItemCommandListner: command ="+ command.getLabel() ); if (command == RssTagHandler.CMD_RSS_ITEM_SELECT) { RssItem rssItem = (RssItem) UiAccess.getAttribute(item, RssItem.ATTRIBUTE_KEY); String rssUrl = rssItem.getLink(); if (rssUrl != null && this.rssBrowser != null) { this.rssBrowser.getRssTagHandler().onViewUrl(rssUrl, item); } if (rssItem != null && StyleSheet.display != null) { // #style rssDescriptionAlert Alert alert = new Alert( rssItem.getTitle(), rssItem.getDescription(), null, AlertType.INFO, de.enough.polish.ui.StyleSheet.rssdescriptionalertStyle); alert.setTimeout(Alert.FOREVER); alert.addCommand(RssTagHandler.CMD_GO_TO_ARTICLE); alert.addCommand(HtmlTagHandler.CMD_BACK); alert.setCommandListener(this); StyleSheet.display.setCurrent(alert); this.url = rssItem.getLink(); } } else { this.rssBrowser.handleCommand(command); } }
/** * Called when user clicks an item in the list. Starts an activity to open the url for that item. */ @Override protected void onListItemClick(ListView l, View v, int position, long id) { // Wrokround since PullToRefreshView already has one item in this list. RssItem item = mAdapter.getItem(position - 1); // Creates and starts an intent to open the item.link url. Intent intent = new Intent(); intent.setClass(this, DetailActivity.class); intent.putExtra("data", item.getDescription()); startActivity(intent); }
public boolean insertToDB(RssItem item) { // query if it already exit Cursor cursor = getContentResolver() .query( RSSApp.RssItems.CONTENT_URI, PROJECTION, RSSApp.RssItems.COLUMN_NAME_PUBDATE + "=" + "'" + item.getPubDate() + "'", null, null); int count = 0; if (cursor != null) { count = cursor.getCount(); } if (count == 0) { ContentValues values = new ContentValues(); values.put(RSSApp.RssItems.COLUMN_NAME_TITLE, item.getTitle()); values.put(RSSApp.RssItems.COLUMN_NAME_DESCRIPTION, item.getDescription()); values.put(RSSApp.RssItems.COLUMN_NAME_PUBDATE, item.getPubDate()); Uri newUri = getContentResolver().insert(RSSApp.RssItems.CONTENT_URI, values); if (newUri != null) { log("insertToDB: " + newUri); return true; } else { log("insertToDb: fail!"); } } else { mHandler.post( new Runnable() { @Override public void run() { Toast.makeText(getApplicationContext(), "no more update !", Toast.LENGTH_SHORT) .show(); } }); log("DB already has this record : title = " + item.getTitle()); } return false; }