Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes #3

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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 @@ -274,7 +274,7 @@ class EditorInstance(private val ims: InputMethodService) {
val ic = inputConnection ?: return false
val isHalfShapePunct = Rime.showAsciiPunch()
// In Gboard, an ideographic full stop is only produced after a letter or digit (with Unicode categories L* or Nd).
return (isHalfShapePunct || ic.getTextBeforeCursor(2, 0)?.firstOrNull()?.isLetterOrDigit() == true)
return (ic.getTextBeforeCursor(2, 0)?.firstOrNull()?.isLetterOrDigit() == true)
&& ic.deleteSurroundingText(1, 0)
&& ic.commitText(if (isHalfShapePunct) ". " else "。", 1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hk.eduhk.typeduck.data.theme.Config;
import hk.eduhk.typeduck.util.ConfigGetter;
import hk.eduhk.typeduck.util.DimensionsKt;
import hk.eduhk.typeduck.util.KeyboardSizeUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -97,18 +98,18 @@ public class Keyboard {
// 3. 由于高度只能取整数,缩放后仍然存在余数的,由 auto_height_index 指定的行吸收(遵循四舍五入)
// 特别的,当值为负数时,为倒序序号(-1即倒数第一个);当值大于按键行数时,为最后一行
private int autoHeightIndex, keyboardHeight;

public static float adjustRatio = Math.min(ScreenUtils.getScreenWidth(), ScreenUtils.getScreenHeight()) / 1000f;
public static float adjustRatio = Math.min(KeyboardSizeUtils.getScreenWidth(), KeyboardSizeUtils.getScreenHeight()) / 1000f;
public static float adjustRatioSmall = (float) Math.cbrt(adjustRatio);

public int getPadding() {
return (ScreenUtils.getScreenWidth() - mDisplayWidth) / 2;
return (KeyboardSizeUtils.getScreenWidth() - mDisplayWidth) / 2;
}

/** Creates a keyboard from the given xml key layout file. */
public Keyboard() {
// some magic
final double width = ScreenUtils.getScreenWidth(), height = ScreenUtils.getScreenHeight();
KeyboardSizeUtils.refreshSize();
final double width = KeyboardSizeUtils.getScreenWidth(), height = KeyboardSizeUtils.getScreenHeight();
final double widthHeightProduct = width * height;
final double screenNarrowness = 2.0 / (height / width + width / height);

Expand Down
51 changes: 51 additions & 0 deletions app/src/main/java/hk/eduhk/typeduck/util/KeyboardSizeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package hk.eduhk.typeduck.util

import android.annotation.SuppressLint
import android.graphics.Point
import android.os.Build
import android.view.WindowInsets
import hk.eduhk.typeduck.ime.core.Trime
import kotlin.math.floor
import splitties.systemservices.windowManager


object KeyboardSizeUtils {

private val point = Point(-1, -1)

@SuppressLint("NewApi")
@JvmStatic
fun refreshSize() {
val windowManager = Trime.getService().windowManager?: return
var currentVersion = Build.VERSION.SDK_INT

if (currentVersion >= Build.VERSION_CODES.R) {
val metrics = windowManager.currentWindowMetrics
val bounds = metrics.bounds
val insets = metrics.windowInsets.getInsets(
WindowInsets.Type.navigationBars() or
WindowInsets.Type.displayCutout()
)
point.set(bounds.width() - insets.left - insets.right,
bounds.height() - insets.top - insets.bottom)
} else {
windowManager.defaultDisplay.getSize(point)
}
}

@JvmStatic
fun getScreenWidth(): Int {
if (point.x < 0) {
refreshSize()
}
return point.x
}

@JvmStatic
fun getScreenHeight(): Int {
if (point.y < 0) {
refreshSize()
}
return if (point.x <= point.y) point.y else point.y - floor(0.2 * point.y).toInt()
}
}