Skip to content

Commit fb99245

Browse files
tumuyanBambooin
authored andcommitted
feat: define enter key label for different sense
1 parent bc98e2c commit fb99245

File tree

6 files changed

+173
-14
lines changed

6 files changed

+173
-14
lines changed

app/src/main/assets/rime/tongwenfeng.trime.yaml

+13-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ style:
9797
text_size: 14 #编码区字号
9898
vertical_correction: -5
9999
vertical_gap: *sgap #键盘行距
100+
action_label_type: never #是否使用App的ActionLabel内容作为Enter键的文本 only | first | last | never
101+
enter_labels: # 定义Enter键的文本
102+
go: 前往
103+
done: 完成
104+
next: 下个
105+
pre: 上个
106+
search: 搜索
107+
send: 发送
108+
default: Enter # 定义默认Enter键的文本
100109

101110
fallback_colors:
102111
candidate_text_color: text_color
@@ -1018,7 +1027,7 @@ preset_keyboards:
10181027
- {click: space, long_click: Mode_switch, swipe_left: "Left", swipe_right: "Right", swipe_up: Schema_switchcn, width: 30, key_back_color: bkg, key_text_color: tkg}
10191028
- {click: '.', label: '。', long_click: liquid_keyboard_clipboard, key_back_color: bh4, key_text_color: th4}
10201029
- {click: '/', long_click: liquid_keyboard_switch , key_text_size: "18", key_back_color: bh4, key_text_color: th4}
1021-
- {click: Return, swipe_up: Escape, width: 15, key_back_color: benter, key_text_color: tenter}
1030+
- {click: Return, composing: Return1, swipe_up: Escape, width: 15, key_back_color: benter, key_text_color: tenter}
10221031

10231032
letter:
10241033
author: "暖暖"
@@ -1067,7 +1076,7 @@ preset_keyboards:
10671076
- {label: '______', click: space, long_click: space_R2, swipe_left: "Left", swipe_right: "Right", swipe_up: Keyboard_fbj, width: 30, key_back_color: bkg, key_text_color: tkg}
10681077
- {click: '.', label: '。', long_click: Keyboard_kao, key_back_color: bh4, key_text_color: th4}
10691078
- {click: space_R2, long_click: liquid_keyboard_switch, key_text_size: "18", key_back_color: bh4, key_text_color: th4}
1070-
- {click: Return, swipe_up: Escape, width: 15, key_back_color: benter, key_text_color: tenter}
1079+
- {click: Return, composing: Return1, swipe_up: Escape, width: 15, key_back_color: benter, key_text_color: tenter}
10711080

10721081
number:
10731082
author: "暖暖"
@@ -3880,7 +3889,8 @@ preset_keys:
38803889
VOLUME_MUTE: {label: 静音, send: VOLUME_MUTE}
38813890
# 编辑
38823891
Shift_L: {label: Shift, preview: '⇪', functional: false, send: Shift_L}
3883-
Return: {label: Enter, preview: '↩', functional: false, send: Return}
3892+
Return: { label: enter_labels, preview: '↩', functional: false, send: Return }
3893+
Return1: {label: Enter, preview: '↩', functional: false, send: Return}
38843894
Hide: {label: 隐藏, send: BACK}
38853895
BackSpace: {label: 退格, preview: '⇦', repeatable: true, functional: false, send: BackSpace}
38863896
space: {repeatable: false, preview: ' ', functional: false, label: '_______', send: space}

app/src/main/assets/rime/trime.yaml

+21-11
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ style:
8989
long_text_font: comment.ttf #剪贴板等可能包含大段文本使用的字体
9090
#background_folder: #背景图保存在background目录下的哪个子目录
9191
key_long_text_border: 1
92+
action_label_type: never #是否使用App的ActionLabel内容作为Enter键的文本 only | first | last | never
93+
enter_labels: # 定义Enter键的文本
94+
go: 前往
95+
done: 完成
96+
next: 下个
97+
pre: 上个
98+
search: 搜索
99+
send: 发送
100+
default: Enter # 定义默认Enter键的文本
92101

