Make the OSC control panel draggable

This commit is contained in:
lynxnb 2023-03-30 23:42:44 +02:00 committed by Billy Laws
parent d7e38e9556
commit d69c9f472f

View File

@ -11,6 +11,7 @@ import android.os.Bundle
import android.os.Vibrator
import android.os.VibratorManager
import android.view.*
import android.view.View.OnTouchListener
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.isGone
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -72,6 +73,7 @@ class OnScreenEditActivity : AppCompatActivity() {
.show()
}
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState : Bundle?) {
super.onCreate(savedInstanceState)
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
@ -129,6 +131,8 @@ class OnScreenEditActivity : AppCompatActivity() {
binding.gridButton.setIconResource(if (!snapToGrid) R.drawable.ic_grid_on else R.drawable.ic_grid_off)
binding.resetButton.setOnClickListener { resetAction() }
binding.dragHandle.setOnTouchListener(dragPanelListener)
binding.onScreenControllerView.setEditMode(EditMode.Move)
binding.onScreenControllerView.selectAllButtons()
}
@ -182,4 +186,13 @@ class OnScreenEditActivity : AppCompatActivity() {
binding.scaleSlider.slider.value = (button.config.scale - OnScreenConfiguration.MinScale) / (OnScreenConfiguration.MaxScale - OnScreenConfiguration.MinScale) * 100f
binding.opacitySlider.slider.value = (button.config.alpha - OnScreenConfiguration.MinAlpha) / (OnScreenConfiguration.MaxAlpha - OnScreenConfiguration.MinAlpha).toFloat() * 100f
}
@SuppressLint("ClickableViewAccessibility")
private val dragPanelListener = OnTouchListener { view : View, event : MotionEvent ->
if (event.action == MotionEvent.ACTION_MOVE) {
binding.controlPanel.x = event.rawX - binding.controlPanel.width / 2
binding.controlPanel.y = event.rawY - view.height / 2
}
true
}
}