diff --git a/.gitignore b/.gitignore index 185b1a64..95af1b44 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ gradle.properties /ShaderError.glsl /.kotlin /.lwjgl +/local.properties diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/android/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/android/build.gradle.kts b/android/build.gradle.kts new file mode 100644 index 00000000..642ae2c5 --- /dev/null +++ b/android/build.gradle.kts @@ -0,0 +1,62 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.icegps.orx" + compileSdk { + version = release(36) + } + + defaultConfig { + applicationId = "com.icegps.orx" + minSdk = 28 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + buildFeatures { + viewBinding = true + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } +} + +kotlin { + compilerOptions.jvmTarget = JvmTarget.JVM_17 +} + +dependencies { + implementation(libs.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(libs.androidx.activity) + implementation(libs.androidx.constraintlayout) + implementation(libs.mapbox.maps) + implementation(project(":math")) + implementation(project(":orx-triangulation")) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(project(":icegps-common")) + implementation(project(":icegps-shared")) + + testImplementation(libs.junit) + androidTestImplementation(libs.ext.junit) + androidTestImplementation(libs.androidx.espresso.core) +} \ No newline at end of file diff --git a/android/proguard-rules.pro b/android/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/android/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/android/src/androidTest/java/com/icegps/orx/ExampleInstrumentedTest.kt b/android/src/androidTest/java/com/icegps/orx/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..2973c094 --- /dev/null +++ b/android/src/androidTest/java/com/icegps/orx/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.icegps.orx + +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("com.icegps.orx", appContext.packageName) + } +} \ No newline at end of file diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml new file mode 100644 index 00000000..d92b7ef5 --- /dev/null +++ b/android/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/src/main/java/com/icegps/orx/MainActivity.kt b/android/src/main/java/com/icegps/orx/MainActivity.kt new file mode 100644 index 00000000..727e01d0 --- /dev/null +++ b/android/src/main/java/com/icegps/orx/MainActivity.kt @@ -0,0 +1,77 @@ +package com.icegps.orx + +import android.os.Bundle +import android.util.Log +import androidx.activity.enableEdgeToEdge +import androidx.appcompat.app.AppCompatActivity +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsCompat +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.icegps.common.helper.GeoHelper +import com.icegps.orx.databinding.ActivityMainBinding +import com.icegps.shared.SharedHttpClient +import com.icegps.shared.SharedJson +import com.icegps.shared.api.OpenElevation +import com.icegps.shared.api.OpenElevationApi +import com.icegps.shared.ktx.TAG +import com.icegps.shared.model.GeoPoint +import com.mapbox.geojson.Point +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.launchIn +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onEach +import kotlinx.coroutines.flow.update +import org.openrndr.extra.triangulation.DelaunayTriangulation +import org.openrndr.math.Vector2 +import org.openrndr.math.Vector3 + +class MainActivity : AppCompatActivity() { + private lateinit var binding: ActivityMainBinding + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) + ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> + val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) + v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) + insets + } + } +} + +class MainViewModel : ViewModel() { + private val geoHelper = GeoHelper.getSharedInstance() + private val openElevation: OpenElevationApi = OpenElevation(SharedHttpClient(SharedJson())) + + private val _points = MutableStateFlow>(emptyList()) + + init { + _points.map { + openElevation.lookup(it.map { GeoPoint(it.longitude(), it.latitude(), it.altitude()) }) + }.catch { + Log.e(TAG, "高程请求失败", it) + }.map { + it.map { + val enu = + geoHelper.wgs84ToENU(lon = it.longitude, lat = it.latitude, hgt = it.altitude) + Vector2(enu.x, enu.y) + } + }.onEach { + val triangulation = DelaunayTriangulation(it) + triangulation.triangles().map { + it.contour + } + }.launchIn(viewModelScope) + } + + fun addPoint(point: Point) { + _points.update { + it.toMutableList().apply { + add(point) + } + } + } +} \ No newline at end of file diff --git a/android/src/main/res/drawable/ic_launcher_background.xml b/android/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/android/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/src/main/res/drawable/ic_launcher_foreground.xml b/android/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/android/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/android/src/main/res/layout/activity_main.xml b/android/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..86a5d977 --- /dev/null +++ b/android/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/android/src/main/res/mipmap-anydpi/ic_launcher.xml b/android/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 00000000..6f3b755b --- /dev/null +++ b/android/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/android/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 00000000..6f3b755b --- /dev/null +++ b/android/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/src/main/res/mipmap-hdpi/ic_launcher.webp b/android/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 00000000..c209e78e Binary files /dev/null and b/android/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/android/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/android/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 00000000..b2dfe3d1 Binary files /dev/null and b/android/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/android/src/main/res/mipmap-mdpi/ic_launcher.webp b/android/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 00000000..4f0f1d64 Binary files /dev/null and b/android/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/android/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/android/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 00000000..62b611da Binary files /dev/null and b/android/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/android/src/main/res/mipmap-xhdpi/ic_launcher.webp b/android/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 00000000..948a3070 Binary files /dev/null and b/android/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/android/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/android/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 00000000..1b9a6956 Binary files /dev/null and b/android/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/android/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/android/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 00000000..28d4b77f Binary files /dev/null and b/android/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 00000000..9287f508 Binary files /dev/null and b/android/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/android/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/android/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 00000000..aa7d6427 Binary files /dev/null and b/android/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 00000000..9126ae37 Binary files /dev/null and b/android/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/android/src/main/res/values-night/themes.xml b/android/src/main/res/values-night/themes.xml new file mode 100644 index 00000000..e19e9124 --- /dev/null +++ b/android/src/main/res/values-night/themes.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/android/src/main/res/values/colors.xml b/android/src/main/res/values/colors.xml new file mode 100644 index 00000000..c8524cd9 --- /dev/null +++ b/android/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/android/src/main/res/values/mapbox_access_token.xml b/android/src/main/res/values/mapbox_access_token.xml new file mode 100644 index 00000000..1a4ff3a3 --- /dev/null +++ b/android/src/main/res/values/mapbox_access_token.xml @@ -0,0 +1,4 @@ + + + pk.eyJ1IjoienpxMSIsImEiOiJjbWYzbzV1MzQwMHJvMmpvbG1wbjJwdjUyIn0.LvKjIrCv9dAFcGxOM52f2Q + \ No newline at end of file diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml new file mode 100644 index 00000000..0c8c773f --- /dev/null +++ b/android/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + icegps-orx + \ No newline at end of file diff --git a/android/src/main/res/values/themes.xml b/android/src/main/res/values/themes.xml new file mode 100644 index 00000000..f31f908a --- /dev/null +++ b/android/src/main/res/values/themes.xml @@ -0,0 +1,9 @@ + + + + +