Skip to content

Commit 07cc725

Browse files
committed
Prevent too frequent resizing
This reverts commit 1d3dc6d and implements another solution Keyboards push up the bottom of app. - If skkPrefs.candidatesMinHeight is false, push up all the height of candidatesView too and this resizes the app too often (old behavior) - If true, push up only the minimum height of it (fixed value) and place the rest of the candidates *over* the app
1 parent 527b050 commit 07cc725

5 files changed

Lines changed: 21 additions & 24 deletions

File tree

app/src/main/java/jp/deadend/noname/skk/CandidatesViewContainer.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class CandidatesViewContainer(screen: Context, attrs: AttributeSet) : LinearLayo
3535
setSize(-1)
3636
}
3737
}
38+
internal val minHeight = resources.getDimensionPixelSize(R.dimen.candidates_scroll_button_width)
3839
private lateinit var mService: SKKService
3940

4041
private val mActivePointers = mutableListOf<Pair<Int, Float>>()
@@ -169,9 +170,8 @@ class CandidatesViewContainer(screen: Context, attrs: AttributeSet) : LinearLayo
169170
if (px > 0) {
170171
binding.candidates.setTextSize(px)
171172
}
172-
val buttonSize = resources.getDimensionPixelSize(R.dimen.candidates_scroll_button_width)
173-
val width = mService.inputViewWidth - buttonSize * 2
174-
val height = if (lines > 0) (px * lines * LINE_SCALE).toInt() else buttonSize
173+
val width = mService.inputViewWidth - minHeight * 2 // minHeight == size of square button
174+
val height = if (lines > 0) (px * lines * LINE_SCALE).toInt() else minHeight
175175
val newLayoutParams = LayoutParams(width, height)
176176
if (binding.frame.layoutParams.width != newLayoutParams.width ||
177177
binding.frame.layoutParams.height != newLayoutParams.height

app/src/main/java/jp/deadend/noname/skk/SKKPrefs.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ class SKKPrefs(context: Context) {
2929
putInt(res.getString(R.string.pref_candidates_size), value)
3030
}
3131

32-
var candidatesReserveLines: Boolean
33-
get() = prefs.getBoolean(res.getString(R.string.pref_candidates_reserve_lines), false)
32+
var candidatesMinHeight: Boolean
33+
get() = prefs.getBoolean(res.getString(R.string.pref_candidates_min_height), true)
3434
set(value) = prefs.edit {
35-
putBoolean(res.getString(R.string.pref_candidates_reserve_lines), value)
35+
putBoolean(res.getString(R.string.pref_candidates_min_height), value)
3636
}
3737

3838
var candidatesNormalLines: Int

app/src/main/java/jp/deadend/noname/skk/SKKService.kt

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -841,17 +841,16 @@ class SKKService : InputMethodService() {
841841
//dLog("lifecycle: ${Thread.currentThread().stackTrace[2].methodName}")
842842
super.onComputeInsets(outInsets)
843843
if (outInsets == null || mInputView == null || mCandidatesViewContainer == null) return
844+
val height = mInputView!!.height + mCandidatesViewContainer!!.height // paddingBottom は除外
844845
outInsets.apply {
845-
if (isFloating()) {
846-
val height = mInputView!!.height + mCandidatesViewContainer!!.height
847-
contentTopInsets = height
848-
touchableInsets = Insets.TOUCHABLE_INSETS_REGION
849-
touchableRegion.set(leftOffset, 0, leftOffset + mInputView!!.keyboard.width, height)
850-
} else {
851-
contentTopInsets = visibleTopInsets
852-
// CandidatesViewに対して強制的にActivityをリサイズさせるためのhack
853-
touchableInsets = Insets.TOUCHABLE_INSETS_VISIBLE
846+
contentTopInsets = when {
847+
isFloating() -> height // 高さをすべて無効にして floating を実現
848+
skkPrefs.candidatesMinHeight -> contentTopInsets -
849+
mCandidatesViewContainer!!.minHeight // 常時表示される分だけを確保し固定
850+
else -> visibleTopInsets // 変動する CandidatesView の高さも確保
854851
}
852+
touchableInsets = Insets.TOUCHABLE_INSETS_REGION
853+
touchableRegion.set(leftOffset, 0, leftOffset + mInputView!!.keyboard.width, height)
855854
}
856855
}
857856

@@ -1325,7 +1324,7 @@ class SKKService : InputMethodService() {
13251324
mCandidatesViewContainer?.apply {
13261325
if (list.isNullOrEmpty()) {
13271326
setAlpha(skkPrefs.inactiveAlpha)
1328-
lines = if (skkPrefs.candidatesReserveLines) viewLines else 0
1327+
lines = 0
13291328
} else {
13301329
setAlpha(skkPrefs.activeAlpha)
13311330
lines = viewLines
@@ -1336,9 +1335,7 @@ class SKKService : InputMethodService() {
13361335

13371336
fun requestChooseCandidate(index: Int) = mCandidatesView?.choose(index)
13381337

1339-
fun clearCandidatesView() = mCandidatesViewContainer?.let {
1340-
setCandidates(null, "", if (skkPrefs.candidatesReserveLines) it.lines else 0)
1341-
}
1338+
fun clearCandidatesView() = setCandidates(null, "", 0)
13421339

13431340
// カーソル直前に引数と同じ文字列があるなら,それを消してtrue なければfalse
13441341
fun prepareReConversion(candidate: String): Boolean {

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
<string name="pref_abbrev_key" translatable="false">PrefKeyAbbrevKey</string>
8181
<string name="pref_hankaku_kana_key" translatable="false">PrefKeyHankakuKanaKey</string>
8282
<string name="pref_candidates_size" translatable="false">PrefKeyCandidatesSize</string>
83-
<string name="pref_candidates_reserve_lines" translatable="false">PrefKeyCandidatesReserveLines</string>
83+
<string name="pref_candidates_min_height" translatable="false">PrefKeyCandidatesMinHeight</string>
8484
<string name="pref_candidates_normal_lines" translatable="false">PrefKeyCandidatesNormalLines</string>
8585
<string name="pref_candidates_emoji_lines" translatable="false">PrefKeyCandidatesEmojiLines</string>
8686
<string name="pref_use_candidates_view" translatable="false">PrefKeyUseCandidatesView</string>

app/src/main/res/xml/prefs_main.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
app:showSeekBarValue="true"
2727
app:title="候補表示の文字サイズ" />
2828
<androidx.preference.CheckBoxPreference
29-
app:defaultValue="false"
29+
app:defaultValue="true"
3030
app:iconSpaceReserved="false"
31-
app:key="@string/pref_candidates_reserve_lines"
32-
app:summary="画面のちらつきを減らせる可能性があります"
33-
app:title="候補表示を閉じない" />
31+
app:key="@string/pref_candidates_min_height"
32+
app:summary="変換中にリサイズで画面がちらつかず安定します"
33+
app:title="候補表示をアプリ上に重ねて伸ばす" />
3434
<androidx.preference.SeekBarPreference
3535
android:max="10"
3636
app:defaultValue="2"

0 commit comments

Comments
 (0)