tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lrese...@apache.org
Subject svn commit: r780956 - in /tuscany/sandbox/travelsample/scatours-android-ui/src: com/scatours/android/ scatours/ scatours/common/
Date Tue, 02 Jun 2009 06:54:45 GMT
Author: lresende
Date: Tue Jun  2 06:54:44 2009
New Revision: 780956

URL: http://svn.apache.org/viewvc?rev=780956&view=rev
Log:
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.

Added:
    tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/
    tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java   (with
props)
    tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
  (with props)
    tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/
    tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java   (with
props)
    tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java   (with
props)
Modified:
    tuscany/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java

Modified: tuscany/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java?rev=780956&r1=780955&r2=780956&view=diff
==============================================================================
--- tuscany/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java
(original)
+++ tuscany/sandbox/travelsample/scatours-android-ui/src/com/scatours/android/TripSearch.java
Tue Jun  2 06:54:44 2009
@@ -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.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 @@
         
         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 @@
                     }})
                     .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

Added: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java?rev=780956&view=auto
==============================================================================
--- tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java (added)
+++ tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java Tue
Jun  2 06:54:44 2009
@@ -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);
+}

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearch.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java?rev=780956&view=auto
==============================================================================
--- tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
(added)
+++ tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
Tue Jun  2 06:54:44 2009
@@ -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);
+
+    }
+
+}

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/SCAToursSearchProxy.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java?rev=780956&view=auto
==============================================================================
--- tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java (added)
+++ tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java Tue
Jun  2 06:54:44 2009
@@ -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);
+    }
+}

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripItem.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java
URL: http://svn.apache.org/viewvc/tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java?rev=780956&view=auto
==============================================================================
--- tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java (added)
+++ tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java Tue
Jun  2 06:54:44 2009
@@ -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;
+    }
+    
+    
+    
+
+    
+  
+}

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tuscany/sandbox/travelsample/scatours-android-ui/src/scatours/common/TripLeg.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message