|
| 1 | +/* Copyright 2024 Esri |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + * |
| 15 | + */ |
| 16 | + |
| 17 | +package com.esri.arcgismaps.sample.snaptofeatures.components |
| 18 | + |
| 19 | +import androidx.compose.foundation.BorderStroke |
| 20 | +import androidx.compose.foundation.background |
| 21 | +import androidx.compose.foundation.layout.Arrangement |
| 22 | +import androidx.compose.foundation.layout.Column |
| 23 | +import androidx.compose.foundation.layout.Row |
| 24 | +import androidx.compose.foundation.layout.fillMaxWidth |
| 25 | +import androidx.compose.foundation.layout.padding |
| 26 | +import androidx.compose.foundation.rememberScrollState |
| 27 | +import androidx.compose.foundation.shape.RoundedCornerShape |
| 28 | +import androidx.compose.foundation.verticalScroll |
| 29 | +import androidx.compose.material3.Divider |
| 30 | +import androidx.compose.material3.MaterialTheme |
| 31 | +import androidx.compose.material3.Surface |
| 32 | +import androidx.compose.material3.Switch |
| 33 | +import androidx.compose.material3.Text |
| 34 | +import androidx.compose.material3.TextButton |
| 35 | +import androidx.compose.runtime.Composable |
| 36 | +import androidx.compose.runtime.State |
| 37 | +import androidx.compose.ui.Alignment |
| 38 | +import androidx.compose.ui.Alignment.Companion.CenterHorizontally |
| 39 | +import androidx.compose.ui.Modifier |
| 40 | +import androidx.compose.ui.unit.dp |
| 41 | +import com.arcgismaps.mapping.layers.FeatureLayer |
| 42 | +import com.arcgismaps.mapping.view.geometryeditor.SnapSourceSettings |
| 43 | +import com.esri.arcgismaps.sample.sampleslib.theme.SampleTypography |
| 44 | + |
| 45 | +/** |
| 46 | + * Composable component to display the snapping configuration settings. |
| 47 | + */ |
| 48 | +@Composable |
| 49 | +fun SnapSettings( |
| 50 | + onSnappingChanged: (Boolean) -> Unit = { }, |
| 51 | + isSnappingEnabled: Boolean, |
| 52 | + snapSourceList: State<List<SnapSourceSettings>>, |
| 53 | + isSnapSourceEnabled: MutableList<Boolean>, |
| 54 | + onSnapSourceChanged: (Boolean, Int) -> Unit = { _: Boolean, _: Int -> }, |
| 55 | + onDismiss: () -> Unit = { } |
| 56 | +) { |
| 57 | + Surface( |
| 58 | + Modifier |
| 59 | + .background(MaterialTheme.colorScheme.background) |
| 60 | + .verticalScroll(rememberScrollState()) |
| 61 | + ) { |
| 62 | + Column(Modifier.background(MaterialTheme.colorScheme.background)) { |
| 63 | + Row( |
| 64 | + modifier = Modifier |
| 65 | + .fillMaxWidth() |
| 66 | + .padding(20.dp, 20.dp, 20.dp, 0.dp), |
| 67 | + verticalAlignment = Alignment.CenterVertically, |
| 68 | + horizontalArrangement = Arrangement.SpaceBetween |
| 69 | + ) { |
| 70 | + Text( |
| 71 | + style = SampleTypography.titleMedium, |
| 72 | + text = "Snap Settings", |
| 73 | + color = MaterialTheme.colorScheme.primary |
| 74 | + ) |
| 75 | + TextButton( onClick = onDismiss ) |
| 76 | + { Text(text = "Done") } |
| 77 | + } |
| 78 | + if (snapSourceList.value.isEmpty()) { |
| 79 | + Surface( |
| 80 | + modifier = Modifier.padding(20.dp), |
| 81 | + tonalElevation = 1.dp, |
| 82 | + shape = RoundedCornerShape(20.dp), |
| 83 | + border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant) |
| 84 | + ) { |
| 85 | + Column( |
| 86 | + modifier = Modifier.padding(14.dp) |
| 87 | + ) { |
| 88 | + Row( |
| 89 | + verticalAlignment = Alignment.CenterVertically, |
| 90 | + horizontalArrangement = Arrangement.Center |
| 91 | + ) { |
| 92 | + Text( |
| 93 | + style = SampleTypography.bodyMedium, |
| 94 | + color = MaterialTheme.colorScheme.primary, |
| 95 | + modifier = Modifier.weight(12f), |
| 96 | + text = "No valid snap sources." |
| 97 | + ) |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + } else { |
| 102 | + Surface( |
| 103 | + modifier = Modifier.padding(20.dp), |
| 104 | + tonalElevation = 1.dp, |
| 105 | + shape = RoundedCornerShape(20.dp), |
| 106 | + border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant) |
| 107 | + ) { |
| 108 | + Column( |
| 109 | + modifier = Modifier.padding(14.dp) |
| 110 | + ) { |
| 111 | + Row( |
| 112 | + modifier = Modifier.fillMaxWidth(), |
| 113 | + verticalAlignment = Alignment.CenterVertically, |
| 114 | + horizontalArrangement = Arrangement.SpaceBetween |
| 115 | + ) { |
| 116 | + Text( |
| 117 | + text = "Snapping", |
| 118 | + style = SampleTypography.bodyLarge |
| 119 | + ) |
| 120 | + } |
| 121 | + Divider(color = MaterialTheme.colorScheme.primary, thickness = 0.5.dp) |
| 122 | + Row( |
| 123 | + modifier = Modifier.fillMaxWidth(), |
| 124 | + verticalAlignment = Alignment.CenterVertically, |
| 125 | + horizontalArrangement = Arrangement.SpaceBetween |
| 126 | + ) { |
| 127 | + Text( |
| 128 | + text = "\t\tEnabled", |
| 129 | + style = SampleTypography.bodyLarge, |
| 130 | + ) |
| 131 | + Switch( |
| 132 | + checked = isSnappingEnabled, |
| 133 | + onCheckedChange = { |
| 134 | + onSnappingChanged(it) |
| 135 | + } |
| 136 | + ) |
| 137 | + } |
| 138 | + } |
| 139 | + } |
| 140 | + Surface( |
| 141 | + modifier = Modifier.padding(20.dp), |
| 142 | + tonalElevation = 1.dp, |
| 143 | + shape = RoundedCornerShape(20.dp), |
| 144 | + border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant) |
| 145 | + ) { |
| 146 | + Column( |
| 147 | + modifier = Modifier.padding(14.dp) |
| 148 | + ) { |
| 149 | + Column { |
| 150 | + Row { |
| 151 | + Text( |
| 152 | + modifier = Modifier.weight(12f), |
| 153 | + text = "Snap Sources", |
| 154 | + ) |
| 155 | + } |
| 156 | + Divider(color = MaterialTheme.colorScheme.primary, thickness = 0.5.dp) |
| 157 | + for (index in snapSourceList.value.indices) { |
| 158 | + Row( |
| 159 | + modifier = Modifier.fillMaxWidth(), |
| 160 | + verticalAlignment = Alignment.CenterVertically, |
| 161 | + horizontalArrangement = Arrangement.SpaceBetween |
| 162 | + ) { |
| 163 | + Text( |
| 164 | + modifier = Modifier.weight(1f), |
| 165 | + text = "\t\t${(snapSourceList.value[index].source as FeatureLayer).name}" |
| 166 | + ) |
| 167 | + Switch( |
| 168 | + checked = isSnapSourceEnabled[index], |
| 169 | + onCheckedChange = { newValue -> |
| 170 | + onSnapSourceChanged(newValue, index) |
| 171 | + } |
| 172 | + ) |
| 173 | + } |
| 174 | + Divider( |
| 175 | + color = MaterialTheme.colorScheme.primary, |
| 176 | + thickness = 0.5.dp |
| 177 | + ) |
| 178 | + } |
| 179 | + } |
| 180 | + Divider(thickness = 0.5.dp) |
| 181 | + TextButton( |
| 182 | + modifier = Modifier.align(CenterHorizontally), |
| 183 | + onClick = { |
| 184 | + for (x in snapSourceList.value.indices) { |
| 185 | + onSnapSourceChanged(true, x) |
| 186 | + } |
| 187 | + } |
| 188 | + ) |
| 189 | + { |
| 190 | + Text(text = "Enable All Sources") |
| 191 | + } |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | +} |
0 commit comments