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