Skip to content

Commit

Permalink
feat: add draft manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tumuyan authored and Bambooin committed Jan 11, 2022
1 parent 37dbe5d commit 9772300
Show file tree
Hide file tree
Showing 19 changed files with 571 additions and 52 deletions.
43 changes: 25 additions & 18 deletions app/src/main/assets/rime/tongwenfeng.trime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -858,20 +858,23 @@ liquid_keyboard:
single_width: 60 #single类型的按键宽度
vertical_gap: 8 #纵向按键间隙
margin_x: 2 #左右按键间隙的1/2
keyboards: [emoji, math, ascii, cn, clipboard, history, exit, list , table, symbol, ids , pinyin, jp, unit, exit, grease, rusa, korea, lation, yinbiao, exit] #tab列表
keyboards: [emoji, math, ascii, cn, history, clipboard, draft, list, exit, ids , jp, table, symbol, pinyin, grease, rusa, korea, lation, yinbiao, unit, exit] #tab列表
exit:
name: 返回
type: NO_KEY
keys: EXIT
history:
name: 常用
type: HISTORY
emoji:
type: SINGLE
keys: "🙂😂🤣😆🙃😅🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
keys: "🙂😂🤣😆🙃😅🥺🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
clipboard:
type: CLIPBOARD
name: 剪贴
history:
name: 最近
type: HISTORY
draft:
type: DRAFT
name: 草稿
math: #tab名称
type: SINGLE
name: 数学
Expand Down Expand Up @@ -910,6 +913,7 @@ liquid_keyboard:
-
symbol:
name: 特殊
type: SINGLE
keys: "△▽○◇□☆▲▼●◆■★▷◁▶◀♻♲†⚝✡⚹✦✸✹�×⌫☑☒✅❎✔✘✓✗☼☽♀☻◐㏂☀☾♂☹◑㏘☜☝☞☚☟☛▪•‥…∷※♩♪♫♬§°♭♯♮‖¶№◎¤۞℗®©卍卐℡™㏇Φ↖↑↗◤㊤◥←↔→㊧㊥㊨↙↓↘◣㊦◢⇄⇅⇆⇤↩⇥❏❐◲〼▢▣⇦⇧⇨⇩⇪↶▸◂▴▾✁↷✍⏍ϟ📝✎✆☱☰☴⚿⛮⚙☲☯☵⛶☩☐☳☷☶💬🗨⟲ღ✈☂🎤🌐🔍"
unit:
name: 单位
Expand Down Expand Up @@ -950,7 +954,7 @@ liquid_keyboard:
ids:
type: SINGLE
name: IDS
keys: "⿰⿱⿲⿳⿴⿵⿶⿷⿸⿹⿺⿻"
keys: "⿰⿱⿲⿳⿴⿵⿶⿷⿸⿹⿺⿻↷↔"
jp:
type: SINGLE
name: 假名
Expand Down Expand Up @@ -3906,28 +3910,31 @@ preset_keys:
CommitScriptText: {label: 编码, send: Shift+Return}
CommitComment: {label: 编码, send: Control+Shift+Return}
DeleteCandidate: {label: 删词, send: Control+Delete, functional: false}
#切换键盘
Keyboard_letter: { label: 字母, functional: true, send: Eisu_toggle, select: default }
Keyboard_default: { label: 返回, functional: false, send: Eisu_toggle, select: .default }
Keyboard_switch: { label: 键盘, functional: true, send: Eisu_toggle, select: .next }
Keyboard_number: { label: 123, functional: false, send: Eisu_toggle, select: number }
Keyboard_numberb: { label: 123, functional: false, send: Eisu_toggle, select: numberb }
Keyboard_symbols: { label: 更多, functional: false, send: Eisu_toggle, select: symbols }
Keyboard_move: { label: ❖, functional: true, send: Eisu_toggle, select: move }
Keyboard_next: { label: 后退, functional: false, send: Eisu_toggle, select: .next }
Keyboard_last: { label: 后退, functional: false, send: Eisu_toggle, select: .last }
Keyboard_last_lock: { label: 返回, send: Eisu_toggle, select: .last_lock } #直接切換到下一键盘
liquid_keyboard_switch: { label: 更多, send: function, command: liquid_keyboard, option: "特殊" }
liquid_keyboard_switch2: { toggle: _liquid_keyboard, send: Mode_switch, states: [ 更多, 更多 ] }
liquid_keyboard_emoji: { label: 🙂, send: function, command: liquid_keyboard, option: "emoji" }
liquid_keyboard_clipboard: { label: 剪贴, send: function, command: liquid_keyboard, option: "剪贴" }
# rime状态
Mode_switch: {toggle: ascii_mode, functional: false, send: Mode_switch, states: [ 中文, 西文 ]}
Zenkaku_Hankaku: {toggle: full_shape, send: Mode_switch, states: [ 半角, 全角 ]}
Henkan: {toggle: simplification, send: Mode_switch, states: [ 汉字, 汉字 ]}
Charset_switch: {toggle: extended_charset, send: Mode_switch, states: [ 常用, 增广 ]}
Punct_switch: {toggle: ascii_punct, send: Mode_switch, states: [ 。,, ., ]}
liquid_keyboard_switch: { toggle: _liquid_keyboard, send: Mode_switch, states: [ 更多, 更多 ] }
liquid_keyboard_clipboard: {label: 剪贴板, send: function, command: liquid_keyboard, option: "剪贴"}
# trime设置
IME_switch: {label: 🌐, send: LANGUAGE_SWITCH} #彈出對話框選擇輸入法
IME_last: {label: 上一输入法, send: LANGUAGE_SWITCH, select: .last} #直接切換到上一輸入法
IME_next: {label: 下一输入法, send: LANGUAGE_SWITCH, select: .next} #直接切換到下一輸入法
Keyboard_letter: {label: 字母, functional: true, send: Eisu_toggle, select: default}
Keyboard_default: {label: 返回, functional: false, send: Eisu_toggle, select: .default}
Keyboard_switch: {label: 键盘, functional: true, send: Eisu_toggle, select: .next}
Keyboard_number: {label: 123, functional: false, send: Eisu_toggle, select: number}
Keyboard_numberb: {label: 123, functional: false, send: Eisu_toggle, select: numberb}
Keyboard_symbols: {label: 更多, functional: false, send: Eisu_toggle, select: symbols}
Keyboard_move: {label: ❖, functional: true, send: Eisu_toggle, select: move}
Keyboard_next: {label: 后退, functional: false, send: Eisu_toggle, select: .next}
Keyboard_last: {label: 后退, functional: false, send: Eisu_toggle, select: .last}
Keyboard_last_lock: {label: 返回, send: Eisu_toggle, select: .last_lock} #直接切換到下一键盘
Schema_switch: {label: 下一方案, functional: false, send: Control+Shift+1}
Schema_Eng: {label: En, functional: true, send: Control+Shift+0}
Theme_settings: {label: 主题, send: SETTINGS, option: "theme"}
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/assets/rime/trime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -921,17 +921,21 @@ preset_keys:
Henkan: {toggle: simplification, send: Mode_switch, states: [ 漢字, 汉字 ]}
Charset_switch: {toggle: extended_charset, send: Mode_switch, states: [ 常用, 增廣 ]}
Punct_switch: {toggle: ascii_punct, send: Mode_switch, states: [ 。,, ., ]}
# trime設定
IME_switch: {label: 🌐, send: LANGUAGE_SWITCH} #彈出對話框選擇輸入法
IME_last: {label: 上一輸入法, send: LANGUAGE_SWITCH, select: .last} #直接切換到上一輸入法
IME_next: {label: 下一輸入法, send: LANGUAGE_SWITCH, select: .next} #直接切換到下一輸入法
#切换键盘
Keyboard_symbols: {label: 符號, send: Eisu_toggle, select: symbols}
Keyboard_number: {label: 數字, send: Eisu_toggle, select: number}
Keyboard_letter: {label: 字母, send: Eisu_toggle, select: default}
Keyboard_default: {label: 返回, send: Eisu_toggle, select: .default}
Keyboard_switch: {label: 鍵盤, send: Eisu_toggle, select: .next}
liquid_keyboard_switch: { label: 更多, send: function, command: liquid_keyboard, option: "特殊" }
liquid_keyboard_switch2: { toggle: _liquid_keyboard, send: Mode_switch, states: [ 更多, 更多 ] }
liquid_keyboard_emoji: { label: 🙂, send: function, command: liquid_keyboard, option: "emoji" }
liquid_keyboard_clipboard: { label: 剪贴, send: function, command: liquid_keyboard, option: "剪贴" }
# trime設定
IME_switch: { label: 🌐, send: LANGUAGE_SWITCH } #彈出對話框選擇輸入法
IME_last: { label: 上一輸入法, send: LANGUAGE_SWITCH, select: .last } #直接切換到上一輸入法
IME_next: { label: 下一輸入法, send: LANGUAGE_SWITCH, select: .next } #直接切換到下一輸入法
Schema_switch: {label: 下一方案, send: Control+Shift+1}
liquid_keyboard_switch: { toggle: _liquid_keyboard, send: Mode_switch, states: [ 更多, 更多 ] }
one_hand_switch_1: {toggle: _one_hand_mode_1, send: Mode_switch, states: [ 左手, 普通 ]}
one_hand_switch_2: {toggle: _one_hand_mode_2, send: Mode_switch, states: [ 右手, 普通 ]}
one_hand_switch_3: {toggle: _one_hand_mode_3, send: Mode_switch, states: [ 左手, 右手 ]}
Expand Down
18 changes: 10 additions & 8 deletions app/src/main/java/com/osfans/trime/clipboard/ClipboardAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ClipboardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
private Integer textColor;
private float textSize;
private Typeface textFont;
private Drawable background;
private Config config;

