Skip to content

Commit

Permalink
Convert to Kotlin
Browse files Browse the repository at this point in the history
- Also, Use Gson
  • Loading branch information
elevenfive committed Mar 28, 2019
1 parent ec0d947 commit 60d052b
Show file tree
Hide file tree
Showing 11 changed files with 283 additions and 428 deletions.
11 changes: 9 additions & 2 deletions app/build.gradle
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
Expand Down Expand Up @@ -30,6 +32,11 @@ android {

dependencies {
implementation project(":libndt7")
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
repositories {
mavenCentral()
}

This file was deleted.

49 changes: 49 additions & 0 deletions app/src/main/java/net/measurementlab/ndt7/android/MainActivity.kt
@@ -0,0 +1,49 @@
package net.measurementlab.ndt7.android

import android.os.Handler
import android.os.Looper
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Toast

private const val TAG = "MainActivity"

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val settings = Settings()
settings.hostname = "35.235.104.27"
settings.port = 443
settings.skipTlsCertificateVerification = true
val client = MyClient(settings)

if (!client.runDownload()) {
Toast.makeText(this, "runDownload failed", Toast.LENGTH_SHORT).show()
}
}

private inner class MyClient constructor(settings: Settings) : Client(settings) {

override fun onLogInfo(message: String?) {
Log.i(TAG, "onLogInfo: $message")
}

override fun onError(error: String?) {
Log.e(TAG, "onError: $error")

Handler(Looper.getMainLooper()).post { Toast.makeText(this@MainActivity, error, Toast.LENGTH_SHORT).show() }
}

override fun onServerDownloadMeasurement(measurement: Measurement) {
Log.d(TAG, "server measurement: $measurement")
}

override fun onClientDownloadMeasurement(measurement: Measurement) {
Log.d(TAG, "client measurement: $measurement")
}
}
}
11 changes: 9 additions & 2 deletions build.gradle
@@ -1,12 +1,19 @@
buildscript {

ext.kotlin_version = '1.3.21'
ext.okhttp_version = '3.14.0'
ext.support_library_version = '28.0.0'
ext.constraint_layout_version = '1.1.3'
ext.android_gradle_plugin_version = '3.3.2'
ext.gson_version = '2.8.5'

repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "com.android.tools.build:gradle:$android_gradle_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand Down
12 changes: 10 additions & 2 deletions libndt7/build.gradle
@@ -1,4 +1,6 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 28
Expand Down Expand Up @@ -27,6 +29,12 @@ android {
}

dependencies {
api 'com.squareup.okhttp3:okhttp:3.14.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.google.code.gson:gson:$gson_version"
}

repositories {
mavenCentral()
}

0 comments on commit 60d052b

Please sign in to comment.