-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mutually exclusive gestures example
- Loading branch information
Showing
5 changed files
with
219 additions
and
2 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
76 changes: 76 additions & 0 deletions
76
app/src/main/java/ru/dgis/sdk/demo/MutuallyExclusiveGesturesActivity.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,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 | ||
} | ||
} | ||
} | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
app/src/main/res/layout/activity_mutually_exclusive_gestures_settings.xml
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,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> |
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