public ClipboardAdapter(Context context, List<SimpleKeyBean> itemlist) {
myContext = context;
Expand All @@ -43,17 +43,13 @@ public void configStyle(int keyMarginX, int keyMarginTop) {
this.keyMarginTop = keyMarginTop;

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

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

background =
config.getDrawable(
"long_text_back_color", "key_border", "key_long_text_border", "round_corner", null);

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

Expand Down Expand Up @@ -86,7 +82,10 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int in
((ClipboardAdapter.ItemViewHolder) viewHolder);

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

String text = searchHistoryBean.getText();
if (text.length() > 300) itemViewHold.mTitle.setText(text.substring(0, 300));
else itemViewHold.mTitle.setText(text);

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

Expand All @@ -109,8 +108,11 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int in

}

if (background != null) itemViewHold.listItemLayout.setBackground(background);
Drawable background =
config.getDrawable(
"long_text_back_color", "key_border", "key_long_text_border", "round_corner", null);

if (background != null) itemViewHold.listItemLayout.setBackground(background);
// 如果设置了回调,则设置点击事件
if (mOnItemClickListener != null) {
itemViewHold.listItemLayout.setOnClickListener(
Expand Down
168 changes: 168 additions & 0 deletions app/src/main/java/com/osfans/trime/draft/DraftAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package com.osfans.trime.draft;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
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 androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.blankj.utilcode.util.ToastUtils;
import com.google.android.flexbox.FlexboxLayoutManager;
import com.osfans.trime.R;
import com.osfans.trime.ime.symbol.SimpleKeyBean;
import com.osfans.trime.setup.Config;
import java.util.List;

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

public DraftAdapter(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("key_long_text_size");
if (textSize <= 0) textSize = config.getFloat("label_text_size");

background =
config.getDrawable(
"long_text_back_color", "key_border", "key_long_text_border", "round_corner", null);

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);
}

private 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 ItemViewHolder) {
SimpleKeyBean searchHistoryBean = list.get(index);
final ItemViewHolder itemViewHold = ((ItemViewHolder) viewHolder);

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

String text = searchHistoryBean.getText();
if (text.length() > 300) itemViewHold.mTitle.setText(text.substring(0, 300));
else itemViewHold.mTitle.setText(text);

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 (background != null)
itemViewHold.listItemLayout.setBackground(
Config.get(myContext)
.getDrawable(
"long_text_back_color",
"key_border",
"key_long_text_border",
"round_corner",
null));

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

itemViewHold.listItemLayout.setOnLongClickListener(
view -> {
int position = itemViewHold.getLayoutPosition();
// TODO 长按删除、编辑剪贴板
// 当文本较长时,目前样式只缩略显示为 3 行,长按时 toast 消息可以预览全文,略有用处。
ToastUtils.showShort(list.get(position).getText());
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 OnItemClickListener {
void onItemClick(View view, int position);
}

private OnItemClickListener mOnItemClickListener;

public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
this.mOnItemClickListener = mOnItemClickListener;
}
}
Loading

0 comments on commit 9772300

Please sign in to comment.