Skip to content

Commit

Permalink
add mutually exclusive gestures example
Browse files Browse the repository at this point in the history
  • Loading branch information
Sameri11 committed Aug 2, 2023
1 parent e48bc0d commit 46a9ae1
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
android:roundIcon="@mipmap/icon_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MutuallyExclusiveGesturesActivity"
android:exported="false" />
<activity
android:name=".GesturesMapPointActivity"
android:exported="false" />
Expand Down
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 @@ -53,6 +53,10 @@ class MainActivity : AppCompatActivity() {
Page("Gestures: center point") {
val intent = Intent(this@MainActivity, GesturesMapPointActivity::class.java)
startActivity(intent)
},
Page("Mutually exclusive gestures") {
val intent = Intent(this@MainActivity, MutuallyExclusiveGesturesActivity::class.java)
startActivity(intent)
}
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ru.dgis.sdk.demo

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import ru.dgis.sdk.demo.common.addSettingsLayout
import ru.dgis.sdk.demo.databinding.ActivityGesturesBinding
import ru.dgis.sdk.demo.databinding.ActivityMutuallyExclusiveGesturesSettingsBinding
import ru.dgis.sdk.map.Gesture
import java.util.EnumSet

/**
* Sample activity for demonstration of maps's Gesture Manager possibilities in terms of setting rules for gestures
*
* For further details check [SDK Documentation](https://docs.2gis.com/en/android/sdk/reference/7.0/ru.dgis.sdk.map.GestureManager#nav-lvl1--setMutuallyExclusiveGestures)
*/
class MutuallyExclusiveGesturesActivity : AppCompatActivity() {

private val binding by lazy { ActivityGesturesBinding.inflate(layoutInflater) }
private val settingsBinding by lazy { ActivityMutuallyExclusiveGesturesSettingsBinding.inflate(layoutInflater) }
private val mapView by lazy { binding.mapView }
private val gestureManager by lazy { mapView.gestureManager }

private var checkedGestures = EnumSet.noneOf(Gesture::class.java)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(binding.root)
binding.addSettingsLayout().apply {
settingsDrawerInnerLayout.addView(settingsBinding.root)
}

/**
* Using hack here to delay settings initialization until map is ready and gestureManager is not null for sure
*/
mapView.getMapAsync {
initSettings()
}
}

private fun initSettings() {
val gestureManager = this.gestureManager!!
settingsBinding.apply {
val checkboxes = listOf(
tiltCheckbox,
rotationCheckbox,
scailingCheckbox,
shiftCheckbox,
multiTouchShiftCheckbox
)
checkboxes.forEach { checkBox ->
checkBox.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
checkedGestures.add(ru.dgis.sdk.map.Gesture.entries.first { it.name == checkBox.tag })
} else {
checkedGestures.remove(ru.dgis.sdk.map.Gesture.entries.first { it.name == checkBox.tag })
}
}
}

applyRuleButton.setOnClickListener {
gestureManager.setMutuallyExclusiveGestures(listOf(checkedGestures))
checkedGestures = EnumSet.noneOf(Gesture::class.java)
checkboxes.forEach {
it.isChecked = false
}
}

cleanRulesButton.setOnClickListener {
gestureManager.setMutuallyExclusiveGestures(listOf())
checkedGestures = EnumSet.noneOf(Gesture::class.java)
checkboxes.forEach {
it.isChecked = false
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
style="@style/SubheadMediumLeftBlack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gestures" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/BodyRegularLeftBlack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:text="@string/shift" />

<CheckBox
android:id="@+id/shiftCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/shift" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/BodyRegularLeftBlack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:text="@string/tilt" />

<CheckBox
android:id="@+id/tiltCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/tilt" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/BodyRegularLeftBlack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:text="@string/scailing" />

<CheckBox
android:id="@+id/scailingCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/scailing" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/BodyRegularLeftBlack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:text="@string/rotation" />

<CheckBox
android:id="@+id/rotationCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/rotation" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
style="@style/BodyRegularLeftBlack"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_weight="1"
android:text="@string/multi_touch_shift" />

<CheckBox
android:id="@+id/multiTouchShiftCheckbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/multi_touch_shift" />
</LinearLayout>

<Button
android:id="@+id/applyRuleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="48dp"
android:text="@string/apply_rule" />

<Button
android:id="@+id/cleanRulesButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="48dp"
android:backgroundTint="@android:color/holo_red_light"
android:text="@string/clear_rules" />

<View
android:layout_width="match_parent"
android:layout_height="24dp" />
</LinearLayout>
7 changes: 5 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@
<string name="distancediffmm">distanceDiffMm</string>
<string name="anglediffinscalingdeg">angleDiffInScalingDeg</string>
<string name="distancediffinscalingmm">distanceDiffInScalingMm</string>
<string name="scailing">SCAILING</string>
<string name="scailing">SCALING</string>
<string name="scaleratiothreshold">scaleRatioThreshold</string>
<string name="scaleratiothresholdinrotation">scaleRatioThresholdInRotation</string>
<string name="tilt">TILT</string>
<string name="lenondegreemm">lenOnDegreeMm</string>
<string name="horizontalswervedeg">horizontalSwerveDeg</string>
<string name="verticalswervedeg">verticalSwerveDeg</string>
<string name="thresholdmm">thresholdMm</string>
<string name="multi_touch_shift">MULTI TOUCH SHIFT</string>
<string name="multi_touch_shift">MULTI_TOUCH_SHIFT</string>
<string name="rotation_center">ROTATION CENTER</string>
<string name="choose">Choose</string>
<string name="scailing_center">SCAILING CENTER</string>
<string name="gestures">GESTURES</string>
<string name="apply_rule">Apply Rule</string>
<string name="clear_rules">Clear Rules</string>
<string-array name="route_search_types">
<item>Car</item>
<item>Pedestrian</item>
Expand Down

0 comments on commit 46a9ae1

Please sign in to comment.