Skip to content

Commit 7db976d

Browse files
committed
feat: add Quick Settings tile for keyboard switching (#1113)
Add TileService to show keyboard picker from notification shade: - KeyboardTileService.kt: TileService implementation (Android 7.0+) - AndroidManifest.xml: Register tile service with BIND_QUICK_SETTINGS_TILE Tile shows active/inactive state based on current input method. Tapping opens system input method picker for quick switching. — claude-opus-4-5-20251101
1 parent ee0bb8d commit 7db976d

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
<meta-data android:name="android.view.im" android:resource="@xml/method"/>
3232
</service>
3333

34+
<!-- Quick Settings Tile for keyboard switching (Android 7.0+) -->
35+
<service
36+
android:name="tribixbite.cleverkeys.KeyboardTileService"
37+
android:label="@string/app_name"
38+
android:icon="@mipmap/ic_launcher"
39+
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE"
40+
android:exported="true">
41+
<intent-filter>
42+
<action android:name="android.service.quicksettings.action.QS_TILE"/>
43+
</intent-filter>
44+
</service>
45+
3446
<activity android:name="tribixbite.cleverkeys.SettingsActivity" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/settingsTheme" android:exported="true" android:directBootAware="true">
3547
<intent-filter>
3648
<action android:name="android.intent.action.MAIN"/>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package tribixbite.cleverkeys
2+
3+
import android.content.Intent
4+
import android.os.Build
5+
import android.provider.Settings
6+
import android.service.quicksettings.Tile
7+
import android.service.quicksettings.TileService
8+
import android.view.inputmethod.InputMethodManager
9+
import androidx.annotation.RequiresApi
10+
11+
/**
12+
* Quick Settings tile for CleverKeys keyboard.
13+
*
14+
* Tapping the tile opens the input method picker, allowing users to quickly
15+
* switch to CleverKeys or see available keyboards.
16+
*
17+
* Requires Android 7.0 (API 24) or higher.
18+
*
19+
* @see <a href="https://github.com/Julow/Unexpected-Keyboard/issues/1113">Issue #1113</a>
20+
*/
21+
@RequiresApi(Build.VERSION_CODES.N)
22+
class KeyboardTileService : TileService() {
23+
24+
override fun onStartListening() {
25+
super.onStartListening()
26+
updateTileState()
27+
}
28+
29+
override fun onClick() {
30+
super.onClick()
31+
32+
// Show input method picker dialog
33+
val imm = getSystemService(INPUT_METHOD_SERVICE) as? InputMethodManager
34+
if (imm != null) {
35+
imm.showInputMethodPicker()
36+
} else {
37+
// Fallback: open keyboard settings
38+
val intent = Intent(Settings.ACTION_INPUT_METHOD_SETTINGS).apply {
39+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
40+
}
41+
startActivityAndCollapse(intent)
42+
}
43+
}
44+
45+
override fun onTileAdded() {
46+
super.onTileAdded()
47+
updateTileState()
48+
}
49+
50+
private fun updateTileState() {
51+
val tile = qsTile ?: return
52+
53+
// Check if CleverKeys is the current input method
54+
val currentIme = Settings.Secure.getString(
55+
contentResolver,
56+
Settings.Secure.DEFAULT_INPUT_METHOD
57+
)
58+
val isCleverKeysActive = currentIme?.contains(packageName) == true
59+
60+
tile.state = if (isCleverKeysActive) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
61+
tile.label = getString(R.string.app_name)
62+
tile.contentDescription = if (isCleverKeysActive) {
63+
"CleverKeys is active. Tap to switch keyboard."
64+
} else {
65+
"Tap to switch to CleverKeys keyboard."
66+
}
67+
68+
tile.updateTile()
69+
}
70+
}

0 commit comments

Comments
 (0)