This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void startElement(String uri, String localName, String qName, Attributes atts) { | |
chars = new StringBuffer(); | |
} | |
public void characters(char ch[], int start, int length) { | |
chars.append(new String(ch, start, length)); | |
} | |
public void endElement(String uri, String localName, String qName) throws SAXException { | |
if (localName.equalsIgnoreCase("title")){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
refreshList(); | |
} | |
private void refreshList(){ | |
rssService = new RssService(this); | |
rssService.execute(BLOG_URL); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RssService extends AsyncTask<String, Void, List<Article>> { | |
private ProgressDialog progress; | |
private Context context; | |
private ArticleListFragment articleListFrag; | |
public RssService(ArticleListFragment articleListFragment) { | |
context = articleListFragment.getActivity(); | |
articleListFrag = articleListFragment; | |
progress = new ProgressDialog(context); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected List<Article> doInBackground(String... urls) { | |
String feed = urls[0]; | |
URL url = null; | |
try { | |
SAXParserFactory spf = SAXParserFactory.newInstance(); | |
SAXParser sp = spf.newSAXParser(); | |
XMLReader xr = sp.getXMLReader(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void onPostExecute(final List<Article> articles) { | |
Log.e("ASYNC", "POST EXECUTE"); | |
articleListFrag.getActivity().runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
for (Article a : articles){ | |
Log.d("DB", "Searching DB for GUID: " + a.getGuid()); | |
DbAdapter dba = new DbAdapter(articleListFrag.getActivity()); | |
dba.openToRead(); | |
Article fetchedArticle = dba.getBlogListing(a.getGuid()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArticleListAdapter adapter = new ArticleListAdapter(articleListFrag.getActivity(), articles); | |
articleListFrag.setListAdapter(adapter); | |
adapter.notifyDataSetChanged(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sqrt(x: Double): Double = ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sqrt = {x-> ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sqrtIter(guess: Double, x: Double): Double = | |
if (isGoodEnough(guess, x)) guess | |
else sqrtIter(improve(guess, x), x) | |
def improve(guess: Double, x: Double) = | |
(guess + x / guess) / 2 | |
def isGoodEnough(guess: Double, x: Double) = | |
abs(guess * guess - x) < 0.001 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Improve the guess using Newton's method | |
def improve = { guess, x -> | |
(guess + x / guess) / 2 | |
} | |
//Check if our guess is good enough, within a chosen threshold | |
def isGoodEnough = {guess, x -> | |
abs(guess * guess - x) < 0.001 | |
} |
OlderNewer