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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
| package com.example.agence;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.app.DatePickerDialog;
import android.app.Dialog;
//import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.ActionBarActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class RechercheRapideActivity extends ActionBarActivity implements View.OnClickListener {
private Fonction_BDD datasource;
Button rechercher = null;//déclaration du bouton retour
//
Date d;
Date f;
long ff=9223372036854775807L;
Date d1;
Date f1;
static String Age="cc";
String value;
static String Age1="ccd";
String value1;
static String Age2="cca";
String value2;
static String Age3="ccv";
String value3;
static String Age4="ccqs";
String value4;
static String Age5="cch";
String value5;
static String Age6="cckiu";
String value6;
static String Age7="ccmpol";
String value7;
static String Age8="ccbv";
String value8="ll";
RadioGroup group = null;
private AutoCompleteTextView autocompleteCountry= null;
private AutoCompleteTextView autocompleteCountry2= null;
// private AutoCompleteTextView DateDeDepart= null; // date de départ
// private AutoCompleteTextView DateDeRetour= null; // date de retour
//private Button startPickDate; // déclaration du bouton calendrier aller
//private Button endPickDate; //déclaration du bouton calendrier retour
//private Calendar startDate;
//private Calendar endDate;
//static final int DATE_DIALOG_ID = 0;
//private TextView activeDateDisplay;
//private Calendar activeDate;
private EditText mStartTime;
private EditText mEndTime;
private DatePickerDialogFragment mDatePickerDialogFragment;
String[] cl = { "Economique", "Affaires", "Première" }; //valeurs possibles pr le spinner classe
String[] premierDigit = { "1","2","3","4","5","6","7","8","9"}; //valeurs possibles pr le spinner adultes
String[] deuxiemeDigit = {"0", "1","2","3"}; //valeurs possibles pr le spinner enfants
String[] troisiemeDigit = {"0","1", "2","3", "4","5","6"}; //valeurs possibles pr le spinner bébés
Spinner s; // spinner classe
Spinner s1; //spinner adultes
Spinner s2; //spinner enfants
Spinner s3; //spinner bébés
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recherche_rapide);
getSupportActionBar().hide();
mStartTime = (EditText) findViewById(R.id.start_date);
mEndTime = (EditText) findViewById(R.id.end_date);
mDatePickerDialogFragment = new DatePickerDialogFragment();
mStartTime.setOnClickListener(this);
mEndTime.setOnClickListener(this);
/* capture our View elements for the start date function */
// startDateDisplay = (TextView) findViewById(R.id.startDateDisplay);
// DateDeDepart = (AutoCompleteTextView) findViewById(R.id.DateDeDepart);
// startPickDate = (Button) findViewById(R.id.startPickDate);
/* get the current date */
// startDate = Calendar.getInstance();
/* add a click listener to the button
startPickDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDateDialog(DateDeDepart, startDate);
}
});
capture our View elements for the end date function
// DateDeRetour = (TextView) findViewById(R.id.DateDeRetour);
DateDeRetour = (AutoCompleteTextView) findViewById(R.id.DateDeRetour);
endPickDate = (Button) findViewById(R.id.endPickDate);
get the current date
endDate = Calendar.getInstance();
add a click listener to the button
endPickDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDateDialog(DateDeRetour, endDate);
}
});
display the current date (this method is below)
updateDisplay(DateDeDepart, startDate);
updateDisplay(DateDeRetour, endDate);
*/
rechercher = (Button)findViewById(R.id.rechercher);
rechercher.setOnClickListener(rechercherListener);
s = (Spinner) findViewById(R.id.classe);
ArrayAdapter<String> adapter0 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cl);
s.setAdapter(adapter0);
s1 = (Spinner) findViewById(R.id.Adultes);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, premierDigit);
s1.setAdapter(adapter1);
s2 = (Spinner) findViewById(R.id.Enfants);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, deuxiemeDigit);
s2.setAdapter(adapter2);
s3 = (Spinner) findViewById(R.id.bebes);
ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, troisiemeDigit);
s3.setAdapter(adapter3);
autocompleteCountry = (AutoCompleteTextView) findViewById(R.id.autocompleteCountry);
autocompleteCountry2 = (AutoCompleteTextView) findViewById(R.id.autocompleteCountry2);
datasource = new Fonction_BDD(RechercheRapideActivity.this);
datasource.open();
String[] countries = datasource.getAllCountriesss();
String[] countries_Arr = datasource.getAllCountriesss_Arr();
// Print out the values to the log
for(int i = 0; i < countries.length; i++)
{
Log.i(this.toString(), countries[i]);
}
for(int i = 0; i < countries_Arr.length; i++)
{
Log.i(this.toString(), countries_Arr[i]);
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item_1, countries);
autocompleteCountry.setAdapter(adapter);
ArrayAdapter<String> adapter11 = new ArrayAdapter<String>(this, R.layout.list_item_2, countries_Arr);
autocompleteCountry2.setAdapter(adapter11);
group = (RadioGroup)findViewById(R.id.group);
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.start_date) {
mDatePickerDialogFragment.setFlag(DatePickerDialogFragment.FLAG_START_DATE);
mDatePickerDialogFragment.show(getSupportFragmentManager(), "datePicker");
} else if (id == R.id.end_date) {
mDatePickerDialogFragment.setFlag(DatePickerDialogFragment.FLAG_END_DATE);
mDatePickerDialogFragment.show(getSupportFragmentManager(), "datePicker");
}
}
public class DatePickerDialogFragment extends DialogFragment implements
DatePickerDialog.OnDateSetListener {
public static final int FLAG_START_DATE = 0;
public static final int FLAG_END_DATE = 1;
private int flag = 0;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void setFlag(int i) {
flag = i;
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar calendar = Calendar.getInstance();
calendar.set(year, monthOfYear, dayOfMonth);
SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy");
if (flag == FLAG_START_DATE) {
mStartTime.setText(format.format(calendar.getTime()));
} else if (flag == FLAG_END_DATE) {
mEndTime.setText(format.format(calendar.getTime()));
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private OnClickListener rechercherListener = new OnClickListener() {
@Override
public void onClick(View v) {
value= s.getSelectedItem().toString();
value1= s1.getSelectedItem().toString();
value2=s2.getSelectedItem().toString();
value3=s3.getSelectedItem().toString();
value4=autocompleteCountry.getText().toString();
value5=autocompleteCountry2.getText().toString();
value6=mStartTime.getText().toString();
value7=mEndTime.getText().toString();
final RadioButton group1_c =(RadioButton)findViewById(group.getCheckedRadioButtonId());
String r1=(String)group1_c.getText();
datasource.open();
// Client tabb=null;
// tabb=values.toArray(tabb);
int rep=0;
boolean livreFromBdd = datasource.checkNom_aero(value4);
//Si un livre est retourné (donc si le livre à bien été ajouté à la BDD)
if(livreFromBdd != true){
rep=rep+1;
}
int rep1=0;
boolean livreFromBdd1 = datasource.checkNom_aero_arr(value5);
//Si un livre est retourné (donc si le livre à bien été ajouté à la BDD)
if(livreFromBdd1 != true){
rep1=rep1+1;
}
datasource.close();
if(((value4.equals(""))|| (value5.equals(""))|| (value6.equals("")))&&(r1.equals(" Aller-simple"))){
message();
}
else if(((value4.equals(""))|| (value5.equals(""))|| (value6.equals(""))|| (value7.equals("")))&&(r1.equals(" Aller - retour"))){
message();
}
else if((rep>0) &(rep1>0)){
rep=0;
rep1=0;
message_dep_arr();
}
else if(rep>0){
rep=0;
message_dep();
}
else if(rep1>0){
rep1=0;
message_arr();
}
else{
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
try {
d = sdf.parse(value6);
if(!value7.equals(""))
f = sdf.parse(value7);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long dd= d.getTime();
if(!value7.equals(""))
{ ff=f.getTime();
}
if(dd>ff){
boite();
//la date debu est sup a date fin
}
else{
//if(group.getCheckedRadioButtonId() == R.id.group)
// value8="2";
Intent secondeActivite=new Intent(RechercheRapideActivity.this, ResultatRechercheRapideActivity.class);
// Bundle bundleExtras =new Bundle();
// bundleExtras.putString(Age,value);
//secondeActivite.putExtras(bundleExtras) ;
secondeActivite.putExtra(Age,value);
secondeActivite.putExtra(Age1,value1);
secondeActivite.putExtra(Age2,value2);
secondeActivite.putExtra(Age3,value3);
secondeActivite.putExtra(Age4,value4);
secondeActivite.putExtra(Age5,value5);
secondeActivite.putExtra(Age6,value6);
secondeActivite.putExtra(Age7,value7);
secondeActivite.putExtra(Age8,r1);
startActivity(secondeActivite);}}
}
};
/*
private void updateDisplay(TextView dateDisplay, Calendar date) {
dateDisplay.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(date.get(Calendar.DAY_OF_MONTH)).append(" ")
.append(date.get(Calendar.MONTH)+ 1).append(" ")
.append(date.get(Calendar.YEAR)).append(""));
}
public void showDateDialog(TextView dateDisplay, Calendar date) {
activeDateDisplay = dateDisplay;
activeDate = date;
showDialog(DATE_DIALOG_ID);
}
private OnDateSetListener dateSetListener = new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
activeDate.set(Calendar.YEAR, year);
activeDate.set(Calendar.MONTH, monthOfYear);
activeDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
updateDisplay(activeDateDisplay, activeDate);
unregisterDateDisplay();
}
};
private void unregisterDateDisplay() {
activeDateDisplay = null;
activeDate = null;
}
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, dateSetListener, activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
}
return null;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog);
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(activeDate.get(Calendar.YEAR), activeDate.get(Calendar.MONTH), activeDate.get(Calendar.DAY_OF_MONTH));
break;
}
}*/
private TextWatcher textWatcher = new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
};
public void message(){
Toast v=Toast.makeText(this, " Veuillez remplir tous les champs ", Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout) v.getView();
if (layout.getChildCount() > 0) {
TextView tv = (TextView) layout.getChildAt(0);
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
v.setGravity(Gravity.CENTER, 0, 0);
v.show();
}
public void message_dep(){
Toast v=Toast.makeText(this, " L'aéroport "+value4+" n'existe pas ", Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout) v.getView();
if (layout.getChildCount() > 0) {
TextView tv = (TextView) layout.getChildAt(0);
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
v.setGravity(Gravity.CENTER, 0, 0);
v.show();
}
public void message_dep_arr(){
Toast v=Toast.makeText(this, " L'aéroport "+value4+" et "+value5+" n'existent pas ", Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout) v.getView();
if (layout.getChildCount() > 0) {
TextView tv = (TextView) layout.getChildAt(0);
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
v.setGravity(Gravity.CENTER, 0, 0);
v.show();
}
public void message_arr(){
Toast v=Toast.makeText(this, " L'aéroport "+value5+" n'existe pas ", Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout) v.getView();
if (layout.getChildCount() > 0) {
TextView tv = (TextView) layout.getChildAt(0);
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
v.setGravity(Gravity.CENTER, 0, 0);
v.show();
}
public void boite(){
Toast v= Toast.makeText(this, " La date de départ est supérieure à la date de retour ", Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout) v.getView();
if (layout.getChildCount() > 0) {
TextView tv = (TextView) layout.getChildAt(0);
tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
}
v.setGravity(Gravity.CENTER, 0, 0);
v.show();
}
} |
Partager