Skip to content

Commit 0de8f23

Browse files
WhiredPlanckBambooin
authored andcommitted
refactor: apply spotless to unify style
1 parent 5200a7e commit 0de8f23

13 files changed

+79
-91
lines changed

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

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import android.view.inputmethod.InputConnection
1010
import com.osfans.trime.Rime
1111
import com.osfans.trime.ime.enums.InlineModeType
1212
import com.osfans.trime.ime.text.TextInputManager
13-
import timber.log.Timber
1413

1514
class EditorInstance(private val ims: InputMethodService) {
1615

app/src/main/java/com/osfans/trime/ime/core/Speech.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import android.speech.RecognizerIntent;
2626
import android.speech.SpeechRecognizer;
2727
import androidx.annotation.NonNull;
28-
import androidx.annotation.Nullable;
2928
import androidx.annotation.StringRes;
3029
import com.blankj.utilcode.util.ToastUtils;
3130
import com.osfans.trime.R;
@@ -106,20 +105,22 @@ public void onResults(Bundle results) {
106105
speechRecognizer.destroy();
107106
}
108107
Timber.i("onResults");
109-
@Nullable Trime trime = Trime.getService();
110-
if (trime == null) return;
111-
final ArrayList<String> matches =
112-
results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
113-
final String openccConfig = Config.get(context).getString("speech_opencc_config");
114-
for (String result : matches) trime.commitText(Rime.openccConvert(result, openccConfig));
108+
final Trime trime = Trime.getServiceOrNull();
109+
if (trime != null) {
110+
final ArrayList<String> matches =
111+
results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
112+
final String openccConfig = Config.get(context).getString("speech_opencc_config");
113+
for (String result : matches) trime.commitText(Rime.openccConvert(result, openccConfig));
114+
}
115115
}
116116

117117
@Override
118118
public void onRmsChanged(float rmsdB) {
119119
Timber.i("onRmsChanged: %s", rmsdB);
120120
}
121121

