Skip to content

Commit 1efe8ab

Browse files
committed
refactor(data): completely remove methods/variables should can only handle by AppPrefs from Config
1 parent da4f6ab commit 1efe8ab

File tree

5 files changed

+23
-47
lines changed

5 files changed

+23
-47
lines changed

app/src/main/java/com/osfans/trime/data/AppPrefs.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import java.lang.ref.WeakReference
1414
* Helper class for an organized access to the shared preferences.
1515
*/
1616
class AppPrefs(
17-
private val shared : SharedPreferences
17+
private val shared: SharedPreferences
1818
) {
1919
private val applicationContext: WeakReference<Context> = WeakReference(appContext)
2020

@@ -257,10 +257,10 @@ class AppPrefs(
257257
get() = prefs.getPref(SWIPE_TIME_HI, 80)
258258
private set
259259
var longPressTimeout: Int = 0
260-
get() = prefs.getPref(LONG_PRESS_TIMEOUT, 20)
260+
get() = prefs.getPref(LONG_PRESS_TIMEOUT, 400)
261261
private set
262262
var repeatInterval: Int = 0
263-
get() = prefs.getPref(REPEAT_INTERVAL, 4)
263+
get() = prefs.getPref(REPEAT_INTERVAL, 50)
264264
private set
265265
var deleteCandidateTimeout: Int = 0
266266
get() = prefs.getPref(DELETE_CANDIDATE_TIMEOUT, 2000)

app/src/main/java/com/osfans/trime/data/Config.java

-20
Original file line numberDiff line numberDiff line change
@@ -759,26 +759,6 @@ public PositionType getWinPos() {
759759
return PositionType.Companion.fromString(getString("layout/position"));
760760
}
761761

762-
public int getLongTimeout() {
763-
int progress = appPrefs.getKeyboard().getLongPressTimeout();
764-
if (progress > 60) progress = 60;
765-
return progress * 10 + 100;
766-
}
767-
768-
public int getRepeatInterval() {
769-
int progress = appPrefs.getKeyboard().getRepeatInterval();
770-
if (progress > 9) progress = 9;
771-
return progress * 10 + 10;
772-
}
773-
774-
public static int getDeleteCandidateTimeout() {
775-
return appPrefs.getKeyboard().getDeleteCandidateTimeout();
776-
}
777-
778-
public static boolean getShouldLongClickDeleteCandidate() {
779-
return appPrefs.getKeyboard().getShouldLongClickDeleteCandidate();
780-
}
781-
782762
public int getLiquidPixel(String key) {
783763
if (liquidKeyboard != null) {
784764
if (liquidKeyboard.containsKey(key)) {

app/src/main/java/com/osfans/trime/ime/keyboard/KeyboardView.java

+9-18
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import android.view.LayoutInflater;
3939
import android.view.MotionEvent;
4040
import android.view.View;
41-
import android.view.ViewConfiguration;
4241
import android.view.ViewGroup;
4342
import android.view.inputmethod.EditorInfo;
4443
import android.widget.PopupWindow;
@@ -202,17 +201,12 @@ public interface OnKeyboardActionListener {
202201
private int mComboCount = 0;
203202
private boolean mComboMode = false;
204203

205-
private static int REPEAT_INTERVAL = 50; // ~20 keys per second
206-
private static int REPEAT_START_DELAY = 400;
207-
private static int LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
208-
209204
private static final int MAX_NEARBY_KEYS = 12;
210205
private final int[] mDistances = new int[MAX_NEARBY_KEYS];
211206

212207
// For multi-tap
213208
private int mLastSentIndex;
214209
private long mLastTapTime;
215-
private static int MULTI_TAP_INTERVAL = 800; // milliseconds
216210
private final StringBuilder mPreviewLabel = new StringBuilder(1);
217211

218212
/** Whether the keyboard bitmap needs to be redrawn before it's blitted. * */
@@ -298,8 +292,8 @@ public void setEnterLabel(int action, CharSequence actionLabel) {
298292
}
299293

300294
@NonNull
301-
private AppPrefs getPrefs() {
302-
return AppPrefs.Companion.defaultInstance();
295+
private static AppPrefs getPrefs() {
296+
return AppPrefs.defaultInstance();
303297
}
304298

305299
private final MyHandler mHandler = new MyHandler(this);
@@ -324,7 +318,7 @@ public void handleMessage(Message msg) {
324318
case MSG_REPEAT:
325319
if (mKeyboardView.repeatKey()) {
326320
Message repeat = Message.obtain(this, MSG_REPEAT);
327-
sendMessageDelayed(repeat, REPEAT_INTERVAL);
321+
sendMessageDelayed(repeat, getPrefs().getKeyboard().getRepeatInterval());
328322
}
329323
break;
330324
case MSG_LONGPRESS:
@@ -403,11 +397,6 @@ public void reset() {
403397
mPaintSymbol.setTextSize(mSymbolSize);
404398
mPreviewText.setTypeface(config.getFont("preview_font"));
405399

406-
REPEAT_INTERVAL = config.getRepeatInterval();
407-
REPEAT_START_DELAY = config.getLongTimeout() + 1;
408-
LONG_PRESS_TIMEOUT = config.getLongTimeout();
409-
MULTI_TAP_INTERVAL = config.getLongTimeout();
410-
411400
mEnterLabels = config.getmEnterLabels();
412401
enterLabelMode = config.getInt("enter_label_mode");
413402
invalidateAllKeys();
@@ -1576,7 +1565,8 @@ else if (action == MotionEvent.ACTION_UP)
15761565
if (mCurrentKey >= 0 && mKeys[mCurrentKey].getClick().isRepeatable()) {
15771566
mRepeatKeyIndex = mCurrentKey;
15781567
final Message msg = mHandler.obtainMessage(MSG_REPEAT);
1579-
mHandler.sendMessageDelayed(msg, REPEAT_START_DELAY);
1568+
final int repeatStartDelay = getPrefs().getKeyboard().getLongPressTimeout() + 1;
1569+
mHandler.sendMessageDelayed(msg, repeatStartDelay);
15801570
// Delivering the key could have caused an abort
15811571
if (mAbortKey) {
15821572
mRepeatKeyIndex = NOT_A_KEY;
@@ -1585,7 +1575,7 @@ else if (action == MotionEvent.ACTION_UP)
15851575
}
15861576
if (mCurrentKey != NOT_A_KEY) {
15871577
final Message msg = mHandler.obtainMessage(MSG_LONGPRESS, me);
1588-
mHandler.sendMessageDelayed(msg, LONG_PRESS_TIMEOUT);
1578+
mHandler.sendMessageDelayed(msg, getPrefs().getKeyboard().getLongPressTimeout());
15891579
}
15901580
showPreview(keyIndex, 0);
15911581
break;
@@ -1617,7 +1607,7 @@ else if (action == MotionEvent.ACTION_UP)
16171607
// Start new long press if key has changed
16181608
if (keyIndex != NOT_A_KEY) {
16191609
final Message msg = mHandler.obtainMessage(MSG_LONGPRESS, me);
1620-
mHandler.sendMessageDelayed(msg, LONG_PRESS_TIMEOUT);
1610+
mHandler.sendMessageDelayed(msg, getPrefs().getKeyboard().getLongPressTimeout());
16211611
}
16221612
}
16231613
showPreview(mCurrentKey);
@@ -1768,7 +1758,8 @@ private void resetMultiTap() {
17681758
private void checkMultiTap(long eventTime, int keyIndex) {
17691759
if (keyIndex == NOT_A_KEY) return;
17701760
// final Key key = mKeys[keyIndex];
1771-
if (eventTime > mLastTapTime + MULTI_TAP_INTERVAL || keyIndex != mLastSentIndex) {
1761+
final int multiTabInterval = getPrefs().getKeyboard().getLongPressTimeout();
1762+
if (eventTime > mLastTapTime + multiTabInterval || keyIndex != mLastSentIndex) {
17721763
resetMultiTap();
17731764
}
17741765
}

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public interface EventListener {
8080
private int candidateViewHeight, commentHeight, candidateSpacing, candidatePadding;
8181
private boolean shouldShowComment = true, isCommentOnTop, candidateUseCursor;
8282

83+
@NonNull
84+
private AppPrefs getAppPrefs() {
85+
return AppPrefs.defaultInstance();
86+
}
87+
8388
public void reset() {
8489
Config config = Config.get();
8590
candidateHighlight = new PaintDrawable(config.getColor("hilited_candidate_back_color"));
@@ -179,7 +184,7 @@ private void onCandidateClick(int index, boolean isLongClick) {
179184
if (candidate != null) {
180185
if (candidate instanceof ComputedCandidate.Word) {
181186
if (listener.get() != null) {
182-
if (isLongClick && Config.getShouldLongClickDeleteCandidate()) {
187+
if (isLongClick && getAppPrefs().getKeyboard().getShouldLongClickDeleteCandidate()) {
183188
listener.get().onCandidateLongClicked(index + startNum);
184189
} else {
185190
listener.get().onCandidatePressed(index + startNum);
@@ -393,7 +398,7 @@ public boolean onTouchEvent(@NonNull MotionEvent me) {
393398
long durationMs = timeMove - timeDown;
394399
setPressed(false);
395400
if (me.getActionMasked() == MotionEvent.ACTION_UP) {
396-
onCandidateClick(highlightIndex, durationMs >= Config.getDeleteCandidateTimeout());
401+
onCandidateClick(highlightIndex, durationMs >= getAppPrefs().getKeyboard().getDeleteCandidateTimeout());
397402
}
398403
highlightIndex = -1;
399404
invalidate();

app/src/main/res/xml/keyboard_preference.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -258,19 +258,19 @@
258258
app:unit="@string/unit__time_ms"
259259
app:useSimpleSummaryProvider="true" />
260260
<com.osfans.trime.ui.components.DialogSeekBarPreference
261-
android:defaultValue="20"
261+
android:defaultValue="400"
262262
android:key="keyboard__key_long_press_timeout"
263263
android:title="@string/keyboard__long_press_timeout_title"
264264
android:widgetLayout="@layout/seek_bar_dialog"
265265
app:allowDividerAbove="false"
266266
app:iconSpaceReserved="false"
267-
app:max="60"
268-
app:min="10"
267+
app:max="800"
268+
app:min="100"
269269
app:seekBarIncrement="10"
270270
app:unit="@string/unit__time_ms"
271271
app:useSimpleSummaryProvider="true" />
272272
<com.osfans.trime.ui.components.DialogSeekBarPreference
273-
android:defaultValue="40"
273+
android:defaultValue="30"
274274
android:key="keyboard__key_repeat_interval"
275275
android:title="@string/keyboard__key_repeat_interval_title"
276276
app:allowDividerAbove="false"

0 commit comments

Comments
 (0)