summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/scatours-android-ui/src/scatours
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-06-02 06:56:59 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-06-02 06:56:59 +0000
commit27dec0710cc7da2d2eda9b49178ca1334fc756d5 (patch)
treeb0e12db11cea63f1c01253bc49e34ee114780867 /sandbox/travelsample/scatours-android-ui/src/scatours
parent504c8e86cada492c4532aa09f145e87c344270c5 (diff)
Refactoring to follow the same package naming used in other modules + renaming main activity to become search activity and introducing search results view
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@780957 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox/travelsample/scatours-android-ui/src/scatours')
-rw-r--r--sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java24
-rw-r--r--sandbox/travelsample/scatours-android-ui/src/scatours/android/TripSearch.java134
-rw-r--r--sandbox/travelsample/scatours-android-ui/src/scatours/jsonrpc/JSONRpc.java63
3 files changed, 198 insertions, 23 deletions
diff --git a/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java b/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
index 6bc36651ed..d43d5f7029 100644
--- a/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
+++ b/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
@@ -28,11 +28,7 @@ import org.json.JSONObject;
import scatours.common.TripItem;
import scatours.common.TripLeg;
-
-import android.util.Log;
-
-import com.scatours.android.R;
-import com.scatours.services.jsonrpc.JSONRpc;
+import scatours.jsonrpc.JSONRpc;
public class SCAToursSearchProxy implements SCAToursSearch {
// see http://developer.android.com/guide/developing/tools/emulator.html
@@ -81,22 +77,4 @@ public class SCAToursSearchProxy implements SCAToursSearch {
tripCatalog.toArray(catalogArray);
return catalogArray;
}
-
- public static void main(String[] args) {
- SCAToursSearch searchProxy = new SCAToursSearchProxy();
- TripLeg tripLeg = new TripLeg();
-
- tripLeg.setFromLocation("LGW");
- tripLeg.setToLocation("FLR");
- tripLeg.setFromDate("06/12/09");
- tripLeg.setToDate("13/12/09");
- tripLeg.setNoOfPeople("2");
-
- TripItem[] tripsAvailable = searchProxy.search(tripLeg);
-
- int foundTrips = tripsAvailable.length;
- System.out.println(foundTrips);
-
- }
-
}
diff --git a/sandbox/travelsample/scatours-android-ui/src/scatours/android/TripSearch.java b/sandbox/travelsample/scatours-android-ui/src/scatours/android/TripSearch.java
new file mode 100644
index 0000000000..e2eb98625b
--- /dev/null
+++ b/sandbox/travelsample/scatours-android-ui/src/scatours/android/TripSearch.java
@@ -0,0 +1,134 @@
+package scatours.android;
+
+import scatours.SCAToursSearch;
+import scatours.SCAToursSearchProxy;
+import scatours.common.TripItem;
+import scatours.common.TripLeg;
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.AdapterView;
+import android.widget.ArrayAdapter;
+import android.widget.AutoCompleteTextView;
+import android.widget.Button;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemSelectedListener;
+
+public class TripSearch extends Activity {
+
+ static final String[] AIRPORT_CODES = new String[] {
+ "LGW - London Gatwick Airport",
+ "FLR - Luigi Ridolfi Airport",
+ "SFO - San Francisco Airport",
+ "GRU - Sao Paulo Airport",
+ "GIG - Rio de Janeiro Airport"
+ };
+
+
+ private AutoCompleteTextView txtFromLocation,
+ txtToLocation,
+ txtDateStart,
+ txtDateEnd,
+ txtNumberOfPeople;
+ private Button btnSearch;
+
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.search);
+
+
+ ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, AIRPORT_CODES);
+
+ txtFromLocation = (AutoCompleteTextView) findViewById(R.id.edit_fromLocation);
+ //ArrayAdapter adapterFrom = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, AIRPORT_CODES);
+ txtFromLocation.setAdapter(adapter);
+
+ txtToLocation = (AutoCompleteTextView) findViewById(R.id.edit_toLocation);
+ //ArrayAdapter adapterTo = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, AIRPORT_CODES);
+ txtToLocation.setAdapter(adapter);
+
+ txtDateStart = (AutoCompleteTextView) findViewById(R.id.edit_date_start);
+ txtDateEnd = (AutoCompleteTextView) findViewById(R.id.edit_date_end);
+ txtNumberOfPeople = (AutoCompleteTextView) findViewById(R.id.edit_NumberOfPeople);
+
+ btnSearch = (Button) this.findViewById(R.id.btnSearch);
+
+ doListen();
+ }
+
+ private void doListen() {
+
+ txtFromLocation.setOnItemClickListener(new OnItemClickListener() {
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Log.i(getString(R.string.app_name),">>Item Clicked: " +AIRPORT_CODES[position]);
+ }
+
+ });
+
+ txtFromLocation.setOnItemSelectedListener(new OnItemSelectedListener() {
+
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
+ Log.i(getString(R.string.app_name),">>Item Selected: " +AIRPORT_CODES[position]);
+ }
+
+ public void onNothingSelected(AdapterView<?> parent) {
+ Log.i(getString(R.string.app_name),">>Selection cleared");
+ }
+
+ });
+
+
+ //closeButton
+ btnSearch.setOnClickListener( new OnClickListener() {
+ public void onClick(View v) {
+
+ doTripSearch(v);
+ /*
+ //Search trips here
+ new AlertDialog.Builder(TripSearch.this)
+ .setTitle("SCATour")
+ .setMessage("You're about to search for trips !")
+ .setIcon(R.drawable.icon)
+ .setPositiveButton(R.string.alert_yes, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int whichButton) {
+
+ }})
+ .setNegativeButton(R.string.alert_cancel, new DialogInterface.OnClickListener(){
+ public void onClick(DialogInterface dialog, int which) {
+
+ }
+ })
+ .show();*/
+ }
+ });
+
+ }
+
+
+ private void doTripSearch(View view) {
+ SCAToursSearch searchProxy = new SCAToursSearchProxy();
+ TripLeg tripLeg = new TripLeg();
+
+ Log.i(getString(R.string.app_name),"From : " + txtFromLocation.getText().toString() );
+ Log.i(getString(R.string.app_name),"To : " + txtToLocation.getText().toString() );
+ Log.i(getString(R.string.app_name),"Start Date : " + txtDateStart.getText().toString() );
+ Log.i(getString(R.string.app_name),"End Date : " + txtDateEnd.getText().toString() );
+ Log.i(getString(R.string.app_name),"NumberOfPeople : " + txtNumberOfPeople.getText().toString() );
+
+ tripLeg.setFromLocation("LGW");
+ tripLeg.setToLocation("FLR");
+ tripLeg.setFromDate("06/12/09");
+ tripLeg.setToDate("13/12/09");
+ tripLeg.setNoOfPeople("2");
+
+ TripItem[] tripsAvailable = searchProxy.search(tripLeg);
+
+ Log.i(getString(R.string.app_name),"Found " + tripsAvailable.length + " trips");
+ }
+
+} \ No newline at end of file
diff --git a/sandbox/travelsample/scatours-android-ui/src/scatours/jsonrpc/JSONRpc.java b/sandbox/travelsample/scatours-android-ui/src/scatours/jsonrpc/JSONRpc.java
new file mode 100644
index 0000000000..c6a9cd8702
--- /dev/null
+++ b/sandbox/travelsample/scatours-android-ui/src/scatours/jsonrpc/JSONRpc.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package scatours.jsonrpc;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class JSONRpc {
+
+ protected JSONRpc() {
+
+ }
+
+ public static JSONObject invoke(String serviceURI, String rpcRequest) throws JSONException{
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost httpPost = new HttpPost(serviceURI);
+
+ JSONObject result = null;
+ try {
+ httpPost.setHeader("Content-Type", "text/xml");
+ httpPost.setEntity(new StringEntity(rpcRequest));
+
+ HttpResponse httpResponse = httpClient.execute(httpPost);
+ if (httpResponse.getStatusLine().getStatusCode() == 200) {
+ String jsonResult = EntityUtils.toString(httpResponse.getEntity());
+ result = new JSONObject(jsonResult);
+ } else {
+ String errorMessage = httpResponse.getStatusLine()
+ .getReasonPhrase();
+ System.out.println(errorMessage);
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+}