Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. private void StartForceCheckoutCheckServiceIfNotRunning()
  2. {
  3. try
  4. {
  5. Intent intent = new Intent(GPRSService.this , ForceCheckOutService.class);
  6.  
  7. if(!ForceCheckOutService.IsForceCheckoutServiceRunning())
  8. {
  9. LogWriter.Log(TAG, "GPRSService - starting StartForceCheckoutCheckService from GPRSService");
  10.  
  11. ContextCompat.startForegroundService(getApplicationContext(), intent);
  12. }
  13. else
  14. {
  15. //GrabLog.Log(TAG, "GPRSService - StartForceCheckoutCheckService already running, do nothing", GrabLog.USER_ID_TRUPTI);
  16. }
  17. }
  18. catch (Exception e)
  19. {
  20. e.printStackTrace();
  21. LogWriter.Log(TAG, "GPRSService - StartForceCheckoutCheckService excep - "+e.toString());
  22. }
  23. }
  24.  
  25. public static boolean IsRunning()
  26. {
  27. return m_ServiceIsRunning;
  28. }
  29.  
  30. @Subscribe
  31. public void onEvent(Integer event)
  32. {
  33.  
  34. }
  35.  
  36. private static final int TWO_MINUTES = 1000 * 60 * 2;
  37.  
  38. /** Determines whether one Location reading is better than the current Location fix
  39. * @param location The new Location that you want to evaluate
  40. * @param currentBestLocation The current Location fix, to which you want to compare the new one
  41. */
  42. protected boolean isBetterLocation(Location location, Location currentBestLocation) {
  43. if (currentBestLocation == null) {
  44. // A new location is always better than no location
  45. return true;
  46. }
  47.  
  48. // Check whether the new location fix is newer or older
  49. long timeDelta = location.getTime() - currentBestLocation.getTime();
  50. boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
  51. boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
  52. boolean isNewer = timeDelta > 0;
  53.  
  54. // If it's been more than two minutes since the current location, use the new location
  55. // because the user has likely moved
  56. if (isSignificantlyNewer) {
  57. return true;
  58. // If the new location is more than two minutes older, it must be worse
  59. } else if (isSignificantlyOlder) {
  60. return false;
  61. }
  62.  
  63. // Check whether the new location fix is more or less accurate
  64. int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
  65. boolean isLessAccurate = accuracyDelta > 0;
  66. boolean isMoreAccurate = accuracyDelta < 0;
  67. boolean isSignificantlyLessAccurate = accuracyDelta > 200;
  68.  
  69. // Check if the old and new location are from the same provider
  70. boolean isFromSameProvider = isSameProvider(location.getProvider(),
  71. currentBestLocation.getProvider());
  72.  
  73. // Determine location quality using a combination of timeliness and accuracy
  74. if (isMoreAccurate) {
  75. return true;
  76. } else if (isNewer && !isLessAccurate) {
  77. return true;
  78. } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
  79. return true;
  80. }
  81. return false;
  82. }
  83.  
  84. /** Checks whether two providers are the same */
  85. private boolean isSameProvider(String provider1, String provider2) {
  86. if (provider1 == null) {
  87. return provider2 == null;
  88. }
  89. return provider1.equals(provider2);
  90. }
  91.  
  92.  
  93. if (isMoreAccurate)
  94. {
  95. return true;
  96. }
  97. else if (isNewer && !isLessAccurate)
  98. {
  99. return true;
  100. }
  101. else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)
  102. {
  103. return true;
  104. }
  105.  
  106. return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement