summaryrefslogtreecommitdiffstats
path: root/sandbox/travelsample/scatours-android-ui/src/scatours/android/TripSearch.java
blob: b64c14a583b999dd17b58911981729656e1dc0d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
package 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;
import android.content.Intent;
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");
        
        Log.i(getString(R.string.app_name),"Calling Results view...");
        
        displayTripSearchResults(tripsAvailable);
        
        /*
        try {
            Intent resultView = new Intent(this, TripSearchResults.class);
            resultView.putExtra("results", tripsAvailable);
            startActivity(resultView);
        } catch(Exception e) {
            Log.e(getString(R.string.app_name), e.getMessage());
        }
        */
        
        //TripSearchResults searchResults = new TripSearchResults(tripsAvailable);
        //searchResults.setContentView(R.layout.search_results);
        
        Log.i(getString(R.string.app_name),"Called...");

    }
    
    private void displayTripSearchResults(TripItem[] tripsAvailable) {

        String result = "";
        for(TripItem item : tripsAvailable) {
            Log.i(getString(R.string.app_name), "Item type:" + item.getType());
            if (item.getType().equals(TripItem.TRIP)) {
                result += item.getDescription() + " (" + item.getCurrency() + " " + item.getPrice() + ")\n";  
            }
        }

        
        //Search trips here
        new AlertDialog.Builder(TripSearch.this) 
        .setTitle("SCATour")
        .setMessage("Found:\n" + result)
        .setIcon(R.drawable.icon)
        .setCancelable(false)
        .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();

    }

}