Programmende aktuelisiert
[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
7 import net.yacy.rss.Feed;
8 import net.yacy.rss.RSSFeedParser;
9
10 import org.apache.http.HttpResponse;
11 import org.apache.http.client.ClientProtocolException;
12 import org.apache.http.client.methods.HttpGet;
13 import org.apache.http.client.methods.HttpPost;
14 import org.apache.http.impl.client.DefaultHttpClient;
15
16 import android.app.Activity;
17 import android.net.ConnectivityManager;
18 import android.content.Context;
19 import android.os.Bundle;
20 import android.view.View;
21 import android.widget.EditText;
22 import android.widget.Toast;
23
24 public class YacyAndroidActivity extends Activity 
25 {
26         // Beispiel: http://search.yacy.net/yacysearch.html
27         // ?query=tagesspiegel&Enter=Search&verify=false
28         // &nav=hosts%2Ctopics%2Cfiletype&startRecord=0
29         // &resource=global&urlmaskfilter=.*&prefermaskfilter=
30         // &indexof=off&meanCount=5&maximumRecords=10
31         StringBuilder url = new StringBuilder("http://search.yacy.net/yacysearch.rss?query=");
32         String urlRest = new String("&Enter=Search&verify=false&nav=hosts%2Ctopics%2Cfiletype&startRecord=0&resource=global&urlmaskfilter=.*&prefermaskfilter=&indexof=off&meanCount=5&maximumRecords=10");
33         
34     /** Called when the activity is first created. */
35     @Override
36     public void onCreate(Bundle savedInstanceState) 
37     {
38         super.onCreate(savedInstanceState);
39         setContentView(R.layout.main);
40     }
41     
42     /** Send the search-query to yacy */
43     public void onClickBtnSend(View view)
44     {
45 Context context = getApplicationContext();
46         final DefaultHttpClient client = new DefaultHttpClient();
47         final HttpGet get ;
48         final HttpResponse response;
49         final EditText eingabe;
50         final StringBuilder tmp = new StringBuilder();
51         final RSSFeedParser parser = new RSSFeedParser();
52         final Feed feed; 
53         
54         try
55                 {
56                 eingabe = (EditText)findViewById(R.id.eingabe);
57                 url.append(eingabe.getText());
58                 url.append(urlRest);
59                 get = new HttpGet(url.toString());
60                 response = client.execute(get);
61                 // Rückgabe auslesen
62                 BufferedReader rd = new BufferedReader(new InputStreamReader(
63                                         response.getEntity().getContent()));
64                         String line = "";
65                                                 
66                         while ((line = rd.readLine()) != null) 
67                         {
68                                 tmp.append(line);                               
69                         
70                         }
71                         // Rückgabe parsen
72                         feed = parser.readFeed(tmp);
73 //Toast toast = Toast.makeText(context, tmp.toString(), Toast.LENGTH_LONG);                     
74 //toast.show();                         
75                 }
76                 catch (ClientProtocolException e)
77                 {
78                         // TODO Auto-generated catch block
79                         e.printStackTrace();
80                 }
81                 catch (IOException e)
82                 {
83                         // TODO Auto-generated catch block
84                         e.printStackTrace();
85                 }
86 Toast toast = Toast.makeText(context, "Programmende", Toast.LENGTH_LONG);                       
87 toast.show();           
88         
89         
90         
91     }
92 }