Skip to content

Commit 67975a0

Browse files
committed
perf: adjust candidate swipe action tigger
1 parent 8762f0f commit 67975a0

File tree

3 files changed

+46
-15
lines changed

3 files changed

+46
-15
lines changed

app/src/main/java/com/osfans/trime/ime/core/Trime.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ public void selectLiquidKeyboard(final int tabIndex) {
442442
liquidKeyboard.setLand(orientation == Configuration.ORIENTATION_LANDSCAPE);
443443
liquidKeyboard.calcPadding(mainInputView.getWidth());
444444
symbolKeyboardType = liquidKeyboard.select(tabIndex);
445-
updateComposing();
446445
tabView.updateTabWidth();
447446
if (inputRootBinding != null) {
448447
mTabRoot.setBackground(mCandidateRoot.getBackground());
@@ -451,8 +450,8 @@ public void selectLiquidKeyboard(final int tabIndex) {
451450
} else {
452451
symbolKeyboardType = SymbolKeyboardType.NO_KEY;
453452
symbolInputView.setVisibility(View.GONE);
454-
updateComposing();
455453
}
454+
updateComposing();
456455
}
457456
if (mainInputView != null)
458457
mainInputView.setVisibility(tabIndex >= 0 ? View.GONE : View.VISIBLE);

app/src/main/java/com/osfans/trime/ime/text/Composition.java

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package com.osfans.trime.ime.text;
2020

2121
import android.annotation.SuppressLint;
22-
import android.annotation.TargetApi;
2322
import android.content.Context;
2423
import android.content.res.Configuration;
2524
import android.content.res.Resources;
@@ -146,7 +145,6 @@ public void updateDrawState(TextPaint ds) {
146145
}
147146
}
148147

149-
@TargetApi(21)
150148
public static class LetterSpacingSpan extends UnderlineSpan {
151149
private final float letterSpacing;
152150

app/src/main/java/com/osfans/trime/ime/text/ScrollView.java

+45-11
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ protected void onFinishInflate() {
4646
}
4747
}
4848

49+
private int swipeActionLimit = 200;
50+
private float swipeStartX = -1;
51+
4952
@SuppressLint("ClickableViewAccessibility")
5053
@Override
5154
public boolean onTouchEvent(@NonNull MotionEvent ev) {
@@ -73,9 +76,20 @@ public void fling(int velocityY) {
7376
public void commOnTouchEvent(@NonNull MotionEvent ev) {
7477
int action = ev.getAction();
7578
switch (action) {
76-
/* case MotionEvent.ACTION_DOWN:
77-
break; **/
79+
case MotionEvent.ACTION_DOWN:
80+
swipeActionLimit = Math.min(getWidth() / 4, getHeight() * 10);
81+
Timber.i(
82+
"commOnTouchEvent limit = "
83+
+ swipeActionLimit
84+
+ ", "
85+
+ getWidth() / 4
86+
+ ", "
87+
+ getHeight() * 4);
88+
if (swipeActionLimit < 50) swipeActionLimit = 100;
89+
break;
90+
7891
case MotionEvent.ACTION_UP:
92+
swipeStartX = -1;
7993
isMoving = false;
8094
// Fingers loose
8195
if (isNeedAnimation()) {
@@ -92,19 +106,39 @@ public void commOnTouchEvent(@NonNull MotionEvent ev) {
92106
}
93107

94108
// TODO: 翻页后、手指抬起前,降低滑动速度增加阻尼感
95-
if (inner.getLeft() > 100 && Rime.hasLeft()) {
109+
if (inner.getLeft() > swipeActionLimit && Rime.hasLeft()) {
96110
if (pageUpAction != null) pageUpAction.run();
97111
if (inner.getWidth() > this.getWidth())
98112
scrollTo(this.getWidth() - inner.getWidth() + 400, 0);
99-
} else if (inner.getWidth() - inner.getRight() > 100
100-
&& Trime.getService().hasCandidateExPage()) {
101-
if (pageExAction != null) pageExAction.run();
102-
} else if (inner.getWidth() - inner.getRight() > 100 && Rime.hasRight()) {
103-
if (pageDownAction != null) pageDownAction.run();
104-
if (inner.getWidth() > this.getWidth()) {
105-
scrollTo(-400, 0);
106-
}
107113
} else {
114+
// Timber.d("commOnTouchEvent "+getWidth() + "-" + inner.getWidth() +"+" +
115+
// getScrollX()+", p=" +scrollEndPosition+", x="+ev.getX());
116+
Timber.d(
117+
"commOnTouchEvent dif=" + (swipeStartX - ev.getX()) + " limit=" + swipeActionLimit);
118+
119+
if (swipeStartX < 0) {
120+
if (getWidth() - inner.getWidth() + getScrollX() >= 0) {
121+
swipeStartX = ev.getX();
122+
}
123+
} else if (swipeStartX - ev.getX() > swipeActionLimit) {
124+
if (Trime.getService().hasCandidateExPage()) {
125+
if (pageExAction != null) pageExAction.run();
126+
return;
127+
} else if (Rime.hasRight()) {
128+
if (pageDownAction != null) pageDownAction.run();
129+
swipeStartX = -1;
130+
if (inner.getWidth() > this.getWidth()) {
131+
scrollTo(-swipeActionLimit, 0);
132+
inner.layout(
133+
inner.getRight(),
134+
inner.getTop(),
135+
inner.getRight() + inner.getWidth(),
136+
inner.getBottom());
137+
}
138+
return;
139+
}
140+
}
141+
108142
// When the scroll to the top or the most when it will not scroll, then move the layout.
109143
isNeedMove();
110144
// Log.d("MotionEvent "+isMoveing," d="+deltaX+" left="+left+" LR="+inner.getLeft()+",

0 commit comments

Comments
 (0)