@Override protected void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate() + " + this.hashCode()); super.onCreate(savedInstanceState); setContentView(R.layout.activity_nexrad_view); eventBusProvider.getEventBus().register(this); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); // Create the LocationRequest object mLocationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_LOW_POWER) .setInterval(10 * 60 * 1000) // 10 seconds, in milliseconds .setFastestInterval(1 * 60 * 1000); // 1 second, in milliseconds if (PackageManager.PERMISSION_GRANTED != ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)) { ActivityCompat.requestPermissions(this, INITIAL_PERMS, INITIAL_REQUEST); } if (PreferenceManager.getDefaultSharedPreferences(this) .getString(SettingsActivity.KEY_PREF_NEXRAD_EMAILADDRESS, null) == null) { startSettings(true); } else { if (((NexradApp) getApplication()).getLastKnownLocation() != null) { RadarBitmapView radarView = (RadarBitmapView) findViewById(R.id.radarView); radarView.onEvent( new LocationChangeEvent(((NexradApp) getApplication()).getLastKnownLocation())); } } }
@Override public void onLocationChanged(Location location) { LatLongCoordinates locationLatLong = new LatLongCoordinates(location.getLatitude(), location.getLongitude()); if (((NexradApp) getApplication()).getLocationMode() == NexradApp.LocationMode.GPS) { LocationChangeEvent event = new LocationChangeEvent(locationLatLong); eventBusProvider.getEventBus().post(event); } }
@Override protected void onDestroy() { Log.d(TAG, "onDestroy() + " + this.hashCode()); super.onDestroy(); eventBusProvider.getEventBus().unregister(this); RadarBitmapView radarView = (RadarBitmapView) findViewById(R.id.radarView); if (radarView != null) { radarView.releaseBitmap(); } }
@Override public void onConnectionFailed(ConnectionResult connectionResult) { if (connectionResult.hasResolution()) { try { // Start an Activity that tries to resolve the error connectionResult.startResolutionForResult(this, CONNECTION_FAILURE_RESOLUTION_REQUEST); } catch (IntentSender.SendIntentException e) { Log.e(TAG, "Resolution of connection error failed", e); eventBusProvider .getEventBus() .post(new AppMessage("error resolving connection failure", AppMessage.Type.ERROR)); } } else { Log.i( TAG, "Location services connection failed with code " + connectionResult.getErrorCode()); eventBusProvider .getEventBus() .post( new AppMessage( "error connecting to GooglePlay services: " + connectionResult.getErrorCode(), AppMessage.Type.ERROR)); } }