Back to project page Crescendo.
The source code is released under:
GNU General Public License
If you think the Android project Crescendo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.crescendo.crescendo; /*from ww w . j a v a 2s. c o m*/ import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; import android.os.AsyncTask; import android.util.Log; public class RhymeGetter extends AsyncTask<Void, Void, String[]> { String userinput; RhymeDictionary rhyme; public RhymeGetter(String x, RhymeDictionary r){ userinput=x; rhyme=r; } @Override protected String[] doInBackground(Void... arg0) { try{ String webnames = "http://rhymebrain.com/talk?function=getRhymes&word="+userinput; URL url = new URL(webnames); URLConnection urlc = url.openConnection(); //BufferedInputStream buffer = new BufferedInputStream(urlc.getInputStream()); BufferedReader buffer = new BufferedReader(new InputStreamReader(urlc.getInputStream(), "UTF8")); StringBuilder builder = new StringBuilder(); int byteRead; while ((byteRead = buffer.read()) != -1) builder.append((char) byteRead); buffer.close(); String text=builder.toString(); String x= text; ArrayList<String> dict= new ArrayList<String>(); for (int i=0; i<x.length()-7;i++){ if (x.substring(i, i+4).equals("word")){ boolean word=false; int y=i; for (;!word;y++){ if (x.charAt(y)==','){ word=true; } } dict.add(x.substring(i+7, y-2)); Log.d("Rhyme", x.substring(i+7, y-2)); } } return dict.toArray(new String[dict.size()]); }catch(Exception e){ e.printStackTrace(); return new String[1]; } } @Override protected void onPostExecute(String[] s){ rhyme.setListView(s); } }