/* package whatever; // don't place package name! */
import android.app.Service
import android.content.Context
import android.content.Intent
import android.location.Location
import android.location.LocationManager
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import com.napoleonit.monita.utilities.log.MLog
/**
* Created by user on 03.05.16.
*/
private val TAG
: String = "BOOMBOOMTESTGPS" private var mLocationManager: LocationManager? = null
private val LOCATION_INTERVAL
: Long = 10000 private val LOCATION_DISTANCE
: Float = 0f
class MyService : Service() {
class LocationListener
(gpS_PROVIDER
: String) : android.
location.
LocationListener {
var mLastLocation: LocationListener? = null
fun LocationListener
(provider
: String) { MLog.d(TAG, "LocationListener $provider");
var mLastLocation = Location(provider);
}
override fun onLocationChanged(location: Location?) {
MLog.d(TAG, "onLocationChanged: $location");
mLastLocation?.onLocationChanged(location);
}
override fun onProviderEnabled
(provider
: String) { MLog.d(TAG, "onProviderEnabled: " + provider);
}
override fun onProviderDisabled
(provider
: String) { MLog.d(TAG, "onProviderDisabled " + provider);
}
override fun onStatusChanged
(provider
: String, status
: Int, extras
: Bundle
) { MLog.d(TAG, "onStatusChanged " + provider);
}
}
var mLocationListeners = arrayOf(
LocationListener (LocationManager.GPS_PROVIDER),
LocationListener (LocationManager.NETWORK_PROVIDER))
override fun onBind(arg0 : Intent): IBinder? {
return null;
}
override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
MLog.d(TAG, "onStartCommand");
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
override fun onCreate() {
MLog.d(TAG, "onCreate");
initializeLocationManager();
try {
mLocationManager?.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
mLocationListeners[1]);
Log.i(TAG, "fail to request location update, ignore", ex)
MLog.d(TAG, "network provider does not exist ${ex.message}")
}
try {
mLocationManager?.requestLocationUpdates(
LocationManager.GPS_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
mLocationListeners[0])
Log.i(TAG, "fail to request location update, ignore", ex)
Log.d(TAG, "gps provider does not exist ${ex.message}")
}
}
override fun onDestroy() {
var y: Int = 0
MLog.d(TAG, "onDestroy")
super.onDestroy()
if (mLocationManager != null) {
for (i:LocationListener in mLocationListeners) {
try {
mLocationManager.removeUpdates(mLocationListeners[y])
y++
Log.i(TAG, "fail to remove location listeners, ignore", ex)
}
}
}
}
private fun initializeLocationManager() {
Log.e(TAG, "initializeLocationManager");
if (mLocationManager == null) {
mLocationManager
= applicationContext.
getSystemService(Context.
LOCATION_SERVICE) as
(LocationManager
) }
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGFuZHJvaWQuYXBwLlNlcnZpY2UKaW1wb3J0IGFuZHJvaWQuY29udGVudC5Db250ZXh0CmltcG9ydCBhbmRyb2lkLmNvbnRlbnQuSW50ZW50CmltcG9ydCBhbmRyb2lkLmxvY2F0aW9uLkxvY2F0aW9uCmltcG9ydCBhbmRyb2lkLmxvY2F0aW9uLkxvY2F0aW9uTWFuYWdlcgppbXBvcnQgYW5kcm9pZC5vcy5CdW5kbGUKaW1wb3J0IGFuZHJvaWQub3MuSUJpbmRlcgppbXBvcnQgYW5kcm9pZC51dGlsLkxvZwppbXBvcnQgY29tLm5hcG9sZW9uaXQubW9uaXRhLnV0aWxpdGllcy5sb2cuTUxvZwoKCi8qKgogKiBDcmVhdGVkIGJ5IHVzZXIgb24gMDMuMDUuMTYuCiAqLwoKCnByaXZhdGUgdmFsIFRBRzogU3RyaW5nID0gIkJPT01CT09NVEVTVEdQUyIKcHJpdmF0ZSB2YXIgbUxvY2F0aW9uTWFuYWdlcjogTG9jYXRpb25NYW5hZ2VyPyA9IG51bGwKcHJpdmF0ZSB2YWwgTE9DQVRJT05fSU5URVJWQUw6IExvbmcgPSAxMDAwMApwcml2YXRlIHZhbCBMT0NBVElPTl9ESVNUQU5DRTogRmxvYXQgPSAwZgoKY2xhc3MgTXlTZXJ2aWNlIDogU2VydmljZSgpIHsKC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9IG51bGwpIHsKICAgICAgICAgICAgZm9yIChpOkxvY2F0aW9uTGlzdGVuZXIgaW4gbUxvY2F0aW9uTGlzdGVuZXJzKSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICAgIG1Mb2NhdGlvbk1hbmFnZXIucmVtb3ZlVXBkYXRlcyhtTG9jYXRpb25MaXN0ZW5lcnNbeV0pCiAgICAgICAgICAgICAgICAgICAgeSsrCiAgICAgICAgICAgICAgICB9IGNhdGNoIChleDogRXhjZXB0aW9uKSB7CiAgICAgICAgICAgICAgICAgICAgTG9nLmkoVEFHLCAiZmFpbCB0byByZW1vdmUgbG9jYXRpb24gbGlzdGVuZXJzLCBpZ25vcmUiLCBleCkKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBwcml2YXRlIGZ1biBpbml0aWFsaXplTG9jYXRpb25NYW5hZ2VyKCkgewogICAgICAgIExvZy5lKFRBRywgImluaXRpYWxpemVMb2NhdGlvbk1hbmFnZXIiKTsKICAgICAgICBpZiAobUxvY2F0aW9uTWFuYWdlciA9PSBudWxsKSB7CiAgICAgICAgICAgIG1Mb2NhdGlvbk1hbmFnZXIgPSBhcHBsaWNhdGlvbkNvbnRleHQuZ2V0U3lzdGVtU2VydmljZShDb250ZXh0LkxPQ0FUSU9OX1NFUlZJQ0UpIGFzIChMb2NhdGlvbk1hbmFnZXIpCiAgICAgICAgfQogICAgfQoKfQ==
Main.java:3: error: ';' expected
import android.app.Service
^
Main.java:4: error: ';' expected
import android.content.Context
^
Main.java:5: error: ';' expected
import android.content.Intent
^
Main.java:6: error: ';' expected
import android.location.Location
^
Main.java:7: error: ';' expected
import android.location.LocationManager
^
Main.java:8: error: ';' expected
import android.os.Bundle
^
Main.java:9: error: ';' expected
import android.os.IBinder
^
Main.java:10: error: ';' expected
import android.util.Log
^
Main.java:11: error: ';' expected
import com.napoleonit.monita.utilities.log.MLog
^
Main.java:24: error: '{' expected
class MyService : Service() {
^
Main.java:27: error: '{' expected
class LocationListener(gpS_PROVIDER: String) : android.location.LocationListener {
^
Main.java:29: error: ';' expected
var mLastLocation: LocationListener? = null
^
Main.java:29: error: <identifier> expected
var mLastLocation: LocationListener? = null
^
Main.java:29: error: illegal start of type
var mLastLocation: LocationListener? = null
^
Main.java:29: error: <identifier> expected
var mLastLocation: LocationListener? = null
^
Main.java:29: error: ';' expected
var mLastLocation: LocationListener? = null
^
Main.java:31: error: <identifier> expected
fun LocationListener(provider: String) {
^
Main.java:31: error: ';' expected
fun LocationListener(provider: String) {
^
Main.java:31: error: illegal start of type
fun LocationListener(provider: String) {
^
Main.java:31: error: <identifier> expected
fun LocationListener(provider: String) {
^
Main.java:31: error: ';' expected
fun LocationListener(provider: String) {
^
Main.java:32: error: illegal start of type
MLog.d(TAG, "LocationListener $provider");
^
Main.java:32: error: <identifier> expected
MLog.d(TAG, "LocationListener $provider");
^
Main.java:32: error: illegal start of type
MLog.d(TAG, "LocationListener $provider");
^
Main.java:36: error: ';' expected
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: invalid method declaration; return type required
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: <identifier> expected
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: ';' expected
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: illegal start of type
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: <identifier> expected
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: ';' expected
override fun onLocationChanged(location: Location?) {
^
Main.java:37: error: <identifier> expected
MLog.d(TAG, "onLocationChanged: $location");
^
Main.java:37: error: <identifier> expected
MLog.d(TAG, "onLocationChanged: $location");
^
Main.java:37: error: illegal start of type
MLog.d(TAG, "onLocationChanged: $location");
^
Main.java:38: error: <identifier> expected
mLastLocation?.onLocationChanged(location);
^
Main.java:38: error: illegal start of type
mLastLocation?.onLocationChanged(location);
^
Main.java:38: error: <identifier> expected
mLastLocation?.onLocationChanged(location);
^
Main.java:41: error: class, interface, or enum expected
override fun onProviderEnabled(provider: String) {
^
Main.java:43: error: class, interface, or enum expected
}
^
Main.java:47: error: class, interface, or enum expected
}
^
Main.java:51: error: class, interface, or enum expected
}
^
Main.java:61: error: class, interface, or enum expected
}
^
Main.java:65: error: class, interface, or enum expected
super.onStartCommand(intent, flags, startId);
^
Main.java:66: error: class, interface, or enum expected
return START_STICKY;
^
Main.java:67: error: class, interface, or enum expected
}
^
Main.java:71: error: class, interface, or enum expected
initializeLocationManager();
^
Main.java:72: error: class, interface, or enum expected
try {
^
Main.java:75: error: class, interface, or enum expected
} catch (ex: java.lang.SecurityException) {
^
Main.java:109: error: class, interface, or enum expected
if (mLocationManager == null) {
^
49 errors