Skip to content

Commit 827ae93

Browse files
DarkJoker360momenabdulrazek
authored andcommitted
Introduce auto-switch after apostrophes
* For faster typing add a setting that automatically switches to letter layout after typing aphostophes. Signed-off-by: DarkJoker360 <simoespo159@gmail.com>
1 parent 5d3023d commit 827ae93

6 files changed

Lines changed: 34 additions & 3 deletions

File tree

java/res/values/cm_strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM
5555
<!-- Preference item for always showing the emoji key -->
5656
<string name="show_emoji_key">Show emoji key</string>
5757
<string name="show_emoji_key_summary">Always show emoji key.</string>
58+
59+
<!-- Preference item for auto-switching back to letters after typing an apostrophe on the symbols keyboard -->
60+
<string name="auto_switch_after_apostrophe">Auto-switch after apostrophes</string>
61+
<string name="auto_switch_after_apostrophe_summary">Automatically switch back to the letter keyboard after an apostrophe</string>
5862
</resources>

java/res/xml/prefs_screen_preferences.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@
5454
android:summary="@string/use_double_space_period_summary"
5555
android:defaultValue="true"
5656
android:persistent="true" />
57+
<CheckBoxPreference
58+
android:key="pref_auto_switch_after_apostrophe"
59+
android:title="@string/auto_switch_after_apostrophe"
60+
android:summary="@string/auto_switch_after_apostrophe_summary"
61+
android:defaultValue="false"
62+
android:persistent="true" />
5763
<CheckBoxPreference
5864
android:key="vibrate_on"
5965
android:title="@string/vibrate_on_keypress"

java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ public void loadKeyboard(final EditorInfo editorInfo, final SettingsValues setti
134134
&& settingsValues.mIsSplitKeyboardEnabled);
135135
mKeyboardLayoutSet = builder.build();
136136
try {
137+
mState.setAutoSwitchAfterApostrophe(settingsValues.mAutoSwitchAfterApostrophe);
137138
mState.onLoadKeyboard(currentAutoCapsState, currentRecapitalizeState);
138139
mKeyboardTextsSet.setLocale(mRichImm.getCurrentSubtypeLocale(), mThemeContext);
139140
} catch (KeyboardLayoutSetException e) {

java/src/com/android/inputmethod/keyboard/internal/KeyboardState.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public interface SwitchActions {
8989
private boolean mIsSymbolShifted;
9090
private boolean mPrevMainKeyboardWasShiftLocked;
9191
private boolean mPrevSymbolsKeyboardWasShifted;
92+
private boolean mAutoSwitchAfterApostrophe;
9293
private int mRecapitalizeMode;
9394

9495
// For handling double tap.
@@ -125,6 +126,10 @@ public KeyboardState(final SwitchActions switchActions) {
125126
mRecapitalizeMode = RecapitalizeStatus.NOT_A_RECAPITALIZE_MODE;
126127
}
127128

129+
public void setAutoSwitchAfterApostrophe(final boolean enabled) {
130+
mAutoSwitchAfterApostrophe = enabled;
131+
}
132+
128133
public void onLoadKeyboard(final int autoCapsFlags, final int recapitalizeMode) {
129134
if (DEBUG_EVENT) {
130135
Log.d(TAG, "onLoadKeyboard: " + stateToString(autoCapsFlags, recapitalizeMode));
@@ -618,6 +623,10 @@ private static boolean isSpaceOrEnter(final int c) {
618623
return c == Constants.CODE_SPACE || c == Constants.CODE_ENTER;
619624
}
620625

626+
private boolean shouldSwitchBackAfterApostrophe(final int code) {
627+
return mAutoSwitchAfterApostrophe && code == Constants.CODE_SINGLE_QUOTE;
628+
}
629+
621630
public void onEvent(final Event event, final int autoCapsFlags, final int recapitalizeMode) {
622631
final int code = event.isFunctionalKeyEvent() ? event.mKeyCode : event.mCodePoint;
623632
if (DEBUG_EVENT) {
@@ -649,15 +658,18 @@ public void onEvent(final Event event, final int autoCapsFlags, final int recapi
649658
// after the user hits an emoji letter followed by an enter or a space.
650659
break;
651660
}
652-
if (!isSpaceOrEnter(code) && (Constants.isLetterCode(code)
661+
if (shouldSwitchBackAfterApostrophe(code)) {
662+
toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
663+
mPrevSymbolsKeyboardWasShifted = false;
664+
} else if (!isSpaceOrEnter(code) && (Constants.isLetterCode(code)
653665
|| code == Constants.CODE_OUTPUT_TEXT)) {
654666
mSwitchState = SWITCH_STATE_SYMBOL;
655667
}
656668
break;
657669
case SWITCH_STATE_SYMBOL:
658670
// Switch back to alpha keyboard mode if user types one or more non-space/enter
659-
// characters followed by a space/enter.
660-
if (isSpaceOrEnter(code)) {
671+
// characters followed by a space/enter or an apostrophe (when enabled).
672+
if (isSpaceOrEnter(code) || shouldSwitchBackAfterApostrophe(code)) {
661673
toggleAlphabetAndSymbols(autoCapsFlags, recapitalizeMode);
662674
mPrevSymbolsKeyboardWasShifted = false;
663675
}

java/src/com/android/inputmethod/latin/settings/Settings.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
9999
public static final String PREF_ENABLE_METRICS_LOGGING = "pref_enable_metrics_logging";
100100
public static final String PREF_SHOW_NUMBER_ROW = "pref_show_number_row";
101101
public static final String PREF_SHOW_NUMBER_ROW_PASSWORD = "pref_show_number_row_password";
102+
public static final String PREF_AUTO_SWITCH_AFTER_APOSTROPHE =
103+
"pref_auto_switch_after_apostrophe";
102104

103105
public static final String PREF_SHOW_LONGPRESS_HINTS = "pref_show_longpress_hints";
104106

@@ -358,6 +360,10 @@ public static boolean readBackspaceTrackpadEnabled(final SharedPreferences prefs
358360
return prefs.getBoolean(PREF_BACKSPACE_TRACKPAD, true);
359361
}
360362

363+
public static boolean readAutoSwitchAfterApostrophe(final SharedPreferences prefs) {
364+
return prefs.getBoolean(PREF_AUTO_SWITCH_AFTER_APOSTROPHE, false);
365+
}
366+
361367
public static boolean readUseFullscreenMode(final Resources res) {
362368
return res.getBoolean(R.bool.config_use_fullscreen_mode);
363369
}

java/src/com/android/inputmethod/latin/settings/SettingsValues.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class SettingsValues {
7777
public final boolean mBlockPotentiallyOffensive;
7878
public final boolean mSpaceTrackpadEnabled;
7979
public final boolean mBackspaceTrackpadEnabled;
80+
public final boolean mAutoSwitchAfterApostrophe;
8081
// Use bigrams to predict the next word when there is no input for it yet
8182
public final boolean mBigramPredictionEnabled;
8283
public final boolean mGestureInputEnabled;
@@ -225,6 +226,7 @@ public SettingsValues(final Context context, final SharedPreferences prefs, fina
225226
}
226227
mSpaceTrackpadEnabled = Settings.readSpaceTrackpadEnabled(prefs);
227228
mBackspaceTrackpadEnabled = Settings.readBackspaceTrackpadEnabled(prefs);
229+
mAutoSwitchAfterApostrophe = Settings.readAutoSwitchAfterApostrophe(prefs);
228230
}
229231

230232
public boolean isMetricsLoggingEnabled() {

0 commit comments

Comments
 (0)