Skip to content

Commit

Permalink
增加符号键盘和剪贴板
Browse files Browse the repository at this point in the history
1. 增加符号键盘,实现了根据配置加载按键、可以滚动显示键盘、点击上屏的主要功能。
2. 滑动键盘以标签页的形式展示多组多组键盘,标签列表占用原键盘布局的候选栏位置,并且完全共用候选栏的皮肤参数。按键填充在LiquidKeyboard中,除背景色共用原皮肤的背景参数外,其他参数可以单独设定。
3. 在滑动键盘内增加内置剪贴板,提供监控剪贴板变化、列表显示、点击上屏的简单功能。剪贴板删除、查找、合并、编辑等功能目前未实现,背景色参数设定未实现。
4. 去除ScrollView一些未使用的变量。

短期无法完善剪贴板,因此先提交已完成基本功能的代码。
  • Loading branch information
tumuyan committed Aug 27, 2021
1 parent 802a851 commit b39e356
Show file tree
Hide file tree
Showing 27 changed files with 1,850 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ libs/*
# vim
*.swp

/app/release/output-metadata.json
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2'
implementation 'com.google.android.flexbox:flexbox:3.0.0'
}
repositories {
mavenCentral()
Expand Down
97 changes: 97 additions & 0 deletions app/src/main/assets/rime/trime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ style:
text_size: 16 #編碼區字號
vertical_correction: -10
vertical_gap: 1 #鍵盤行距
long_text_font: comment.ttf #剪贴板等可能包含大段文本使用的字体

fallback_colors:
candidate_text_color: text_color
Expand Down Expand Up @@ -663,6 +664,102 @@ preset_color_schemes:
off_key_text_color: 0x7f7f7f
text_color: 0x7f7f7f

liquid_keyboard:
author: "tumuyan"
key_height: 40 #按键高度
key_height_land: 40 #横屏模式按键高度
single_width: 60 #single类型的按键宽度
vertical_gap: 5 #纵向按键间隙
margin_x: 1 #左右按键间隙的1/2
keyboards: [emoji, math, ascii, cn, clipboard, list ,ids , exit, jp, table, symbol, pinyin, grease, rusa, korea, lation, yinbiao, unit, test, exit] #tab列表
exit:
name: 返回
type: NO_KEY
keys: EXIT
emoji:
type: SINGLE
keys: "🙂😂🤣😆🙃😅🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
clipboard:
type: CLIPBOARD
name: 剪贴板
math: #tab名称
type: SINGLE
name: 数学
keys: "≈=≠≌<>≤≥≡()[]{}-+±×*/÷&∥%‰‱°′″∫∮∯∬∭∰∞∑∧∏∈∵∴⊥∝∨∪•√〒∝∽∈∩∧⊙⌒∥∟∣∂∆∞≌∉∪∨⊕⊿⊥∠∫∬∭" #tab中的按键列表
test:
type: SINGLE
keys: #keys列表可以使用多种格式混合书写。
-
-
-
-
-
-
- ……
-
-
-
-
- ——
- { click: "——" }
- { click: "——", label: "破折号" }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
symbol:
type: SINGLE
keys: "△▽○◇□☆▲▼●◆■★▷◁▶◀�×⌫✡☑☒✅❎✔✘✓✗☼☽♀☻◐㏂☀☾♂☹◑㏘☜☝☞☚☟☛▪•‥…∷※♩♪♫♬§°♭♯♮‖¶№◎¤۞℗®©卍卐℡™㏇Φ↖↑↗◤㊤◥←↔→㊧㊥㊨↙↓↘◣㊦◢⇄⇅⇆⇤↩⇥❏❐◲〼▢▣⇦⇧⇨⇩⇪↶▸◂▴▾✁↷✍⏍ϟ📝✎✆☱☰☴⚿⛮⚙☲☯☵⛶☩☐☳☷☶💬🗨⟲ღ✈☂🎤🌐🔍"
unit:
name: 单位
type: SINGLE
keys: "℃¥$€฿£㎡m³℉¥£¢₠¹²³⁴⁵ⁿ⁶⁷⁸⁹⁰ˣ⁺⁻⁼⁽⁾½⅓¼⅔¾₁₂₃₄₅ₙ₆₇₈₉₀ₓ₊₋₌₍₎℅"
list:
name: 列表
type: SINGLE
keys: "①②③④⑤⑥⑦⑧⑨⑩⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩➊➋➌➍➎➏➐➑➒➓㊀㊁㊂㊃㊄㊅㊆㊇㊈㊉ⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ"
pinyin:
name: 拼音
type: SINGLE
keys: "āáǎàōóēéěèǒòīíǐìūúǖǘǚǜǔùêüńňㄚㄛㄜㄧㄨㄩㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙ"
grease:
type: SINGLE
keys: "ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψω"
rusa:
type: SINGLE
keys: "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдеёжзийклмнопрстуфхцчшщъыьэюя"
lation:
type: SINGLE
keys: "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŠŸŒàáâãäåæçèéêëìíîïðñòóõôöøùúûüýþšÿœ"
korea:
type: SINGLE
name: "韩文"
keys: "dㅏㅑㅓㅕㅗㅛㅜㅠㅡㅣㅐㅒㅔㅖㅘㅙㅚㅝㅞㅟㅢㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎㄲㄸㅚㅆㅉ㉠㉡㉢㉣㉤㉥㉦㉧㉨㉩㉪㉫㉬㉭㉮㉯㉰㉱㉲㉳㉴㉵㉶㉷㉸㉹㉺㉻㈀㈁㈂㈃㈄㈅㈆㈇㈈㈉㈊㈋㈌㈍㈎㈏㈐㈑㈒㈓㈔㈕㈖㈗㈘㈙㈚㈛"
yinbiao:
type: SINGLE
name: "音标"
keys: ["a:", "ɔ:", "ɜː", "i:", "u:", "ʌ", "ɒ", "ə", "ɪ", "ʊ", "e", "æ", "eɪ", "aɪ", "ɔɪ", "ɪə", "eə", "ʊə", "əʊ", "aʊ", "p", "t", "k", "f", "θ", "s", "b", "d", "g", "v", "ð", "z", "ʃ", "h", "ts", "tʃ", "j", "tr", "ʒ", "r", "dz", "dʒ", "dr", "w", "m", "n", "ŋ", "l"]
ascii:
type: SINGLE
name: 英文
keys: ",.?!:;/\\|*-+=^$`'\"^~@#%&()[]{}_"
ids:
type: SINGLE
keys: "⿰⿱⿲⿳⿴⿵⿶⿷⿸⿹⿺⿻"



