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 @@ -8,8 +8,11 @@ import android.content.SharedPreferences
import android.content.res.Configuration
import android.content.res.Resources
import android.graphics.Color
import android.graphics.Outline
import android.graphics.Rect
import android.graphics.drawable.GradientDrawable
import androidx.core.graphics.ColorUtils
import helium314.keyboard.latin.utils.CenterCropDrawable
import android.os.Build
import android.view.Gravity
import android.view.MotionEvent
Expand Down Expand Up @@ -194,26 +197,10 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
KeyboardLayoutSet.clearKeyboardCache()

val colors = Settings.getValues().mColors
val bgColor = colors.get(ColorType.MAIN_BACKGROUND)
val textColor = colors.get(ColorType.KEY_TEXT)
val cornerRadius = CORNER_RADIUS_DP * density
val bottomBarHeight = (BOTTOM_BAR_HEIGHT_DP * density).toInt()

// Configure or create bottom bar inside main_keyboard_frame
val bottomContainer = frame.findViewById<FrameLayout>(R.id.floating_bottom_bar)
if (bottomContainer != null) {
val bottomLp = bottomContainer.layoutParams as? LinearLayout.LayoutParams
?: LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, bottomBarHeight)
bottomLp.width = LinearLayout.LayoutParams.MATCH_PARENT
bottomLp.height = bottomBarHeight
bottomContainer.layoutParams = bottomLp
bottomContainer.setPadding(0, 0, 0, 0)
bottomContainer.removeAllViews()
bottomBar = createBottomBar(bottomBarHeight, bgColor, textColor, density, cornerRadius)
bottomContainer.addView(bottomBar)
bottomContainer.visibility = View.VISIBLE
}

// Configure FrameLayout layoutParams
val lp = frame.layoutParams as? FrameLayout.LayoutParams ?: FrameLayout.LayoutParams(
floatingWidth,
Expand All @@ -236,21 +223,37 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
frame.translationX = posX.toFloat()
frame.translationY = posY.toFloat()

// Background styling: rounded corners and elevation
val bgDrawable = GradientDrawable().apply {
setColor(bgColor)
cornerRadii = floatArrayOf(
cornerRadius, cornerRadius,
cornerRadius, cornerRadius,
cornerRadius, cornerRadius,
cornerRadius, cornerRadius
)
// Background styling: the same background as docked (color or wallpaper), with rounded corners and elevation.
// The corners come from the outline, as a wallpaper has no rounded shape of its own.
frame.background = null
colors.setBackground(frame, ColorType.MAIN_BACKGROUND)
// a wallpaper can have any color, so the controls need their own backing to stay visible
val controlBacking = if (frame.background is CenterCropDrawable)
ColorUtils.setAlphaComponent(colors.get(ColorType.MAIN_BACKGROUND), 0xFF)
else Color.TRANSPARENT
frame.outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View, outline: Outline) {
outline.setRoundRect(0, 0, view.width, view.height, cornerRadius)
}
}
frame.background = bgDrawable
frame.clipToOutline = true
frame.outlineProvider = ViewOutlineProvider.BACKGROUND
frame.elevation = 8f * density

// Configure or create bottom bar inside main_keyboard_frame
val bottomContainer = frame.findViewById<FrameLayout>(R.id.floating_bottom_bar)
if (bottomContainer != null) {
val bottomLp = bottomContainer.layoutParams as? LinearLayout.LayoutParams
?: LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, bottomBarHeight)
bottomLp.width = LinearLayout.LayoutParams.MATCH_PARENT
bottomLp.height = bottomBarHeight
bottomContainer.layoutParams = bottomLp
bottomContainer.setPadding(0, 0, 0, 0)
bottomContainer.removeAllViews()
bottomBar = createBottomBar(bottomBarHeight, textColor, controlBacking, density)
bottomContainer.addView(bottomBar)
bottomContainer.visibility = View.VISIBLE
}

KeyboardSwitcher.getInstance().reloadKeyboard()

(frame.findViewById<View>(R.id.keyboard_view_wrapper) as? View)?.requestLayout()
Expand Down Expand Up @@ -428,10 +431,9 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
@SuppressLint("ClickableViewAccessibility")
private fun createBottomBar(
height: Int,
bgColor: Int,
textColor: Int,
density: Float,
cornerRadius: Float
controlBacking: Int,
density: Float
): FrameLayout {
val dm = context.resources.displayMetrics
val minHeight = (120 * density).toInt()
Expand All @@ -441,15 +443,6 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
FrameLayout.LayoutParams.MATCH_PARENT,
height
)
background = GradientDrawable().apply {
setColor(bgColor)
cornerRadii = floatArrayOf(
0f, 0f,
0f, 0f,
cornerRadius, cornerRadius,
cornerRadius, cornerRadius
)
}
}

