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
| linBoutonRechercheTexte = new LinearLayout(RestouActivity.this);
linBoutonRechercheTexte.setLayoutParams(new LayoutParams(215, 40));
View v = RestouActivity.this.getLayoutInflater().inflate(R.layout.searchbar, null);
linBoutonRechercheTexte.addView(v);
edit = (AutoCompleteTextView)v.findViewById(R.id.edit);
edit.setOnFocusChangeListener(new OnFocusChangeListener(){
public void onFocusChange(View arg0, boolean arg1) {
if(RestouActivity.this.edit.getText().toString().equals("")){
RestouActivity.this.edit.setText("Rechercher par Ville / CP");
}
}
});
edit.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
RestouActivity.this.edit.setText("");
}
});
edit.setOnEditorActionListener(new OnEditorActionListener(){
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
String texteRecherche = v.getText().toString();
if(Global.log){
Log.i("Texte à rechercher : ", texteRecherche);
}
final LocationManager lm = (LocationManager)getSystemService(RestouActivity.this.LOCATION_SERVICE);
if(wasFirstDisabled && lm.isProviderEnabled(Global.provider)){
dialog = new ProgressDialog(RestouActivity.this);
dialog.show();
dialog.setContentView(R.layout.splashscreenprogressdialog);
Log.i("", "GPS activé");
lm.requestLocationUpdates(Global.provider, 0, 0, new LocationListener(){
public void onLocationChanged(Location arg0) {
lat = String.valueOf(arg0.getLatitude());
lon = String.valueOf(arg0.getLongitude());
updatedGPS = true;
Log.e("GPS", "location changed: lat="+lat+", lon="+lon);
}
public void onProviderDisabled(String arg0) {
Log.e("GPS", "provider disabled " + arg0);
}
public void onProviderEnabled(String arg0) {
Log.e("GPS", "provider enabled " + arg0);
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
Log.e("GPS", "status changed to " + arg0 + "-" + arg1 + "-");
}
});
if(updatedGPS){
loc.setLatitude(Double.valueOf(lat));
loc.setLongitude(Double.valueOf(lon));
}else{
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(crit, true);
try{
loc = lm.getLastKnownLocation(Global.provider);
}catch(Exception e){
}
}
RestouActivity.this.launchWait();
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
wasFirstDisabled = false;
}else{
Criteria crit = new Criteria();
crit.setAccuracy(Criteria.ACCURACY_FINE);
String provider = lm.getBestProvider(crit, true);
try{
loc = lm.getLastKnownLocation(Global.provider);
}catch(Exception e){
}
RestouActivity.this.doNextSteps(1, texteRecherche);
}
RestouActivity.this.edit.setText("");
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(), 0);
return false;
}
});
//linRecherche.removeView(linBoutonRechercheTexte);
linRecherche.addView(linBoutonRechercheTexte); |
Partager