diff --git a/.github/workflows/build-kotlin.yml b/.github/workflows/build-kotlin.yml new file mode 100644 index 0000000..4ab7485 --- /dev/null +++ b/.github/workflows/build-kotlin.yml @@ -0,0 +1,40 @@ +name: build-kotlin + +on: + workflow_dispatch: + push: + branches: [main] + pull_request: + branches: [main] + +defaults: + run: + work-directory: ./kotlin/ + +concurrency: + # cancel jobs on PRs only + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checking out branch + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + + - name: Setup Android SDK + uses: android-actions/setup-android@v3 + + - name: Build with Gradle + run: ./gradlew build + + - name: Unit test + run: ./gradlew test diff --git a/kotlin/app/build.gradle.kts b/kotlin/app/build.gradle.kts new file mode 100644 index 0000000..a3a758b --- /dev/null +++ b/kotlin/app/build.gradle.kts @@ -0,0 +1,51 @@ +plugins { + alias(libs.plugins.androidApplication) + alias(libs.plugins.jetbrainsKotlinAndroid) +} + +android { + namespace = "software.amazon.location.polyline" + compileSdk = 34 + + defaultConfig { + applicationId = "software.amazon.location.polyline" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(libs.androidx.activity) + implementation(libs.androidx.constraintlayout) + implementation(project(":polyline")) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + + implementation("org.maplibre.gl:android-sdk:11.2.0") +} \ No newline at end of file diff --git a/kotlin/app/proguard-rules.pro b/kotlin/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/kotlin/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 \ No newline at end of file diff --git a/kotlin/app/src/androidTest/java/software/amazon/location/polylinedemo/ExampleInstrumentedTest.kt b/kotlin/app/src/androidTest/java/software/amazon/location/polylinedemo/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..5712f8c --- /dev/null +++ b/kotlin/app/src/androidTest/java/software/amazon/location/polylinedemo/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package software.amazon.location.polylinedemo + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.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.getInstrumentation().targetContext + assertEquals("software.amazon.location.polyline", appContext.packageName) + } +} \ No newline at end of file diff --git a/kotlin/app/src/main/AndroidManifest.xml b/kotlin/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..7f005ff --- /dev/null +++ b/kotlin/app/src/main/AndroidManifest.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/app/src/main/java/software/amazon/location/polylinedemo/MainActivity.kt b/kotlin/app/src/main/java/software/amazon/location/polylinedemo/MainActivity.kt new file mode 100644 index 0000000..9b1d414 --- /dev/null +++ b/kotlin/app/src/main/java/software/amazon/location/polylinedemo/MainActivity.kt @@ -0,0 +1,146 @@ +package software.amazon.location.polylinedemo + +import androidx.appcompat.app.AppCompatActivity +import android.graphics.Color +import android.os.Bundle +import android.view.LayoutInflater +import org.maplibre.android.MapLibre +import org.maplibre.android.camera.CameraPosition +import org.maplibre.android.geometry.LatLng +import org.maplibre.android.maps.MapView +import org.maplibre.android.style.layers.LineLayer +import org.maplibre.android.style.layers.Property +import org.maplibre.android.style.layers.PropertyFactory +import org.maplibre.android.style.sources.GeoJsonOptions +import org.maplibre.android.style.sources.GeoJsonSource + +import software.amazon.location.polyline.R +import software.amazon.location.polyline.encodeFromLngLatArray +import software.amazon.location.polyline.decodeToLineStringFeature + +class MainActivity : AppCompatActivity() { + + // Declare a variable for MapView + private lateinit var mapView: MapView + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + // Init MapLibre + MapLibre.getInstance(this) + + // Init layout view + val inflater = LayoutInflater.from(this) + val rootView = inflater.inflate(R.layout.activity_main, null) + setContentView(rootView) + + // Init the MapView + mapView = rootView.findViewById(R.id.mapView) + mapView.getMapAsync { map -> + map.setStyle("https://demotiles.maplibre.org/style.json") { style -> + + val lngLatArray : Array = arrayOf( + doubleArrayOf(-28.193, -61.38823), + doubleArrayOf(-26.78675, -45.01442), + doubleArrayOf(-9.20863, -43.2583), + doubleArrayOf(-9.20863, -52.20348), + doubleArrayOf(-26.78675, -53.26775), + doubleArrayOf(-28.193, -61.38823), + doubleArrayOf(-20.10706, -61.21942), + doubleArrayOf(-19.05238, -57.07888), + doubleArrayOf(-8.85706, -57.07888), + doubleArrayOf(-9.20863, -61.21942), + doubleArrayOf(-20.10706, -61.21942), + doubleArrayOf(-0.068, -60.70753), + doubleArrayOf(2.7445, -43.75829), + doubleArrayOf(-0.068, -60.70753), + doubleArrayOf(11.182, -60.53506), + doubleArrayOf(6.96325, -55.11851), + doubleArrayOf(11.182, -60.53506), + doubleArrayOf(16.807, -54.51079), + doubleArrayOf(3.47762, -65.61471), + doubleArrayOf(11.182, -60.53506), + doubleArrayOf(22.432, -60.18734), + doubleArrayOf(25.59606, -42.99168), + doubleArrayOf(22.432, -60.18734), + doubleArrayOf(31.22106, -59.83591), + doubleArrayOf(32.62731, -53.05697), + doubleArrayOf(31.22106, -59.83591), + doubleArrayOf(38.25231, -59.65879), + doubleArrayOf(40.36169, -53.05697), + doubleArrayOf(40.01012, -54.71438), + doubleArrayOf(44.22887, -53.26775), + doubleArrayOf(47.39294, -55.5186), + doubleArrayOf(46.68981, -59.65879), + doubleArrayOf(53.72106, -59.30172), + doubleArrayOf(51.26012, -56.11118), + doubleArrayOf(56.182, -53.89389), + doubleArrayOf(60.40075, -56.69477), + doubleArrayOf(51.26012, -56.11118), + doubleArrayOf(53.72106, -59.30172), + doubleArrayOf(58.64294, -59.48073), + ); + + // Encode and decode the route polyline to demonstrate how the APIs are used. + val routePolyline = encodeFromLngLatArray(lngLatArray); + val decodedGeoJSON = + decodeToLineStringFeature(routePolyline); + + style.addSource( + GeoJsonSource( + "polylineSource", + decodedGeoJSON, + GeoJsonOptions().withLineMetrics(true) + ) + ) + + style.addLayer( + LineLayer("polyline", "polylineSource") + .withProperties( + PropertyFactory.lineColor(Color.RED), + PropertyFactory.lineWidth(2.0f), + PropertyFactory.lineCap(Property.LINE_CAP_ROUND), + PropertyFactory.lineJoin(Property.LINE_JOIN_ROUND) + ) + ) + } + + map.cameraPosition = CameraPosition.Builder().target(LatLng(0.0,0.0)).zoom(1.0).build() + } + } + + override fun onStart() { + super.onStart() + mapView.onStart() + } + + override fun onResume() { + super.onResume() + mapView.onResume() + } + + override fun onPause() { + super.onPause() + mapView.onPause() + } + + override fun onStop() { + super.onStop() + mapView.onStop() + } + + override fun onLowMemory() { + super.onLowMemory() + mapView.onLowMemory() + } + + override fun onDestroy() { + super.onDestroy() + mapView.onDestroy() + } + + override fun onSaveInstanceState(outState: Bundle) { + super.onSaveInstanceState(outState) + mapView.onSaveInstanceState(outState) + } +} \ No newline at end of file diff --git a/kotlin/app/src/main/res/drawable/ic_launcher_background.xml b/kotlin/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/kotlin/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kotlin/app/src/main/res/drawable/ic_launcher_foreground.xml b/kotlin/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/kotlin/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/kotlin/app/src/main/res/layout/activity_main.xml b/kotlin/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..d75d3d8 --- /dev/null +++ b/kotlin/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/kotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/kotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/kotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/kotlin/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/kotlin/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/kotlin/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/kotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/kotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/kotlin/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/kotlin/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/kotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/kotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/kotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/kotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/kotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/kotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/kotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/kotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/kotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/kotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/kotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/kotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/kotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/kotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/kotlin/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/kotlin/app/src/main/res/values-night/themes.xml b/kotlin/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..c0667d8 --- /dev/null +++ b/kotlin/app/src/main/res/values-night/themes.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/kotlin/app/src/main/res/values/colors.xml b/kotlin/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..c8524cd --- /dev/null +++ b/kotlin/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/kotlin/app/src/main/res/values/strings.xml b/kotlin/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..8a70c01 --- /dev/null +++ b/kotlin/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + PolylineDemo + \ No newline at end of file diff --git a/kotlin/app/src/main/res/values/themes.xml b/kotlin/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..e92b397 --- /dev/null +++ b/kotlin/app/src/main/res/values/themes.xml @@ -0,0 +1,9 @@ + + + + +