-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK-#] add compose-map package examples
- Loading branch information
Showing
27 changed files
with
1,155 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/src/main/java/ru/dgis/sdk/demo/compose/CaptionSlider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.