public static WordEntry GetWordOfTheDay () { var entry = new WordEntry (); try { string url = "http://toolserver.org/~enwikt/wotd/"; XDocument doc = XDocument.Load (url); XElement today = doc.Root.Element ("channel").Element ("item"); entry.Title = today.Element ("title").Value; entry.Description = today.Element ("description").Value; entry.Link = today.Element ("link").Value; // Remove the date from the title entry.Title = entry.Title.Substring (entry.Title.IndexOf (':') + 1).Trim (); } catch (Exception ex) { entry.Title = "Error"; entry.Description = ex.Message; } return entry; }
// Build a widget update to show the current Wiktionary // "Word of the day." Will block until the online API returns. public RemoteViews buildUpdate(Context context) { var entry = WordEntry.GetWordOfTheDay(); // Build an update that holds the updated widget contents var updateViews = new RemoteViews(context.PackageName, Resource.Layout.widget_word); updateViews.SetTextViewText(Resource.Id.word_title, entry.Title); updateViews.SetTextViewText(Resource.Id.definition, entry.Description); // When user clicks on widget, launch to Wiktionary definition page if (!string.IsNullOrEmpty(entry.Link)) { Intent defineIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(entry.Link)); PendingIntent pendingIntent = PendingIntent.GetActivity(context, 0, defineIntent, 0); updateViews.SetOnClickPendingIntent(Resource.Id.widget, pendingIntent); } return(updateViews); }
public static WordEntry GetWordOfTheDay() { var entry = new WordEntry(); try { string url = "http://toolserver.org/~enwikt/wotd/"; XDocument doc = XDocument.Load(url); XElement today = doc.Root.Element("channel").Element("item"); entry.Title = today.Element("title").Value; entry.Description = today.Element("description").Value; entry.Link = today.Element("link").Value; // Remove the date from the title entry.Title = entry.Title.Substring(entry.Title.IndexOf(':') + 1).Trim(); } catch (Exception ex) { entry.Title = "Error"; entry.Description = ex.Message; } return(entry); }