android_keys:
name: [VoidSymbol, SOFT_LEFT, SOFT_RIGHT, HOME, BACK, CALL, ENDCALL,
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.osfans.trime.ime.SymbolKeyboard;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.flexbox.FlexboxLayoutManager;
import com.osfans.trime.R;
import com.osfans.trime.setup.Config;

import java.util.List;


public class ClipboardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context myContext;
private List<SimpleKeyBean> list;
private int keyMarginX, keyMarginTop;
private Integer textColor;
private float textSize;
private Typeface textFont;

public ClipboardAdapter(Context context, List<SimpleKeyBean> itemlist) {
myContext = context;
list = itemlist;
}

@Override
public int getItemCount() {
return list.size();
}

public void configStyle(int keyMarginX, int keyMarginTop) {
this.keyMarginX = keyMarginX;
this.keyMarginTop = keyMarginTop;

// 边框尺寸、圆角、字号直接读取主题通用参数。配色优先读取liquidKeyboard专用参数。
Config config = Config.get(myContext);
textColor = config.getLiquidColor("long_text_color");
if (textColor == null)
textColor = config.getLiquidColor("key_text_color");

textSize = config.getFloat("long_text_size");
if (textSize <= 0)
textSize = config.getFloat("label_text_size");

textFont = config.getFont("long_text_font");
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(myContext).inflate(R.layout.simple_key_item, parent, false);
return new ItemViewHolder(view);
}

static class ItemViewHolder extends RecyclerView.ViewHolder {
public ItemViewHolder(View view) {
super(view);

listItemLayout = view.findViewById(R.id.listitem_layout);
mTitle = view.findViewById(R.id.simple_key);
}

LinearLayout listItemLayout;
TextView mTitle;
}

@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int index) {

if (viewHolder instanceof ClipboardAdapter.ItemViewHolder) {
SimpleKeyBean searchHistoryBean = list.get(index);
final ClipboardAdapter.ItemViewHolder itemViewHold = ((ClipboardAdapter.ItemViewHolder) viewHolder);

if (textFont != null)
itemViewHold.mTitle.setTypeface(textFont);
itemViewHold.mTitle.setText(searchHistoryBean.getText());

if (textSize > 0)
itemViewHold.mTitle.setTextSize(textSize);

ViewGroup.LayoutParams lp = itemViewHold.listItemLayout.getLayoutParams();
if (lp instanceof FlexboxLayoutManager.LayoutParams) {
FlexboxLayoutManager.LayoutParams flexboxLp =
(FlexboxLayoutManager.LayoutParams) itemViewHold.listItemLayout.getLayoutParams();

itemViewHold.mTitle.setTextColor(textColor);

int marginTop = flexboxLp.getMarginTop();
int marginX = flexboxLp.getMarginLeft();
if (keyMarginTop > 0)
marginTop = keyMarginTop;
if (keyMarginX > 0)
marginX = keyMarginX;

flexboxLp.setMargins(
marginX, marginTop, marginX, flexboxLp.getMarginBottom()
);

// TODO 设置剪贴板列表样式
// copy SimpleAdapter会造成高度始终为3行无法自适应的效果。

}

//如果设置了回调,则设置点击事件
if (mOnItemClickLitener != null) {
itemViewHold.listItemLayout.setOnClickListener(view -> {
int position = itemViewHold.getLayoutPosition();
mOnItemClickLitener.onItemClick(itemViewHold.listItemLayout, position);
});
}

itemViewHold.listItemLayout.setOnLongClickListener(view -> {
int position = itemViewHold.getLayoutPosition();
// TODO 长按删除、编辑剪贴板
// 当文本较长时,目前样式只缩略显示为3行,长按时tosat消息可以预览全文,略有用处。
Toast.makeText(myContext, list.get(position).getText(), Toast.LENGTH_SHORT).show();
return true;
});

// TODO 剪贴板列表点击时产生背景变色效果
itemViewHold.listItemLayout.setOnTouchListener((view, motionEvent) -> {
int action = motionEvent.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:

case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:

break;
}
return false;
});

}
}

