package com.jens.automation2; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.Toast; public class ActivityManageSpecificPoi extends Activity { public LocationManager myLocationManager; MyLocationListenerGps myLocationListenerGps = new MyLocationListenerGps(); Location locationGps = null, locationNetwork = null; // Location locationWifi = null; MyLocationListenerNetwork myLocationListenerNetwork = new MyLocationListenerNetwork(); Button bGetPosition, bSavePoi; ImageButton ibShowOnMap; EditText guiPoiName, guiPoiLatitude, guiPoiLongitude, guiPoiRadius; private static ProgressDialog progressDialog; @Override protected void onPause() { super.onPause(); Miscellaneous.logEvent("i", "ActivityManageSpecificPoi", getResources().getString(R.string.logClearingBothLocationListeners) , 5); myLocationManager.removeUpdates(myLocationListenerGps); myLocationManager.removeUpdates(myLocationListenerNetwork); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.manage_specific_poi); myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); bGetPosition = (Button)findViewById(R.id.bGetPosition); ibShowOnMap = (ImageButton)findViewById(R.id.ibShowOnMap); guiPoiName = (EditText)findViewById(R.id.etPoiName); guiPoiLatitude = (EditText)findViewById(R.id.etPoiLatitude); guiPoiLongitude = (EditText)findViewById(R.id.etPoiLongitude); guiPoiRadius = (EditText)findViewById(R.id.etPoiRadius); bGetPosition.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hideKeyboard(); getNotificationDialog(getResources().getString(R.string.positioningWindowNotice)).show(); } }); bSavePoi = (Button)findViewById(R.id.bSavePoi); bSavePoi.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hideKeyboard(); if(ActivityMainPoi.poiToEdit == null) createPoi(); else changePoi(); } }); ibShowOnMap.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hideKeyboard(); showOnMap(); } }); if(ActivityMainPoi.poiToEdit != null) editPoi(ActivityMainPoi.poiToEdit); //else // new Poi to be created } private void createPoi() { myLocationManager.removeUpdates(myLocationListenerGps); ActivityMainPoi.poiToEdit = new PointOfInterest(); ActivityMainPoi.poiToEdit.setLocation(new Location("POINT_LOCATION")); if(loadFormValuesToVariable()) if(ActivityMainPoi.poiToEdit.create(this)) { this.setResult(RESULT_OK); finish(); } } private void changePoi() { myLocationManager.removeUpdates(myLocationListenerGps); if(loadFormValuesToVariable()) if(ActivityMainPoi.poiToEdit.change(this)) { this.setResult(RESULT_OK); finish(); } } private void getLocation() { Criteria critNetwork = new Criteria(); critNetwork.setPowerRequirement(Criteria.POWER_LOW); critNetwork.setAltitudeRequired(false); critNetwork.setSpeedRequired(false); critNetwork.setBearingRequired(false); critNetwork.setCostAllowed(false); critNetwork.setAccuracy(Criteria.ACCURACY_COARSE); Criteria critGps = new Criteria(); critGps.setAltitudeRequired(false); critGps.setSpeedRequired(false); critGps.setBearingRequired(false); critGps.setCostAllowed(true); critGps.setAccuracy(Criteria.ACCURACY_FINE); String provider1 = myLocationManager.getBestProvider(critNetwork, true); String provider2 = myLocationManager.getBestProvider(critGps, true); // String provider3 = myLocationManager.getProvider("wifi"); if(provider1 == null | provider2 == null) { Toast.makeText(this, getResources().getString(R.string.logNoSuitableProvider), Toast.LENGTH_LONG).show(); return; } else { Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider1, 3); myLocationManager.requestLocationUpdates(provider1, 500, Settings.satisfactoryAccuracyNetwork, myLocationListenerNetwork); Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.logGettingPositionWithProvider) + " " + provider2, 3); myLocationManager.requestLocationUpdates(provider2, 500, Settings.satisfactoryAccuracyGps, myLocationListenerGps); } } private void compareLocations() { if(locationGps != null) { guiPoiLatitude.setText(String.valueOf(locationGps.getLatitude())); guiPoiLongitude.setText(String.valueOf(locationGps.getLongitude())); if(locationNetwork != null) { Miscellaneous.logEvent("i", "POI Manager", getResources().getString(R.string.comparing), 4); double variance = locationGps.distanceTo(locationNetwork); String text = getResources().getString(R.string.distanceBetween) + " " + String.valueOf(Math.round(variance)) + " " + getResources().getString(R.string.radiusSuggestion); // Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG).show(); Miscellaneous.logEvent("i", "POI Manager", text, 4); // if(variance > 50 && guiPoiRadius.getText().toString().length()>0 && Integer.parseInt(guiPoiRadius.getText().toString())