Skip to content

Commit

Permalink
增加功能及修复bug
Browse files Browse the repository at this point in the history
- [x]  增加.9图支持,解决画面拉伸问题(背景图需要以.9.png结尾)
- [x]  候选词背景图(皮肤增加参数 /style/candidate_background)
- [x]  增加开关:候选栏开关的提示是否显示箭头(有奇怪的bug,需要刷新主题或者切换方案之类的操作才会有效)入口在偏好设置-视图-在候选栏中显示状态时带箭头符号
- [x]  增加参数:横屏按键高度(这里没有生效),横屏键盘左右padding,竖屏全面屏抬起键盘的高度 对应参数均在/style/keyboard_padding_landscape,  /style/keyboard_padding_portrait
- [x]  候选词栏滑动到顶部、尾部的阻尼效果
- [x]  候选词滑动到尾部、顶部自动翻页
- [x]  修复翻页时候选词栏没有复位的bug
- [x]  候选与键盘使用一张完整的图(皮肤增加/style/root_background参数),候选栏与键盘原有背景图叠加在其上显示
- [x]  解决bilibili横屏无候选词的bug
- [x]  增加剪贴板API。在其他设置中,增加了剪贴板3个选项。当剪贴板内容发生变化时,自动发送剪贴板内容给指定的应用。选项“去重规则”和“过滤规则”每一行为一条正则表达式。每次通知剪贴板管理器,都会保存“去重规则”处理过的string。如果相邻两次剪贴内容,使用“去重规则”处理过后,内容不变,则不通知。如果内容与“过滤规则”匹配,则不通知指定App
  • Loading branch information
tumuyan committed Aug 1, 2021
1 parent 0a1fa57 commit ca40d18
Show file tree
Hide file tree
Showing 16 changed files with 764 additions and 47 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/com/osfans/trime/Composition.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,12 @@ public void reset(Context context) {
setMinHeight(config.getPixel("layout/min_height"));
setMaxWidth(config.getPixel("layout/max_width"));
setMaxHeight(config.getPixel("layout/max_height"));
int margin_x, margin_y;
int margin_x, margin_y, margin_bottom;
margin_x = config.getPixel("layout/margin_x");
margin_y = config.getPixel("layout/margin_y");
setPadding(margin_x, margin_y, margin_x, margin_y);
margin_bottom = config.getPixel("layout/margin_bottom",margin_y);
System.out.println("Composition setPadding=" + margin_x+", "+margin_y+", "+margin_bottom);
setPadding(margin_x, margin_y, margin_x, margin_bottom);
max_length = config.getInt("layout/max_length");
sticky_lines = config.getInt("layout/sticky_lines");
movable = config.getString("layout/movable");
Expand Down
109 changes: 109 additions & 0 deletions app/src/main/java/com/osfans/trime/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.NinePatch;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.NinePatchDrawable;
import android.os.SystemClock;
import android.util.TypedValue;

Expand Down Expand Up @@ -64,6 +68,8 @@ public class Config {
private Map<String, String> fallbackColors;
private Map presetColorSchemes, presetKeyboards;

private String[] ClipBoardCompare,ClipBoardOutput,ClipBoardManager;

public Config(Context context) {
self = this;
mPref = Function.getPref(context);
Expand All @@ -73,6 +79,54 @@ public Config(Context context) {
prepareRime(context);
deployTheme(context);
init();
prepareCLipBoardRule();
}

private void prepareCLipBoardRule(){
ClipBoardCompare = mPref.getString("pref_clipboard_compare", "").trim().split("\n");
ClipBoardOutput = mPref.getString("pref_clipboard_output", "").trim().split("\n");
ClipBoardManager = mPref.getString("pref_clipboard_manager", "").trim().split(",");
}

public String[] getClipBoardCompare(){ return ClipBoardCompare;}

public String[] getClipBoardOutput(){ return ClipBoardOutput;}

public String[] getClipBoardManager(){ return ClipBoardManager; }

public boolean hasClipBoardManager(){
if(ClipBoardManager.length==2){
if(ClipBoardManager[0].length()>0 && ClipBoardManager[1].length()>0)
return true;
}
return false;
}

public void setClipBoardManager(String str) {
SharedPreferences.Editor edit = mPref.edit();
edit.putString("pref_clipboard_manager", str);
edit.apply();
prepareCLipBoardRule();
}

public void setClipBoardCompare(String str) {
String s = str.replaceAll("\\s*\n\\s*","\n").trim();
ClipBoardCompare = s.split("\n");

SharedPreferences.Editor edit = mPref.edit();
edit.putString("pref_clipboard_compare", s);
edit.apply();

System.out.println("setClipBoardCompare "+s);
}

public void setClipBoardOutput(String str) {
String s = str.replaceAll("\\s*\n\\s*","\n").trim();
ClipBoardOutput = s.split("\n");

SharedPreferences.Editor edit = mPref.edit();
edit.putString("pref_clipboard_output", s);
edit.apply();
}

public String getTheme() {
Expand Down Expand Up @@ -257,6 +311,7 @@ private void init() {
presetColorSchemes = (Map<String, Object>) m.get("preset_color_schemes");
presetKeyboards = (Map<String, Object>) m.get("preset_keyboards");
Rime.setShowSwitches(getShowSwitches());
Rime.setShowSwitchArrow(getShowSwitchArrow());
reset();
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -283,19 +338,45 @@ private Object _getValue(String k1, String k2) {
return null;
}


private Object _getValue(String k1, String k2,Object defaultValue) {
Map<String, Object> m;
if (mStyle != null && mStyle.containsKey(k1)) {
m = (Map<String, Object>) mStyle.get(k1);
if (m != null && m.containsKey(k2)) return m.get(k2);
}
if (mDefaultStyle != null && mDefaultStyle.containsKey(k1)) {
m = (Map<String, Object>) mDefaultStyle.get(k1);
if (m != null && m.containsKey(k2)) return m.get(k2);
}
return defaultValue;
}

private Object _getValue(String k1) {
if (mStyle != null && mStyle.containsKey(k1)) return mStyle.get(k1);
if (mDefaultStyle != null && mDefaultStyle.containsKey(k1)) return mDefaultStyle.get(k1);
return null;
}

private Object _getValue(String k1,Object defaultValue) {
if (mStyle != null && mStyle.containsKey(k1)) return mStyle.get(k1);
return defaultValue;
}

public Object getValue(String s) {
String[] ss = s.split("/");
if (ss.length == 1) return _getValue(ss[0]);
else if (ss.length == 2) return _getValue(ss[0], ss[1]);
return null;
}

public Object getValue(String s,Object defaultValue) {
String[] ss = s.split("/");
if (ss.length == 1) return _getValue(ss[0],defaultValue);
else if (ss.length == 2) return _getValue(ss[0], ss[1],defaultValue);
return null;
}

public boolean hasKey(String s) {
return getValue(s) != null;
}
Expand Down Expand Up @@ -365,6 +446,14 @@ public int getPixel(String key) {
return getPixel(getFloat(key));
}


public int getPixel(String key,int defaultValue) {
float v = getFloat(key,Float.MAX_VALUE);
if(v==Float.MAX_VALUE)
return defaultValue;
return getPixel(v);
}

public static Integer getPixel(Map m, String k, Object s) {
Object o = getValue(m, k, s);
if (o == null) return null;
Expand Down Expand Up @@ -475,6 +564,12 @@ public float getFloat(String key) {
return Float.valueOf(o.toString());
}

public float getFloat(String key,float defaultValue) {
Object o = getValue(key,defaultValue);
if (o == null) return defaultValue;
return Float.valueOf(o.toString());
}

public int getInt(String key) {
Object o = getValue(key);
if (o == null) return 0;
Expand Down Expand Up @@ -579,6 +674,16 @@ private Drawable drawableObject(Object o) {
name = new File(nameDirectory, name).getPath();
File f = new File(name);
if (f.exists()) {
if(name.contains(".9.png")){
Bitmap bitmap= BitmapFactory.decodeFile(name);
byte[] chunk = bitmap.getNinePatchChunk();
// 如果.9.png没有经过第一步,那么chunk就是null, 只能按照普通方式加载
if(NinePatch.isNinePatchChunk(chunk)) {
return new NinePatchDrawable(bitmap, chunk, new Rect(), null);
}else{
System.out.println("drawableObject() chunk null, file="+name);
}
}
return new BitmapDrawable(BitmapFactory.decodeFile(name));
}
}
Expand Down Expand Up @@ -645,6 +750,10 @@ private boolean getShowSwitches() {
return mPref.getBoolean("show_switches", true);
}

private boolean getShowSwitchArrow(){
return mPref.getBoolean("show_switche_arrow", true);
}

public boolean getShowPreview() {
return mPref.getBoolean("show_preview", false);
}
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/com/osfans/trime/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.osfans.trime;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
Expand Down Expand Up @@ -80,24 +81,35 @@ public class Keyboard {

private boolean mLock; //切換程序時記憶鍵盤
private String mAsciiKeyboard; //英文鍵盤
private boolean land=false; //橫屏模式下,键盘左右两侧到屏幕边缘的距离

/**
* Creates a keyboard from the given xml key layout file.
*
* @param context the application or service context
*/
public Keyboard(Context context) {

land = ( context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) ;

Config config = Config.get(context);

DisplayMetrics dm = context.getResources().getDisplayMetrics();
mDisplayWidth = dm.widthPixels;
if(land)
mDisplayWidth = mDisplayWidth - config.getPixel("keyboard_padding_landscape")*2;
/* Height of the screen */
int mDisplayHeight = dm.heightPixels;
//Log.v(TAG, "keyboard's display metrics:" + dm);

Config config = Config.get(context);
mDefaultHorizontalGap = config.getPixel("horizontal_gap");
mDefaultVerticalGap = config.getPixel("vertical_gap");
mDefaultWidth = (int) (mDisplayWidth * config.getDouble("key_width") / 100);

mDefaultHeight = config.getPixel("key_height");
if(land)
mDefaultHeight = config.getPixel("key_height_land",mDefaultHeight);

mProximityThreshold = (int) (mDefaultWidth * SEARCH_DISTANCE);
mProximityThreshold = mProximityThreshold * mProximityThreshold; // Square it for comparison
mRoundCorner = config.getFloat("round_corner");
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/osfans/trime/KeyboardSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public void init(int displayWidth) {
reset(context);
}

private boolean land;
public void init(int displayWidth,boolean isLand) {
if ((currentId >= 0) && (displayWidth == currentDisplayWidth)) {
return;
}
land = isLand;
currentDisplayWidth = displayWidth;
reset(context);
}

public Keyboard getCurrentKeyboard() {
return mKeyboards[currentId];
}
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/com/osfans/trime/Rime.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ public RimeCandidate[] getCandidates() {
Integer value = (Integer) o.get("value");
if (value == null) value = 0;
candidates[i].text = states.get(value).toString();
candidates[i].comment =
o.containsKey("options") ? "" : kRightArrow + states.get(1 - value).toString();

if (showSwitchArrow)
candidates[i].comment = o.containsKey("options") ? "" : kRightArrow + states.get(1 - value).toString();
else
candidates[i].comment = o.containsKey("options") ? "" : states.get(1 - value).toString();
i++;
}
return candidates;
Expand Down Expand Up @@ -226,11 +229,16 @@ public void toggleOption(int i) {
public static int META_ALT_ON = get_modifier_by_name("Alt");
public static int META_RELEASE_ON = get_modifier_by_name("Release");
private static boolean showSwitches = true;
private static boolean showSwitchArrow = false;

public static void setShowSwitches(boolean show) {
showSwitches = show;
}

public static void setShowSwitchArrow(boolean show){
showSwitchArrow = show;
}

public static boolean hasMenu() {
return isComposing() && mContext.menu.num_candidates != 0;
}
Expand Down
Loading

0 comments on commit ca40d18

Please sign in to comment.