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