Advertisement
Neshoz

Untitled

Feb 18th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 24.85 KB | None | 0 0
  1. package se.malmo.lighthouse.siberianhusky;
  2.  
  3. import android.Manifest;
  4. import android.annotation.TargetApi;
  5. import android.app.AlertDialog;
  6. import android.app.NotificationManager;
  7. import android.app.PendingIntent;
  8. import android.content.BroadcastReceiver;
  9. import android.content.Context;
  10. import android.content.DialogInterface;
  11. import android.content.Intent;
  12. import android.content.IntentFilter;
  13. import android.content.pm.PackageManager;
  14. import android.location.Location;
  15. import android.os.Bundle;
  16. import android.support.annotation.NonNull;
  17. import android.support.v4.app.ActivityCompat;
  18. import android.support.v4.app.NotificationCompat;
  19. import android.support.v4.content.ContextCompat;
  20. import android.util.Log;
  21. import android.view.View;
  22. import android.widget.Button;
  23. import android.widget.SeekBar;
  24. import android.widget.TextView;
  25. import android.widget.Toast;
  26.  
  27. import com.google.android.gms.maps.CameraUpdateFactory;
  28. import com.google.android.gms.maps.GoogleMap;
  29. import com.google.android.gms.maps.OnMapReadyCallback;
  30. import com.google.android.gms.maps.SupportMapFragment;
  31. import com.google.android.gms.maps.model.LatLng;
  32.  
  33. import java.util.ArrayList;
  34. import java.util.HashMap;
  35. import java.util.List;
  36. import java.util.Map;
  37.  
  38. import se.malmo.lighthouse.siberianhusky.Services.SavedRouteService;
  39. import se.malmo.lighthouse.siberianhusky.models.Contact;
  40. import se.malmo.lighthouse.siberianhusky.models.MapLocationDrawer;
  41. import se.malmo.lighthouse.siberianhusky.models.Route;
  42. import se.malmo.lighthouse.siberianhusky.models.RouteCoordinate;
  43. import se.malmo.lighthouse.siberianhusky.models.SMSClass;
  44. import se.malmo.lighthouse.siberianhusky.repositories.DataBaseFetcher;
  45. import se.malmo.lighthouse.siberianhusky.utils.Constants;
  46. import se.malmo.lighthouse.siberianhusky.utils.DistanceConverter;
  47. import se.malmo.lighthouse.siberianhusky.utils.NotificationWrapper;
  48.  
  49. public class RunSelectedRouteActivity extends ToolbarMenu implements OnMapReadyCallback, SeekBar.OnSeekBarChangeListener, GoogleMap.OnMapLoadedCallback {
  50.  
  51.     public static final int MY_PERMISSIONS_REQUEST_CODE = 100;
  52.     private List<Contact> emergencyList;
  53.     private DataBaseFetcher dataBaseFetcher;
  54.     private Route route;
  55.     private GoogleMap map;
  56.     private MapLocationDrawer mapLocationDrawer;
  57.     private List<LatLng> polyList;
  58.    
  59.     private boolean paused;
  60.     private boolean isWithin;
  61.     private boolean hasReceievedBroadcast;
  62.     private int routeIDHolder;
  63.     private AlertDialog dialog;
  64.     private AlertDialog.Builder builder;
  65.  
  66.     private TextView sliderText;
  67.     private SeekBar slideBar;
  68.     private Button emergencyButton;
  69.     private Button pauseOrResumeButton;
  70.     private boolean minimized = false;
  71.     private boolean serviceIsRunning;
  72.  
  73.     private Location lastLocation;
  74.     private Location currentLocation;
  75.     private BroadcastReceiver broadcastReceiver;
  76.  
  77.     @Override
  78.     protected void onCreate(Bundle savedInstanceState) {
  79.         super.onCreate(savedInstanceState);
  80.         setContentView(R.layout.tracking_activity);
  81.  
  82.         SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
  83.         mapFragment.getMapAsync(this);
  84.  
  85.         dataBaseFetcher = new DataBaseFetcher(this);
  86.         route = dataBaseFetcher.getRouteByID(getIntent().getExtras().getInt("routeID"));
  87.         emergencyList = dataBaseFetcher.getAllContacts();   // Get contacts
  88.         mapLocationDrawer = new MapLocationDrawer(this);
  89.         polyList = new ArrayList<>();
  90.         routeIDHolder = route.getRouteID();
  91.  
  92.         for (RouteCoordinate rc : route.getRouteCoordinates()) {
  93.             LatLng latLng = new LatLng(rc.getLatitude(), rc.getLongtitude());
  94.             polyList.add(latLng);
  95.         }
  96.  
  97.         /**
  98.          * Init the last location
  99.          */
  100.         lastLocation = new Location("Destination");
  101.         lastLocation.setLatitude(polyList.get(polyList.size() - 1).latitude);
  102.         lastLocation.setLongitude(polyList.get(polyList.size() - 1).longitude);
  103.  
  104.         /**
  105.          * Get everything necessary from View
  106.          */
  107.         pauseOrResumeButton = (Button) findViewById(R.id.tracking_activity_pause_resume);
  108.         Button finishButton = (Button) findViewById(R.id.tracking_activity_finish);
  109.         emergencyButton = (Button) findViewById(R.id.tracking_activity_Emergency);
  110.         slideBar = (SeekBar) findViewById(R.id.seekbar);
  111.         sliderText = (TextView) findViewById(R.id.slider_text);
  112.  
  113.         sliderText.setText(R.string.slide_to_send);
  114.         slideBar.setOnSeekBarChangeListener(this);
  115.         paused = false;
  116.         /**
  117.          * Either pause or resume
  118.          */
  119.         pauseOrResumeButton.setOnClickListener(new View.OnClickListener() {
  120.             @Override
  121.             public void onClick(View v) {
  122.                 if (!paused) {
  123.                     paused = true;
  124.                     pauseOrResumeButton.setText("Resume");
  125.                     Intent intent = new Intent(RunSelectedRouteActivity.this, SavedRouteService.class);
  126.                     stopService(intent);
  127.                     serviceIsRunning = false;
  128.                 } else {
  129.                     paused = false;
  130.                     pauseOrResumeButton.setText("Pause");
  131.                     Intent intent = new Intent(RunSelectedRouteActivity.this, SavedRouteService.class);
  132.                     Bundle bundle = new Bundle();
  133.                     bundle.putInt("routeID", route.getRouteID());
  134.                     intent.putExtras(bundle);
  135.                     startService(intent);
  136.                     serviceIsRunning = true;
  137.                 }
  138.             }
  139.         });
  140.  
  141.         /**
  142.          * User clicked on finish, code below is pretty self explanatory.
  143.          */
  144.         finishButton.setOnClickListener(new View.OnClickListener() {
  145.             @Override
  146.             public void onClick(View v) {
  147.                 String distanceType = dataBaseFetcher.getSettings().getDistanceType();
  148.                 double distanceToLast = 0;
  149.  
  150.  
  151.                 if (currentLocation != null && lastLocation != null) {
  152.                     distanceToLast = currentLocation.distanceTo(lastLocation);
  153.  
  154.                     if (DistanceConverter.isKilometers(distanceType) && distanceToLast < 1000) { // meter is displayed
  155.                         distanceType = "m";
  156.                     } else { // km or miles is displayed
  157.                         distanceToLast = DistanceConverter.convertDistance(distanceToLast, distanceType);
  158.                     }
  159.                 }
  160.  
  161.                 builder = new AlertDialog.Builder(RunSelectedRouteActivity.this);
  162.                 builder.setMessage(getString(R.string.finish_dialog, distanceToLast, distanceType));
  163.  
  164.                 builder.setPositiveButton("Finish", new DialogInterface.OnClickListener() {
  165.                     @Override
  166.                     public void onClick(DialogInterface dialog, int which) {
  167.                         if (broadcastReceiver != null) {
  168.                             unregisterReceiver(broadcastReceiver);
  169.                         }
  170.                         /**
  171.                          * Kill the service and send the user back to the start menu
  172.                          */
  173.                         Intent intent = new Intent(RunSelectedRouteActivity.this, SavedRouteService.class);
  174.                         stopService(intent);
  175.                         intent = new Intent(RunSelectedRouteActivity.this, StartMenuActivity.class);
  176.                         startActivity(intent);
  177.                         dialog.dismiss();
  178.                     }
  179.                 });
  180.                 /**
  181.                  * Just do nothing
  182.                  */
  183.                 builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  184.                     @Override
  185.                     public void onClick(DialogInterface dialog, int which) {
  186.                         dialog.dismiss();
  187.                     }
  188.                 });
  189.  
  190.                 builder.create();
  191.                 builder.show();
  192.             }
  193.         });
  194.  
  195.         /**
  196.          * Send emergency SMS
  197.          */
  198.         emergencyButton.setOnClickListener(new View.OnClickListener() {
  199.             @Override
  200.             public void onClick(View v) {
  201.                 emergencyButtonHandler(); // Run send emergency.
  202.                 resetSlider();
  203.             }
  204.         });
  205.     }
  206.  
  207.     /**
  208.      * Seekbar methods
  209.      *
  210.      */
  211.     @Override
  212.     public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
  213.         if (progress > Constants.P_95) {
  214.             seekBar.setThumb(ContextCompat.getDrawable(this, R.drawable.slider_icon));
  215.         }
  216.     }
  217.  
  218.     /**
  219.      * Displaying a double with very many decimals isn't very useful for the user, so I wrote a method to simply convert a double to something more appropriate to show the user.
  220.      * Converts a double, if it's below 1k, only pull the meters from the double, if it's above 1k, convert it do display something like: x.yy
  221.      *
  222.      * @param convertFrom the double you want to convert
  223.      * @return the converted double
  224.      */
  225.     private Double convertDouble(double convertFrom) {
  226.         double converted = 0;
  227.         String value = String.valueOf(convertFrom);
  228.  
  229.         if (convertFrom < 1000) {
  230.             String s = value.substring(0, 3);
  231.             converted = Double.parseDouble(s);
  232.         } else if (convertFrom > 1000) {
  233.             char[] parts = new char[]{
  234.                     value.charAt(0),
  235.                     '.',
  236.                     value.charAt(1),
  237.                     value.charAt(2)
  238.             };
  239.             String s = String.valueOf(parts);
  240.             converted = Double.parseDouble(s);
  241.         }
  242.  
  243.         return converted;
  244.     }
  245.  
  246.     @Override
  247.     public void onStartTrackingTouch(SeekBar seekBar) {
  248.         sliderText.setVisibility(View.INVISIBLE);
  249.     }
  250.  
  251.     @Override
  252.     public void onStopTrackingTouch(SeekBar seekBar) {
  253.         Log.d("onStopTrackingTouch", "onStopTrackingTouch");
  254.         if (seekBar.getProgress() < Constants.P_80) {
  255.             seekBar.setProgress(Constants.ZERO);
  256.             slideBar.setBackgroundResource(R.drawable.slider_bg_red);
  257.             sliderText.setVisibility(View.VISIBLE);
  258.             sliderText.setText(R.string.slide_to_send);
  259.  
  260.         } else {
  261.             seekBar.setProgress(Constants.P_100);
  262.             sliderText.setVisibility(View.VISIBLE);
  263.             sliderText.setText(R.string.click_to_send);
  264.             slideBar.setVisibility(View.INVISIBLE);
  265.             emergencyButton.setVisibility(View.VISIBLE);
  266.  
  267.         }
  268.     }
  269.  
  270.     private void resetSlider() {
  271.         slideBar.setVisibility(View.VISIBLE);
  272.         slideBar.setProgress(Constants.ZERO);
  273.         emergencyButton.setVisibility(View.INVISIBLE);
  274.         slideBar.setBackgroundResource(R.drawable.slider_bg_red);
  275.         sliderText.setVisibility(View.VISIBLE);
  276.         sliderText.setText(R.string.slide_to_send);
  277.     }
  278.  
  279.     /**
  280.      * Check SEND_SMS and ACCESS_FINE_LOCATION permissions
  281.      */
  282.     @TargetApi(23)
  283.     private boolean checkAndRequestPermissions() {
  284.         int sendSMSPermission = checkSelfPermission(android.Manifest.permission.SEND_SMS);
  285.         int accessFineLocationPermission = checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION);
  286.         List<String> listPermissionsNeeded = new ArrayList<>();
  287.         if (sendSMSPermission != PackageManager.PERMISSION_GRANTED) {
  288.             listPermissionsNeeded.add(Manifest.permission.SEND_SMS);
  289.         }
  290.         if (accessFineLocationPermission != PackageManager.PERMISSION_GRANTED) {
  291.             listPermissionsNeeded.add(Manifest.permission.ACCESS_FINE_LOCATION);
  292.         }
  293.         if (!listPermissionsNeeded.isEmpty()) {
  294.             requestPermissions(listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]), MY_PERMISSIONS_REQUEST_CODE);
  295.             return false;
  296.         }
  297.         return true;
  298.     }
  299.  
  300.     @TargetApi(23)
  301.     @Override
  302.     public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  303.         switch (requestCode) {
  304.             case MY_PERMISSIONS_REQUEST_CODE: {
  305.                 Map<String, Integer> permissionsMap = new HashMap<>();
  306.                 // Initialize the map with both permissions
  307.                 permissionsMap.put(Manifest.permission.SEND_SMS, PackageManager.PERMISSION_GRANTED);
  308.                 permissionsMap.put(Manifest.permission.ACCESS_FINE_LOCATION, PackageManager.PERMISSION_GRANTED);
  309.  
  310.                 // Fill with actual results from user
  311.                 if (grantResults.length > Constants.ZERO) {
  312.                     for (int i = Constants.ZERO; i < permissions.length; i++) {
  313.                         permissionsMap.put(permissions[i], grantResults[i]);
  314.                     }
  315.                     // Check for both permissions
  316.                     if (permissionsMap.get(Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED && permissionsMap.get(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
  317.  
  318.                         Toast.makeText(RunSelectedRouteActivity.this, "Both Permissions Granted", Toast.LENGTH_SHORT)
  319.                                 .show();
  320.  
  321.                     } else {
  322.                         // Permission is denied (this is the first time, when "never ask again" is not checked) so ask again explaining the usage of permission
  323.                         // shouldShowRequestPermissionRationale will return true
  324.                         // Show the dialog or snackbar saying its necessary and try again otherwise proceed with setup.
  325.                         if (shouldShowRequestPermissionRationale(Manifest.permission.SEND_SMS) || shouldShowRequestPermissionRationale(Manifest.permission.ACCESS_FINE_LOCATION)) {
  326.                             showDialogOK("SMS and Location Services Permission required for this app", new DialogInterface.OnClickListener() {
  327.                                 @Override
  328.                                 public void onClick(DialogInterface dialog, int which) {
  329.                                     switch (which) {
  330.                                         case DialogInterface.BUTTON_POSITIVE:
  331.                                             checkAndRequestPermissions();
  332.                                             break;
  333.                                         case DialogInterface.BUTTON_NEGATIVE:
  334.                                             // proceed with logic by disabling the related features or quit the app.
  335.                                             break;
  336.                                     }
  337.                                 }
  338.                             });
  339.                         } else {
  340.                             Toast.makeText(this, "Go to settings and enable permissions", Toast.LENGTH_LONG)
  341.                                     .show();
  342.                             //proceed with logic by disabling the related features or quit the app.                        }
  343.                         }
  344.                     }
  345.                 }
  346.             }
  347.             default:
  348.                 super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  349.         }
  350.     }
  351.  
  352.     /**
  353.      * Called when user clicks Emergency button
  354.      */
  355.     public void emergencyButtonHandler() {
  356.         //if permissions are ok
  357.         if (checkAndRequestPermissions()) {
  358.  
  359.             SMSClass smsClass = new SMSClass(this);
  360.  
  361.             if (emergencyList.size() > Constants.ZERO) {
  362.  
  363.                 smsClass.sendSMS(emergencyList, currentLocation.getLatitude(), currentLocation.getLongitude(), dataBaseFetcher.getSettings().getUserTextMessage());
  364.                 Toast.makeText(this, "Emergency SMS sent!", Toast.LENGTH_SHORT).show();
  365.  
  366.             } else {
  367.                 // else - show alert - OK: go to add contact, Cancel: go to start menu.
  368.                 builder = new AlertDialog.Builder(this);
  369.                 builder.setTitle(R.string.no_ICE_title)
  370.                         .setMessage(R.string.no_ICE_msg)
  371.                         .setPositiveButton(R.string.add_edit_contact, new DialogInterface.OnClickListener() {
  372.  
  373.                             @Override
  374.                             public void onClick(DialogInterface dialogInterface, int id) {
  375.                                 // Go to contacts
  376.                                 Intent intent = new Intent(getBaseContext(), ContactActivity.class);
  377.                                 startActivity(intent);
  378.                             }
  379.                         })
  380.                         .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  381.                                     @Override
  382.                                     public void onClick(DialogInterface dialogInterface, int id) {
  383.                                     }
  384.                                 }
  385.                         );
  386.                 dialog = builder.create();
  387.                 dialog.setCanceledOnTouchOutside(false);
  388.                 dialog.setCancelable(false);
  389.                 dialog.show();
  390.             }
  391.         }
  392.         resetSlider();
  393.     }
  394.  
  395.     // Show dialog.
  396.     private void showDialogOK(String message, DialogInterface.OnClickListener okListener) {
  397.         new AlertDialog.Builder(this)
  398.                 .setMessage(message)
  399.                 .setPositiveButton("OK", okListener)
  400.                 .setNegativeButton("Cancel", okListener)
  401.                 .create()
  402.                 .show();
  403.     }
  404.  
  405.     @Override
  406.     public void onMapReady(GoogleMap googleMap) {
  407.         map = googleMap;
  408.         map.setOnMapLoadedCallback(this);
  409.         googleMap.setMapType(dataBaseFetcher.getSettings().getMapType());
  410.  
  411.         /**
  412.          * To avoid NullPointerException we check if the list is empty or not before we perform any logic including it. Get the first coordinate and place a marker from our own class
  413.          * Why not just place the marker without it? Because if we have a method inside it zoom within all the marker positions we "draw" with our drawer.
  414.          * Simply get the first and last index, place markers and zoom within is, kids stuff.
  415.          */
  416.         if (!polyList.isEmpty()) {
  417.             googleMap.addMarker(mapLocationDrawer.addStartLocationMarkerToMap(polyList.get(0)));
  418.             googleMap.addMarker(mapLocationDrawer.addEndLocationMarkerToMap(polyList.get(polyList.size() - 1)));
  419.             mapLocationDrawer.drawRoute(googleMap, polyList);
  420.             map.moveCamera(CameraUpdateFactory.zoomTo(dataBaseFetcher.getSettings().getZoomMap()));
  421.         }
  422.  
  423.         if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
  424.             googleMap.setMyLocationEnabled(true);
  425.         }
  426.     }
  427.  
  428.     @Override
  429.     public void onMapLoaded(){
  430.  
  431.     }
  432.  
  433.     /**
  434.      * Disable the back button
  435.      */
  436.     @Override
  437.     public void onBackPressed() {
  438.         if(!paused){
  439.             Toast.makeText(RunSelectedRouteActivity.this, "You must pause before you can go back", Toast.LENGTH_SHORT).show();
  440.         }
  441.         else{
  442.             Intent stopServiceIntent = new Intent(this, SavedRouteService.class);
  443.             stopService(stopServiceIntent);
  444.             Intent switchActivityIntent = new Intent(this, SelectRouteActivity.class);
  445.             startActivity(switchActivityIntent);
  446.         }
  447.     }
  448.  
  449.     @Override
  450.     public void onDestroy() {
  451.         if( dialog != null && dialog.isShowing()) {
  452.             dialog.dismiss();
  453.         }
  454.         super.onDestroy();
  455.         Intent intent = new Intent(RunSelectedRouteActivity.this, SavedRouteService.class);
  456.         stopService(intent);
  457.         if(paused){
  458.             NotificationWrapper.NotificationCancelAll(this);
  459.         }
  460.         resetSlider();
  461.         broadcastReceiver = null;
  462.     }
  463.  
  464.     @Override
  465.     public void onStop() {
  466.         super.onStop();
  467.         Intent intent = new Intent(RunSelectedRouteActivity.this, SavedRouteService.class);
  468.         stopService(intent);
  469.         if(paused){
  470.             NotificationWrapper.NotificationCancelAll(this);
  471.         }
  472.         resetSlider();
  473.     }
  474.  
  475.     @Override
  476.     public void onPause(){
  477.         super.onPause();
  478.         resetSlider();
  479.  
  480.         Intent pauseIntent = new Intent();
  481.         pauseIntent.setAction("PAUSE_ACTION");
  482.         Bundle pauseBundle = new Bundle();
  483.         pauseBundle.putInt("id", routeIDHolder);
  484.         pauseIntent.putExtras(pauseBundle);
  485.         PendingIntent pausePending = PendingIntent.getBroadcast(getBaseContext(), 0, pauseIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  486.  
  487.         Intent terminateIntent = new Intent();
  488.         pauseIntent.setAction("FINISH_ACTION");
  489.         Bundle terminateBundle = new Bundle();
  490.         terminateBundle.putInt("id", routeIDHolder);
  491.         terminateIntent.putExtras(terminateBundle);
  492.         PendingIntent terminatePending = PendingIntent.getBroadcast(getBaseContext(), 0, terminateIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  493.  
  494.         if(Constants.serviceStatus.equals("running")){
  495.             NotificationCompat.Builder builder = new NotificationCompat.Builder(getBaseContext())
  496.                     .setSmallIcon(R.mipmap.iconsafepassage)
  497.                     .setContentTitle("Tracking")
  498.                     .addAction(R.drawable.pause_icon, "", pausePending)
  499.                     .addAction(R.drawable.stop_icon, "", terminatePending);
  500.  
  501.             NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  502.             nManager.notify(Constants.SMALL_NOTI_ID, builder.build());
  503.         }
  504.         else{
  505.             Intent resumeIntent = new Intent();
  506.             resumeIntent.setAction("RESUME_ACTION");
  507.             Bundle resumeBundle = new Bundle();
  508.             resumeBundle.putInt("id", routeIDHolder);
  509.             resumeBundle.putString("Flag", "RunSelectedRoute");
  510.             resumeIntent.putExtras(resumeBundle);
  511.             PendingIntent resumePending = PendingIntent.getBroadcast(getBaseContext(), 0, resumeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
  512.  
  513.             NotificationCompat.Builder builder = new NotificationCompat.Builder(getBaseContext())
  514.                     .setSmallIcon(R.mipmap.iconsafepassage)
  515.                     .setContentTitle("Tracking")
  516.                     .addAction(R.drawable.resume_icon, "", resumePending)
  517.                     .addAction(R.drawable.stop_icon, "", terminatePending);
  518.  
  519.             NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  520.             nManager.notify(Constants.SMALL_NOTI_ID, builder.build());
  521.         }
  522.         minimized = true;
  523.         unregisterReceiver(broadcastReceiver);
  524.     }
  525.  
  526.     @TargetApi(16)
  527.     @Override
  528.     public void onResume() {
  529.         super.onResume();
  530.         dataBaseFetcher = new DataBaseFetcher(this);
  531.         emergencyList = dataBaseFetcher.getAllContacts();
  532.  
  533.             broadcastReceiver = new BroadcastReceiver() {
  534.                 @Override
  535.                 public void onReceive(Context context, Intent intent) {
  536.                         currentLocation = intent.getExtras().getParcelable("currentLocation");
  537.  
  538.                         if (currentLocation.getLatitude() > 0 && currentLocation.getLatitude() > 0) {
  539.                             map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), dataBaseFetcher.getSettings().getZoomMap()));
  540.                             Log.d("Pos: ", "" + currentLocation.getLatitude());
  541.                         }
  542.                         /**
  543.                          * DON'T NEED THIS AT THE MOMENT, LEAVE IT HERE THOUGH. This is connected to the onLocationChanged method in the SavedRouteService.
  544.                          */
  545.                     /*
  546.                     if(!isWithin && hasReceievedBroadcast){
  547.                         TaskStackBuilder stackBuilder = TaskStackBuilder.create(getBaseContext());
  548.                         stackBuilder.addParentStack(RunSelectedRouteActivity.class);
  549.                         stackBuilder.addNextIntent(new Intent(RunSelectedRouteActivity.this, RunSelectedRouteActivity.class));
  550.  
  551.                         NotificationCompat.Builder simpleNoti = new NotificationCompat.Builder(getBaseContext())
  552.                                 .setSmallIcon(R.mipmap.ic_launcher)
  553.                                 .setContentTitle("Deviated from Route!")
  554.                                 .setContentText("You have deviated from your route, please go back or pause the app")
  555.                                 .setVibrate(new long[] {0, 1000, 500, 1000});
  556.                     }
  557.                     */
  558.                 }
  559.             };
  560.  
  561.         Log.d("FROM SERVICE, STATUS: ", Constants.serviceStatus);
  562.         if(Constants.serviceStatus.equals("notRunning")){
  563.             pauseOrResumeButton.setText("Resume");
  564.         }
  565.         else{
  566.             pauseOrResumeButton.setText("Pause");
  567.         }
  568.         registerReceiver(broadcastReceiver, new IntentFilter("locationUpdates"));
  569.  
  570.     }
  571. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement