Skip to content

Commit

Permalink
Merge pull request #225 from 2gis/feature-SDK-#-add-preset-option-to-…
Browse files Browse the repository at this point in the history
…navigation

[SDK] Added a graphics preset switcher to the navigation
  • Loading branch information
asmin289 authored Aug 29, 2024
2 parents 9e06c48 + 5bcaf82 commit e08daec
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/src/main/java/ru/dgis/sdk/demo/NavigationActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.RadioGroup
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
Expand All @@ -25,6 +26,7 @@ import ru.dgis.sdk.demo.databinding.ActivityNavigationBinding
import ru.dgis.sdk.demo.vm.NavigationViewModel
import ru.dgis.sdk.geometry.point
import ru.dgis.sdk.map.DgisMapObject
import ru.dgis.sdk.map.GraphicsPreset
import ru.dgis.sdk.map.Map
import ru.dgis.sdk.map.MapView
import ru.dgis.sdk.map.ScreenDistance
Expand All @@ -42,6 +44,7 @@ class NavigationActivity : AppCompatActivity(), TouchEventsObserver {

private var viewModel: NavigationViewModel? = null

private lateinit var graphicPreset: RadioGroup
private lateinit var map: Map
private lateinit var mapView: MapView
private lateinit var binding: ActivityNavigationBinding
Expand All @@ -56,6 +59,8 @@ class NavigationActivity : AppCompatActivity(), TouchEventsObserver {
binding = ActivityNavigationBinding.inflate(layoutInflater)
setContentView(binding.root)

graphicPreset = findViewById(R.id.graphicPreset)
graphicPreset.check(R.id.normalPreset)
mapView = findViewById(R.id.mapView)
routeEditorView = findViewById(R.id.routeEditorView)
navigationView = findViewById(R.id.navigationView)
Expand All @@ -76,6 +81,22 @@ class NavigationActivity : AppCompatActivity(), TouchEventsObserver {
)
}
)
when (it.graphicsPresetHintChannel.value) {
GraphicsPreset.LITE -> graphicPreset.check(R.id.litePreset)
GraphicsPreset.NORMAL -> graphicPreset.check(R.id.normalPreset)
GraphicsPreset.IMMERSIVE -> graphicPreset.check(R.id.immersivePreset)
else -> {}
}
}
}

graphicPreset.setOnCheckedChangeListener { _, checkedId ->
mapView.getMapAsync { map ->
when (checkedId) {
R.id.litePreset -> map.graphicsPreset = GraphicsPreset.LITE
R.id.normalPreset -> map.graphicsPreset = GraphicsPreset.NORMAL
R.id.immersivePreset -> map.graphicsPreset = GraphicsPreset.IMMERSIVE
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions app/src/main/res/layout/activity_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,41 @@
android:text="Use simulation"
tools:ignore="HardcodedText" />

<RadioGroup
android:id="@+id/graphicPreset"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:paddingStart="24dp"
android:paddingEnd="24dp">

<RadioButton
android:id="@+id/litePreset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Lite"
tools:ignore="HardcodedText" />

<RadioButton
android:id="@+id/normalPreset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Normal"
tools:ignore="HardcodedText" />

<RadioButton
android:id="@+id/immersivePreset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Immersive"
tools:ignore="HardcodedText" />

</RadioGroup>

<TextView
android:id="@+id/availabilityTextView"
android:layout_width="match_parent"
Expand All @@ -173,6 +208,7 @@
tools:ignore="HardcodedText" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

<androidx.constraintlayout.widget.Group
android:id="@+id/route_editing_group"
android:layout_width="wrap_content"
Expand Down

0 comments on commit e08daec

Please sign in to comment.