Skip to content

Commit 1196d0c

Browse files
committed
Merge branch 'copilot/add-key-map-constraint' into develop
2 parents bb4028d + 2474a5a commit 1196d0c

File tree

17 files changed

+135
-11
lines changed

17 files changed

+135
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- #1871 action to modify any system settings
77
- #1221 action to show a custom notification
88
- #1491 action to toggle/enable/disable hotspot
9+
- #1414 constraint for when the keyboard is showing
910

1011
## [4.0.0 Beta 2](https://github.com/sds100/KeyMapper/releases/tag/v4.0.0-beta.02)
1112

base/src/main/java/io/github/sds100/keymapper/base/constraints/ChooseConstraintViewModel.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ class ChooseConstraintViewModel @Inject constructor(
7777
ConstraintId.IME_CHOSEN,
7878
ConstraintId.IME_NOT_CHOSEN,
7979

80+
ConstraintId.KEYBOARD_SHOWING,
81+
ConstraintId.KEYBOARD_NOT_SHOWING,
82+
8083
ConstraintId.DEVICE_IS_LOCKED,
8184
ConstraintId.DEVICE_IS_UNLOCKED,
8285
ConstraintId.LOCK_SCREEN_SHOWING,
@@ -204,6 +207,12 @@ class ChooseConstraintViewModel @Inject constructor(
204207
ConstraintId.IME_NOT_CHOSEN,
205208
-> onSelectImeChosenConstraint(constraintType)
206209

210+
ConstraintId.KEYBOARD_SHOWING ->
211+
returnResult.emit(ConstraintData.KeyboardShowing)
212+
213+
ConstraintId.KEYBOARD_NOT_SHOWING ->
214+
returnResult.emit(ConstraintData.KeyboardNotShowing)
215+
207216
ConstraintId.DEVICE_IS_LOCKED ->
208217
returnResult.emit(ConstraintData.DeviceIsLocked)
209218

base/src/main/java/io/github/sds100/keymapper/base/constraints/Constraint.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ sealed class ConstraintData {
127127
override val id: ConstraintId = ConstraintId.IME_NOT_CHOSEN
128128
}
129129

130+
@Serializable
131+
data object KeyboardShowing : ConstraintData() {
132+
override val id: ConstraintId = ConstraintId.KEYBOARD_SHOWING
133+
}
134+
135+
@Serializable
136+
data object KeyboardNotShowing : ConstraintData() {
137+
override val id: ConstraintId = ConstraintId.KEYBOARD_NOT_SHOWING
138+
}
139+
130140
@Serializable
131141
data object DeviceIsLocked : ConstraintData() {
132142
override val id: ConstraintId = ConstraintId.DEVICE_IS_LOCKED
@@ -334,6 +344,9 @@ object ConstraintEntityMapper {
334344
getImeLabel(),
335345
)
336346

347+
ConstraintEntity.KEYBOARD_SHOWING -> ConstraintData.KeyboardShowing
348+
ConstraintEntity.KEYBOARD_NOT_SHOWING -> ConstraintData.KeyboardNotShowing
349+
337350
ConstraintEntity.DEVICE_IS_UNLOCKED -> ConstraintData.DeviceIsUnlocked
338351
ConstraintEntity.DEVICE_IS_LOCKED -> ConstraintData.DeviceIsLocked
339352
ConstraintEntity.LOCK_SCREEN_SHOWING -> ConstraintData.LockScreenShowing
@@ -570,6 +583,16 @@ object ConstraintEntityMapper {
570583
)
571584
}
572585

586+
is ConstraintData.KeyboardShowing -> ConstraintEntity(
587+
uid = constraint.uid,
588+
ConstraintEntity.KEYBOARD_SHOWING,
589+
)
590+
591+
is ConstraintData.KeyboardNotShowing -> ConstraintEntity(
592+
uid = constraint.uid,
593+
ConstraintEntity.KEYBOARD_NOT_SHOWING,
594+
)
595+
573596
is ConstraintData.DeviceIsLocked -> ConstraintEntity(
574597
uid = constraint.uid,
575598
ConstraintEntity.DEVICE_IS_LOCKED,

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintDependency.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum class ConstraintDependency {
1111
WIFI_SSID,
1212
WIFI_STATE,
1313
CHOSEN_IME,
14+
KEYBOARD_VISIBLE,
1415
DEVICE_LOCKED_STATE,
1516
LOCK_SCREEN_SHOWING,
1617
PHONE_STATE,

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintId.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ enum class ConstraintId {
3737
IME_CHOSEN,
3838
IME_NOT_CHOSEN,
3939

40+
KEYBOARD_SHOWING,
41+
KEYBOARD_NOT_SHOWING,
42+
4043
DEVICE_IS_LOCKED,
4144
DEVICE_IS_UNLOCKED,
4245
LOCK_SCREEN_SHOWING,

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintSnapshot.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class LazyConstraintSnapshot(
5757
networkAdapter.connectedWifiSSIDFlow.firstBlocking()
5858
}
5959
private val chosenImeId: String? by lazy { inputMethodAdapter.chosenIme.value?.id }
60+
private val isKeyboardShowing: Boolean by lazy {
61+
accessibilityService.isInputMethodVisible.firstBlocking()
62+
}
6063
private val callState: CallState by lazy { phoneAdapter.getCallState() }
6164
private val isCharging: Boolean by lazy { powerAdapter.isCharging.value }
6265

@@ -139,6 +142,8 @@ class LazyConstraintSnapshot(
139142
is ConstraintData.WifiOn -> isWifiEnabled
140143
is ConstraintData.ImeChosen -> chosenImeId == constraint.data.imeId
141144
is ConstraintData.ImeNotChosen -> chosenImeId != constraint.data.imeId
145+
is ConstraintData.KeyboardShowing -> isKeyboardShowing
146+
is ConstraintData.KeyboardNotShowing -> !isKeyboardShowing
142147
is ConstraintData.DeviceIsLocked -> isLocked
143148
is ConstraintData.DeviceIsUnlocked -> !isLocked
144149
is ConstraintData.InPhoneCall ->

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintUiHelper.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,13 @@ class ConstraintUiHelper(
135135
getString(R.string.constraint_ime_not_chosen_description, label)
136136
}
137137

138+
is ConstraintData.KeyboardShowing -> getString(
139+
R.string.constraint_keyboard_showing_description,
140+
)
141+
is ConstraintData.KeyboardNotShowing -> getString(
142+
R.string.constraint_keyboard_not_showing_description,
143+
)
144+
138145
is ConstraintData.DeviceIsLocked -> getString(R.string.constraint_device_is_locked)
139146
is ConstraintData.DeviceIsUnlocked -> getString(R.string.constraint_device_is_unlocked)
140147
is ConstraintData.InPhoneCall -> getString(R.string.constraint_in_phone_call)

base/src/main/java/io/github/sds100/keymapper/base/constraints/ConstraintUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.material.icons.outlined.CallEnd
1010
import androidx.compose.material.icons.outlined.FlashlightOff
1111
import androidx.compose.material.icons.outlined.FlashlightOn
1212
import androidx.compose.material.icons.outlined.Keyboard
13+
import androidx.compose.material.icons.outlined.KeyboardHide
1314
import androidx.compose.material.icons.outlined.Lock
1415
import androidx.compose.material.icons.outlined.LockOpen
1516
import androidx.compose.material.icons.outlined.MobileOff
@@ -78,6 +79,9 @@ object ConstraintUtils {
7879
ConstraintId.IME_NOT_CHOSEN,
7980
-> ComposeIconInfo.Vector(Icons.Outlined.Keyboard)
8081

82+
ConstraintId.KEYBOARD_SHOWING -> ComposeIconInfo.Vector(Icons.Outlined.Keyboard)
83+
ConstraintId.KEYBOARD_NOT_SHOWING -> ComposeIconInfo.Vector(Icons.Outlined.KeyboardHide)
84+
8185
ConstraintId.DEVICE_IS_LOCKED -> ComposeIconInfo.Vector(Icons.Outlined.Lock)
8286
ConstraintId.DEVICE_IS_UNLOCKED -> ComposeIconInfo.Vector(Icons.Outlined.LockOpen)
8387

@@ -124,6 +128,8 @@ object ConstraintUtils {
124128
ConstraintId.WIFI_DISCONNECTED -> R.string.constraint_wifi_disconnected
125129
ConstraintId.IME_CHOSEN -> R.string.constraint_ime_chosen
126130
ConstraintId.IME_NOT_CHOSEN -> R.string.constraint_ime_not_chosen
131+
ConstraintId.KEYBOARD_SHOWING -> R.string.constraint_keyboard_showing
132+
ConstraintId.KEYBOARD_NOT_SHOWING -> R.string.constraint_keyboard_not_showing
127133
ConstraintId.DEVICE_IS_LOCKED -> R.string.constraint_device_is_locked
128134
ConstraintId.DEVICE_IS_UNLOCKED -> R.string.constraint_device_is_unlocked
129135
ConstraintId.IN_PHONE_CALL -> R.string.constraint_in_phone_call

base/src/main/java/io/github/sds100/keymapper/base/constraints/DetectConstraintsUseCase.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.sds100.keymapper.base.constraints
22

3+
import android.os.Build
34
import dagger.assisted.Assisted
45
import dagger.assisted.AssistedFactory
56
import dagger.assisted.AssistedInject
@@ -16,6 +17,7 @@ import io.github.sds100.keymapper.system.network.NetworkAdapter
1617
import io.github.sds100.keymapper.system.phone.PhoneAdapter
1718
import io.github.sds100.keymapper.system.power.PowerAdapter
1819
import kotlinx.coroutines.flow.Flow
20+
import kotlinx.coroutines.flow.emptyFlow
1921
import kotlinx.coroutines.flow.map
2022
import kotlinx.coroutines.flow.merge
2123

@@ -89,7 +91,14 @@ class DetectConstraintsUseCaseImpl @AssistedInject constructor(
8991

9092
ConstraintDependency.PHONE_STATE -> phoneAdapter.callStateFlow.map { dependency }
9193
ConstraintDependency.CHARGING_STATE -> powerAdapter.isCharging.map { dependency }
92-
ConstraintDependency.HINGE_STATE -> foldableAdapter.hingeState.map { dependency }
94+
ConstraintDependency.HINGE_STATE ->
95+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
96+
foldableAdapter.hingeState.map { dependency }
97+
} else {
98+
emptyFlow()
99+
}
100+
ConstraintDependency.KEYBOARD_VISIBLE ->
101+
accessibilityService.isInputMethodVisible.map { dependency }
93102
}
94103
}
95104
}

base/src/main/java/io/github/sds100/keymapper/base/sorting/comparators/KeyMapConstraintsComparator.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class KeyMapConstraintsComparator(
138138

139139
ConstraintData.HingeClosed -> Success("")
140140
ConstraintData.HingeOpen -> Success("")
141+
ConstraintData.KeyboardNotShowing -> Success("")
142+
ConstraintData.KeyboardShowing -> Success("")
141143
}
142144
}
143145
}

0 commit comments

Comments
 (0)