Android Open Source - Wikipedia-Daily-Widget Featured Article Handler






From Project

Back to project page Wikipedia-Daily-Widget.

License

The source code is released under:

GNU General Public License

If you think the Android project Wikipedia-Daily-Widget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.rmc.dfaw;
//from  w  w  w  .  j  a  v a 2 s .c  o m
import org.jsoup.Jsoup;
import org.jsoup.select.Elements;

import android.util.Log;

public class FeaturedArticleHandler extends WikiWidgetHandler {
  final static String WIKI_FEATURED_ARTICLE_PATH = "https://en.wikipedia.org/w/api.php?action=featuredfeed&feed=featured&feedformat=atom";
  final String articleEndText = "Full article...";
  public FeaturedArticleHandler() {
    super(WIKI_FEATURED_ARTICLE_PATH);

  }

  public String generateClickURL(String summary) {

    org.jsoup.nodes.Document doc = Jsoup.parse(summary);

    Elements links = doc.select("a[href]");
    String storyLink = null;
    for (int z = 0; z < links.size(); z++) {
      if (links.get(z).hasAttr("href")
          && links.get(z).text().equals(articleEndText)) {
        storyLink = links.get(z).attr("href");
      }
    }
    if (storyLink == null) {
      storyLink = "";
    }
    return WIKI_BASE_URL + storyLink;
  }

  public String extractFeaturedArticleURL(String[] story) {

    String storyLink = generateClickURL(story[SUMMARY_INDEX]);

    String storyURL = null;
    if (storyLink != null) {
      storyURL = WIKI_BASE_URL + storyLink;
    } else {
      storyURL = WIKI_BASE_URL;
      Log.e("UpdateStory", "Unable to get URL for the complete article");
    }

    return storyURL;
  }

  public String cleanupSummary(String strSummary) {
    strSummary = super.cleanupSummary(strSummary);
    String temp[] = strSummary.split("\\(Full.article");
        return temp[0] + "\nTap to see more..";
  }
}




Java Source Code List

com.rmc.dfaw.FeaturedArticleHandler.java
com.rmc.dfaw.OnThisDayHandler.java
com.rmc.dfaw.UpdateStoryService.java
com.rmc.dfaw.WikiWidgetActivity.java
com.rmc.dfaw.WikiWidgetHandler.java
com.rmc.dfaw.WikiWidgetLauncherScreen.java
com.rmc.dfaw.WikiWidgetProvider4By2.java
com.rmc.dfaw.WikiWidgetProvider4By3.java
com.rmc.dfaw.WikiWidgetProvider4By4.java
com.rmc.dfaw.WikiWidgetProviderBase.java