Skip to content

Commit

Permalink
Sample app with stub polyline library.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbalfour-amzn committed Sep 9, 2024
1 parent 1e93e77 commit a7e58e1
Show file tree
Hide file tree
Showing 39 changed files with 1,219 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build-kotlin.yml
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions kotlin/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
21 changes: 21 additions & 0 deletions kotlin/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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)
}
}
26 changes: 26 additions & 0 deletions kotlin/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.PolylineDemo"
tools:targetApi="31">
<activity
android:name="software.amazon.location.polylinedemo.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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<DoubleArray> = 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)
}
}
Loading

0 comments on commit a7e58e1

Please sign in to comment.