/*=====================添加OnItemClickListener回调================================*/
public interface OnItemClickLitener {
void onItemClick(View view, int position);
}

private ClipboardAdapter.OnItemClickLitener mOnItemClickLitener;

public void setOnItemClickLitener(ClipboardAdapter.OnItemClickLitener mOnItemClickLitener) {
this.mOnItemClickLitener = mOnItemClickLitener;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.osfans.trime.ime.SymbolKeyboard;

public class ClipboardBean extends SimpleKeyBean {
private long time;
private String text;
private String html;
private int type;

public long getTime() {
return time;
}

public String getHtml() {
return html;
}

public String getText() {
return text;
}

public int getType() {
return type;
}

public void setText(String text) {
this.text = text;
}

public void setTime(long time) {
this.time = time;
}

public void setType(int type) {
this.type = type;
}

public ClipboardBean(String text) {
this.text = text;
this.time = System.currentTimeMillis();
this.type = 0;
this.html = "";
}

public ClipboardBean(String text, String html) {
this.text = text;
this.time = System.currentTimeMillis();
this.type = 1;
this.html = html;
}

public ClipboardBean(String text, String html, int type, long time) {
this.text = text;
this.time = time;
this.type = type;
this.html = html;
}

}
Loading

0 comments on commit b39e356

Please sign in to comment.