mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-19 21:13:12 -07:00
Add Android Touchpad Only Control Option (#130)
This commit is contained in:
parent
be824917b0
commit
385a382577
7 changed files with 148 additions and 1 deletions
|
@ -74,6 +74,11 @@ class Preferences(context: Context)
|
||||||
get() = sharedPreferences.getBoolean(onScreenControlsEnabledKey, true)
|
get() = sharedPreferences.getBoolean(onScreenControlsEnabledKey, true)
|
||||||
set(value) { sharedPreferences.edit().putBoolean(onScreenControlsEnabledKey, value).apply() }
|
set(value) { sharedPreferences.edit().putBoolean(onScreenControlsEnabledKey, value).apply() }
|
||||||
|
|
||||||
|
val touchpadOnlyEnabledKey get() = resources.getString(R.string.preferences_touchpad_only_key)
|
||||||
|
var touchpadOnlyEnabled
|
||||||
|
get() = sharedPreferences.getBoolean(touchpadOnlyEnabledKey, false)
|
||||||
|
set(value) { sharedPreferences.edit().putBoolean(touchpadOnlyEnabledKey, value).apply() }
|
||||||
|
|
||||||
val logVerboseKey get() = resources.getString(R.string.preferences_log_verbose_key)
|
val logVerboseKey get() = resources.getString(R.string.preferences_log_verbose_key)
|
||||||
var logVerbose
|
var logVerbose
|
||||||
get() = sharedPreferences.getBoolean(logVerboseKey, false)
|
get() = sharedPreferences.getBoolean(logVerboseKey, false)
|
||||||
|
|
|
@ -39,6 +39,7 @@ import com.metallic.chiaki.common.Preferences
|
||||||
import com.metallic.chiaki.common.ext.viewModelFactory
|
import com.metallic.chiaki.common.ext.viewModelFactory
|
||||||
import com.metallic.chiaki.lib.ConnectInfo
|
import com.metallic.chiaki.lib.ConnectInfo
|
||||||
import com.metallic.chiaki.session.*
|
import com.metallic.chiaki.session.*
|
||||||
|
import com.metallic.chiaki.touchcontrols.TouchpadOnlyFragment
|
||||||
import com.metallic.chiaki.touchcontrols.TouchControlsFragment
|
import com.metallic.chiaki.touchcontrols.TouchControlsFragment
|
||||||
import kotlinx.android.synthetic.main.activity_stream.*
|
import kotlinx.android.synthetic.main.activity_stream.*
|
||||||
|
|
||||||
|
@ -79,12 +80,25 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
||||||
viewModel.onScreenControlsEnabled.observe(this, Observer {
|
viewModel.onScreenControlsEnabled.observe(this, Observer {
|
||||||
if(onScreenControlsSwitch.isChecked != it)
|
if(onScreenControlsSwitch.isChecked != it)
|
||||||
onScreenControlsSwitch.isChecked = it
|
onScreenControlsSwitch.isChecked = it
|
||||||
|
if(onScreenControlsSwitch.isChecked)
|
||||||
|
touchpadOnlySwitch.isChecked = false
|
||||||
})
|
})
|
||||||
onScreenControlsSwitch.setOnCheckedChangeListener { _, isChecked ->
|
onScreenControlsSwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||||
viewModel.setOnScreenControlsEnabled(isChecked)
|
viewModel.setOnScreenControlsEnabled(isChecked)
|
||||||
showOverlay()
|
showOverlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModel.touchpadOnlyEnabled.observe(this, Observer {
|
||||||
|
if(touchpadOnlySwitch.isChecked != it)
|
||||||
|
touchpadOnlySwitch.isChecked = it
|
||||||
|
if(touchpadOnlySwitch.isChecked)
|
||||||
|
onScreenControlsSwitch.isChecked = false
|
||||||
|
})
|
||||||
|
touchpadOnlySwitch.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
viewModel.setTouchpadOnlyEnabled(isChecked)
|
||||||
|
showOverlay()
|
||||||
|
}
|
||||||
|
|
||||||
viewModel.session.attachToTextureView(textureView)
|
viewModel.session.attachToTextureView(textureView)
|
||||||
viewModel.session.state.observe(this, Observer { this.stateChanged(it) })
|
viewModel.session.state.observe(this, Observer { this.stateChanged(it) })
|
||||||
textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
|
||||||
|
@ -100,6 +114,11 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe
|
||||||
fragment.controllerStateCallback = { viewModel.input.touchControllerState = it }
|
fragment.controllerStateCallback = { viewModel.input.touchControllerState = it }
|
||||||
fragment.onScreenControlsEnabled = viewModel.onScreenControlsEnabled
|
fragment.onScreenControlsEnabled = viewModel.onScreenControlsEnabled
|
||||||
}
|
}
|
||||||
|
if(fragment is TouchpadOnlyFragment)
|
||||||
|
{
|
||||||
|
fragment.controllerStateCallback = { viewModel.input.touchControllerState = it }
|
||||||
|
fragment.touchpadOnlyEnabled = viewModel.touchpadOnlyEnabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume()
|
override fun onResume()
|
||||||
|
|
|
@ -35,6 +35,9 @@ class StreamViewModel(val preferences: Preferences, val logManager: LogManager,
|
||||||
private var _onScreenControlsEnabled = MutableLiveData<Boolean>(preferences.onScreenControlsEnabled)
|
private var _onScreenControlsEnabled = MutableLiveData<Boolean>(preferences.onScreenControlsEnabled)
|
||||||
val onScreenControlsEnabled: LiveData<Boolean> get() = _onScreenControlsEnabled
|
val onScreenControlsEnabled: LiveData<Boolean> get() = _onScreenControlsEnabled
|
||||||
|
|
||||||
|
private var _touchpadOnlyEnabled = MutableLiveData<Boolean>(preferences.touchpadOnlyEnabled)
|
||||||
|
val touchpadOnlyEnabled: LiveData<Boolean> get() = _touchpadOnlyEnabled
|
||||||
|
|
||||||
override fun onCleared()
|
override fun onCleared()
|
||||||
{
|
{
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
|
@ -46,4 +49,10 @@ class StreamViewModel(val preferences: Preferences, val logManager: LogManager,
|
||||||
preferences.onScreenControlsEnabled = enabled
|
preferences.onScreenControlsEnabled = enabled
|
||||||
_onScreenControlsEnabled.value = enabled
|
_onScreenControlsEnabled.value = enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setTouchpadOnlyEnabled(enabled: Boolean)
|
||||||
|
{
|
||||||
|
preferences.touchpadOnlyEnabled = enabled
|
||||||
|
_touchpadOnlyEnabled.value = enabled
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.metallic.chiaki.touchcontrols
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.LiveData
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
|
import com.metallic.chiaki.R
|
||||||
|
import com.metallic.chiaki.lib.ControllerState
|
||||||
|
import kotlinx.android.synthetic.main.fragment_controls.*
|
||||||
|
|
||||||
|
class TouchpadOnlyFragment : Fragment()
|
||||||
|
{
|
||||||
|
private var controllerState = ControllerState()
|
||||||
|
private set(value)
|
||||||
|
{
|
||||||
|
val diff = field != value
|
||||||
|
field = value
|
||||||
|
if(diff)
|
||||||
|
controllerStateCallback?.let { it(value) }
|
||||||
|
}
|
||||||
|
|
||||||
|
var controllerStateCallback: ((ControllerState) -> Unit)? = null
|
||||||
|
var touchpadOnlyEnabled: LiveData<Boolean>? = null
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View
|
||||||
|
= inflater.inflate(R.layout.fragment_touchpad_only, container, false)
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?)
|
||||||
|
{
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
touchpadButtonView.buttonPressedCallback = buttonStateChanged(ControllerState.BUTTON_TOUCHPAD)
|
||||||
|
|
||||||
|
touchpadOnlyEnabled?.observe(this, Observer {
|
||||||
|
view.visibility = if(it) View.VISIBLE else View.GONE
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buttonStateChanged(buttonMask: UInt) = { pressed: Boolean ->
|
||||||
|
controllerState = controllerState.copy().apply {
|
||||||
|
buttons =
|
||||||
|
if(pressed)
|
||||||
|
buttons or buttonMask
|
||||||
|
else
|
||||||
|
buttons and buttonMask.inv()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,12 +23,18 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"/>
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/touchpadOnlyFragment"
|
||||||
|
android:name="com.metallic.chiaki.touchcontrols.TouchpadOnlyFragment"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
android:id="@+id/overlay"
|
android:id="@+id/overlay"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
tools:paddingRight="48dp"
|
tools:paddingRight="12dp"
|
||||||
tools:paddingTop="25dp"
|
tools:paddingTop="25dp"
|
||||||
android:fitsSystemWindows="true">
|
android:fitsSystemWindows="true">
|
||||||
|
|
||||||
|
@ -52,6 +58,17 @@
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:textColor="@color/stream_text"/>
|
android:textColor="@color/stream_text"/>
|
||||||
|
|
||||||
|
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||||
|
android:id="@+id/touchpadOnlySwitch"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="200dp"
|
||||||
|
android:text="Touchpad only"
|
||||||
|
android:textColor="@color/stream_text"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:switchPadding="8dp" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
27
android/app/src/main/res/layout/fragment_touchpad_only.xml
Normal file
27
android/app/src/main/res/layout/fragment_touchpad_only.xml
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipChildren="false">
|
||||||
|
|
||||||
|
<com.metallic.chiaki.touchcontrols.ControlsBackgroundView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
tools:layout_editor_absoluteX="0dp"
|
||||||
|
tools:layout_editor_absoluteY="90dp" />
|
||||||
|
|
||||||
|
<com.metallic.chiaki.touchcontrols.ButtonView
|
||||||
|
android:id="@+id/touchpadButtonView"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:layout_marginEnd="32dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:padding="8dp"
|
||||||
|
app:drawableIdle="@drawable/control_button_touchpad"
|
||||||
|
app:drawablePressed="@drawable/control_button_touchpad_pressed"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -94,6 +94,7 @@
|
||||||
<!-- Don't localize these -->
|
<!-- Don't localize these -->
|
||||||
<string name="preferences_discovery_enabled_key">discovery_enabled</string>
|
<string name="preferences_discovery_enabled_key">discovery_enabled</string>
|
||||||
<string name="preferences_on_screen_controls_enabled_key">on_screen_controls_enabled</string>
|
<string name="preferences_on_screen_controls_enabled_key">on_screen_controls_enabled</string>
|
||||||
|
<string name="preferences_touchpad_only_key">touchpad_only_enabled</string>
|
||||||
<string name="preferences_log_verbose_key">log_verbose</string>
|
<string name="preferences_log_verbose_key">log_verbose</string>
|
||||||
<string name="preferences_import_settings_key">import_settings</string>
|
<string name="preferences_import_settings_key">import_settings</string>
|
||||||
<string name="preferences_export_settings_key">export_settings</string>
|
<string name="preferences_export_settings_key">export_settings</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue