11package com.yoimerdr.android.virtualjoystick
22
33import android.graphics.Color
4- import android.graphics.drawable.VectorDrawable
54import android.os.Bundle
65import android.view.View
76import android.widget.AdapterView
@@ -13,10 +12,10 @@ import androidx.appcompat.app.AppCompatActivity
1312import com.google.android.material.floatingactionbutton.FloatingActionButton
1413import com.yoimerdr.android.virtualjoystick.databinding.ActivityMainBinding
1514import com.yoimerdr.android.virtualjoystick.control.Control
16- import com.yoimerdr.android.virtualjoystick.control. drawer.ControlDrawer
17- import com.yoimerdr.android.virtualjoystick.control.drawer.DrawableControlDrawer
18- import com.yoimerdr.android.virtualjoystick.control. drawer.HighlightControlDrawer
19- import com.yoimerdr.android.virtualjoystick.utils.log.Logger
15+ import com.yoimerdr.android.virtualjoystick.drawer.core .ControlDrawer
16+ import com.yoimerdr.android.virtualjoystick.api.log.LoggerSupplier.DefaultLogger
17+ import com.yoimerdr.android.virtualjoystick.drawer.drawable.DrawableDrawer
18+ import com.yoimerdr.android.virtualjoystick.drawer.drawable.DirectionalDrawableDrawer
2019import com.yoimerdr.android.virtualjoystick.views.JoystickView
2120
2221class MainActivity : AppCompatActivity () {
@@ -47,17 +46,17 @@ class MainActivity : AppCompatActivity() {
4746 " Yellow" to Color .YELLOW
4847 )
4948
50- private val drawers = mapOf (
51- " Circle " to Control . DrawerType . CIRCLE . ordinal,
52- " Arc " to Control . DrawerType . ARC .ordinal,
53- " Circle Arc " to Control . DrawerType . CIRCLE_ARC .ordinal ,
54- " Highlight " to - 1 , " Drawable" to - 2
49+ private val drawers = Control . DrawerType .entries.associate {
50+ it.titleName() to it. ordinal
51+ } + mapOf (
52+ " Drawable " to - 1 ,
53+ " State Drawable" to - 2 ,
5554 )
5655
57- private val directionTypes = mapOf (
58- " Complete " to Control .DirectionType .COMPLETE ,
59- " Simple " to Control . DirectionType . SIMPLE
60- )
56+
57+ private val directionTypes = Control .DirectionType .entries.associateBy {
58+ it.titleName()
59+ }
6160
6261 private val boundedTypes = mapOf (
6362 " True" to true ,
@@ -76,6 +75,23 @@ class MainActivity : AppCompatActivity() {
7675 private lateinit var magnitudeFormat: String
7776 private lateinit var ndcPositionFormat: String
7877
78+ companion object {
79+ fun String.capitalize (): String {
80+ return this .replaceFirstChar { char -> if (char.isLowerCase()) char.titlecase() else char.toString() }
81+ }
82+
83+ fun Enum <* >.titleName (): String {
84+ val name = name
85+ .lowercase()
86+ .split(" _" )
87+ .joinToString(separator = " " ) {
88+ it.capitalize()
89+ }
90+
91+ return name.capitalize()
92+ }
93+ }
94+
7995 override fun onCreate (savedInstanceState : Bundle ? ) {
8096 super .onCreate(savedInstanceState)
8197 binding = ActivityMainBinding .inflate(layoutInflater)
@@ -112,14 +128,6 @@ class MainActivity : AppCompatActivity() {
112128 val selected = parent?.getItemAtPosition(position) ? : return
113129 val color = colors[selected] ? : return
114130
115- val drawer = drawer
116- if (drawer != null && drawer is DrawableControlDrawer ) {
117- if (drawer.drawable is VectorDrawable )
118- drawer.drawable = drawer.drawable.apply {
119- setTint(color)
120- }
121- }
122-
123131 vJoystick.setPrimaryColor(color)
124132 }
125133
@@ -246,17 +254,17 @@ class MainActivity : AppCompatActivity() {
246254 vJoystick.apply {
247255 setMoveStartListener {
248256 onMovement(it)
249- Logger .log(" START: $it " )
257+ DefaultLogger .log(" START: $it " )
250258 }
251259
252260 setMoveEndListener {
253261 onMovement(Control .Direction .NONE )
254- Logger .log(" END" )
262+ DefaultLogger .log(" END" )
255263 }
256264
257265 setMoveListener {
258266 onMovement(it)
259- Logger .log(" MOVE: $it " )
267+ DefaultLogger .log(" MOVE: $it " )
260268 }
261269 }
262270 }
@@ -265,17 +273,27 @@ class MainActivity : AppCompatActivity() {
265273 val typeId = drawers[drawerSelected] ? : return
266274 if (typeId < 0 ) {
267275 val color = colors[spnPrimaryColor.selectedItem] ? : return
276+ tvDirection.isPressed
268277 drawer = when (typeId) {
269- - 1 -> HighlightControlDrawer (color, 0.48f )
270- - 2 -> {
271-
272- DrawableControlDrawer .fromDrawableRes(
273- this @MainActivity,
274- R .drawable.baseline_adb_24,
275- color,
276- bounded
277- )
278- }
278+ - 1 -> DrawableDrawer .fromDrawableRes(
279+ this @MainActivity,
280+ R .drawable.baseline_adb_24,
281+ color,
282+ )
283+ - 2 -> DirectionalDrawableDrawer (
284+ listOf<Pair <Control .Direction , Int >>(
285+ Control .Direction .RIGHT to R .drawable.dpad_modern_r,
286+ Control .Direction .UP to R .drawable.dpad_modern_u,
287+ Control .Direction .LEFT to R .drawable.dpad_modern_l,
288+ Control .Direction .DOWN to R .drawable.dpad_modern_d,
289+ ).map {
290+ it.first to DrawableDrawer .getDrawable(
291+ this @MainActivity,
292+ it.second
293+ )
294+ }
295+
296+ )
279297
280298 else -> null
281299 }
@@ -288,6 +306,16 @@ class MainActivity : AppCompatActivity() {
288306 Control .DrawerBuilder ()
289307 else Control .DrawerBuilder .from(drawer!! )
290308
309+ val drawerType = Control .DrawerType
310+ .fromId(typeId)
311+
312+ if (drawerType in listOf (
313+ Control .DrawerType .WEDGE ,
314+ )
315+ )
316+ builder.circleRadiusRatio(0.43f )
317+ // .circleRadius(DrawerRadius.Zero)
318+
291319 drawer = builder
292320 .colors(
293321 colors[spnPrimaryColor.selectedItem] ? : Color .RED ,
@@ -303,6 +331,7 @@ class MainActivity : AppCompatActivity() {
303331 vJoystick.setControlDrawer(
304332 drawer!!
305333 )
334+ // vJoystick.setInvalidRadius(0f)
306335 }
307336 }
308337
0 commit comments