1 package net.yacy.yacyAndroid;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.util.ArrayList;
8 import net.yacy.rss.Feed;
9 import net.yacy.rss.FeedMessage;
10 import net.yacy.rss.RSSFeedParser;
12 import org.apache.http.HttpResponse;
13 import org.apache.http.client.ClientProtocolException;
14 import org.apache.http.client.methods.HttpGet;
15 import org.apache.http.client.methods.HttpPost;
16 import org.apache.http.impl.client.DefaultHttpClient;
18 import android.app.Activity;
19 import android.net.ConnectivityManager;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.text.util.Linkify;
23 import android.view.View;
24 import android.widget.EditText;
25 import android.widget.TextView;
26 import android.widget.Toast;
28 public class YacyAndroidActivity extends Activity
30 // Beispiel: http://search.yacy.net/yacysearch.html
31 // ?query=tagesspiegel&Enter=Search&verify=false
32 // &nav=hosts%2Ctopics%2Cfiletype&startRecord=0
33 // &resource=global&urlmaskfilter=.*&prefermaskfilter=
34 // &indexof=off&meanCount=5&maximumRecords=10
35 StringBuilder url = new StringBuilder("http://search.yacy.net/yacysearch.rss?query=");
36 String urlRest = new String("&Enter=Search&verify=false&nav=hosts%2Ctopics%2Cfiletype&startRecord=0&resource=global&urlmaskfilter=.*&prefermaskfilter=&indexof=off&meanCount=5&maximumRecords=10");
38 /** Called when the activity is first created. */
40 public void onCreate(Bundle savedInstanceState)
42 super.onCreate(savedInstanceState);
43 setContentView(R.layout.main);
46 /** Send the search-query to yacy */
47 public void onClickBtnSend(View view)
49 Context context = getApplicationContext();
50 final DefaultHttpClient client = new DefaultHttpClient();
52 final HttpResponse response;
53 final EditText eingabe;
54 final StringBuilder tmp = new StringBuilder();
55 final RSSFeedParser parser = new RSSFeedParser();
57 final ArrayList liste;
58 FeedMessage fm = new FeedMessage();
63 // Ein- und Ausgabefeld vorbereiten
64 eingabe = (EditText)findViewById(R.id.eingabe);
65 ausgabe = (TextView) findViewById(R.id.ausgabe);
66 url.append(eingabe.getText());
68 get = new HttpGet(url.toString());
69 response = client.execute(get);
71 BufferedReader rd = new BufferedReader(new InputStreamReader(
72 response.getEntity().getContent()));
75 while ((line = rd.readLine()) != null)
81 liste = parser.readFeed(tmp);
82 for (int i = 0; i < liste.size(); i++)
84 fm = (FeedMessage) liste.get(i);
85 ausgabe.append(System.getProperty("line.separator"));
86 ausgabe.append(fm.getLink());
87 ausgabe.append(System.getProperty("line.separator"));
88 ausgabe.append(fm.getTitle());
89 Linkify.addLinks(ausgabe, Linkify.WEB_URLS);
91 //Toast toast = Toast.makeText(context, tmp.toString(), Toast.LENGTH_LONG);
94 catch (ClientProtocolException e)
96 // TODO Auto-generated catch block
101 // TODO Auto-generated catch block
106 // TODO Auto-generated catch block
109 Toast toast = Toast.makeText(context, "Programmende", Toast.LENGTH_LONG);