import android.app.Service
import android.content.Context
import android.content.Intent
import android.location.Location
import android.location.LocationListener
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 = 1000 private val LOCATION_DISTANCE
: Float = 10f
abstract 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]);
MLog.d(TAG, "gps provider does not exist " + ex.message)
}
}
override fun onDestroy() {
var y: Int = 0; // Костыль; Проблема с for in
MLog.d(TAG, "onDestroy")
super.onDestroy()
if (mLocationManager != null) {
for(i 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
) }
}
}
aW1wb3J0IGFuZHJvaWQuYXBwLlNlcnZpY2UKaW1wb3J0IGFuZHJvaWQuY29udGVudC5Db250ZXh0CmltcG9ydCBhbmRyb2lkLmNvbnRlbnQuSW50ZW50CmltcG9ydCBhbmRyb2lkLmxvY2F0aW9uLkxvY2F0aW9uCmltcG9ydCBhbmRyb2lkLmxvY2F0aW9uLkxvY2F0aW9uTGlzdGVuZXIKaW1wb3J0IGFuZHJvaWQubG9jYXRpb24uTG9jYXRpb25NYW5hZ2VyCmltcG9ydCBhbmRyb2lkLm9zLkJ1bmRsZQppbXBvcnQgYW5kcm9pZC5vcy5JQmluZGVyCmltcG9ydCBhbmRyb2lkLnV0aWwuTG9nCmltcG9ydCBjb20ubmFwb2xlb25pdC5tb25pdGEudXRpbGl0aWVzLmxvZy5NTG9nCgoKLyoqCiAqIENyZWF0ZWQgYnkgdXNlciBvbiAwMy4wNS4xNi4KICovCgoKcHJpdmF0ZSB2YWwgVEFHOiBTdHJpbmcgPSAiQk9PTUJPT01URVNUR1BTIgpwcml2YXRlIHZhciBtTG9jYXRpb25NYW5hZ2VyOiBMb2NhdGlvbk1hbmFnZXIgPSBudWxsISEKcHJpdmF0ZSB2YWwgTE9DQVRJT05fSU5URVJWQUw6IExvbmcgPSAxMDAwCnByaXZhdGUgdmFsIExPQ0FUSU9OX0RJU1RBTkNFOiBGbG9hdCA9IDEwZgoKYWJzdHJhY3QgY2xhc3MgTXlTZXJ2aWNlIDogU2VydmljZSgpIHsKCgogICAgY2xhc3MgTG9jYXRpb25MaXN0ZW5lcihncFNfUFJPVklERVI6IFN0cmluZykgOiBhbmRyb2lkLmxvY2F0aW9uLkxvY2F0aW9uTGlzdGVuZXIgewoKICAgICAgICB2YXIgbUxhc3RMb2NhdGlvbjogTG9jYXRpb25MaXN0ZW5lciA9IG51bGwhIQoKICAgICAgICBmdW4gTG9jYXRpb25MaXN0ZW5lcihwcm92aWRlcjogU3RyaW5nKSB7CiAgICAgICAgICAgIE1Mb2cuZChUQUcsICJMb2NhdGlvbkxpc3RlbmVyICIgKyBwcm92aWRlcik7CiAgICAgICAgICAgIHZhciBtTGFzdExvY2F0aW9uID0gTG9jYXRpb24ocHJvdmlkZXIpOwogICAgICAgIH0KCiAgICAgICAgb3ZlcnJpZGUgZnVuIG9uTG9jYXRpb25DaGFuZ2VkKGxvY2F0aW9uOiBMb2NhdGlvbj8pIHsKICAgICAgICAgICAgTUxvZy5kKFRBRywgIm9uTG9jYXRpb25DaGFuZ2VkOiAiICsgbG9jYXRpb24pOwogICAgICAgICAgICBtTGFzdExvY2F0aW9uLm9uTG9jYXRpb25DaGFuZ2VkKGxvY2F0aW9uKTsKICAgICAgICB9CgogICAgICAgIG92ZXJyaWRlIGZ1biBvblByb3ZpZGVyRW5hYmxlZChwcm92aWRlcjogU3RyaW5nKSB7CiAgICAgICAgICAgIE1Mb2cuZChUQUcsICJvblByb3ZpZGVyRW5hYmxlZDogIiArIHByb3ZpZGVyKTsKICAgICAgICB9CgogICAgICAgIG92ZXJyaWRlIGZ1biBvblByb3ZpZGVyRGlzYWJsZWQocHJvdmlkZXI6IFN0cmluZykgewogICAgICAgICAgICBNTG9nLmQoVEFHLCAib25Qcm92aWRlckRpc2FibGVkICIgKyBwcm92aWRlcik7CiAgICAgICAgfQoKICAgICAgICBvdmVycmlkZSBmdW4gb25TdGF0dXNDaGFuZ2VkKHByb3ZpZGVyOiBTdHJpbmcsIHN0YXR1czogSW50LCBleHRyYXM6IEJ1bmRsZSkgewogICAgICAgICAgICBNTG9nLmQoVEFHLCAib25TdGF0dXNDaGFuZ2VkICIgKyBwcm92aWRlcik7CiAgICAgICAgfQogICAgfQoKICAgIHZhciBtTG9jYXRpb25MaXN0ZW5lcnMgPSBhcnJheU9mKAogICAgICAgICAgICBMb2Nh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b25EZXN0cm95KCkgewogICAgICAgIHZhciB5OiBJbnQgPSAwOyAvLyDQmtC+0YHRgtGL0LvRjDsg0J/RgNC+0LHQu9C10LzQsCDRgSBmb3IgaW4KICAgICAgICBNTG9nLmQoVEFHLCAib25EZXN0cm95IikKICAgICAgICBzdXBlci5vbkRlc3Ryb3koKQogICAgICAgIGlmIChtTG9jYXRpb25NYW5hZ2VyICE9IG51bGwpIHsKICAgICAgICAgICAgZm9yKGkgaW4gbUxvY2F0aW9uTGlzdGVuZXJzKSB7CiAgICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICAgICBtTG9jYXRpb25NYW5hZ2VyLnJlbW92ZVVwZGF0ZXMobUxvY2F0aW9uTGlzdGVuZXJzW3ldKQogICAgICAgICAgICAgICAgICAgeSsrOwogICAgICAgICAgICAgICB9IGNhdGNoIChleDogRXhjZXB0aW9uKSB7CiAgICAgICAgICAgICAgICAgICBMb2cuaShUQUcsICJmYWlsIHRvIHJlbW92ZSBsb2NhdGlvbiBsaXN0ZW5lcnMsIGlnbm9yZSIsIGV4KQogICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgcHJpdmF0ZSBmdW4gaW5pdGlhbGl6ZUxvY2F0aW9uTWFuYWdlcigpIHsKICAgICAgICBMb2cuZShUQUcsICJpbml0aWFsaXplTG9jYXRpb25NYW5hZ2VyIik7CiAgICAgICAgaWYgKG1Mb2NhdGlvbk1hbmFnZXIgPT0gbnVsbCkgewogICAgICAgICAgICBtTG9jYXRpb25NYW5hZ2VyID0gYXBwbGljYXRpb25Db250ZXh0LmdldFN5c3RlbVNlcnZpY2UoQ29udGV4dC5MT0NBVElPTl9TRVJWSUNFKSBhcyAoTG9jYXRpb25NYW5hZ2VyKQogICAgICAgIH0KICAgIH0KCn0=
Main.java:1: error: ';' expected
import android.app.Service
^
Main.java:2: error: ';' expected
import android.content.Context
^
Main.java:3: error: ';' expected
import android.content.Intent
^
Main.java:4: error: ';' expected
import android.location.Location
^
Main.java:5: error: ';' expected
import android.location.LocationListener
^
Main.java:6: error: ';' expected
import android.location.LocationManager
^
Main.java:7: error: ';' expected
import android.os.Bundle
^
Main.java:8: error: ';' expected
import android.os.IBinder
^
Main.java:9: error: ';' expected
import android.util.Log
^
Main.java:10: error: ';' expected
import com.napoleonit.monita.utilities.log.MLog
^
Main.java:23: error: '{' expected
abstract class MyService : Service() {
^
Main.java:26: error: '{' expected
class LocationListener(gpS_PROVIDER: String) : android.location.LocationListener {
^
Main.java:28: error: ';' expected
var mLastLocation: LocationListener = null!!
^
Main.java:28: error: <identifier> expected
var mLastLocation: LocationListener = null!!
^
Main.java:28: error: ';' expected
var mLastLocation: LocationListener = null!!
^
Main.java:30: error: <identifier> expected
fun LocationListener(provider: String) {
^
Main.java:30: error: ';' expected
fun LocationListener(provider: String) {
^
Main.java:30: error: illegal start of type
fun LocationListener(provider: String) {
^
Main.java:30: error: <identifier> expected
fun LocationListener(provider: String) {
^
Main.java:30: error: ';' expected
fun LocationListener(provider: String) {
^
Main.java:31: error: illegal start of type
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: <identifier> expected
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: illegal start of type
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: ')' expected
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: ';' expected
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: illegal start of type
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: <identifier> expected
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:31: error: ';' expected
MLog.d(TAG, "LocationListener " + provider);
^
Main.java:32: error: <identifier> expected
var mLastLocation = Location(provider);
^
Main.java:35: error: ';' expected
override fun onLocationChanged(location: Location?) {
^
Main.java:35: error: invalid method declaration; return type required
override fun onLocationChanged(location: Location?) {
^
Main.java:35: error: <identifier> expected
override fun onLocationChanged(location: Location?) {
^
Main.java:35: error: ';' expected
override fun onLocationChanged(location: Location?) {
^
Main.java:35: error: illegal start of type
override fun onLocationChanged(location: Location?) {
^
Main.java:35: error: <identifier> expected
override fun onLocationChanged(location: Location?) {
^
Main.java:35: error: ';' expected
override fun onLocationChanged(location: Location?) {
^
Main.java:36: error: <identifier> expected
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: <identifier> expected
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: illegal start of type
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: ')' expected
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: ';' expected
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: illegal start of type
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: <identifier> expected
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:36: error: ';' expected
MLog.d(TAG, "onLocationChanged: " + location);
^
Main.java:37: error: illegal start of type
mLastLocation.onLocationChanged(location);
^
Main.java:37: error: <identifier> expected
mLastLocation.onLocationChanged(location);
^
Main.java:40: error: class, interface, or enum expected
override fun onProviderEnabled(provider: String) {
^
Main.java:42: error: class, interface, or enum expected
}
^
Main.java:46: error: class, interface, or enum expected
}
^
Main.java:50: error: class, interface, or enum expected
}
^
Main.java:59: error: class, interface, or enum expected
}
^
Main.java:63: error: class, interface, or enum expected
super.onStartCommand(intent, flags, startId);
^
Main.java:64: error: class, interface, or enum expected
return START_STICKY;
^
Main.java:65: error: class, interface, or enum expected
}
^
Main.java:69: error: class, interface, or enum expected
initializeLocationManager();
^
Main.java:70: error: class, interface, or enum expected
try {
^
Main.java:73: error: class, interface, or enum expected
} catch(ex: IllegalArgumentException) {
^
Main.java:80: error: class, interface, or enum expected
MLog.d(TAG, "onDestroy")
^
Main.java:87: error: class, interface, or enum expected
} catch (ex: Exception) {
^
Main.java:96: error: class, interface, or enum expected
if (mLocationManager == null) {
^
60 errors