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
|
import android.app.Activity;
import ...
public class Ecran_creation extends Activity implements LocationListener {
/** Called when the activity is first created. */
// on déclare tout les éléments qui vont être utilisés dans cette classe ici
Button BretourCr;
Button BvaliderCr;
EditText nom;
EditText espece;
EditText description;
EditText image;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
//l'écran visible est creer.xml
setContentView(R.layout.creer);
// on attache tout les éléments crées dans la classe aux éléments existants dans "res", ici ce sont les éléments des fichiers xml
BretourCr = (Button) findViewById(R.id.B_retourCr);
BvaliderCr = (Button) findViewById(R.id.B_validerCr);
nom = (EditText) findViewById(R.id.saisie_nom);
espece= (EditText) findViewById(R.id.saisie_espece);
description= (EditText) findViewById(R.id.saisie_description);
image= (EditText) findViewById(R.id.saisie_image);
BretourCr.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
retour();
}
});
BvaliderCr.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
validerCr();
}
});
}
catch (Exception e) {
System.out.println(e);
}
}
public void retour()
{
// retour au menu principal
/*
Bundle objetbunble = new Bundle();
Intent intent = new Intent(Ecran_creation.this, NoresiActivity.class);
intent.putExtras(objetbunble);
startActivity(intent);
*/
this.closeContextMenu();
}
public void validerCr()
{
// TEST !
/****************************
* Mise à jour position *
***************************/
try {
LocationListener onLocationChange = new LocationListener() {
public void onLocationChanged(Location loc) {
double lat = loc.getLatitude();
double lon = loc.getLongitude();
System.out.println("latitude :" + lat + "\n" + "longitude :" + lon );
}
public void onProviderDisabled(String provider) {}
public void onProviderEnabled(String provider) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
};
LocationManager locationManager = (LocationManager)getSystemService( Context.LOCATION_SERVICE );
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_COARSE );
String provider = locationManager.getBestProvider( criteria, true );
if ( provider == null ) {
System.out.println("Problème");
return;
}
Location lastLocation = locationManager.getLastKnownLocation(provider);
double latitude = lastLocation.getLatitude();
double longitude = lastLocation.getLongitude();
System.out.println("latitude2 :" + latitude + "\n" + "longitude2 :" + longitude );
}
catch (Exception e) {
System.out.println("Echec :" + e);
}
}
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub
}
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
} |
Partager