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