From 8b9dd17f6428b2b8f12fe7d90dced615131f0db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 24 Sep 2019 21:51:32 +0200 Subject: [PATCH] Draw DPad on Android --- android/app/build.gradle | 3 +- .../java/com/metallic/chiaki/MainActivity.kt | 17 ++ .../metallic/chiaki/touchcontrols/DPadView.kt | 49 ++++++ .../src/main/res/drawable/control_dpad.xml | 34 ++++ .../app/src/main/res/layout/activity_main.xml | 8 + android/app/src/main/res/values/colors.xml | 2 + assets/controls/dpad.svg | 153 ++++++++++++++++++ 7 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 android/app/src/main/java/com/metallic/chiaki/touchcontrols/DPadView.kt create mode 100644 android/app/src/main/res/drawable/control_dpad.xml create mode 100644 assets/controls/dpad.svg diff --git a/android/app/build.gradle b/android/app/build.gradle index a22f442..4a3dc4f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -20,8 +20,7 @@ android { "-DCHIAKI_ENABLE_GUI=OFF", "-DCHIAKI_ENABLE_ANDROID=ON", "-DCHIAKI_LIB_ENABLE_OPUS=OFF", - "-DCHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT=ON", - "-DCMAKE_VERBOSE_MAKEFILE=ON" + "-DCHIAKI_LIB_OPENSSL_EXTERNAL_PROJECT=ON" } } } diff --git a/android/app/src/main/java/com/metallic/chiaki/MainActivity.kt b/android/app/src/main/java/com/metallic/chiaki/MainActivity.kt index 2cafb12..e1913b3 100644 --- a/android/app/src/main/java/com/metallic/chiaki/MainActivity.kt +++ b/android/app/src/main/java/com/metallic/chiaki/MainActivity.kt @@ -1,3 +1,20 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + package com.metallic.chiaki import android.content.Context diff --git a/android/app/src/main/java/com/metallic/chiaki/touchcontrols/DPadView.kt b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/DPadView.kt new file mode 100644 index 0000000..73f6ee3 --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/DPadView.kt @@ -0,0 +1,49 @@ +/* + * This file is part of Chiaki. + * + * Chiaki is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Chiaki is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Chiaki. If not, see . + */ + +package com.metallic.chiaki.touchcontrols + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.util.Log +import android.view.MotionEvent +import android.view.View +import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat +import com.metallic.chiaki.R + +class DPadView @JvmOverloads constructor( + context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 +) : View(context, attrs, defStyleAttr) +{ + private val colorPrimary = resources.getColor(R.color.control_primary, null) + private val dpadDrawable = VectorDrawableCompat.create(resources, R.drawable.control_dpad, null) + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + dpadDrawable?.setBounds(0, 0, width, height) + dpadDrawable?.setTint(colorPrimary) + dpadDrawable?.draw(canvas) + } + + override fun onTouchEvent(event: MotionEvent): Boolean + { + Log.i("DPadView", "onTouchEvent $event") + return true + } + +} \ No newline at end of file diff --git a/android/app/src/main/res/drawable/control_dpad.xml b/android/app/src/main/res/drawable/control_dpad.xml new file mode 100644 index 0000000..7d1dc15 --- /dev/null +++ b/android/app/src/main/res/drawable/control_dpad.xml @@ -0,0 +1,34 @@ + + + + + + diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index 7e350d7..8a23077 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -51,4 +51,12 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/morningEditText" /> + + \ No newline at end of file diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml index 35f5d47..11bd053 100644 --- a/android/app/src/main/res/values/colors.xml +++ b/android/app/src/main/res/values/colors.xml @@ -6,4 +6,6 @@ @android:color/white @android:color/black + + @android:color/white diff --git a/assets/controls/dpad.svg b/assets/controls/dpad.svg new file mode 100644 index 0000000..0884b63 --- /dev/null +++ b/assets/controls/dpad.svg @@ -0,0 +1,153 @@ + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + +