Skip to content

Commit

Permalink
Merge pull request #11 from mokapsing/save-user-dict
Browse files Browse the repository at this point in the history
feat&fix: sync changes from tumuyan
  • Loading branch information
mokapsing authored Sep 1, 2023
2 parents 4085aee + 36840b0 commit 46c6b37
Show file tree
Hide file tree
Showing 26 changed files with 898 additions and 33 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
android:launchMode="singleTask"
android:parentActivityName=".settings.PrefMainActivity" />

<activity
android:name=".ui.main.LiquidKeyboardActivity"
android:parentActivityName=".ui.main.PrefMainActivity"
/>
<!-- Using an activity alias to disable/enable the app icon in the launcher -->
<activity-alias
android:name="com.osfans.trime.PrefLauncherAlias"
Expand Down
25 changes: 20 additions & 5 deletions app/src/main/assets/rime/trime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ style:
- {start: "", move: 'ㄓ ', end: ""}
- {start: "", composition: "%s", end: "", letter_spacing: 0} #letter_spacing需要>=Android5.0。TODO: 不爲0時,會導致不換行的問題
- {start: "\n", label: "%s.", candidate: "%s", comment: " %s", end: "", sep: " "}
liquid_keyboard_window: #液态键盘模式下显示的悬浮窗口組件
- {start: "", click: "space", label: " 空格 "}
- {start: "", click: "BackSpace", label: " 删除 "}
- {start: "", click: "Return", label: " 回车 "}
- {start: "", click: "liquid_keyboard_exit", label: " 返回 "}
key_font: symbol.ttf #鍵盤字型
key_height: 44 #鍵高
key_long_text_size: 14 #長標籤字號
Expand Down Expand Up @@ -693,7 +698,7 @@ liquid_keyboard:
single_width: 60 #single类型的按键宽度
vertical_gap: 1 #纵向按键间隙
margin_x: 0.5 #左右按键间隙的1/2
keyboards: [emoji, math, ascii, cn, history, clipboard, draft, tabs, exit, candidate, list, ids , table, symbol, unit, new, jp, pinyin, grease, rusa, korea, lation, yinbiao, exit] #tab列表
keyboards: [emoji, math, ascii, cn, history, clipboard, draft, collection, tabs, exit, candidate, list, ids , table, symbol, unit, new, jp, pinyin, grease, rusa, korea, lation, yinbiao, yanwenzi, symbollist, exit] #tab列表
exit:
name: 返回
type: NO_KEY
Expand All @@ -712,10 +717,13 @@ liquid_keyboard:
type: HISTORY
emoji:
type: SINGLE
keys: "🙂😂🤣😆🙃😅🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
keys: "🙂😂🤣😆🙃😅🥺🙈🙉🙊☹😑😄🤐😨😱🌚🌝🤔❤💔🌹💣👌👍😣😥😮🙄😏😕😯😪😫😴😌🤑😉😋😎😍😘😚😛😜😝😒😓😔😲😷🤒😇🤓🤗🤕🙁😖😞😟😤😢😭😦😧😨😩😬😰😳😵😡😠☝✌🖕👎🙏🤘👏💪💋☘🍀🌸☕🍵🍺🍻🍦🍬🍚🍜🍲🍖🎂💤"
clipboard:
type: CLIPBOARD
name: 剪贴
collection:
type: COLLECTION
name: 收藏
draft:
type: DRAFT
name: 草稿
Expand Down Expand Up @@ -792,6 +800,10 @@ liquid_keyboard:
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"]
yanwenzi:
type: VAR_LENGTH
name: "颜文字"
keys: ["⎛⎝≥⏝⏝≤⎠⎞", "^_^", "^ω^", "^o^", "~\\(≧▽≦)/~", "*^_^*", "↖(^ω^)↗", "(^o^)/", "(=^▽^=)", "=^_^=", "(*^ω^*)", "٩(๑^o^๑)۶", "o( ̄▽ ̄)o", "Y(^_^)Y", "٩( 'ω' )و", "╰(*´︶`*)╯", "*罒▽罒*", "ヾ ^_^♪", "= ̄ω ̄=", "︿( ̄︶ ̄)︿", "(´▽`)ノ♪", "乁( ˙ ω˙乁)", "✧*。٩(ˊωˋ*)و✧*。", "~( ̄▽ ̄~)(~ ̄▽ ̄)~", "QwQ", "(●—●)", "(๑• . •๑)", "ヾ(≧O≦)〃嗷~", "罒ω罒", "(。ì _ í。)", "(๑•ี_เ•ี๑)", "ㄟ(≧◇≦)ㄏ", "(*/ω\*)", "●▽●", "٩(๑òωó๑)۶", "✺◟(∗❛ัᴗ❛ั∗)◞✺", "( σ'ω')σ", "♡^▽^♡", "(๑•̀ㅂ•́)و✧", "(ง •̀_•́)ง", "(。・ω・。)ノ♡", "(☆_☆)", "(๑°3°๑)", "_(•̀ω•́ 」∠)_", "♪~(´ε` )", "~(^з^)-☆", "(´∀`)♡", "ლ(´ڡ`ლ)", "(>﹏<)", "T_T", "⊙︿⊙", "〒▽〒", "⊙﹏⊙", "π_π", "(。•́︿•̀。)", "(ToT)/~~~", "╯﹏╰", "ಥ_ಥ", "(╥╯^╰╥)", "(〃′o`)", "●﹏●", "( •̥́ ˍ •̀ू )", "(つд⊂)", "心塞(´-ωก`)", "(╥﹏╥)", "┭┮﹏┭┮", "(;´д`)ゞ", "(´;︵;`)", "(。﹏。)", "┗( T﹏T )┛", "QAQ", "ヘ(_ _ヘ)", "╰(‵□′)╯", "(* ̄︿ ̄)", ">o<", "(-`ェ´-怒)", "ヽ(‘⌒´メ)ノ", "(*`Ω´*)v", "(。•ˇ‸ˇ•。)", "(怒`Д´怒)", "٩(๑`^´๑)۶", "(;`O´)o", "╰_╯", "(#`皿´)<怒怒怒!!!", "<(`^´)>", "(`Δ´)!", "ψ(`∇´)ψ", "(;′⌒`)", "s(・`ヘ´・;)ゞ", "(▼皿▼#)", " ̄へ ̄", "←_←", "(╯‵□′)╯︵┴─┴", "(▼へ▼メ)", "☄ฺ(◣д◢)☄ฺ", "→_→", "⊙_⊙", "d(ŐдŐ๑)", "Σ( ° △ °|||)︴", "(((φ(◎ロ◎;)φ)))", "⊙▽⊙", "(๑ŐдŐ)b", "╭(°A°`)╮", "(๑òᆺó๑)", "⊙ω⊙", "Σ(っ °Д °;)っ", " (゚Д゚≡゚д゚)!?", "( *・ω・)✄╰ひ╯", "(⊙x⊙;)", "┌(。Д。)┐", "(°ー°〃)", "︽⊙_⊙︽", "!!!∑(°Д°ノ)ノ", "(๑ŐдŐ)b☆d(ŐдŐ๑)", "Σ⊙▃⊙川", "ヽ(*。>Д<)o゜", "━((*′д`)爻(′д`*))━!!!!", "=_=", "╮(╯_╰)╭", "(︶︿︶)", "_(:з」∠)_", "@_@", "╮(╯▽╰)╭", "(@ ̄ー ̄@)", "_(:3」∠❀)_", "눈_눈", "╭(╯ε╰)╮", "(ー_ー)!!", "_(:D)∠)_", "o_O", "╭(╯^╰)╮", "(;一_一)", "´_>`", "-_-#", "┑( ̄Д  ̄)┍", "≡ ̄﹏ ̄≡", "○| ̄|_", "-_-||", "ㄟ( ▔, ▔ )ㄏ", "( _ _)ノ|壁", "▄█▀█●"]
ascii:
type: SINGLE
name: 英文
Expand All @@ -804,7 +816,10 @@ liquid_keyboard:
type: SINGLE
name: 假名
keys: "あいうえおかがきぎくぐけげこごさざしじすずせぜそぞただちぢつづてでとどなにぬねのはばぱひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろわをんアィイウェエオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロワヲン"

