Skip to content

Commit 0df77b1

Browse files
authored
chore(release): Global refactor update for release 4.0
2 parents 0f0a9cc + 148e7b0 commit 0df77b1

25 files changed

Lines changed: 336 additions & 792 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
.DS_Store
2+
.gradle
3+
.idea
4+
local.properties
5+
build

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: android
2+
android:
3+
components:
4+
# The SDK version used to compile your project
5+
- android-30
6+
- build-tools-30.0.0
7+
licenses:
8+
- 'android-sdk-license-.+'
9+
before_install:
10+
- yes | sdkmanager "platforms;android-30"
11+
- yes | sdkmanager "build-tools;30.0.0"
12+
- chmod +x gradlew
13+
script:
14+
- ./gradlew :slt:check
15+
- ./gradlew :slt:assembleRelease

README.md

Lines changed: 64 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ repositories {
1717
}
1818
1919
dependencies {
20-
compile 'com.github.quentin7b:android-location-tracker:3.2'
20+
compile 'com.github.quentin7b:android-location-tracker:4.0'
2121
}
2222
```
2323

2424
Don't forget to add the following permissions to your *AndroidManifest.xml*
2525

2626
```xml
27-
<uses-permission android:name="android.permission.INTERNET" />
2827
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
2928
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
3029
```
@@ -33,162 +32,95 @@ Be aware of `Android Marshmallow`'s new [permission system](https://developer.an
3332

3433
```xml
3534
<permission-group
36-
android:name="android.permission-group.LOCATION"
37-
android:label="A label for your permission"
38-
android:description="A description for the permission" />
35+
android:name="android.permission-group.LOCATION"
36+
android:label="A label for your permission"
37+
android:description="A description for the permission" />
3938
```
4039

41-
4240
### Use
4341

4442
As its name says, it's a *simple* library.
45-
To create a tracker you just need to add the below code in your Android Activity/Service
46-
47-
```java
48-
// You can pass an ui Context but it is not mandatory getApplicationContext() would also works
49-
// Be aware if you target android 23, you'll need to handle the runtime-permissions !
50-
// see http://developer.android.com/reference/android/support/v4/content/ContextCompat.html
51-
if ( ContextCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
52-
&& ContextCompat.checkSelfPermission(ctx, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
53-
// You need to ask the user to enable the permissions
54-
} else {
55-
LocationTracker tracker = new LocationTracker(ctx) {
56-
@Override
57-
public void onLocationFound(Location location) {
58-
// Do some stuff
59-
}
60-
};
61-
tracker.startListening();
62-
}
63-
```
43+
To create a tracker you just need to add the below code in your Android Activity / Service / WorkManager
6444

65-
And it's done, as soon as a location has been found, it will call the `onLocationFound()` method and you can do the job.
45+
> Be aware, you'll have to manage runtime permissions on Manifest.permission.ACCESS_FINE_LOCATION & Manifest.permission.ACCESS_COARSE_LOCATION
6646
67-
### Provide custom use
47+
#### Create the tracker
6848

69-
You can call a `LocationTracker` with custom parameters.
70-
To do this, use the following constructor
49+
Constructor is defined as this
7150

72-
```java
73-
LocationTracker(Context context, TrackerSettings settings)
51+
```kotlin
52+
val locationTracker = LocationTracker(
53+
val minTimeBetweenUpdates: Long = 5 * 60 * 1000.toLong(),
54+
val minDistanceBetweenUpdates: Float = 100f,
55+
val shouldUseGPS: Boolean = true,
56+
val shouldUseNetwork: Boolean = true,
57+
val shouldUsePassive: Boolean = true
58+
)
7459
```
7560

76-
As an example:
77-
```java
78-
LocationTracker tracker = new LocationTracker(
79-
context,
80-
new TrackerSettings()
81-
.setUseGPS(true)
82-
.setUseNetwork(false)
83-
.setUsePassive(false)
84-
) {
85-
86-
@Override
87-
public void onLocationFound(Location location) {
88-
// Do some stuff when a new GPS Location has been found
89-
}
90-
};
91-
tracker.startListening()
92-
```
61+
#### Add a listener
9362

94-
This, will call a location tracker that is looking *ONLY* for *GPS* updates.
95-
*Network* and *Passive* updates will not be catched by the Tracker.
96-
97-
### Providers AND metrics custom use
98-
99-
`LocationTracker` allows you to define some custom metrics like
100-
<ul>
101-
<li> The minimum time interval between location updates, in milliseconds </li>
102-
<li> The minimum distance between location updates, in meters </li>
103-
</ul>
104-
105-
To specify those parameters, `LocationTracker` you can set more settings.
106-
Here is an example of call:
107-
```java
108-
TrackerSettings settings =
109-
new TrackerSettings()
110-
.setUseGPS(true)
111-
.setUseNetwork(true)
112-
.setUsePassive(true)
113-
.setTimeBetweenUpdates(30 * 60 * 1000)
114-
.setMetersBetweenUpdates(100);
115-
116-
LocationTracker tracker = new LocationTracker(context, settings) {
117-
118-
@Override
119-
public void onLocationFound(Location location) {
120-
// Do some stuff when a new location has been found.
121-
}
122-
};
123-
tracker.startListening();
124-
```
125-
126-
In this case, when a location is found, the tracker will not call `onLocationFound()` again during *30 minutes*.
127-
Moreover, if the distance between the new location and the older one is less than 100m, `onLocationFound()` will not be called.
63+
```kotlin
64+
locationTracker.addListener(object: Listener {
12865

129-
Be aware that the *time* parameter's priority is higher than the *distance* parameter. So even if the user has moved from 2km, the `tracker` will call `onLocationFound()` only after *30 minutes*.
66+
fun onLocationFound(location: Location) {
67+
}
13068

131-
### Manage the tracker
69+
fun onProviderError(providerError: ProviderError) {
70+
}
13271

133-
By default, after a `LocationTracker` is created, it automatically starts listening to updates... and never stops.
134-
`LocationTracker` has two methods to *start* and *stop* listening for updates.
72+
});
73+
```
13574

136-
If you want to *stop* listening for updates, just call the `stopListening()` method.
137-
For example, if you need a *one shot* position, you can do that:
13875

139-
```java
140-
LocationTracker tracker = new LocationTracker(context) {
76+
#### Start and stop listening
14177

142-
@Override
143-
public void onLocationFound(Location location) {
144-
// Stop listening for updates
145-
stopListening()
146-
// Do some stuff when a new GPS Location has been found
147-
}
148-
};
149-
tracker.startListening();
78+
```kotlin
79+
locationTracker.startListening(context)
80+
//and
81+
locationTracker.stopListening()
15082
```
15183

152-
You can also do it in the `onPause()` Activity method if you want.
84+
### Provide custom use
15385

154-
```java
155-
@Override
156-
protected void onPause() {
157-
if(myTracker != null) {
158-
myTracker.stopListening();
159-
}
160-
super.onPause();
161-
}
162-
```
86+
You can create a `LocationTracker` with custom parameters.
16387

164-
REMEMBER! A `LocationTracker` never stops untill you tell it to do so.
88+
- `minTimeBetweenUpdates` minimum time between two locations to respect before notifying the listeners in milliseconds). Default is *5 minutes*
89+
- `minDistanceBetweenUpdates` minimum distance between two locations to respect before notifying the listeners in meters). Default is *100 meters*
90+
- `shouldUseGPS` specifies if the tracker should use the GPS locations or not. Default is *true*
91+
- `shouldUseNetwork` specifies if the tracker should use the GPS locations or not. Default is *true*
92+
- `shouldUsePassive` specifies if the tracker should use the passive locations or not. Default is *true*
16593

166-
You may want to start listening for updates after all. To do that, `LocationTracker` has a public method named `startListening()`, call it when you want.
94+
With the default parameters, when a location is found, the tracker will not call `onLocationFound()` again during *5 minutes*.
95+
Moreover, if the distance between the new location and the older one is less than *100m*, `onLocationFound()` will not be called.
16796

168-
For example, in the `onResume()` Activity method:
169-
```java
170-
@Override
171-
protected void onResume() {
172-
if(myTracker != null) {
173-
myTracker.startListening();
174-
}
175-
super.onResume();
176-
}
177-
```
178-
### Overriding
97+
> Be aware that the priority of the **time** parameter is higher than the priority of the *distance* parameter.
98+
> So even if the user has moved from 200km, the `tracker` will call `onLocationFound()` only after *30 minutes*.
17999
180-
`LocationTracker` implements Android's [LocationListener](http://developer.android.com/reference/android/location/LocationListener.html) interface.
100+
### Cleaning
181101

182-
By default, it does nothing but logging.
102+
> Be aware! A `LocationTracker` never stops running until you tell it to do so.
183103
184-
Excepts the `onLocationChanged()` method, you can override all the [LocationListener](http://developer.android.com/reference/android/location/LocationListener.html)'s metods, so here is the list:
185-
<ul>
186-
<li>onProviderDisabled(String provider)</li>
187-
<li>onProviderEnabled(String provider)</li>
188-
<li>onStatusChanged(String provider, int status, Bundle extras)</li>
189-
</ul>
104+
If the tracker is running in foreground and not in a service, it might be a good idea to link to the `lifecycle`
190105

191-
### Contact & Questions
106+
The `stopListening` method has an optional parameter `cleanListeners` that is *false* by default.
107+
(calling `stopListening(false)` is the same as calling `stopListening()`).
192108

193-
If you have any questions, fell free to send me a mail.
194-
You can also fork this project, or open an issue :)
109+
When calling `stopListening` we do not remove the listeners you've set, so they will be notified once you start listening again.
110+
But calling `stopListening(true)` will clear the list of registered listeners (same as calling `removeListener` for every registered listener).
111+
112+
```kotlin
113+
tracker.addListener(listener)
114+
tracker.startListening(context)
115+
// listener will be notified
116+
...
117+
tracker.stopListening()
118+
// listener won't receive updated
119+
tracker.startListening(context)
120+
// listener will be notified
121+
...
122+
tracker.stopListening(cleanListeners = true)
123+
// listener won't receive updated for ever
124+
tracker.startListening(context)
125+
// listener won't be notified
126+
```

build.gradle

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
4+
buildscript {
5+
ext.kotlin_version = '1.3.72'
6+
repositories {
7+
google()
8+
mavenCentral()
9+
jcenter()
10+
}
11+
dependencies {
12+
classpath 'com.android.tools.build:gradle:4.0.1'
13+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14+
}
15+
}
16+
17+
allprojects {
18+
repositories {
19+
google()
20+
mavenCentral()
21+
jcenter()
22+
}
23+
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
android.useAndroidX=true

simple-location-tracker/gradle/wrapper/gradle-wrapper.jar renamed to gradle/wrapper/gradle-wrapper.jar

File renamed without changes.

simple-location-tracker/gradle/wrapper/gradle-wrapper.properties renamed to gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
File renamed without changes.

0 commit comments

Comments
 (0)