From 1afecc5bdd5d85aeff9724f38fbd2120c4e24cb7 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Fri, 3 May 2019 15:37:52 +0530 Subject: [PATCH] Initial commit --- .gitignore | 13 ++ .idea/codeStyles/Project.xml | 154 ++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/encodings.xml | 4 + .idea/gradle.xml | 18 ++ .idea/misc.xml | 9 + .idea/runConfigurations.xml | 12 ++ app/.gitignore | 1 + app/build.gradle | 34 ++++ app/proguard-rules.pro | 21 +++ .../speedlogger/ExampleInstrumentedTest.kt | 24 +++ app/src/main/AndroidManifest.xml | 27 +++ .../java/com/andro/speedlogger/CLocation.kt | 10 + .../com/andro/speedlogger/IBaseGpsListener.kt | 18 ++ .../com/andro/speedlogger/MainActivity.kt | 85 +++++++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable/ic_launcher_background.xml | 74 ++++++++ app/src/main/res/layout/activity_main.xml | 33 ++++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 2963 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 4905 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2060 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2783 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4490 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 6895 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6387 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10413 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9128 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15132 bytes app/src/main/res/values/colors.xml | 6 + app/src/main/res/values/strings.xml | 3 + app/src/main/res/values/styles.xml | 11 ++ .../com/andro/speedlogger/ExampleUnitTest.kt | 17 ++ build.gradle | 28 +++ gradle.properties | 15 ++ gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 54329 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 172 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 1 + 41 files changed, 929 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 app/.gitignore create mode 100644 app/build.gradle create mode 100644 app/proguard-rules.pro create mode 100644 app/src/androidTest/java/com/andro/speedlogger/ExampleInstrumentedTest.kt create mode 100644 app/src/main/AndroidManifest.xml create mode 100644 app/src/main/java/com/andro/speedlogger/CLocation.kt create mode 100644 app/src/main/java/com/andro/speedlogger/IBaseGpsListener.kt create mode 100644 app/src/main/java/com/andro/speedlogger/MainActivity.kt create mode 100644 app/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 app/src/main/res/values/colors.xml create mode 100644 app/src/main/res/values/strings.xml create mode 100644 app/src/main/res/values/styles.xml create mode 100644 app/src/test/java/com/andro/speedlogger/ExampleUnitTest.kt create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b75303 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..56f9518 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,154 @@ + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..15a15b2 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..78cd405 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.andro.speedlogger" + minSdkVersion 21 + targetSdkVersion 28 + versionCode 2 + versionName "1.1" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'com.github.anastr:speedviewlib:1.3.1' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/andro/speedlogger/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/andro/speedlogger/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..248667c --- /dev/null +++ b/app/src/androidTest/java/com/andro/speedlogger/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.andro.speedlogger + +import android.support.test.InstrumentationRegistry +import android.support.test.runner.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getTargetContext() + assertEquals("com.andro.speedlogger", appContext.packageName) + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..902cf70 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/andro/speedlogger/CLocation.kt b/app/src/main/java/com/andro/speedlogger/CLocation.kt new file mode 100644 index 0000000..154410d --- /dev/null +++ b/app/src/main/java/com/andro/speedlogger/CLocation.kt @@ -0,0 +1,10 @@ +package com.andro.speedlogger + +import android.location.Location + +class CLocation constructor(location: Location) : Location(location) { + + override fun getSpeed(): Float { + return super.getSpeed() * 3.6f * 2 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/andro/speedlogger/IBaseGpsListener.kt b/app/src/main/java/com/andro/speedlogger/IBaseGpsListener.kt new file mode 100644 index 0000000..7b933b7 --- /dev/null +++ b/app/src/main/java/com/andro/speedlogger/IBaseGpsListener.kt @@ -0,0 +1,18 @@ +package com.andro.speedlogger + +import android.location.GpsStatus +import android.location.Location +import android.location.LocationListener +import android.os.Bundle + +interface IBaseGpsListener : LocationListener, GpsStatus.Listener { + override fun onLocationChanged(location: Location) + + override fun onProviderDisabled(provider: String) + + override fun onProviderEnabled(provider: String) + + override fun onStatusChanged(provider: String, status: Int, extras: Bundle) + + override fun onGpsStatusChanged(event: Int) +} \ No newline at end of file diff --git a/app/src/main/java/com/andro/speedlogger/MainActivity.kt b/app/src/main/java/com/andro/speedlogger/MainActivity.kt new file mode 100644 index 0000000..7eee7ff --- /dev/null +++ b/app/src/main/java/com/andro/speedlogger/MainActivity.kt @@ -0,0 +1,85 @@ +package com.andro.speedlogger + +import android.Manifest +import android.annotation.SuppressLint +import android.content.Context +import android.content.pm.PackageManager +import android.location.Location +import android.location.LocationManager +import android.os.Bundle +import android.support.v4.content.ContextCompat +import android.support.v7.app.AppCompatActivity +import android.widget.Toast +import kotlinx.android.synthetic.main.activity_main.* +import java.util.* + +class MainActivity : AppCompatActivity(), IBaseGpsListener { + + private var state = false + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + start_stop_btn.setOnClickListener { + val locationManager = this.getSystemService(Context.LOCATION_SERVICE) as LocationManager + state = !state + if (state) { + start_stop_btn.text = "Stop" + if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) + != PackageManager.PERMISSION_GRANTED) { + Toast.makeText(this, "Permissions not granted", Toast.LENGTH_SHORT).show() + } else { + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0f, this) + this.updateSpeed(null) + } + } else { + start_stop_btn.text = "Start" + locationManager.removeUpdates(this) + } + } + } + + override fun finish() { + super.finish() + System.exit(0) + } + + @SuppressLint("SetTextI18n") + private fun updateSpeed(location: CLocation?) { + val nCurrentSpeed: Float + if (location != null) { + nCurrentSpeed = location.speed + val fmt = Formatter(StringBuilder()) + fmt.format(Locale.US, "%5.1f", nCurrentSpeed) + var strCurrentSpeed = fmt.toString() + strCurrentSpeed = strCurrentSpeed.replace(' ', '0') + val strUnits = "km/hr" + txtCurrentSpeed.text = "$strCurrentSpeed $strUnits" + gauge.speedTo(strCurrentSpeed.toFloat(), 500) + } else { + txtCurrentSpeed.text = "Not receiving updates.." + } + } + + override fun onLocationChanged(location: Location) { + val myLocation = CLocation(location) + this.updateSpeed(myLocation) + } + + override fun onProviderDisabled(provider: String) { + + } + + override fun onProviderEnabled(provider: String) { + + } + + override fun onStatusChanged(provider: String, status: Int, extras: Bundle) { + + } + + override fun onGpsStatusChanged(event: Int) { + + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..6348baa --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..a0ad202 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,74 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..135999e --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,33 @@ + + + + + +