symbollist:
type: SYMBOL
name: 符号表
keys: [ 符号: '/fh', 电脑: '/dn', 象棋: '/xq', 麻将: '/mj', 骰子: '/sz', 扑克: '/pk', 天气: '/tq', 音乐: '/yy', 八卦: '/bg', 易经: '/lssg', 天体: '/tt', 星座: '/xz', 星号: '/xh', 方块: '/fk', 几何: '/jh', 箭头: '/jt', 数学: '/sx', 上标: '/sb', 下标: '/xb', 单位: '/dw', 货币: '/hb', 拼音: '/py', 注音: '/zy', 假名: '/jm', 片假: '/pjm', 韩文: '/hw', 希腊: '/xl', 希大: '/xld', 罗马: '/lm', 罗大: '/lmd', 俄语: '/ey', 俄大: '/eyd', 表情: '/bq', 一: '/1', 二: '/2', 三: '/3', 四: '/4', 五: '/5', 六: '/6', 七: '/7', 八: '/8', 九: '/9', 零: '/0', 十: '/10', 分数: '/fs', 标点: '/bd', 偏旁: '/pp', 竖标: '/bdz' ]


android_keys:
Expand Down Expand Up @@ -910,8 +925,8 @@ preset_keys:
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_switch: { label: 更多, send: function, command: liquid_keyboard, option: "符号表" }
liquid_keyboard_exit: {label: 返回, send: function, command: liquid_keyboard, option: "-1"} #退出liquidkeyboard
liquid_keyboard_emoji: { label: 🙂, send: function, command: liquid_keyboard, option: "emoji" }
liquid_keyboard_clipboard: { label: 剪贴, send: function, command: liquid_keyboard, option: "剪贴" }
# trime設定
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/com/osfans/trime/core/Rime.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.osfans.trime.data.DataManager;
import com.osfans.trime.data.opencc.OpenCCDictManager;
import com.osfans.trime.ime.core.Trime;
import com.osfans.trime.ime.symbol.SimpleKeyBean;
import java.io.BufferedReader;
import java.io.CharArrayWriter;
import java.io.File;
Expand All @@ -46,6 +47,8 @@
* href="https://github.com/BYVoid/OpenCC">OpenCC</a>
*/
public class Rime {
private static Map<String, Object> mSymbols;

/** Rime編碼區 */
public static class RimeComposition {
int length;
Expand Down Expand Up @@ -145,6 +148,7 @@ public static class RimeSchema {

Map<String, Object> schema = new HashMap<String, Object>();
List<Map<String, Object>> switches = new ArrayList<Map<String, Object>>();
Map<String, Object> symbolMap = new HashMap<>();

public RimeSchema(String schema_id) {
Timber.d("RimeSchema() start");
Expand All @@ -161,6 +165,14 @@ public RimeSchema(String schema_id) {
o = schema_get_value(schema_id, "menu");
if (o == null || !(o instanceof HashMap)) return;
Timber.d("RimeSchema() menu.page_size=" + ((Map<Object, Object>) o).get("page_size"));

// todo 取回的key正常,value为null,导致symbolMap无法正常使用
o = schema_get_value(schema_id, "punctuator/symbols");
if (o != null && o instanceof HashMap) {
symbolMap = (Map<String, Object>) o;
} else {
symbolMap = new HashMap<>();
}
}

public void check() {
Expand Down Expand Up @@ -328,6 +340,26 @@ private static void initSchema() {
Timber.d("initSchema() getStatus");
getStatus();
Timber.d("initSchema() done");
mSymbols = mSchema.symbolMap;
}

public static boolean hasSymbols(String key) {
return (mSymbols.containsKey(key));
}

public static List<String> getSymbols(String key) {
if (mSymbols.containsKey(key)) {
return (List<String>) mSymbols.get(key);
}
return new ArrayList<String>();
}

public static List<SimpleKeyBean> getSymbolKeyBeans() {
List<SimpleKeyBean> list = new ArrayList<>();
for (Map.Entry m : mSymbols.entrySet()) {
list.add(new SimpleKeyBean(m.getKey().toString()));
}
return list;
}

@SuppressWarnings("UnusedReturnValue")
Expand Down Expand Up @@ -691,6 +723,12 @@ public static boolean syncUserData(Context context) {
return b;
}

public static boolean saveUserData(Context context) {
destroy();
get(context, true);
return true;
}

// init
public static native void setup(String shared_data_dir, String user_data_dir);

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/osfans/trime/data/AppPrefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ class AppPrefs(
const val CLIPBOARD_COMPARE_RULES = "other__clipboard_compare"
const val CLIPBOARD_OUTPUT_RULES = "other__clipboard_output"
const val DRAFT_OUTPUT_RULES = "other__draft_output"
const val DRAFT_EXCLUDE_APP = "other__draft_exclude_app"
const val DRAFT_LIMIT = "other__draft_limit"
const val CLIPBOARD_LIMIT = "other__clipboard_limit"
}
Expand Down Expand Up @@ -416,5 +417,8 @@ class AppPrefs(
var draftLimit: String
get() = prefs.getPref(DRAFT_LIMIT, "20")
set(v) = prefs.setPref(DRAFT_LIMIT, v)
var draftExcludeApp: String
get() = prefs.getPref(DRAFT_EXCLUDE_APP, "")
set(v) = prefs.setPref(DRAFT_EXCLUDE_APP, v)
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/data/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private void init(boolean skip_delopy) {
Timber.d("init() finins");
} catch (Exception e) {
e.printStackTrace();
setTheme(defaultName);
if (!themeName.equals(defaultName)) setTheme(defaultName);
}
}

Expand Down
92 changes: 92 additions & 0 deletions app/src/main/java/com/osfans/trime/data/db/CollectionDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.osfans.trime.data.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import androidx.annotation.NonNull;
import com.osfans.trime.ime.core.Trime;
import com.osfans.trime.ime.symbol.SimpleKeyBean;
import java.util.ArrayList;
import java.util.List;
import timber.log.Timber;

public class CollectionDao {

private DbHelper helper;
private static CollectionDao self;
private static String DB_NAME = "collection.db";

public static CollectionDao get() {
if (null == self) self = new CollectionDao();
return self;
}

public CollectionDao() {}

/** 插入新记录 * */
public void insert(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
new Object[] {
clipboardBean.getText(),
clipboardBean.getHtml(),
clipboardBean.getType(),
clipboardBean.getTime()
});
db.close();
}

/** 删除文字相同的剪贴板记录,插入新记录 * */
public void add(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {clipboardBean.getText()});
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
new Object[] {
clipboardBean.getText(),
clipboardBean.getHtml(),
clipboardBean.getType(),
clipboardBean.getTime()
});
db.close();
}

/** 删除记录 * */
public void delete(@NonNull String str) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {str});
db.close();
}

public void delete(@NonNull List<SimpleKeyBean> list) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
for (SimpleKeyBean bean : list) db.delete("t_data", "text=?", new String[] {bean.getText()});
db.close();
}

