Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-#] add compose-map package examples #233

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {
buildFeatures {
viewBinding true
buildConfig true
compose true
}

splits {
Expand All @@ -64,6 +65,9 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}
composeOptions {
kotlinCompilerExtensionVersion = libs.versions.compose.extension.get()
}

applicationVariants.configureEach {
it.compileConfiguration.resolutionStrategy {
Expand Down Expand Up @@ -165,6 +169,7 @@ dependencies {
releaseImplementation libs.firebase.crashlytics.ndk

implementation libs.dgis.sdk
implementation libs.dgis.compose

implementation libs.huawei.base
implementation libs.huawei.location
Expand All @@ -176,4 +181,15 @@ dependencies {
classifier = "sources"
}
}

// Compose
def composeBom = platform(libs.compose.bom)
implementation(composeBom)
implementation(libs.compose.foundational)
implementation(libs.compose.material3)
implementation(libs.compose.preview)
implementation(libs.compose.material)
debugImplementation(libs.compose.preview.debug)
implementation(libs.navigation.runtime)
implementation(libs.navigation.compose)
}
110 changes: 35 additions & 75 deletions app/config/androidLint/baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<issues format="6" by="lint 8.2.0" type="baseline" client="gradle" dependencies="false" name="AGP (8.2.0)" variant="all" version="8.2.0">
<issues format="6" by="lint 8.5.1" type="baseline" client="gradle" dependencies="false" name="AGP (8.5.1)" variant="all" version="8.5.1">

<issue
id="UnusedAttribute"
Expand Down Expand Up @@ -56,6 +56,39 @@
column="26"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.ModalBottomSheetLayout"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/ru/dgis/sdk/demo/compose/screens/ObjectsScreen.kt"
line="9"
column="8"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.ModalBottomSheetValue"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/ru/dgis/sdk/demo/compose/screens/ObjectsScreen.kt"
line="10"
column="8"/>
</issue>

<issue
id="UsingMaterialAndMaterial3Libraries"
message="Using a material import while also using the material3 library"
errorLine1="import androidx.compose.material.rememberModalBottomSheetState"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/java/ru/dgis/sdk/demo/compose/screens/ObjectsScreen.kt"
line="11"
column="8"/>
</issue>

<issue
id="VectorPath"
message="Very long vector path (1138 characters), which is bad for performance. Considering reducing precision, removing minor details or rasterizing vector."
Expand Down Expand Up @@ -155,17 +188,6 @@
column="12"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.color.colorAccent` appears to be unused"
errorLine1=" &lt;color name=&quot;colorAccent&quot;>@color/laurel&lt;/color>"
errorLine2=" ~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values/colors.xml"
line="5"
column="12"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.color.splash_background` appears to be unused"
Expand All @@ -177,28 +199,6 @@
column="12"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.color.text_foreground_day` appears to be unused"
errorLine1=" &lt;color name=&quot;text_foreground_day&quot;>#000&lt;/color>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values/colors.xml"
line="11"
column="12"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.color.text_foreground_night` appears to be unused"
errorLine1=" &lt;color name=&quot;text_foreground_night&quot;>#fff&lt;/color>"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values/colors.xml"
line="12"
column="12"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.color.status_bar_back` appears to be unused"
Expand Down Expand Up @@ -947,24 +947,6 @@
column="1"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.drawable.ic_minivan` appears to be unused">
<location
file="src/main/res/drawable/ic_minivan.png"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.drawable.ic_nav_point` appears to be unused"
errorLine1="&lt;vector xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;"
errorLine2="^">
<location
file="src/main/res/drawable/ic_nav_point.xml"
line="1"
column="1"/>
</issue>

<issue
id="UnusedResources"
message="The resource `R.drawable.ic_pin` appears to be unused"
Expand Down Expand Up @@ -1242,7 +1224,7 @@
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/res/values/strings.xml"
line="57"
line="63"
column="19"/>
</issue>

Expand Down Expand Up @@ -1292,28 +1274,6 @@
file="src/main/res/drawable-xxhdpi"/>
</issue>

<issue
id="UseTomlInstead"
message="Use version catalog instead"
errorLine1=" releaseImplementation &apos;com.google.firebase:firebase-analytics-ktx&apos;"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="build.gradle"
line="161"
column="27"/>
</issue>

<issue
id="UseTomlInstead"
message="Use version catalog instead"
errorLine1=" releaseImplementation &apos;com.google.firebase:firebase-crashlytics-ndk&apos;"
errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="build.gradle"
line="162"
column="27"/>
</issue>

<issue
id="ContentDescription"
message="Missing `contentDescription` attribute on image"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
android:name=".DownloadTerritoriesActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustNothing" />
<activity
android:name=".ComposeActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustNothing" />
<activity
android:name=".LocaleSwitchActivity"
android:screenOrientation="portrait"
Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/ru/dgis/sdk/demo/ComposeActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ru.dgis.sdk.demo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.lifecycle.viewmodel.compose.viewModel
import ru.dgis.sdk.demo.compose.MapViewModel
import ru.dgis.sdk.demo.compose.screens.HomeScreen
import ru.dgis.sdk.map.MapTheme

class ComposeActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
val viewModel = viewModel<MapViewModel>()

// Update the theme to match the system settings.
val theme = if (isSystemInDarkTheme()) {
MapTheme.defaultDarkTheme
} else {
MapTheme.defaultTheme
}
viewModel.state.setTheme(theme)

HomeScreen(
mapState = viewModel.state
)
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/java/ru/dgis/sdk/demo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class MainActivity : AppCompatActivity() {
private val RECORD_REQUEST_CODE = 101

private val pages = listOf(
Page("Compose Examples") {
val intent = Intent(this@MainActivity, ComposeActivity::class.java)
startActivity(intent)
},
Page("Generic Map") {
val intent = Intent(this@MainActivity, GenericMapActivity::class.java)
startActivity(intent)
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/ru/dgis/sdk/demo/compose/CaptionSlider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ru.dgis.sdk.demo.compose

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable

@Composable
fun CaptionSlider(caption: String, value: Int, onValueChange: (Int) -> Unit) {
Column {
Text(text = "$caption: $value")
androidx.compose.material3.Slider(
value = value.toFloat(),
onValueChange = { newValue ->
onValueChange(newValue.toInt())
},
valueRange = 0f..100f,
steps = 100
)
}
}
43 changes: 43 additions & 0 deletions app/src/main/java/ru/dgis/sdk/demo/compose/EnumToggle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ru.dgis.sdk.demo.compose

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

interface Displayable {
val displayName: String
}

val <T> T.displayName: String
get() = if (this is Displayable) this.displayName else this.toString()

@Composable
inline fun <reified T : Enum<T>> EnumToggle(
value: T,
isSelected: Boolean,
crossinline onSelected: (T) -> Unit
) {
Button(
onClick = { onSelected(value) },
colors = ButtonDefaults.buttonColors(
containerColor = if (isSelected) {
MaterialTheme.colorScheme.primary
} else {
Color.LightGray
},
contentColor = if (isSelected) {
Color.White
} else {
Color.Black
}
),
shape = RoundedCornerShape(8.dp)
) {
Text(text = value.displayName)
}
}
58 changes: 58 additions & 0 deletions app/src/main/java/ru/dgis/sdk/demo/compose/MapControls.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ru.dgis.sdk.demo.compose

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import ru.dgis.sdk.compose.map.controls.CompassComposable
import ru.dgis.sdk.compose.map.controls.IndoorComposable
import ru.dgis.sdk.compose.map.controls.MyLocationComposable
import ru.dgis.sdk.compose.map.controls.TrafficComposable
import ru.dgis.sdk.compose.map.controls.ZoomComposable
import ru.dgis.sdk.map.Map

@Composable
fun MapControls(map: Map) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(5.dp),
contentAlignment = Alignment.CenterStart
) {
Column(
modifier = Modifier
.align(Alignment.TopEnd)
.padding(top = 30.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
TrafficComposable(map)
}
Column(
modifier = Modifier.align(Alignment.CenterEnd),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
ZoomComposable(map)
}
Column(
modifier = Modifier
.align(Alignment.BottomEnd)
.padding(bottom = 30.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
CompassComposable(map)
MyLocationComposable(map)
}
Column(
modifier = Modifier.align(Alignment.CenterStart),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
IndoorComposable(map)
}
}
}
Loading
Loading