diff --git a/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt b/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt index 17d8da4..780fec2 100644 --- a/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt +++ b/android/app/src/main/java/com/metallic/chiaki/common/Preferences.kt @@ -74,6 +74,11 @@ class Preferences(context: Context) get() = sharedPreferences.getBoolean(onScreenControlsEnabledKey, true) 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) var logVerbose get() = sharedPreferences.getBoolean(logVerboseKey, false) diff --git a/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt b/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt index 43dee24..eee3908 100644 --- a/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt +++ b/android/app/src/main/java/com/metallic/chiaki/stream/StreamActivity.kt @@ -39,6 +39,7 @@ import com.metallic.chiaki.common.Preferences import com.metallic.chiaki.common.ext.viewModelFactory import com.metallic.chiaki.lib.ConnectInfo import com.metallic.chiaki.session.* +import com.metallic.chiaki.touchcontrols.TouchpadOnlyFragment import com.metallic.chiaki.touchcontrols.TouchControlsFragment import kotlinx.android.synthetic.main.activity_stream.* @@ -79,12 +80,25 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe viewModel.onScreenControlsEnabled.observe(this, Observer { if(onScreenControlsSwitch.isChecked != it) onScreenControlsSwitch.isChecked = it + if(onScreenControlsSwitch.isChecked) + touchpadOnlySwitch.isChecked = false }) onScreenControlsSwitch.setOnCheckedChangeListener { _, isChecked -> viewModel.setOnScreenControlsEnabled(isChecked) 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.state.observe(this, Observer { this.stateChanged(it) }) textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ -> @@ -100,6 +114,11 @@ class StreamActivity : AppCompatActivity(), View.OnSystemUiVisibilityChangeListe fragment.controllerStateCallback = { viewModel.input.touchControllerState = it } fragment.onScreenControlsEnabled = viewModel.onScreenControlsEnabled } + if(fragment is TouchpadOnlyFragment) + { + fragment.controllerStateCallback = { viewModel.input.touchControllerState = it } + fragment.touchpadOnlyEnabled = viewModel.touchpadOnlyEnabled + } } override fun onResume() diff --git a/android/app/src/main/java/com/metallic/chiaki/stream/StreamViewModel.kt b/android/app/src/main/java/com/metallic/chiaki/stream/StreamViewModel.kt index 8f59f72..db95e0e 100644 --- a/android/app/src/main/java/com/metallic/chiaki/stream/StreamViewModel.kt +++ b/android/app/src/main/java/com/metallic/chiaki/stream/StreamViewModel.kt @@ -35,6 +35,9 @@ class StreamViewModel(val preferences: Preferences, val logManager: LogManager, private var _onScreenControlsEnabled = MutableLiveData(preferences.onScreenControlsEnabled) val onScreenControlsEnabled: LiveData get() = _onScreenControlsEnabled + private var _touchpadOnlyEnabled = MutableLiveData(preferences.touchpadOnlyEnabled) + val touchpadOnlyEnabled: LiveData get() = _touchpadOnlyEnabled + override fun onCleared() { super.onCleared() @@ -46,4 +49,10 @@ class StreamViewModel(val preferences: Preferences, val logManager: LogManager, preferences.onScreenControlsEnabled = enabled _onScreenControlsEnabled.value = enabled } + + fun setTouchpadOnlyEnabled(enabled: Boolean) + { + preferences.touchpadOnlyEnabled = enabled + _touchpadOnlyEnabled.value = enabled + } } \ No newline at end of file diff --git a/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchpadOnlyFragment.kt b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchpadOnlyFragment.kt new file mode 100644 index 0000000..54f2c8b --- /dev/null +++ b/android/app/src/main/java/com/metallic/chiaki/touchcontrols/TouchpadOnlyFragment.kt @@ -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 . + */ + +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? = 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() + + } + } +} \ No newline at end of file diff --git a/android/app/src/main/res/layout/activity_stream.xml b/android/app/src/main/res/layout/activity_stream.xml index 27a32d0..770c42c 100644 --- a/android/app/src/main/res/layout/activity_stream.xml +++ b/android/app/src/main/res/layout/activity_stream.xml @@ -23,12 +23,18 @@ android:layout_width="match_parent" android:layout_height="match_parent"/> + + @@ -52,6 +58,17 @@ android:layout_marginLeft="8dp" android:textColor="@color/stream_text"/> + + diff --git a/android/app/src/main/res/layout/fragment_touchpad_only.xml b/android/app/src/main/res/layout/fragment_touchpad_only.xml new file mode 100644 index 0000000..a42b78a --- /dev/null +++ b/android/app/src/main/res/layout/fragment_touchpad_only.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml index 38739a8..bbadf15 100644 --- a/android/app/src/main/res/values/strings.xml +++ b/android/app/src/main/res/values/strings.xml @@ -94,6 +94,7 @@ discovery_enabled on_screen_controls_enabled + touchpad_only_enabled log_verbose import_settings export_settings