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.view.View;
23 import android.widget.EditText;
24 import android.widget.TextView;
25 import android.widget.Toast;
27 public class YacyAndroidActivity extends Activity
29 // Beispiel: http://search.yacy.net/yacysearch.html
30 // ?query=tagesspiegel&Enter=Search&verify=false
31 // &nav=hosts%2Ctopics%2Cfiletype&startRecord=0
32 // &resource=global&urlmaskfilter=.*&prefermaskfilter=
33 // &indexof=off&meanCount=5&maximumRecords=10
34 StringBuilder url = new StringBuilder("http://search.yacy.net/yacysearch.rss?query=");
35 String urlRest = new String("&Enter=Search&verify=false&nav=hosts%2Ctopics%2Cfiletype&startRecord=0&resource=global&urlmaskfilter=.*&prefermaskfilter=&indexof=off&meanCount=5&maximumRecords=10");
37 /** Called when the activity is first created. */
39 public void onCreate(Bundle savedInstanceState)
41 super.onCreate(savedInstanceState);
42 setContentView(R.layout.main);
45 /** Send the search-query to yacy */
46 public void onClickBtnSend(View view)
48 Context context = getApplicationContext();
49 final DefaultHttpClient client = new DefaultHttpClient();
51 final HttpResponse response;
52 final EditText eingabe;
53 final StringBuilder tmp = new StringBuilder();
54 final RSSFeedParser parser = new RSSFeedParser();
56 final ArrayList liste;
57 FeedMessage fm = new FeedMessage();
62 // Ein- und Ausgabefeld vorbereiten
63 eingabe = (EditText)findViewById(R.id.eingabe);
64 ausgabe = (TextView) findViewById(R.id.ausgabe);
65 url.append(eingabe.getText());
67 get = new HttpGet(url.toString());
68 response = client.execute(get);
70 BufferedReader rd = new BufferedReader(new InputStreamReader(
71 response.getEntity().getContent()));
74 while ((line = rd.readLine()) != null)
80 liste = parser.readFeed(tmp);
81 for (int i = 0; i < liste.size(); i++)
83 fm = (FeedMessage) liste.get(i);
84 ausgabe.append(System.getProperty("line.separator"));
85 ausgabe.append(fm.getTitle());
86 ausgabe.append(System.getProperty("line.separator"));
87 ausgabe.append(fm.getLink());
89 //Toast toast = Toast.makeText(context, tmp.toString(), Toast.LENGTH_LONG);
92 catch (ClientProtocolException e)
94 // TODO Auto-generated catch block
99 // TODO Auto-generated catch block
104 // TODO Auto-generated catch block
107 Toast toast = Toast.makeText(context, "Programmende", Toast.LENGTH_LONG);