-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(util): fine tune ImeUtils (InputMethodUtils)
- Loading branch information
1 parent
f5ca6bb
commit da18332
Showing
3 changed files
with
53 additions
and
37 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/osfans/trime/common/InputMethodUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.osfans.trime.common | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.provider.Settings | ||
import android.view.inputmethod.InputMethodManager | ||
import timber.log.Timber | ||
|
||
object InputMethodUtils { | ||
private const val IME_ID: String = "com.osfans.trime/.TrimeImeService" | ||
|
||
fun checkIsTrimeEnabled(context: Context): Boolean { | ||
val activeImeIds = Settings.Secure.getString( | ||
context.contentResolver, | ||
Settings.Secure.ENABLED_INPUT_METHODS | ||
) ?: "(none)" | ||
Timber.i("List of active IMEs: $activeImeIds") | ||
return activeImeIds.split(":").contains(IME_ID) | ||
} | ||
|
||
fun checkisTrimeSelected(context: Context): Boolean { | ||
val selectedImeIds = Settings.Secure.getString( | ||
context.contentResolver, | ||
Settings.Secure.DEFAULT_INPUT_METHOD | ||
) ?: "(none)" | ||
Timber.i("Selected IME: $selectedImeIds") | ||
return selectedImeIds == IME_ID | ||
} | ||
|
||
fun showImeEnablerActivity(context: Context) { | ||
val intent = Intent() | ||
intent.action = Settings.ACTION_INPUT_METHOD_SETTINGS | ||
intent.addCategory(Intent.CATEGORY_DEFAULT) | ||
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
context.startActivity(intent) | ||
} | ||
|
||
fun showImePicker(context: Context): Boolean { | ||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as? InputMethodManager | ||
return if (imm != null) { | ||
imm.showInputMethodPicker() | ||
true | ||
} else { | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.