122-
private static @StringRes int getErrorText(int errorCode) {
122+
@StringRes
123+
private static int getErrorText(int errorCode) {
123124
final int message;
124125
switch (errorCode) {
125126
case SpeechRecognizer.ERROR_AUDIO:

app/src/main/java/com/osfans/trime/ime/core/Trime.java

+29-42
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ public static Trime getServiceOrNull() {
227227
}
228228

229229
private static final Handler syncBackgroundHandler =
230-
new Handler(
231-
msg -> {
232-
if (!((Trime) msg.obj).isShowInputRequested()) { // 若当前没有输入面板,则后台同步。防止面板关闭后5秒内再次打开
233-
ShortcutUtils.INSTANCE.syncInBackground((Trime) msg.obj);
234-
((Trime) msg.obj).loadConfig();
235-
}
236-
return false;
237-
});
230+
new Handler(
231+
msg -> {
232+
if (!((Trime) msg.obj).isShowInputRequested()) { // 若当前没有输入面板,则后台同步。防止面板关闭后5秒内再次打开
233+
ShortcutUtils.INSTANCE.syncInBackground((Trime) msg.obj);
234+
((Trime) msg.obj).loadConfig();
235+
}
236+
return false;
237+
});
238238

239239
public Trime() {
240240
try {
@@ -258,7 +258,7 @@ public void onWindowShown() {
258258

259259
updateComposing();
260260

261-
for (EventListener listener : (List<EventListener>) eventListeners) {
261+
for (EventListener listener : eventListeners) {
262262
if (listener != null) listener.onWindowShown();
263263
}
264264
}
@@ -280,7 +280,7 @@ public void onWindowHidden() {
280280
syncBackgroundHandler.sendMessageDelayed(msg, 5000); // 输入面板隐藏5秒后,开始后台同步
281281
}
282282

283-
for (EventListener listener : (List<EventListener>) eventListeners) {
283+
for (EventListener listener : eventListeners) {
284284
if (listener != null) listener.onWindowHidden();
285285
}
286286
}
@@ -380,7 +380,7 @@ public void selectLiquidKeyboard(final int tabIndex) {
380380
liquidKeyboard.calcPadding(mainInputView.getWidth());
381381
liquidKeyboard.select(tabIndex);
382382

383-
tabView.updateCandidateWidth();
383+
tabView.updateTabWidth();
384384
if (inputRootBinding != null) {
385385
mTabRoot.setBackground(mCandidateRoot.getBackground());
386386
mTabRoot.move(tabView.getHightlightLeft(), tabView.getHightlightRight());
@@ -408,6 +408,7 @@ private void hideCompositionView() {
408408
if (isPopupWindowMovable.equals("once")) {
409409
popupWindowPos = getImeConfig().getWinPos();
410410
}
411+
411412
if (mPopupWindow != null && mPopupWindow.isShowing()) {
412413
mPopupWindow.dismiss();
413414
mPopupHandler.removeCallbacks(mPopupTimer);
@@ -420,13 +421,13 @@ private void showCompositionView() {
420421
return;
421422
}
422423
compositionRootBinding.compositionRoot.measure(
423-
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
424+
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
424425
mPopupWindow.setWidth(compositionRootBinding.compositionRoot.getMeasuredWidth());
425426
mPopupWindow.setHeight(compositionRootBinding.compositionRoot.getMeasuredHeight());
426427
mPopupHandler.post(mPopupTimer);
427428
}
428429

429-
private void loadBackground() {
430+
public void loadBackground() {
430431
final Config mConfig = getImeConfig();
431432
final int orientation = getResources().getConfiguration().orientation;
432433

@@ -533,7 +534,7 @@ public void onDestroy() {
533534
getImeConfig().destroy();
534535
System.exit(0); // 清理內存
535536
}
536-
for (EventListener listener : (List<EventListener>) eventListeners) {
537+
for (EventListener listener : eventListeners) {
537538
if (listener != null) listener.onDestroy();
538539
}
539540
eventListeners.clear();
@@ -603,7 +604,7 @@ public void onUpdateSelection(
603604
performEscape();
604605
}
605606
// Update the caps-lock status for the current cursor position.
606-
updateCursorCapsToInputView();
607+
dispatchCapsStateToInputView();
607608
}
608609

609610
@Override
@@ -648,15 +649,15 @@ public View onCreateInputView() {
648649
return inputRootBinding.inputRoot;
649650
}
650651

651-
void setShowComment(boolean show_comment) {
652+
public void setShowComment(boolean show_comment) {
652653
// if (mCandidateRoot != null) mCandidate.setShowComment(show_comment);
653654
mComposition.setShowComment(show_comment);
654655
}
655656

656657
@Override
657658
public void onStartInputView(EditorInfo attribute, boolean restarting) {
658659
super.onStartInputView(attribute, restarting);
659-
for (EventListener listener : (List<EventListener>) eventListeners) {
660+
for (EventListener listener : eventListeners) {
660661
if (listener != null) listener.onStartInputView(activeEditorInstance, restarting);
661662
}
662663
if (getPrefs().getOther().getShowStatusBarIcon()) {
@@ -685,24 +686,18 @@ public void bindKeyboardToInputView() {
685686
// Bind the selected keyboard to the input view.
686687
Keyboard sk = keyboardSwitcher.getCurrentKeyboard();
687688
mainKeyboardView.setKeyboard(sk);
688-
updateCursorCapsToInputView();
689+
dispatchCapsStateToInputView();
689690
}
690691
}
691692

692-
// 句首自動大小寫
693-
private void updateCursorCapsToInputView() {
694-
if (autoCaps.contentEquals("false") || TextUtils.isEmpty(autoCaps)) return;
695-
if ((autoCaps.contentEquals("true") || Rime.isAsciiMode())
693+
/**
694+
* Dispatches cursor caps info to input view in order to implement auto caps lock at the start of
695+
* a sentence.
696+
*/
697+
private void dispatchCapsStateToInputView() {
698+
if ((isAutoCaps || Rime.isAsciiMode())
696699
&& (mainKeyboardView != null && !mainKeyboardView.isCapsOn())) {
697-
final InputConnection ic = getCurrentInputConnection();
698-
if (ic != null) {
699-
int caps = 0;
700-
final EditorInfo ei = getCurrentInputEditorInfo();
701-
if ((ei != null) && (ei.inputType != EditorInfo.TYPE_NULL)) {
702-
caps = ic.getCursorCapsMode(ei.inputType);
703-
}
704-
mainKeyboardView.setShifted(false, caps != 0);
705-
}
700+
mainKeyboardView.setShifted(false, activeEditorInstance.getCursorCapsMode() != 0);
706701
}
707702
}
708703

@@ -714,14 +709,6 @@ public void commitText(String text) {
714709
activeEditorInstance.commitText(text, true);
715710
}
716711

717-
public void keyPressVibrate() {
718-
if (inputFeedbackManager != null) inputFeedbackManager.keyPressVibrate();
719-
}
720-
721-
public void keyPressSound() {
722-
if (inputFeedbackManager != null) inputFeedbackManager.keyPressSound(0);
723-
}
724-
725712
/**
726713
* 如果爲{@link KeyEvent#KEYCODE_BACK Back鍵},則隱藏鍵盤
727714
*
@@ -739,7 +726,7 @@ private boolean handleBack(int keyCode) {
739726
public boolean onRimeKey(int[] event) {
740727
updateRimeOption();
741728
final boolean ret = Rime.onKey(event);
742-
activeEditorInstance.commitTextFromRime();
729+
activeEditorInstance.commitRimeText();
743730
return ret;
744731
}
745732

@@ -904,10 +891,10 @@ public void updateComposing() {
904891
activeEditorInstance.updateComposingText();
905892
if (ic != null && !isWinFixed()) isCursorUpdated = ic.requestCursorUpdates(1);
906893
if (mCandidateRoot != null) {
907-
if (isPopupWindowShown) {
894+
if (isPopupWindowEnabled) {
908895
final int startNum = mComposition.setWindow(minPopupSize, minPopupCheckSize);
909896
mCandidate.setText(startNum);
910-
if (isWinFixed() || !isCursorUpdated) showCompositionView();
897+
if (!isCursorUpdated) showCompositionView();
911898
} else {
912899
mCandidate.setText(0);
913900
}

app/src/main/java/com/osfans/trime/ime/symbol/TabTag.java

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// 为了公用候选栏的皮肤参数以及外观,保持了和普通键盘布局相似的代码。此类相当于原键盘布局的Rime.RimeCandidate
55

66
import android.graphics.Rect;
7-
87
import com.osfans.trime.ime.enums.KeyCommandType;
98
import com.osfans.trime.ime.enums.SymbolKeyboardType;
109

app/src/main/java/com/osfans/trime/ime/symbol/TabView.java

+27-23
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
import com.osfans.trime.ime.enums.SymbolKeyboardType;
3535
import com.osfans.trime.setup.Config;
3636
import com.osfans.trime.util.GraphicUtils;
37-
3837
import java.util.ArrayList;
39-
4038
import timber.log.Timber;
4139

4240
// 这是滑动键盘顶部的view,展示了键盘布局的多个标签。
@@ -128,44 +126,48 @@ protected void onDraw(Canvas canvas) {
128126
candidateHighlight.draw(canvas);
129127
}
130128
// Draw tab text
131-
float tabY = (shouldShowComment && isCommentOnTop)
132-
? tabTags.get(0).geometry.centerY() - (candidatePaint.ascent() + candidatePaint.descent()) / 2.0f
129+
float tabY =
130+
/* (shouldShowComment && isCommentOnTop)
131+
? tabTags.get(0).geometry.centerY()
132+
- (candidatePaint.ascent() + candidatePaint.descent()) / 2.0f
133133
+ commentHeight / 2.0f
134-
: tabTags.get(0).geometry.centerY() - (candidatePaint.ascent() + candidatePaint.descent()) / 2.0f;
134+
: */ tabTags.get(0).geometry.centerY()
135+
- (candidatePaint.ascent() + candidatePaint.descent()) / 2.0f;
135136

136-
for (TabTag computedTab: tabTags) {
137+
for (TabTag computedTab : tabTags) {
137138
int i = tabTags.indexOf(computedTab);
138139
// Calculate a position where the text could be centered in the rectangle.
139140
float tabX = computedTab.geometry.centerX();
140141

141-
candidatePaint.setColor(
142-
isHighlighted(i) ? hilitedCandidateTextColor : candidateTextColor);
142+
candidatePaint.setColor(isHighlighted(i) ? hilitedCandidateTextColor : candidateTextColor);
143143
graphicUtils.drawText(canvas, computedTab.text, tabX, tabY, candidatePaint, candidateFont);
144144
// Draw the separator at the right edge of each candidate.
145145
canvas.drawRect(
146-
computedTab.geometry.right - candidateSpacing,
147-
computedTab.geometry.top,
148-
computedTab.geometry.right + candidateSpacing,
149-
computedTab.geometry.bottom,
150-
separatorPaint
151-
);
146+
computedTab.geometry.right - candidateSpacing,
147+
computedTab.geometry.top,
148+
computedTab.geometry.right + candidateSpacing,
149+
computedTab.geometry.bottom,
150+
separatorPaint);
152151
}
153152
}
154153

155-
public void updateCandidateWidth() {
154+
public void updateTabWidth() {
156155
tabTags = TabManager.get().getTabCandidates();
157156
highlightIndex = TabManager.get().getSelected();
158157

159158
int x = 0;
160-
for (TabTag computedTab: tabTags) {
159+
for (TabTag computedTab : tabTags) {
161160
int i = tabTags.indexOf(computedTab);
162-
computedTab.geometry = new Rect(x, 0, x += getTabWidth(i), getHeight());
163-
x += candidateSpacing;
161+
computedTab.geometry = new Rect(x, 0, (int) (x + getTabWidth(i)), getHeight());
162+
x += +getTabWidth(i) + candidateSpacing;
164163
}
165164
LayoutParams params = getLayoutParams();
166165
Timber.i("update, from Height=" + params.height + " width=" + params.width);
167166
params.width = x;
168-
params.height = (shouldShowComment && isCommentOnTop) ? candidateViewHeight + commentHeight : candidateViewHeight;
167+
params.height =
168+
(shouldShowComment && isCommentOnTop)
169+
? candidateViewHeight + commentHeight
170+
: candidateViewHeight;
169171
Timber.i("update, to Height=" + candidateViewHeight + " width=" + x);
170172
setLayoutParams(params);
171173
params = getLayoutParams();
@@ -176,7 +178,7 @@ public void updateCandidateWidth() {
176178
@Override
177179
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
178180
super.onSizeChanged(w, h, oldw, oldh);
179-
updateCandidateWidth();
181+
updateTabWidth();
180182
Timber.i("onSizeChanged() w=" + w + ", Height=" + oldh + "=>" + h);
181183
}
182184

@@ -240,9 +242,9 @@ public boolean onTouchEvent(@NonNull MotionEvent me) {
240242
* @return {@code >=0}: 觸摸點 (x, y) 處候選項序號,從0開始編號; {@code -1}: 觸摸點 (x, y) 處無候選項;
241243
*/
242244
private int getTabIndex(int x, int y) {
243-
//Rect r = new Rect();
245+
// Rect r = new Rect();
244246
int retIndex = -1; // Returns -1 if there is no tab in the hitting rectangle.
245-
for (TabTag computedTab: tabTags) {
247+
for (TabTag computedTab : tabTags) {
246248
/* Enlarge the rectangle to be more responsive to user clicks.
247249
// r.set(tabGeometries[j++]);
248250
//r.inset(0, CANDIDATE_TOUCH_OFFSET); */
@@ -255,6 +257,8 @@ private int getTabIndex(int x, int y) {
255257

256258
private float getTabWidth(int i) {
257259
String s = tabTags.get(i).text;
258-
return s != null ? 2 * candidatePadding + graphicUtils.measureText(candidatePaint, s, candidateFont) : 2 * candidatePadding;
260+
return s != null
261+
? 2 * candidatePadding + graphicUtils.measureText(candidatePaint, s, candidateFont)
262+
: 2 * candidatePadding;
259263
}
260264
}

app/src/main/java/com/osfans/trime/ime/text/Candidate.java

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class Candidate extends View {
4545
/** 處理候選條選字事件 */
4646
public interface EventListener {
4747
void onCandidatePressed(int index);
48+
4849
void onCandidateSymbolPressed(String arrow);
4950
}
5051

app/src/main/java/com/osfans/trime/ime/text/TextInputManager.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ class TextInputManager private constructor() :
4444
CoroutineScope by MainScope(),
4545
Trime.EventListener,
4646
KeyboardView.OnKeyboardActionListener,
47-
Candidate.EventListener
48-
{
47+
Candidate.EventListener {
4948
private val trime get() = Trime.getService()
5049
private val prefs get() = Preferences.defaultInstance()
5150
private val activeEditorInstance: EditorInstance
@@ -243,8 +242,8 @@ class TextInputManager private constructor() :
243242
}
244243
"_liquid_keyboard" -> trime.selectLiquidKeyboard(0)
245244
"_hide_key_hint" -> if (mainKeyboardView != null) mainKeyboardView!!.setShowHint(!value)
246-
else -> if (option.startsWith("_keyboard_")
247-
&& option.length > 10 && value
245+
else -> if (option.startsWith("_keyboard_") &&
246+
option.length > 10 && value
248247
) {
249248
val keyboard = option.substring(10)
250249
keyboardSwitcher.switchToKeyboard(keyboard)

app/src/main/java/com/osfans/trime/settings/PrefMainActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import com.osfans.trime.ime.core.Preferences
2828
import com.osfans.trime.settings.components.SchemaPickerDialog
2929
import com.osfans.trime.util.RimeUtils
3030
import kotlinx.coroutines.CoroutineScope
31-
import kotlinx.coroutines.withContext
3231
import kotlinx.coroutines.Dispatchers
3332
import kotlinx.coroutines.MainScope
3433
import kotlinx.coroutines.launch
34+
import kotlinx.coroutines.withContext
3535
import timber.log.Timber
3636

3737
internal const val FRAGMENT_TAG = "FRAGMENT_TAG"

app/src/main/java/com/osfans/trime/settings/components/ColorPickerDialog.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.osfans.trime.settings.components
22

3-
import androidx.appcompat.app.AlertDialog
43
import android.content.Context
54
import android.os.Build
65
import android.view.WindowManager
6+
import androidx.appcompat.app.AlertDialog
77
import com.osfans.trime.R
88
import com.osfans.trime.ime.core.Preferences
99
import com.osfans.trime.ime.core.Trime

0 commit comments

Comments
 (0)