93102
fallback_colors:
94103
candidate_text_color: text_color
@@ -893,7 +902,8 @@ preset_keys:
893902
VOLUME_MUTE: {label: 靜音, send: VOLUME_MUTE}
894903
# 編輯
895904
Shift_L: {label: Shift, send: Shift_L, shift_lock: ascii_long}
896-
Return: {label: Enter, send: Return}
905+
Return: {label: enter_labels, send: Return}
906+
Return1: {label: Enter, send: Return }
897907
Hide: {label: 隱藏, send: BACK}
898908
BackSpace: {label: 退格, repeatable: true, send: BackSpace}
899909
space: {repeatable: false, functional: false, send: space}
@@ -1036,7 +1046,7 @@ preset_keyboards:
10361046
- {click: space, width: 30}
10371047
- {click: "'", long_click: '"'}
10381048
- {click: BackSpace, width: 15}
1039-
- {click: Return, long_click: CommitComment, width: 15}
1049+
- {click: Return, composing: Return1, long_click: CommitComment, width: 15}
10401050
letter:
10411051
__include: /preset_keyboards/default
10421052
ascii_mode: 1
@@ -1097,7 +1107,7 @@ preset_keyboards:
10971107
- {click: space, width: 30}
10981108
- {click: '.', long_click: '>'}
10991109
- {click: '/', long_click: '?'}
1100-
- {click: Return, long_click: CommitComment, width: 15}
1110+
- {click: Return, composing: Return1, long_click: CommitComment, width: 15}
11011111
qwerty_:
11021112
name: 預設30鍵
11031113
author: "osfans <waxaca@163.com>"
@@ -1141,7 +1151,7 @@ preset_keyboards:
11411151
- {click: Mode_switch, long_click: Menu}
11421152
- {click: space, width: 40}
11431153
- {click: BackSpace, width: 15}
1144-
- {click: Return, long_click: CommitComment, width: 15}
1154+
- {click: Return, composing: Return1, long_click: CommitComment, width: 15}
11451155
qwerty:
11461156
name: 預設26鍵
11471157
author: "osfans <waxaca@163.com>"
@@ -1195,7 +1205,7 @@ preset_keyboards:
11951205
- {click: space, width: 30}
11961206
- {click: '.', long_click: '>'}
11971207
- {click: '/', long_click: '?'}
1198-
- {click: Return, long_click: CommitComment, width: 15}
1208+
- {click: Return, composing: Return1, long_click: CommitComment, width: 15}
11991209
us_intl:
12001210
name: 美式國際
12011211
author: "Terry Tsang <archerindigo@gmail.com>"
@@ -1390,7 +1400,7 @@ preset_keyboards:
13901400
- {label: 'ㄦ', long_click: '"', click: "-"}
13911401
- {long_click: '。', click: ','}
13921402
- {click: BackSpace, long_click: Escape, width: 10}
1393-
- {click: Return, long_click: CommitComment, width: 10}
1403+
- {click: Return, composing: Return1, long_click: CommitComment, width: 10}
13941404
cangjie5:
13951405
name: 倉頡五代鍵盤
13961406
author: "皛筱晓小笨鱼"
@@ -1434,7 +1444,7 @@ preset_keyboards:
14341444
- {click: space, width: 40}
14351445
- {click: Mode_switch, long_click: Menu}
14361446
- {long_click: '>', click: '.'}
1437-
- {click: Return, long_click: CommitComment, width: 10}
1447+
- {click: Return, composing: Return1, long_click: CommitComment, width: 10}
14381448
cangjie6:
14391449
ascii_mode: 0
14401450
name: 倉頡六代
@@ -1492,7 +1502,7 @@ preset_keyboards:
14921502
- {click: ",", long_click: .}
14931503
- {click: space, width: 25}
14941504
- {click: "'", long_click: "?"}
1495-
- {click: Return, long_click: CommitComment, width: 25.5}
1505+
- {click: Return, composing: Return1, long_click: CommitComment, width: 25.5}
14961506
scj6:
14971507
__include: /preset_keyboards/cangjie5
14981508
stroke:
@@ -1517,7 +1527,7 @@ preset_keyboards:
15171527
- {click: Keyboard_symbols, long_click: Keyboard_number, width: 10}
15181528
- {click: space, width: 40}
15191529
- {click: Keyboard_letter, long_click: Menu, width: 10}
1520-
- {click: Return, long_click: CommitComment, width: 20}
1530+
- {click: Return, composing: Return1, long_click: CommitComment, width: 20}
15211531
telegraph:
15221532
name: 電碼
15231533
author: 熊貓阿Bo
@@ -1546,7 +1556,7 @@ preset_keyboards:
15461556
- {click: BackSpace}
15471557
- {click: Keyboard_letter, long_click: Menu}
15481558
- {click: space, width: 60}
1549-
- {click: Return}
1559+
- {click: Return, composing: Return1}
15501560
terra_pinyin:
15511561
name: 地球拼音鍵盤
15521562
author: 默默ㄇㄛˋ
@@ -1590,7 +1600,7 @@ preset_keyboards:
15901600
- {click: space, width: 40}
15911601
- {click: ".", long_click: '"'}
15921602
- {click: '\', long_click: '.', composing: 'ˋ', send_bindings: false} #四聲
1593-
- {click: Return, long_click: CommitComment}
1603+
- {click: Return, composing: Return1, long_click: CommitComment}
15941604
array30:
15951605
name: 行列30配美式國際
15961606
author: "Terry Tsang <archerindigo@gmail.com>"

app/src/main/java/com/osfans/trime/data/Config.java

+29
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import androidx.annotation.NonNull;
3737
import androidx.annotation.Nullable;
3838
import com.osfans.trime.core.Rime;
39+
import com.osfans.trime.ime.enums.ActionLabelType;
3940
import com.osfans.trime.ime.enums.SymbolKeyboardType;
4041
import com.osfans.trime.ime.enums.WindowsPositionType;
4142
import com.osfans.trime.ime.keyboard.Key;
@@ -840,6 +841,34 @@ public String[] getColorNames(String[] keys) {
840841
return names;
841842
}
842843

844+
private Map<String, String> mEnterLabels;
845+
846+
public Map<String, String> getmEnterLabels() {
847+
return mEnterLabels;
848+
}
849+
850+
public ActionLabelType getActionLabelType() {
851+
return ActionLabelType.fromString(getString("action_label_type"));
852+
}
853+
854+
public void initEnterLabels() {
855+
Object enter_labels = getValue("enter_labels");
856+
if (enter_labels == null) mEnterLabels = new HashMap<>();
857+
else mEnterLabels = (Map<String, String>) enter_labels;
858+
859+
String defaultEnterLabel = "Enter";
860+
if (mEnterLabels.containsKey("default")) defaultEnterLabel = mEnterLabels.get("default");
861+
else mEnterLabels.put("default", defaultEnterLabel);
862+
863+
if (!mEnterLabels.containsKey("done")) mEnterLabels.put("done", defaultEnterLabel);
864+
if (!mEnterLabels.containsKey("go")) mEnterLabels.put("go", defaultEnterLabel);
865+
if (!mEnterLabels.containsKey("next")) mEnterLabels.put("next", defaultEnterLabel);
866+
if (!mEnterLabels.containsKey("none")) mEnterLabels.put("none", defaultEnterLabel);
867+
if (!mEnterLabels.containsKey("pre")) mEnterLabels.put("pre", defaultEnterLabel);
868+
if (!mEnterLabels.containsKey("search")) mEnterLabels.put("search", defaultEnterLabel);
869+
if (!mEnterLabels.containsKey("send")) mEnterLabels.put("send", defaultEnterLabel);
870+
}
871+
843872
public Typeface getFont(String key) {
844873
final String name = getString(key);
845874
if (name != null) {

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

+8
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,14 @@ public void onStartInputView(EditorInfo attribute, boolean restarting) {
786786
if (!restarting) setNavBarColor();
787787
setCandidatesViewShown(!Rime.isEmpty()); // 軟鍵盤出現時顯示候選欄
788788

789+
if ((attribute.imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION)
790+
== EditorInfo.IME_FLAG_NO_ENTER_ACTION) {
791+
mainKeyboardView.resetEnterLabel();
792+
} else {
793+
mainKeyboardView.setEnterLabel(
794+
attribute.imeOptions & EditorInfo.IME_MASK_ACTION, attribute.actionLabel);
795+
}
796+
789797
switch (attribute.inputType & InputType.TYPE_MASK_VARIATION) {
790798
case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
791799
case InputType.TYPE_TEXT_VARIATION_PASSWORD:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2015-present, osfans
3+
* waxaca@163.com https://github.com/osfans
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.osfans.trime.ime.enums
19+
20+
import java.util.HashMap
21+
import java.util.Locale
22+
23+
enum class ActionLabelType {
24+
LAST, ONLY, FIRST, NEVER;
25+
26+
companion object {
27+
private val convertMap: HashMap<String, ActionLabelType> = hashMapOf()
28+
29+
init {
30+
for (type in values()) {
31+
convertMap[type.toString()] = type
32+
}
33+
}
34+
35+
@JvmStatic
36+
fun fromString(code: String): ActionLabelType {
37+
if (code.isNullOrBlank()) return LAST
38+
val type = convertMap[code.uppercase(Locale.getDefault())]
39+
return type ?: LAST
40+
}
41+
}
42+
}

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java

+60
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@
4040
import android.view.View;
4141
import android.view.ViewConfiguration;
4242
import android.view.ViewGroup;
43+
import android.view.inputmethod.EditorInfo;
4344
import android.widget.PopupWindow;
4445
import android.widget.TextView;
4546
import androidx.annotation.NonNull;
4647
import com.osfans.trime.R;
4748
import com.osfans.trime.data.AppPrefs;
4849
import com.osfans.trime.data.Config;
4950
import com.osfans.trime.databinding.KeyboardKeyPreviewBinding;
51+
import com.osfans.trime.ime.enums.ActionLabelType;
5052
import com.osfans.trime.ime.enums.KeyEventType;
5153
import com.osfans.trime.ime.lifecycle.CoroutineScopeJava;
5254
import com.osfans.trime.util.LeakGuardHandlerWrapper;
@@ -237,6 +239,61 @@ public interface OnKeyboardActionListener {
237239
private Method findStateDrawableIndex;
238240
private Method getStateDrawable;
239241

242+
private String labelEnter = "";
243+
private Map<String, String> mEnterLabels;
244+
private ActionLabelType actionLabelType;
245+
246+
public void resetEnterLabel() {
247+
labelEnter = mEnterLabels.get("default");
248+
}
249+
250+
public void setEnterLabel(int action, CharSequence actionLabel) {
251+
252+
if (actionLabelType == ActionLabelType.ONLY) {
253+
if (actionLabel != null && actionLabel.length() > 0) labelEnter = actionLabel.toString();
254+
else labelEnter = mEnterLabels.get("default");
255+
return;
256+
}
257+
258+
if (actionLabelType == ActionLabelType.FIRST) {
259+
if (actionLabel != null && actionLabel.length() > 0) {
260+
labelEnter = actionLabel.toString();
261+
return;
262+
}
263+
}
264+
265+
switch (action) {
266+
case EditorInfo.IME_ACTION_DONE:
267+
labelEnter = mEnterLabels.get("done");
268+
break;
269+
case EditorInfo.IME_ACTION_GO:
270+
labelEnter = mEnterLabels.get("go");
271+
break;
272+
case EditorInfo.IME_ACTION_NEXT:
273+
labelEnter = mEnterLabels.get("next");
274+
break;
275+
case EditorInfo.IME_ACTION_PREVIOUS:
276+
labelEnter = mEnterLabels.get("pre");
277+
break;
278+
case EditorInfo.IME_ACTION_SEARCH:
279+
labelEnter = mEnterLabels.get("search");
280+
break;
281+
case EditorInfo.IME_ACTION_SEND:
282+
labelEnter = mEnterLabels.get("send");
283+
break;
284+
case EditorInfo.IME_ACTION_NONE:
285+
labelEnter = mEnterLabels.get("none");
286+
default:
287+
if (actionLabelType == ActionLabelType.LAST) {
288+
if (actionLabel != null && actionLabel.length() > 0) {
289+
labelEnter = actionLabel.toString();
290+
return;
291+
}
292+
}
293+
labelEnter = mEnterLabels.get("default");
294+
}
295+
}
296+
240297
@NonNull
241298
private AppPrefs getPrefs() {
242299
return AppPrefs.Companion.defaultInstance();
@@ -347,6 +404,9 @@ public void reset(final Context context) {
347404
REPEAT_START_DELAY = config.getLongTimeout() + 1;
348405
LONG_PRESS_TIMEOUT = config.getLongTimeout();
349406
MULTI_TAP_INTERVAL = config.getLongTimeout();
407+
408+
mEnterLabels = config.getmEnterLabels();
409+
actionLabelType = config.getActionLabelType();
350410
invalidateAllKeys();
351411
}
352412

0 commit comments

Comments
 (0)