erste Daten kommen zurück
[yacyandroid:yacyandroid.git] / src / net / yacy / yacyAndroid / YacyAndroidActivity.java
1 package net.yacy.yacyAndroid;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.util.ArrayList;
7
8 import net.yacy.rss.Feed;
9 import net.yacy.rss.FeedMessage;
10 import net.yacy.rss.RSSFeedParser;
11
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;
17
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;
26
27 public class YacyAndroidActivity extends Activity 
28 {
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");
36         
37     /** Called when the activity is first created. */
38     @Override
39     public void onCreate(Bundle savedInstanceState) 
40     {
41         super.onCreate(savedInstanceState);
42         setContentView(R.layout.main);
43     }
44     
45     /** Send the search-query to yacy */
46     public void onClickBtnSend(View view)
47     {
48 Context context = getApplicationContext();
49         final DefaultHttpClient client = new DefaultHttpClient();
50         final HttpGet get ;
51         final HttpResponse response;
52         final EditText eingabe;
53         final StringBuilder tmp = new StringBuilder();
54         final RSSFeedParser parser = new RSSFeedParser();
55         final Feed feed; 
56         final ArrayList liste;
57         FeedMessage fm = new FeedMessage();
58         TextView ausgabe;
59         
60         try
61                 {
62                 // Ein- und Ausgabefeld vorbereiten
63                 eingabe = (EditText)findViewById(R.id.eingabe);
64                 ausgabe = (TextView) findViewById(R.id.ausgabe);
65                 url.append(eingabe.getText());
66                 url.append(urlRest);
67                 get = new HttpGet(url.toString());
68                 response = client.execute(get);
69                 // Rückgabe auslesen
70                 BufferedReader rd = new BufferedReader(new InputStreamReader(
71                                         response.getEntity().getContent()));
72                         String line = "";
73                                                 
74                         while ((line = rd.readLine()) != null) 
75                         {
76                                 tmp.append(line);                               
77                         
78                         }
79                         // Rückgabe parsen
80                         liste = parser.readFeed(tmp);
81                         for (int i = 0; i < liste.size(); i++)
82                         {
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());
88                         }
89 //Toast toast = Toast.makeText(context, tmp.toString(), Toast.LENGTH_LONG);                     
90 //toast.show();                         
91                 }
92                 catch (ClientProtocolException e)
93                 {
94                         // TODO Auto-generated catch block
95                         e.printStackTrace();
96                 }
97                 catch (IOException e)
98                 {
99                         // TODO Auto-generated catch block
100                         e.printStackTrace();
101                 }
102         catch (Exception e)
103                 {
104                         // TODO Auto-generated catch block
105                         e.printStackTrace();
106                 }
107 Toast toast = Toast.makeText(context, "Programmende", Toast.LENGTH_LONG);                       
108 toast.show();           
109         
110         
111         
112     }
113 }