// Sleek drag handle pill in center
Expand All @@ -462,8 +455,14 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
this.cornerRadius = 2.5f * density
setColor(defaultPillColor)
}
// the pill is too thin to draw on a backing of its own, so it gets an outline in that color
val pillOutline = if (controlBacking == Color.TRANSPARENT) 0 else (2 * density).toInt()
if (pillOutline > 0) {
dragHandleBg.setStroke(pillOutline, controlBacking)
dragHandleBg.cornerRadius = pillHeight / 2f + pillOutline
}
val dragHandle = View(context).apply {
layoutParams = FrameLayout.LayoutParams(pillWidth, pillHeight).apply {
layoutParams = FrameLayout.LayoutParams(pillWidth + 2 * pillOutline, pillHeight + 2 * pillOutline).apply {
gravity = Gravity.CENTER
}
background = dragHandleBg
Expand All @@ -485,7 +484,7 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
background = GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
this.cornerRadius = keyboardCornerRadiusPx(context.resources)
setColor((textColor and 0x00FFFFFF) or 0x1A000000.toInt())
setColor(ColorUtils.compositeColors((textColor and 0x00FFFFFF) or 0x1A000000, controlBacking))
}
contentDescription = context.getString(R.string.floating_keyboard_dock_handle)
scaleType = android.widget.ImageView.ScaleType.FIT_CENTER
Expand All @@ -494,8 +493,8 @@ class FloatingKeyboardManager(private val context: Context, private val latinIME
bottomBar.addView(dockBtn)

// Corner Resize Handle (Bottom-Right / End)
val defaultBgColor = (textColor and 0x00FFFFFF) or 0x1A000000.toInt()
val activeBgColor = (textColor and 0x00FFFFFF) or 0x55000000.toInt()
val defaultBgColor = ColorUtils.compositeColors((textColor and 0x00FFFFFF) or 0x1A000000, controlBacking)
val activeBgColor = ColorUtils.compositeColors((textColor and 0x00FFFFFF) or 0x55000000, controlBacking)

val resizeBg = GradientDrawable().apply {
shape = GradientDrawable.RECTANGLE
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/helium314/keyboard/latin/LatinIME.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package helium314.keyboard.latin

import helium314.keyboard.latin.utils.CenterCropDrawable
import helium314.keyboard.latin.utils.applyKeyboardStyle
import android.Manifest
import android.annotation.SuppressLint
Expand Down Expand Up @@ -2288,7 +2289,10 @@ class LatinIME : InputMethodService(),
window.isNavigationBarContrastEnforced = true
}
val settingsValues = settings.current
if (!settingsValues.mCustomNavBarColor) {
// from Android 15 the keyboard extends behind the navigation bar, so leave a wallpaper visible there
val showsWallpaper = Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
&& inputView?.findViewById<View>(R.id.main_keyboard_frame)?.background is CenterCropDrawable
if (!settingsValues.mCustomNavBarColor || showsWallpaper) {
setNavigationBarFrameBackground(null)
clearNavigationBarColor()
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import helium314.keyboard.settings.dialogs.ConfirmationDialog
import helium314.keyboard.settings.dialogs.InfoDialog
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@Composable
fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
Expand All @@ -56,8 +57,12 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
showSelectionDialog = false
showDayNightDialog = false
scope.launch(Dispatchers.IO) {
if (!setBackgroundImage(ctx, uri, isNight, isLandscape))
showErrorDialog = true
val success = setBackgroundImage(ctx, uri, isNight, isLandscape)
withContext(Dispatchers.Main) {
// rebuilds the keyboard views, so main thread only
KeyboardSwitcher.getInstance().setThemeNeedsReload()
if (!success) showErrorDialog = true
}
}
}
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
Expand Down Expand Up @@ -119,13 +124,10 @@ fun BackgroundImagePref(setting: Setting, isLandscape: Boolean) {
private fun setBackgroundImage(ctx: Context, uri: Uri, isNight: Boolean, isLandscape: Boolean): Boolean {
val imageFile = Settings.getCustomBackgroundFile(ctx, isNight, isLandscape)
FileUtils.copyContentUriToNewFile(uri, ctx, imageFile)
KeyboardSwitcher.getInstance().setThemeNeedsReload()
val bm = BitmapUtils.decodeSampledBitmap(imageFile, maxDim = 2048, preferLowConfig = true)
if (bm == null) {
imageFile.delete()
return false
}
bm.recycle()
if (bm == null) imageFile.delete()
bm?.recycle()
// also after a failure, as the previous image file is already gone
Settings.clearCachedBackgroundImages(ctx)
return true
return bm != null
}
Loading