-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
112 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/net/pipe01/pinepartner/scripting/api/Location.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package net.pipe01.pinepartner.scripting.api | ||
|
||
import android.annotation.SuppressLint | ||
import com.google.android.gms.location.FusedLocationProviderClient | ||
import com.google.android.gms.location.Priority | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.tasks.await | ||
import net.pipe01.pinepartner.scripting.api.adapters.LocationAdapter | ||
import org.mozilla.javascript.annotations.JSGetter | ||
|
||
class Location : ApiScriptableObject(CLASS_NAME) { | ||
companion object { | ||
const val CLASS_NAME = "Location" | ||
} | ||
|
||
private lateinit var fusedLocationClient: FusedLocationProviderClient | ||
|
||
fun init(fusedLocationClient: FusedLocationProviderClient) { | ||
this.fusedLocationClient = fusedLocationClient | ||
} | ||
|
||
@SuppressLint("MissingPermission") | ||
@JSGetter | ||
fun getCurrent(): LocationAdapter { | ||
val task = fusedLocationClient.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null) | ||
|
||
val location = runBlocking { | ||
task.await() | ||
} | ||
|
||
return newObject<LocationAdapter>(LocationAdapter.CLASS_NAME).apply { | ||
init(location) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
app/src/main/java/net/pipe01/pinepartner/scripting/api/adapters/LocationAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package net.pipe01.pinepartner.scripting.api.adapters | ||
|
||
import android.location.Location | ||
import net.pipe01.pinepartner.scripting.api.ApiScriptableObject | ||
import org.mozilla.javascript.annotations.JSGetter | ||
|
||
class LocationAdapter : ApiScriptableObject(CLASS_NAME) { | ||
companion object { | ||
const val CLASS_NAME = "LocationAdapter" | ||
} | ||
|
||
private lateinit var location: Location | ||
|
||
fun init(location: Location) { | ||
this.location = location | ||
} | ||
|
||
@JSGetter | ||
fun getLatitude() = location.latitude | ||
|
||
@JSGetter | ||
fun getLongitude() = location.longitude | ||
|
||
@JSGetter | ||
fun getAltitude() = if (location.hasAltitude()) location.altitude else null | ||
|
||
@JSGetter | ||
fun getAccuracy() = if (location.hasAccuracy()) location.accuracy else null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters