Skip to content

Commit f53ffcd

Browse files
committed
perf(core): reorganize and improve Trime service
1 parent a887ed1 commit f53ffcd

File tree

13 files changed

+337
-288
lines changed

13 files changed

+337
-288
lines changed

app/src/main/java/com/osfans/trime/clipboard/ClipboardAdapter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int in
145145
}
146146
}
147147

148-
/** 添加 OnItemClickListener 回调 **/
148+
/** 添加 OnItemClickListener 回调 * */
149149
public interface OnItemClickListener {
150150
void onItemClick(View view, int position);
151151
}

app/src/main/java/com/osfans/trime/clipboard/ClipboardDao.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import android.database.Cursor;
44
import android.database.sqlite.SQLiteDatabase;
55
import android.database.sqlite.SQLiteOpenHelper;
6-
76
import androidx.annotation.NonNull;
8-
97
import com.osfans.trime.ime.core.Trime;
108
import com.osfans.trime.ime.symbol.SimpleKeyBean;
119
import java.util.ArrayList;
@@ -38,7 +36,7 @@ public void insert(@NonNull ClipboardBean clipboardBean) {
3836
db.close();
3937
}
4038

41-
/** 删除文字相同的剪贴板记录,插入新记录 **/
39+
/** 删除文字相同的剪贴板记录,插入新记录 * */
4240
public void add(@NonNull ClipboardBean clipboardBean) {
4341
helper = new ClipboardSqlHelper(Trime.getService(), "clipboard.db", null, 1);
4442
SQLiteDatabase db = helper.getWritableDatabase();

app/src/main/java/com/osfans/trime/clipboard/ClipboardSqlHelper.java

-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
import android.content.Context;
44
import android.database.sqlite.SQLiteDatabase;
55
import android.database.sqlite.SQLiteOpenHelper;
6-
76
import androidx.annotation.NonNull;
8-
97
import timber.log.Timber;
108

119
public class ClipboardSqlHelper extends SQLiteOpenHelper {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.osfans.trime.common
2+
3+
import android.view.View
4+
import android.view.Window
5+
import android.widget.FrameLayout
6+
import android.widget.LinearLayout
7+
8+
/** (This Kotlin file has been taken from florisboard project)
9+
* This file has been taken from the Android LatinIME project. Following modifications were done by
10+
* florisboard to the original source code:
11+
* - Convert the code from Java to Kotlin
12+
* - Change package name to match the current project's one
13+
* - Remove method newLayoutParam()
14+
* - Remove method placeViewAt()
15+
* - Remove unnecessary variable params in updateLayoutGravityOf(), lp can directly be used due to
16+
* Kotlin's smart cast feature
17+
* - Remove unused imports
18+
*
19+
* The original source code can be found at the following location:
20+
* https://android.googlesource.com/platform/packages/inputmethods/LatinIME/+/refs/heads/master/java/src/com/android/inputmethod/latin/utils/ViewLayoutUtils.java
21+
*/
22+
object ViewUtils {
23+
fun updateLayoutHeightOf(window: Window, layoutHeight: Int) {
24+
val params = window.attributes
25+
if (params != null && params.height != layoutHeight) {
26+
params.height = layoutHeight
27+
window.attributes = params
28+
}
29+
}
30+
31+
fun updateLayoutHeightOf(view: View, layoutHeight: Int) {
32+
val params = view.layoutParams
33+
if (params != null && params.height != layoutHeight) {
34+
params.height = layoutHeight
35+
view.layoutParams = params
36+
}
37+
}
38+
39+
fun updateLayoutGravityOf(view: View, layoutGravity: Int) {
40+
val lp = view.layoutParams
41+
if (lp is LinearLayout.LayoutParams) {
42+
if (lp.gravity != layoutGravity) {
43+
lp.gravity = layoutGravity
44+
view.layoutParams = lp
45+
}
46+
} else if (lp is FrameLayout.LayoutParams) {
47+
if (lp.gravity != layoutGravity) {
48+
lp.gravity = layoutGravity
49+
view.layoutParams = lp
50+
}
51+
} else {
52+
throw IllegalArgumentException(
53+
"Layout parameter doesn't have gravity: " +
54+
lp.javaClass.name
55+
)
56+
}
57+
}
58+
59+
fun getLocationOnScreen(view: View): IntArray {
60+
val outLocation: IntArray = intArrayOf(0, 0)
61+
view.getLocationOnScreen(outLocation)
62+
return outLocation
63+
}
64+
}

app/src/main/java/com/osfans/trime/ime/core/Preferences.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.preference.PreferenceManager
88
import com.blankj.utilcode.util.PathUtils
99
import com.osfans.trime.R
1010
import com.osfans.trime.ime.enums.InlineModeType
11+
import com.osfans.trime.ime.landscapeinput.LandscapeInputUIMode
1112
import java.lang.ref.WeakReference
1213

1314
/**
@@ -185,8 +186,8 @@ class Preferences(
185186
var inlinePreedit: InlineModeType
186187
get() = InlineModeType.fromString(prefs.getPref(INLINE_PREEDIT_MODE, "preview"))
187188
set(v) = prefs.setPref(INLINE_PREEDIT_MODE, v)
188-
var fullscreenMode: String
189-
get() = prefs.getPref(FULLSCREEN_MODE, "auto")
189+
var fullscreenMode: LandscapeInputUIMode
190+
get() = LandscapeInputUIMode.fromString(prefs.getPref(FULLSCREEN_MODE, "auto_show"))
190191
set(v) = prefs.setPref(FULLSCREEN_MODE, v)
191192
var softCursorEnabled: Boolean = false
192193
get() = prefs.getPref(SOFT_CURSOR_ENABLED, true)

0 commit comments

Comments
 (0)