|
@@ -27,6 +27,7 @@ import com.google.android.gms.location.LocationListener;
|
27
|
27
|
import com.google.android.gms.location.LocationRequest;
|
28
|
28
|
import com.google.android.gms.location.LocationServices;
|
29
|
29
|
|
|
30
|
+import im.delight.android.location.SimpleLocation;
|
30
|
31
|
import timber.log.Timber;
|
31
|
32
|
|
32
|
33
|
public class ScanActivity extends LFScanProcessing implements GoogleApiClient.ConnectionCallbacks,
|
|
@@ -49,6 +50,9 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
|
49
|
50
|
private double currentLatitude;
|
50
|
51
|
private double currentLongitude;
|
51
|
52
|
|
|
53
|
+ //Define a simple location android
|
|
54
|
+ private SimpleLocation simpleLocation;
|
|
55
|
+
|
52
|
56
|
@Override
|
53
|
57
|
protected void onCreate(Bundle savedInstanceState) {
|
54
|
58
|
super.onCreate(savedInstanceState);
|
|
@@ -82,6 +86,14 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
|
82
|
86
|
.setInterval(10 * 1000) // 10 seconds, in milliseconds
|
83
|
87
|
.setFastestInterval(1000); // 1 second, in milliseconds
|
84
|
88
|
|
|
89
|
+ // First Time init
|
|
90
|
+ simpleLocation = new SimpleLocation(this);
|
|
91
|
+ // if we can't access the location yet
|
|
92
|
+ if (!simpleLocation.hasLocationEnabled()) {
|
|
93
|
+ // ask the user to enable location access
|
|
94
|
+ SimpleLocation.openSettings(this);
|
|
95
|
+ }
|
|
96
|
+
|
85
|
97
|
initView();
|
86
|
98
|
initSound();
|
87
|
99
|
}
|
|
@@ -97,6 +109,7 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
|
97
|
109
|
setStatusScan();
|
98
|
110
|
locationClient = LocationServices.getFusedLocationProviderClient(this);
|
99
|
111
|
getLocation();
|
|
112
|
+ getSimpleLocation();
|
100
|
113
|
binding.toggleScan.setOnCheckedChangeListener((buttonView, isChecked) -> statusScanner());
|
101
|
114
|
}
|
102
|
115
|
|
|
@@ -105,6 +118,9 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
|
105
|
118
|
super.onResume();
|
106
|
119
|
//Now lets connect to the API
|
107
|
120
|
mGoogleApiClient.connect();
|
|
121
|
+
|
|
122
|
+ // make the device update its location
|
|
123
|
+ simpleLocation.beginUpdates();
|
108
|
124
|
}
|
109
|
125
|
|
110
|
126
|
@Override
|
|
@@ -115,6 +131,9 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
|
115
|
131
|
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);
|
116
|
132
|
mGoogleApiClient.disconnect();
|
117
|
133
|
}
|
|
134
|
+
|
|
135
|
+ // stop location updates (saves battery)
|
|
136
|
+ simpleLocation.endUpdates();
|
118
|
137
|
}
|
119
|
138
|
|
120
|
139
|
private void setStatusScan() {
|
|
@@ -190,6 +209,13 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
|
190
|
209
|
locationClient.getLastLocation().addOnFailureListener(e -> System.out.println(e.getMessage()));
|
191
|
210
|
}
|
192
|
211
|
|
|
212
|
+ private void getSimpleLocation(){
|
|
213
|
+ double latitude = simpleLocation.getLatitude();
|
|
214
|
+ double longitude = simpleLocation.getLongitude();
|
|
215
|
+ longLat = longitude + "," + latitude;
|
|
216
|
+ Toast.makeText(this, "Simple Location ==> Latitude : " + latitude + ", Longitude : " + longitude, Toast.LENGTH_LONG).show();
|
|
217
|
+ }
|
|
218
|
+
|
193
|
219
|
@Override
|
194
|
220
|
protected void onDestroy() {
|
195
|
221
|
super.onDestroy();
|