Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package helium314.keyboard.accessibility

import android.annotation.SuppressLint
import android.content.Context
import android.media.AudioDeviceInfo.*
import android.media.AudioManager
Expand Down Expand Up @@ -34,7 +35,8 @@ class AccessibilityUtils private constructor() {
private var mTypedWord: String? = null

private fun initInternal(context: Context) {
mContext = context
// the instance is static, do not keep the service alive
mContext = context.applicationContext
mAccessibilityManager = context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager
mAudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
}
Expand Down Expand Up @@ -73,16 +75,11 @@ class AccessibilityUtils private constructor() {
if (speakPassword) return false
}
// Always speak if the user is listening through headphones.
val listeningThroughHeadphones = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
@Suppress("deprecation") // no replacement available
mAudioManager.isWiredHeadsetOn || mAudioManager.isBluetoothA2dpOn
} else {
// try the same as the deprecated thing above, for what we can assume to be headphones
mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any {
when (it.type) {
TYPE_WIRED_HEADSET, TYPE_WIRED_HEADPHONES, TYPE_BLUETOOTH_SCO, TYPE_BLUETOOTH_A2DP, TYPE_USB_HEADSET, TYPE_HEARING_AID, TYPE_BLE_HEADSET -> true
else -> false
}
// what we can assume to be headphones
val listeningThroughHeadphones = mAudioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any {
when (it.type) {
TYPE_WIRED_HEADSET, TYPE_WIRED_HEADPHONES, TYPE_BLUETOOTH_SCO, TYPE_BLUETOOTH_A2DP, TYPE_USB_HEADSET, TYPE_HEARING_AID, TYPE_BLE_HEADSET -> true
else -> false
}
}
return if (listeningThroughHeadphones) {
Expand Down Expand Up @@ -196,6 +193,7 @@ class AccessibilityUtils private constructor() {
private val TAG = AccessibilityUtils::class.java.simpleName
private val CLASS = AccessibilityUtils::class.java.name
private val PACKAGE = AccessibilityUtils::class.java.getPackage()?.name ?: "helium314.keyboard.accessibility"
@SuppressLint("StaticFieldLeak") // holds the application context
val instance = AccessibilityUtils()
/*
* Setting this constant to {@code false} will disable all keyboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import helium314.keyboard.latin.utils.Log
import java.util.Collections

Expand Down Expand Up @@ -44,11 +43,7 @@ object BrowserDetector {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://example.com")).apply {
addCategory(Intent.CATEGORY_BROWSABLE)
}
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PackageManager.MATCH_ALL
} else {
0
}
val flags = PackageManager.MATCH_ALL
val resolveInfos = appContext.packageManager.queryIntentActivities(intent, flags)
for (info in resolveInfos) {
val pkg = info.activityInfo?.packageName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ fun refreshDeviceLocked(context: Context): Boolean {
val keyguardManager = context.getSystemService(Context.KEYGUARD_SERVICE) as? KeyguardManager
val locked = if (keyguardManager == null) {
false
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
keyguardManager.isDeviceLocked
} else {
keyguardManager.isKeyguardLocked
keyguardManager.isDeviceLocked
}
cachedDeviceLocked = locked
lastLockCheckTime = SystemClock.elapsedRealtime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,8 @@ class ClipboardHistoryView @JvmOverloads constructor(
textView.overScrollMode = View.OVER_SCROLL_IF_CONTENT_SCROLLS
textView.isFocusable = false
textView.isFocusableInTouchMode = false
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
textView.breakStrategy = android.text.Layout.BREAK_STRATEGY_SIMPLE
textView.hyphenationFrequency = android.text.Layout.HYPHENATION_FREQUENCY_NONE
}
textView.breakStrategy = android.text.Layout.BREAK_STRATEGY_SIMPLE
textView.hyphenationFrequency = android.text.Layout.HYPHENATION_FREQUENCY_NONE
}

private var pendingCursorListener: Pair<TextView, View.OnLayoutChangeListener>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ object SupportedEmojis {
}

private fun determineMaxSdk(context: Context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
if (context.prefs().contains(Settings.PREF_EMOJI_MAX_SDK)) return
val paint = Paint()
(Settings.getInstance().customEmojiTypeface ?: Settings.getInstance().customTypeface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package helium314.keyboard.latin

import android.annotation.SuppressLint
import android.content.Context
import android.media.AudioManager
import android.os.Build
Expand Down Expand Up @@ -335,6 +336,7 @@ class AudioAndHapticFeedbackManager private constructor() {

companion object {
private const val MIN_GESTURE_HAPTIC_INTERVAL_MS = 40L
@SuppressLint("StaticFieldLeak") // holds the application context
private val sInstance = AudioAndHapticFeedbackManager()

fun getInstance(): AudioAndHapticFeedbackManager = sInstance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
frame.getLocationInWindow(tempLocation)
outRect.set(tempLocation[0], tempLocation[1], tempLocation[0] + frame.width, tempLocation[1] + frame.height)
if (windowWidth > 0 && windowHeight > 0) {
outRect.intersect(0, 0, windowWidth, windowHeight)
if (!outRect.intersect(0, 0, windowWidth, windowHeight)) outRect.setEmpty()
}
return !outRect.isEmpty
}
Expand Down Expand Up @@ -246,9 +246,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
frame.background = bgDrawable
frame.clipToOutline = true
frame.outlineProvider = ViewOutlineProvider.BACKGROUND
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
frame.elevation = 8f * density
}
frame.elevation = 8f * density

KeyboardSwitcher.getInstance().reloadKeyboard()

Expand Down Expand Up @@ -309,9 +307,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
frame.outlineProvider = null
frame.clipToOutline = false
Settings.getValues().mColors.setBackground(frame, ColorType.MAIN_BACKGROUND)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
frame.elevation = 0f
}
frame.elevation = 0f
(latinIME.mInputView as? InputView)?.updateBottomPadding()
latinIME.mInputView?.post { latinIME.mInputView?.requestApplyInsets() }
}
Expand Down Expand Up @@ -404,9 +400,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
frame.outlineProvider = null
frame.clipToOutline = false
Settings.getValues().mColors.setBackground(frame, ColorType.MAIN_BACKGROUND)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
frame.elevation = 0f
}
frame.elevation = 0f
}
ResourceUtils.setFloatingKeyboardWidth(0)
ResourceUtils.setFloatingKeyboardScale(0.0f)
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/helium314/keyboard/latin/InputView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,9 @@ class InputView @JvmOverloads constructor(
if (mNavBarBottomInsets > 0) return mNavBarBottomInsets
val insets = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
rootWindowInsets?.getInsets(WindowInsets.Type.navigationBars())?.bottom ?: 0
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
} else {
@Suppress("DEPRECATION")
rootWindowInsets?.systemWindowInsetBottom ?: 0
} else {
0 // View.getRootWindowInsets needs API 23, the insets come from onApplyWindowInsets
}
if (insets > 0) {
mNavBarBottomInsets = insets
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ class LatinIME : InputMethodService(),
mTempLocation[1] + child.height
)
if (windowWidth > 0 && windowHeight > 0) {
mTempRect.intersect(0, 0, windowWidth, windowHeight)
if (!mTempRect.intersect(0, 0, windowWidth, windowHeight)) mTempRect.setEmpty()
}
if (!mTempRect.isEmpty) {
outRegion.op(mTempRect, Region.Op.UNION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package helium314.keyboard.latin

import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
Expand Down Expand Up @@ -401,6 +402,7 @@ class RichInputMethodManager private constructor() {
private val TAG = RichInputMethodManager::class.java.simpleName
private const val DEBUG = false

@SuppressLint("StaticFieldLeak") // holds the application context
private val instance = RichInputMethodManager()

fun getInstance(): RichInputMethodManager {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.latin.calculator

import android.annotation.SuppressLint
import android.content.Context
import android.content.SharedPreferences
import androidx.core.content.edit
Expand Down Expand Up @@ -102,6 +103,7 @@ class CalculatorHistoryManager private constructor(private val context: Context)
private const val PREF_CALCULATOR_HISTORY = "pref_calculator_history_json"
private const val MAX_HISTORY_ITEMS = 30

@SuppressLint("StaticFieldLeak") // holds the application context
@Volatile
private var instance: CalculatorHistoryManager? = null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only
package helium314.keyboard.latin.cjk

import android.annotation.SuppressLint
import android.content.Context
import android.view.inputmethod.EditorInfo
import android.view.inputmethod.InputConnection
Expand Down Expand Up @@ -190,6 +191,7 @@ class CjkInputManager private constructor(private val context: Context) {
companion object {
private const val TAG = "CjkInputManager"

@SuppressLint("StaticFieldLeak") // holds the application context
@Volatile
private var instance: CjkInputManager? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package helium314.keyboard.latin.permissions

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import androidx.core.content.ContextCompat

/**
Expand All @@ -19,10 +18,6 @@ object PermissionsUtil {
* Queries if al the permissions are granted for the given permission strings.
*/
fun checkAllPermissionsGranted(context: Context?, vararg permissions: String): Boolean {
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) {
// For all pre-M devices, we should have all the permissions granted on install.
return true
}
if (context == null) return false

for (permission in permissions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,25 @@ class CustomSoundManager private constructor(private val appContext: Context) {

private fun checkBluetoothAudioConnected(): Boolean {
val audioManager = appContext.getSystemService(Context.AUDIO_SERVICE) as? AudioManager ?: return false
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
try {
audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { device ->
when (device.type) {
AudioDeviceInfo.TYPE_BLUETOOTH_A2DP,
AudioDeviceInfo.TYPE_BLUETOOTH_SCO,
AudioDeviceInfo.TYPE_HEARING_AID,
AudioDeviceInfo.TYPE_WIRED_HEADSET,
AudioDeviceInfo.TYPE_WIRED_HEADPHONES,
AudioDeviceInfo.TYPE_USB_HEADSET -> true
else -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
device.type == AudioDeviceInfo.TYPE_BLE_HEADSET ||
device.type == AudioDeviceInfo.TYPE_BLE_SPEAKER ||
device.type == AudioDeviceInfo.TYPE_BLE_BROADCAST
} else {
false
}
}
return try {
audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).any { device ->
when (device.type) {
AudioDeviceInfo.TYPE_BLUETOOTH_A2DP,
AudioDeviceInfo.TYPE_BLUETOOTH_SCO,
AudioDeviceInfo.TYPE_HEARING_AID,
AudioDeviceInfo.TYPE_WIRED_HEADSET,
AudioDeviceInfo.TYPE_WIRED_HEADPHONES,
AudioDeviceInfo.TYPE_USB_HEADSET -> true
else -> {
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S &&
(device.type == AudioDeviceInfo.TYPE_BLE_HEADSET ||
device.type == AudioDeviceInfo.TYPE_BLE_SPEAKER)) ||
(Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
device.type == AudioDeviceInfo.TYPE_BLE_BROADCAST)
}
}
} catch (e: Throwable) {
@Suppress("DEPRECATION")
try {
audioManager.isBluetoothA2dpOn || audioManager.isWiredHeadsetOn
} catch (_: Throwable) {
false
}
}
} else {
} catch (e: Throwable) {
@Suppress("DEPRECATION")
try {
audioManager.isBluetoothA2dpOn || audioManager.isWiredHeadsetOn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,17 @@ abstract class AndroidWordLevelSpellCheckerSession(
}

override fun getLocale(): String? {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
val imm = mService.applicationContext.getSystemService(InputMethodManager::class.java)
if (imm != null) {
val currentInputMethodSubtype = imm.currentInputMethodSubtype
if (currentInputMethodSubtype != null) {
val localeString = currentInputMethodSubtype.locale
if (!localeString.isNullOrEmpty()) {
return localeString
}
if ("dummy" == currentInputMethodSubtype.extraValue) {
val prefs = mService.prefs()
return SubtypeSettings.getSelectedSubtype(prefs).locale
}
val imm = mService.applicationContext.getSystemService(InputMethodManager::class.java)
if (imm != null) {
val currentInputMethodSubtype = imm.currentInputMethodSubtype
if (currentInputMethodSubtype != null) {
val localeString = currentInputMethodSubtype.locale
if (!localeString.isNullOrEmpty()) {
return localeString
}
if ("dummy" == currentInputMethodSubtype.extraValue) {
val prefs = mService.prefs()
return SubtypeSettings.getSelectedSubtype(prefs).locale
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,14 +508,8 @@ internal class SuggestionStripLayoutHelper(
}
if (thumb != null && chipBg != null) {
val layerDrawable = LayerDrawable(arrayOf(chipBg, thumb)).apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
setLayerGravity(1, Gravity.CENTER)
setLayerSize(1, thumbW, thumbH)
} else {
val padH = ((width - thumbW) / 2).coerceAtLeast(0)
val padV = 5.dpToPx(context.resources)
setLayerInset(1, padH, padV, padH, padV)
}
setLayerGravity(1, Gravity.CENTER)
setLayerSize(1, thumbW, thumbH)
}
wordView.background = layerDrawable
} else if (thumb != null) {
Expand Down
20 changes: 6 additions & 14 deletions app/src/main/java/helium314/keyboard/latin/utils/NetworkUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package helium314.keyboard.latin.utils
import android.content.Context
import android.net.ConnectivityManager
import android.net.NetworkCapabilities
import android.os.Build
import java.net.NetworkInterface

object NetworkUtils {
Expand All @@ -14,21 +13,14 @@ object NetworkUtils {
try {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
if (cm != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
val network = cm.activeNetwork
if (network != null) {
val capabilities = cm.getNetworkCapabilities(network)
if (capabilities != null) {
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
}
val network = cm.activeNetwork
if (network != null) {
val capabilities = cm.getNetworkCapabilities(network)
if (capabilities != null) {
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
}
return false
} else {
@Suppress("DEPRECATION")
val networkInfo = cm.activeNetworkInfo
@Suppress("DEPRECATION")
return networkInfo != null && networkInfo.isConnected
}
return false
}
} catch (e: Throwable) {
Log.w(TAG, "ConnectivityManager check failed", e)
Expand Down
Loading
Loading