Back to project page HereIAm.
The source code is released under:
GNU General Public License
If you think the Android project HereIAm listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/** * @author Manuel Alejandro Moscoso Dominguez * @version 0.1//ww w . ja v a2s . c o m */ package cl.mamd.here; import java.util.ArrayList; import java.util.List; import cl.mamd.here.entity.HerePoint; import android.location.GpsSatellite; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.pm.ActivityInfo; import android.util.Log; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.ToggleButton; import android.location.GpsStatus; public class MainActivity extends Activity implements LocationListener,GpsStatus.Listener { public Location dataLocation; public LocationManager locationManager; private final static String TAGNAME = "MainActivityHereIam"; private TextView latitude; private TextView longitude; private TextView altitude; private TextView speed; private TextView provider; private TextView gps; private TextView accuracity; private ToggleButton toggle; private LinearLayout layout; private List<HerePoint> values; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); setContentView(R.layout.activity_main); values = new ArrayList<HerePoint>(); /*Widgets*/ latitude = (TextView)findViewById(R.id.latitude); longitude = (TextView)findViewById(R.id.longitude); altitude = (TextView)findViewById(R.id.altitude); speed = (TextView)findViewById(R.id.speed); provider = (TextView)findViewById(R.id.provider); gps = (TextView)findViewById(R.id.gps); accuracity = (TextView)findViewById(R.id.accuracity); toggle = (ToggleButton)findViewById(R.id.toggleButtonOptions); layout = (LinearLayout)findViewById(R.id.additionalLayout); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 0, this); } public void addHerePoint(View view){ HerePoint point = new HerePoint(); point.setName("Punto "+ Integer.toString( this.values.size()+1 )); point.setLatitude(Double.valueOf(this.latitude.getText().toString())); point.setLongitude(Double.valueOf(this.longitude.getText().toString())); point.setAltitude(Double.valueOf(this.altitude.getText().toString())); point.setSpeed(Float.valueOf(this.speed.getText().toString())); point.setAccuracity(Float.valueOf((String) this.accuracity.getText())); this.values.add(point); Log.i(TAGNAME,"Adding point "+Integer.toString( this.values.size())); } /** * * @param view */ public void viewDetail(View view){ if (toggle.isChecked()) { this.layout.setVisibility(LinearLayout.VISIBLE); } else { this.layout.setVisibility(LinearLayout.GONE); } } /** * * @return String */ private String createUrl(){ String onlylat,onlylon; onlylat = latitude.getText().toString().replace(" ",""); onlylon = longitude.getText().toString().replace(" ",""); return "http://maps.google.com/maps?q=loc:"+ onlylat +"," + onlylon; } /** * * @param view */ public void openUrlMap(View view){ String onlylat,onlylon; onlylat = latitude.getText().toString().replace(" ",""); onlylon = longitude.getText().toString().replace(" ",""); Intent navigation = new Intent(Intent.ACTION_VIEW, Uri .parse("http://maps.google.com/maps?q=loc:" + onlylat +"," + onlylon)); startActivity(navigation); } /** * * @param view */ public void sendMail(View view){ String message; message = "Here i'm\n"; message = message + "Latitud:" + latitude.getText().toString() + "\n"; message = message + "Longitud:" + longitude.getText().toString() + "\n"; message = message + "precision:" + accuracity.getText().toString() + "\n"; message = message + "URL:"+createUrl(); message = message + "\n--------------------------------------\n"; Intent email = new Intent(Intent.ACTION_SEND); email.putExtra(Intent.EXTRA_EMAIL, new String[]{"manuelmoscosod@gmail.com"}); email.putExtra(Intent.EXTRA_SUBJECT, "Here i am"); email.putExtra(Intent.EXTRA_TEXT,message); email.setType("message/rfc822"); startActivity(Intent.createChooser(email, "Choose an Email client :")); } @Override public void onLocationChanged(Location location) { // TODO Auto-generated method stub latitude.setText(String.format("%9.6f",location.getLatitude())); longitude.setText(String.format("%9.6f",location.getLongitude())); altitude.setText(String.format("%9.6f",location.getAltitude())); speed.setText(String.format("%9.6f",location.getSpeed())); provider.setText(location.getProvider()); accuracity.setText(String.format("%9.6f",location.getAccuracy())); gps.setText(Integer.toString(location.getExtras().getInt("satellites"))); } @Override public void onProviderDisabled(String arg0) { // TODO Auto-generated method stub } @Override public void onProviderEnabled(String arg0) { // TODO Auto-generated method stub } @Override public void onStatusChanged(String arg0, int arg1, Bundle arg2) { // TODO Auto-generated method stub } @Override protected void onResume() { super.onResume(); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3000, 0, this); } @Override protected void onPause() { super.onPause(); locationManager.removeUpdates(this); } @Override protected void onDestroy() { super.onPause(); locationManager.removeUpdates(this); } @Override public void onGpsStatusChanged(int event) { // TODO Auto-generated method stub Iterable<GpsSatellite> iter = locationManager.getGpsStatus(null).getSatellites(); Integer count = 0; while ( iter.iterator().hasNext() ){ count++; } this.gps.setText(Integer.toString(count)); } }