@Override protected void onResume() { super.onResume(); boolean finish = getIntent().getBooleanExtra("FINISH", false); if (finish) { // clear user profile ClientAuthentication.initProfile(); ClientAuthentication.clearGlobalVariables(); // clear trip, recommendations, etc. Storage.clearAll(); startActivity(new Intent(MainActivity.this, LoginActivity.class)); finish(); } else { /* GetBusStops */ if (Storage.isEmptyBusStops()) { getBusStops(); } /* GetRecommendations */ if (!Storage.isEmptyRecommendations()) { displayRecommendations(); } else { getRecommendations(); } } }
public void sendGeofenceInfo() { Storage.turnLocationsToJson(); JSONObject geofenceInfo = Storage.getGeofenceInfo(); if (geofenceInfo.length() != 0) { String userID = ClientAuthentication.getClientId(); new SendStoreGeofenceInfoRequest().execute(userID, geofenceInfo.toString()); } }
@Override public void processReceivedRecommendations() { displayRecommendations(); if (!ClientAuthentication.getIfRecommendNotifyAdded()) { // add to notify ArrayList<FullTrip> recommendations = Storage.getRecommendations(); int i = 1; for (FullTrip ft : recommendations) { Intent myIntent = new Intent(MainActivity.this, RecommendationAlarmReceiver.class); myIntent.setData(Uri.parse("timer:" + i)); myIntent.putExtra("selectedTrip", ft); PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, myIntent, 0); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // notify the user half an hour before the beginning of the trip am.set(AlarmManager.RTC_WAKEUP, ft.getStartTime().getTime() - 1800000, pendingIntent); ClientAuthentication.setIfRecommendNotifyAdded(true); i++; } } }
@Override public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); if (!Storage.isEmptyLocations()) { sendGeofenceInfo(); Storage.clearLocations(); /* Wait for a second after sending the data because swiping the app off the recent app list kills any background processes immediately and the data doesn't have time to get stored in the database otherwise.*/ try { TimeUnit.SECONDS.sleep(1); } catch (java.lang.InterruptedException e) { Log.d(TAG, e.toString()); } } stopSelf(); }
// Deals with the response by the server public void processFinish(ArrayList<FullTrip> searchResults) { if (searchResults.isEmpty()) { CharSequence text = getString(R.string.java_main_noresults); Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG); toast.show(); Storage.clearSearchResults(); } Intent myIntent = new Intent(MainActivity.this, SearchActivity.class); myIntent.putExtra("destination", destination.getText().toString()); MainActivity.this.startActivity(myIntent); }
@Override public void onDestroy() { super.onDestroy(); if (mGoogleApiClient.isConnected()) { LocationServices.GeofencingApi.removeGeofences(mGoogleApiClient, getGeofencePendingIntent()) .setResultCallback(this); mGoogleApiClient.disconnect(); } if (!Storage.isEmptyLocations()) { sendGeofenceInfo(); } }
// Called when the user clicks on the quick search button public void openMainSearch(View view) { String startPositionLatitude, startPositionLongitude, edPosition, userId, startTime, endTime; String requestTime, priority; Date now = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); startPositionLatitude = String.valueOf(Storage.getLatitude()); startPositionLongitude = String.valueOf(Storage.getLongitude()); edPosition = destination.getText().toString(); userId = ClientAuthentication.getClientId(); startTime = df.format(now); requestTime = df.format(now); endTime = "null"; priority = "distance"; if (!edPosition.trim().isEmpty() && Storage.getLatitude() != 0.0 && Storage.getLongitude() != 0.0) { SendQuickTravelRequest asyncTask = new SendQuickTravelRequest(); asyncTask.delegate = this; asyncTask.execute( userId, startTime, endTime, requestTime, startPositionLatitude, startPositionLongitude, edPosition, priority); } else if (edPosition.trim().isEmpty()) { CharSequence text = getString(R.string.java_search_enterdestination); Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.show(); } else { CharSequence text = getString(R.string.java_search_locationdisabled); Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG); toast.show(); } }
@Override public void processReceivedGetBusStopsResponse() { if (!Storage.isEmptyBusStops()) { // Start the location and geofences service if the user has given permission if (checkPlayServices()) { if (Build.VERSION.SDK_INT >= 23) { checkForPermission(); } else { startService(new Intent(this, LocationService.class)); } } else { CharSequence text = getString(R.string.java_googleplaywarning); Toast toast = Toast.makeText(context, text, Toast.LENGTH_LONG); toast.show(); } } }
public void displayRecommendations() { SearchRecyclerViewAdapter adapter = new SearchRecyclerViewAdapter(Storage.getRecommendations()); recyclerView.setAdapter(adapter); }
public void goToAdvancedSearch(View v) { Storage.clearSearchResults(); startActivity(new Intent(this, SearchActivity.class)); }
private void handleNewLocation(Location location) { Storage.setLatitude(location.getLatitude()); Storage.setLongitude(location.getLongitude()); }