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