fork download
  1. import android.app.Service
  2. import android.content.Context
  3. import android.content.Intent
  4. import android.location.Location
  5. import android.location.LocationListener
  6. import android.location.LocationManager
  7. import android.os.Bundle
  8. import android.os.IBinder
  9. import android.util.Log
  10. import com.napoleonit.monita.utilities.log.MLog
  11.  
  12.  
  13. /**
  14.  * Created by user on 03.05.16.
  15.  */
  16.  
  17.  
  18. private val TAG: String = "BOOMBOOMTESTGPS"
  19. private var mLocationManager: LocationManager = null!!
  20. private val LOCATION_INTERVAL: Long = 1000
  21. private val LOCATION_DISTANCE: Float = 10f
  22.  
  23. abstract class MyService : Service() {
  24.  
  25.  
  26. class LocationListener(gpS_PROVIDER: String) : android.location.LocationListener {
  27.  
  28. var mLastLocation: LocationListener = null!!
  29.  
  30. fun LocationListener(provider: String) {
  31. MLog.d(TAG, "LocationListener " + provider);
  32. var mLastLocation = Location(provider);
  33. }
  34.  
  35. override fun onLocationChanged(location: Location?) {
  36. MLog.d(TAG, "onLocationChanged: " + location);
  37. mLastLocation.onLocationChanged(location);
  38. }
  39.  
  40. override fun onProviderEnabled(provider: String) {
  41. MLog.d(TAG, "onProviderEnabled: " + provider);
  42. }
  43.  
  44. override fun onProviderDisabled(provider: String) {
  45. MLog.d(TAG, "onProviderDisabled " + provider);
  46. }
  47.  
  48. override fun onStatusChanged(provider: String, status: Int, extras: Bundle) {
  49. MLog.d(TAG, "onStatusChanged " + provider);
  50. }
  51. }
  52.  
  53. var mLocationListeners = arrayOf(
  54. LocationListener (LocationManager.GPS_PROVIDER),
  55. LocationListener (LocationManager.NETWORK_PROVIDER))
  56.  
  57. override fun onBind(arg0 : Intent):IBinder {
  58. return null!!;
  59. }
  60.  
  61. override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int {
  62. MLog.d(TAG, "onStartCommand");
  63. super.onStartCommand(intent, flags, startId);
  64. return START_STICKY;
  65. }
  66.  
  67. override fun onCreate() {
  68. MLog.d(TAG, "onCreate");
  69. initializeLocationManager();
  70. try {
  71. mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_INTERVAL, LOCATION_DISTANCE,
  72. mLocationListeners[1]);
  73. } catch(ex: IllegalArgumentException) {
  74. MLog.d(TAG, "gps provider does not exist " + ex.message)
  75. }
  76. }
  77.  
  78. override fun onDestroy() {
  79. var y: Int = 0; // Костыль; Проблема с for in
  80. MLog.d(TAG, "onDestroy")
  81. super.onDestroy()
  82. if (mLocationManager != null) {
  83. for(i in mLocationListeners) {
  84. try {
  85. mLocationManager.removeUpdates(mLocationListeners[y])
  86. y++;
  87. } catch (ex: Exception) {
  88. Log.i(TAG, "fail to remove location listeners, ignore", ex)
  89. }
  90. }
  91. }
  92. }
  93.  
  94. private fun initializeLocationManager() {
  95. Log.e(TAG, "initializeLocationManager");
  96. if (mLocationManager == null) {
  97. mLocationManager = applicationContext.getSystemService(Context.LOCATION_SERVICE) as (LocationManager)
  98. }
  99. }
  100.  
  101. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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
stdout
Standard output is empty