Skip to content

Commit

Permalink
refactor(keyboard): move and rename TrimeKeyEffects
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Sep 21, 2021
1 parent 8f95b32 commit 3c2da03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
27 changes: 14 additions & 13 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import com.osfans.trime.ime.keyboard.Keyboard;
import com.osfans.trime.ime.keyboard.KeyboardSwitch;
import com.osfans.trime.ime.keyboard.KeyboardView;
import com.osfans.trime.ime.keyboard.InputFeedbackManager;
import com.osfans.trime.ime.symbol.LiquidKeyboard;
import com.osfans.trime.ime.symbol.TabView;
import com.osfans.trime.ime.text.Candidate;
Expand Down Expand Up @@ -105,7 +106,7 @@ private Preferences getPrefs() {
private KeyboardView mKeyboardView; // 軟鍵盤
private KeyboardSwitch mKeyboardSwitch;
private Config mConfig; // 配置
@Nullable private TrimeKeyEffects effectManager = null; // 效果管理器
@Nullable private InputFeedbackManager inputFeedbackManager = null; // 效果管理器
private Candidate mCandidate; // 候選
private Composition mComposition; // 編碼
private CompositionContainerBinding compositionContainerBinding;
Expand Down Expand Up @@ -318,7 +319,7 @@ public void onCreate() {
super.onCreate();
self = this;
imeManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
effectManager = new TrimeKeyEffects(this);
inputFeedbackManager = new InputFeedbackManager(this);
mIntentReceiver = new IntentReceiver();
mIntentReceiver.registerReceiver(this);

Expand Down Expand Up @@ -365,7 +366,7 @@ public void onOptionChanged(@NonNull String option, boolean value) {
switch (option) {
case "ascii_mode":
if (!mTempAsciiMode) mAsciiMode = value; // 切換中西文時保存狀態
if (effectManager != null) effectManager.setTtsLanguage(locales[value ? 1 : 0]);
if (inputFeedbackManager != null) inputFeedbackManager.setTtsLanguage(locales[value ? 1 : 0]);
break;
case "_hide_comment":
setShowComment(!value);
Expand Down Expand Up @@ -526,8 +527,8 @@ public void initKeyboard() {
public void onDestroy() {
if (mIntentReceiver != null) mIntentReceiver.unregisterReceiver(this);
mIntentReceiver = null;
if (effectManager != null) effectManager.destroy();
effectManager = null;
if (inputFeedbackManager != null) inputFeedbackManager.destroy();
inputFeedbackManager = null;
inputRootBinding = null;
imeManager = null;
self = null;
Expand Down Expand Up @@ -778,7 +779,7 @@ private boolean isComposing() {
*/
public void commitText(CharSequence text, boolean isRime) {
if (text == null) return;
if (effectManager != null) effectManager.textCommitSpeak(text);
if (inputFeedbackManager != null) inputFeedbackManager.textCommitSpeak(text);
// mEffect.speakCommit(text);
final @Nullable InputConnection ic = getCurrentInputConnection();
if (ic != null) {
Expand Down Expand Up @@ -806,11 +807,11 @@ private boolean commitText() {
}

public void keyPressVibrate() {
if (effectManager != null) effectManager.keyPressVibrate();
if (inputFeedbackManager != null) inputFeedbackManager.keyPressVibrate();
}

public void keyPressSound() {
if (effectManager != null) effectManager.keyPressSound(0);
if (inputFeedbackManager != null) inputFeedbackManager.keyPressSound(0);
}

/**
Expand Down Expand Up @@ -1178,7 +1179,7 @@ public void onKey(int keyCode, int mask) { // 軟鍵盤
@Override
public void onText(CharSequence text) { // 軟鍵盤
Timber.i("onText = %s", text);
if (effectManager != null) effectManager.keyPressSpeak(text);
if (inputFeedbackManager != null) inputFeedbackManager.keyPressSpeak(text);

// Commit current composition before simulate key sequence
if (!Rime.isValidText(text) && isComposing()) {
Expand Down Expand Up @@ -1207,10 +1208,10 @@ public void onText(CharSequence text) { // 軟鍵盤

@Override
public void onPress(int keyCode) {
if (effectManager != null) {
effectManager.keyPressVibrate();
effectManager.keyPressSound(keyCode);
effectManager.keyPressSpeak(keyCode);
if (inputFeedbackManager != null) {
inputFeedbackManager.keyPressVibrate();
inputFeedbackManager.keyPressSound(keyCode);
inputFeedbackManager.keyPressSpeak(keyCode);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.osfans.trime.ime.core
package com.osfans.trime.ime.keyboard

import android.content.Context
import android.media.AudioManager
Expand All @@ -10,13 +10,14 @@ import android.view.HapticFeedbackConstants
import android.view.KeyEvent
import android.view.LayoutInflater
import com.osfans.trime.databinding.InputRootBinding
import com.osfans.trime.ime.core.Preferences
import java.util.Locale
import kotlin.math.ln

/**
* Manage the key press effects, such as vibration, sound, speaking and so on.
*/
class TrimeKeyEffects(
class InputFeedbackManager(
context: Context
) {
private val prefs: Preferences = Preferences.defaultInstance()
Expand Down

0 comments on commit 3c2da03

Please sign in to comment.