Back to project page Go2-Rennes.
The source code is released under:
GNU General Public License
If you think the Android project Go2-Rennes listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/******************************************************************************* * Copyright (c) 2011 Michel DAVID mimah35-at-gmail.com * /*w w w. j a va2s. co m*/ * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. ******************************************************************************/ package fr.gotorennes; import android.content.Intent; import android.location.Location; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import fr.gotorennes.util.BackgroundTask; import fr.gotorennes.util.LocationUtils; public class ProximiteActivity extends AbstractActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.proximite); } @Override protected String getTrackingName() { return "proximites"; } @Override protected void init(Intent intent) { final EditText recherche = (EditText) findViewById(R.id.recherche); Button valider = (Button) findViewById(R.id.valider); valider.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String adresse = recherche.getText().toString(); if("".equals(adresse.trim())) { getRechercheLocaleBackgroundTask().start(ProximiteActivity.this); } else { getRechercheAdresseBackgroundTask(adresse).start(ProximiteActivity.this); } } }); } protected BackgroundTask<Location> getRechercheLocaleBackgroundTask() { return new BackgroundTask<Location>() { @Override protected Location execute() { return LocationUtils.getLocation(getApplicationContext()); } @Override protected void callback(Location result) { if(result != null) { Intent intent = new Intent(ProximiteActivity.this, ProximiteResultActivity.class); intent.putExtra("latitude", result.getLatitude()); intent.putExtra("longitude", result.getLongitude()); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { showError(getString(R.string.erreurPosition)); } } }; } protected BackgroundTask<fr.gotorennes.ItineraireVeloResultActivity.Location> getRechercheAdresseBackgroundTask(final String adresse) { return new BackgroundTask<fr.gotorennes.ItineraireVeloResultActivity.Location>() { @Override protected fr.gotorennes.ItineraireVeloResultActivity.Location execute() { return ItineraireVeloResultActivity.getLocation(getApplicationContext(), adresse); } @Override protected void callback(fr.gotorennes.ItineraireVeloResultActivity.Location result) { if(result != null) { Intent intent = new Intent(ProximiteActivity.this, ProximiteResultActivity.class); intent.putExtra("latitude", result.latitude); intent.putExtra("longitude", result.longitude); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } else { showError(getString(R.string.erreurAdresse)); } } }; } @Override protected int getMapIcon() { return 0; } }