diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-02 06:54:44 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-06-02 06:54:44 +0000 |
commit | 504c8e86cada492c4532aa09f145e87c344270c5 (patch) | |
tree | 4f247e5d3767c9feabf615989f9ff590e2b8b64b /sandbox | |
parent | 07e491b48f99c74a1913abb91a1bc72fe13bb1c5 (diff) |
Initial integration of the Android UI with Search functionality of the SCA Tour sample application. We have a json-rpc search proxy that is going to be used to connecto to remote search service and then use native android support for json in order to parse results.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@780956 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sandbox')
5 files changed, 535 insertions, 18 deletions
diff --git a/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java b/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java index 04c7c59c0c..b1191f0077 100644 --- a/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java +++ b/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java @@ -1,5 +1,9 @@ package com.scatours.android; +import scatours.SCAToursSearch; +import scatours.SCAToursSearchProxy; +import scatours.common.TripItem; +import scatours.common.TripLeg; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; @@ -7,11 +11,32 @@ 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) { @@ -21,18 +46,51 @@ public class TripSearch extends Activity { ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, AIRPORT_CODES); - AutoCompleteTextView textViewFrom = (AutoCompleteTextView) findViewById(R.id.edit_fromLocation); + txtFromLocation = (AutoCompleteTextView) findViewById(R.id.edit_fromLocation); //ArrayAdapter adapterFrom = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, AIRPORT_CODES); - textViewFrom.setAdapter(adapter); + txtFromLocation.setAdapter(adapter); - AutoCompleteTextView textViewTo = (AutoCompleteTextView) findViewById(R.id.edit_toLocation); + txtToLocation = (AutoCompleteTextView) findViewById(R.id.edit_toLocation); //ArrayAdapter adapterTo = new ArrayAdapter(this,android.R.layout.simple_dropdown_item_1line, AIRPORT_CODES); - textViewTo.setAdapter(adapter); + 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"); + } + + }); - Button closeButton = (Button) this.findViewById(R.id.btnSearch); - closeButton.setOnClickListener( new OnClickListener() { + + //closeButton + btnSearch.setOnClickListener( new OnClickListener() { public void onClick(View v) { + + doTripSearch(v); + /* //Search trips here new AlertDialog.Builder(TripSearch.this) .setTitle("SCATour") @@ -44,23 +102,35 @@ public class TripSearch extends Activity { }}) .setNegativeButton(R.string.alert_cancel, new DialogInterface.OnClickListener(){ public void onClick(DialogInterface dialog, int which) { - + } }) - .show(); - - - - + .show();*/ } }); } - - static final String[] AIRPORT_CODES = new String[] { - "LGW - London Gatwick Airport", - "FLR - Luigi Ridolfi Airport", - "SFO - San Francisco Airport" - }; + + + 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/SCAToursSearch.java b/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java new file mode 100644 index 0000000000..36a514b0b8 --- /dev/null +++ b/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java @@ -0,0 +1,29 @@ +/* + * 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; + +import scatours.common.TripItem; +import scatours.common.TripLeg; + +/** + * The Trip service interface + */ +public interface SCAToursSearch { + TripItem[] search(TripLeg tripLeg); +} diff --git a/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java b/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java new file mode 100644 index 0000000000..6bc36651ed --- /dev/null +++ b/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java @@ -0,0 +1,102 @@ +/* + * 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; + +import java.util.ArrayList; +import java.util.List; + +import org.json.JSONArray; +import org.json.JSONException; +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; + +public class SCAToursSearchProxy implements SCAToursSearch { + // see http://developer.android.com/guide/developing/tools/emulator.html + private static final String jsonRPCServiceURI = "http://10.0.2.2:8080/SCAToursComponent/SCAToursSearch"; + private static final String jsonRPCRequest = "{\"id\": 5, \"method\": \"Service.search\", \"params\": [{\"id\": \"5f9a10f2-527f-4d91-a13c-b1aa2baaedd8\", \"fromLocation\": \"LGW\", \"toLocation\": \"FLR\", \"fromDate\": \"06/12/09\", \"toDate\": \"13/12/09\", \"noOfPeople\": \"2\"}]}"; + + private List<TripItem> tripCatalog = new ArrayList<TripItem>(); + + public SCAToursSearchProxy() { + initialize(); + } + + public void initialize() { + JSONObject json = null; + + try { + json = JSONRpc.invoke(jsonRPCServiceURI, jsonRPCRequest); + + if(json == null) { + return; + } + + JSONArray result = json.getJSONArray("result"); + for(int i = 0; i < result.length(); i++) { + TripItem item = new TripItem(); + + item.setName(result.getJSONObject(i).getString("name")); + item.setDescription(result.getJSONObject(i).getString("description")); + item.setLocation(result.getJSONObject(i).getString("location")); + item.setFromDate(result.getJSONObject(i).getString("fromDate")); + item.setToDate(result.getJSONObject(i).getString("toDate")); + item.setPrice(result.getJSONObject(i).getLong("price")); + item.setCurrency(result.getJSONObject(i).getString("currency")); + + tripCatalog.add(item); + } + + } catch (JSONException e) { + e.printStackTrace(); + } + } + + + public TripItem[] search(TripLeg tripLeg) { + TripItem[] catalogArray = new TripItem[tripCatalog.size()]; + 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/common/TripItem.java b/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java new file mode 100644 index 0000000000..1fd78c8dd5 --- /dev/null +++ b/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java @@ -0,0 +1,219 @@ +/* + * 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.common; + + + +public class TripItem { + + public static String FLIGHT = "Flight"; + public static String HOTEL = "Hotel"; + public static String CAR = "Car"; + public static String TRIP = "Trip"; + + private String id; + private String tripId; + private String type; + private String name; + private String description; + private String location; + private String fromDate; + private String toDate; + private double price; + private String currency; + private String link; + private TripItem[] tripItems; // used for a trip made up of trip items + private String customerDetails; + private String agentDetails; + private String bookingCode; + + public TripItem() { + } + + public TripItem(TripItem item) { + this.id = item.getId(); + this.tripId = item.getTripId(); + this.type = item.getType(); + this.name = item.getName(); + this.description = item.getDescription(); + this.location = item.getLocation(); + this.fromDate = item.getFromDate(); + this.toDate = item.getToDate(); + this.price = item.getPrice(); + this.currency = item.getCurrency(); + this.link = item.getLink(); + } + + public TripItem(String id, + String tripId, + String type, + String name, + String description, + String location, + String fromDate, + String toDate, + double price, + String currency, + String link) { + this.id = id; + this.tripId = tripId; + this.type = type; + this.name = name; + this.description = description; + this.location = location; + this.fromDate = fromDate; + this.toDate = toDate; + this.price = price; + this.currency = currency; + this.link = link; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getTripId() { + return tripId; + } + + public void setTripId(String tripId) { + this.tripId = tripId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getFromDate() { + return fromDate; + } + + public void setFromDate(String fromDate) { + this.fromDate = fromDate; + } + + public String getToDate() { + return toDate; + } + + public void setToDate(String toDate) { + this.toDate = toDate; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public String getLink() { + return link; + } + + public void setLink(String link) { + this.link = link; + } + + public TripItem[] getTripItems() { + return tripItems; + } + + public void setTripItems(TripItem[] tripItems) { + this.tripItems = tripItems; + } + + public String getCustomerDetails() { + return customerDetails; + } + + public void setCustomerDetails(String customerDetails) { + this.customerDetails = customerDetails; + } + + public String getAgentDetails() { + return agentDetails; + } + + public void setAgentDetails(String agentDetails) { + this.agentDetails = agentDetails; + } + + public String getBookingCode() { + return bookingCode; + } + + public void setBookingCode(String bookingCode) { + this.bookingCode = bookingCode; + } + + @Override + public boolean equals(Object obj) { + + if (obj instanceof TripItem){ + if (((TripItem)obj).getId().equals(getId())){ + return true; + } + } + + return super.equals(obj); + } +} diff --git a/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java b/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java new file mode 100644 index 0000000000..1af33aa6f9 --- /dev/null +++ b/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java @@ -0,0 +1,97 @@ +/* + * 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.common; + + +public class TripLeg { + + private String id; + private String fromLocation; + private String toLocation; + private String fromDate; + private String toDate; + private String noOfPeople; + + + public TripLeg() { + } + + public TripLeg(String id, + String fromLocation, + String toLocation, + String fromDate, + String toDate, + String noOfPeople) { + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getFromLocation() { + return fromLocation; + } + + public void setFromLocation(String fromLocation) { + this.fromLocation = fromLocation; + } + + public String getToLocation() { + return toLocation; + } + + public void setToLocation(String toLocation) { + this.toLocation = toLocation; + } + + public String getFromDate() { + return fromDate; + } + + public void setFromDate(String fromDate) { + this.fromDate = fromDate; + } + + public String getToDate() { + return toDate; + } + + public void setToDate(String toDate) { + this.toDate = toDate; + } + + public String getNoOfPeople() { + return noOfPeople; + } + + public void setNoOfPeople(String noOfPeople) { + this.noOfPeople = noOfPeople; + } + + + + + + +} |