public List<SimpleKeyBean> getAllSimpleBean() {

List<SimpleKeyBean> list = new ArrayList<>();

String sql = "select text , html , type , time from t_data ORDER BY time DESC";

helper = new DbHelper(Trime.getService(), DB_NAME);

SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
if (cursor != null) {
while (cursor.moveToNext()) {
DbBean v = new DbBean(cursor.getString(0));
list.add(v);
}
cursor.close();
}
db.close();
Timber.d("getAllSimpleBean() size=%s", list.size());
return list;
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/osfans/trime/data/db/DbBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class DbBean extends SimpleKeyBean {
private long time;
private String text;
private final String html;
private int type;
private int type; // 0 text, 1 html

public long getTime() {
return time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class ClipboardDao {

private DbHelper helper;
private static ClipboardDao self;
private static String DB_NAME = "clipboard.db";

public static ClipboardDao get() {
if (null == self) self = new ClipboardDao();
Expand All @@ -25,7 +26,7 @@ public ClipboardDao() {}

/** 插入新记录 * */
public void insert(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.execSQL(
"insert into t_data(text,html,type,time) values(?,?,?,?)",
Expand All @@ -40,7 +41,7 @@ public void insert(@NonNull DbBean clipboardBean) {

/** 删除文字相同的剪贴板记录,插入新记录 * */
public void add(@NonNull DbBean clipboardBean) {
helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {clipboardBean.getText()});
db.execSQL(
Expand All @@ -56,12 +57,19 @@ public void add(@NonNull DbBean clipboardBean) {

/** 删除记录 * */
public void delete(@NonNull String str) {
helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
db.delete("t_data", "text=?", new String[] {str});
db.close();
}

public void delete(@NonNull List<SimpleKeyBean> list) {
helper = new DbHelper(Trime.getService(), DB_NAME);
SQLiteDatabase db = helper.getWritableDatabase();
for (SimpleKeyBean bean : list) db.delete("t_data", "text=?", new String[] {bean.getText()});
db.close();
}

public List<SimpleKeyBean> getAllSimpleBean(int size) {

List<SimpleKeyBean> list = new ArrayList<>();
Expand All @@ -70,7 +78,7 @@ public List<SimpleKeyBean> getAllSimpleBean(int size) {
String sql = "select text , html , type , time from t_data ORDER BY time DESC";
if (size > 0) sql = sql + " limit 0," + size;

helper = new DbHelper(Trime.getService(), "clipboard.db");
helper = new DbHelper(Trime.getService(), DB_NAME);

SQLiteDatabase db = helper.getWritableDatabase();
Cursor cursor = db.rawQuery(sql, null);
Expand Down
Loading

0 comments on commit 46c6b37

Please sign in to comment.