Merge pull request #14539 from keymanapp/fix/android/36-hidden

fix(android): Add "Show On-screen keyboard" preference to display OSK when physical keyboard is connected 👁️
This commit is contained in:
Darcy Wong 2025-08-20 09:34:16 +07:00 committed by GitHub
commit 0a83faac7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 55 additions and 5 deletions

View file

@ -5,10 +5,10 @@
package com.keyman.android;
import com.keyman.engine.util.DownloadFileUtils;
import com.tavultesoft.kmapro.AdjustLongpressDelayActivity;
import com.tavultesoft.kmapro.BuildConfig;
import com.tavultesoft.kmapro.DefaultLanguageResource;
import com.tavultesoft.kmapro.KeymanSettingsActivity;
import com.tavultesoft.kmapro.PreferencesManager;
import com.keyman.engine.KMManager;
import com.keyman.engine.KMManager.KeyboardType;
import com.keyman.engine.KMHardwareKeyboardInterpreter;
@ -30,7 +30,6 @@ import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
@ -287,9 +286,10 @@ public class SystemKeyboard extends InputMethodService implements OnKeyboardEven
return true;
};
// TODO: Implement IME setting similar to Gboard "Show on-screen keyboard" with physical keyboard
// (default false)
return true;
Context context = getApplicationContext();
SharedPreferences prefs = context.getSharedPreferences(PreferencesManager.kma_prefs_name, Context.MODE_PRIVATE);
boolean showOSK = prefs.getBoolean(KeymanSettingsActivity.oskWithPhysicalKeyboardKey, false);
return showOSK;
}
@Override

View file

@ -13,6 +13,7 @@ public class KeymanSettingsActivity extends BaseActivity {
protected static final String sendCrashReport = "SendCrashReport";
public static final String spacebarTextKey = "SpacebarText";
public static final String hapticFeedbackKey = "HapticFeedback";
public static final String oskWithPhysicalKeyboardKey = "ShowOSK";
protected KeymanSettingsFragment innerFragment;

View file

@ -6,6 +6,7 @@ package com.tavultesoft.kmapro;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.Settings;
import android.view.inputmethod.InputMethodManager;
@ -20,6 +21,7 @@ import androidx.preference.SwitchPreference;
import com.keyman.engine.DisplayLanguages;
import com.keyman.engine.KMManager;
import com.keyman.engine.data.Dataset;
import com.tavultesoft.kmapro.PreferencesManager;
import java.util.HashMap;
@ -157,6 +159,31 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat {
}
});
SwitchPreference oskWithPhysicalKeyboardPreference = new SwitchPreference(context);
oskWithPhysicalKeyboardPreference.setKey(KeymanSettingsActivity.oskWithPhysicalKeyboardKey);
oskWithPhysicalKeyboardPreference.setTitle(getString(R.string.show_osk));
oskWithPhysicalKeyboardPreference.setSummary(getString(R.string.show_osk_hint));
SharedPreferences prefs = context.getSharedPreferences(
PreferencesManager.kma_prefs_name, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
boolean showOSK = prefs.getBoolean(
KeymanSettingsActivity.oskWithPhysicalKeyboardKey, false);
oskWithPhysicalKeyboardPreference.setDefaultValue(showOSK);
oskWithPhysicalKeyboardPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue == null) {
return false;
}
editor.putBoolean(KeymanSettingsActivity.oskWithPhysicalKeyboardKey, (boolean)newValue);
editor.commit();
return true;
}
});
SwitchPreference hapticFeedbackPreference = new SwitchPreference(context);
hapticFeedbackPreference.setKey(KeymanSettingsActivity.hapticFeedbackKey);
hapticFeedbackPreference.setTitle(getString(R.string.haptic_feedback));
@ -198,6 +225,8 @@ public class KeymanSettingsFragment extends PreferenceFragmentCompat {
screen.addPreference(adjustKeyboardHeight);
screen.addPreference(adjustLongpressDelay);
screen.addPreference(oskWithPhysicalKeyboardPreference);
screen.addPreference(spacebarTextPreference);
screen.addPreference(hapticFeedbackPreference);

View file

@ -0,0 +1,11 @@
/**
* Keyman is copyright (C) SIL Global. MIT License.
*
*/
package com.tavultesoft.kmapro;
public class PreferencesManager {
// TODO: Separate this from the Keyman Engine preference key name in strings.xml: #13633
public static final String kma_prefs_name = "KMAPreferences";
}

View file

@ -146,6 +146,12 @@
<!-- Context: Keyman Settings menu / Spacebar caption hint -->
<string name="spacebar_caption_hint_blank" comment="Spacebar caption hint - blank">Do not show caption on spacebar</string>
<!-- Context: Keyman Settings menu / Show OSK with Physical Keyboard -->
<string name="show_osk" comment="show OSK when physical keyboard is connected">Show On-Screen Keyboard</string>
<!-- Context: Keyman Settings menu / Show OSK with Physical Keyboard hint -->
<string name="show_osk_hint" comment="When physical keyboard is connected">When physical keyboard is connected</string>
<!-- Context: Keyman Settings menu / Haptic feedback -->
<string name="haptic_feedback" comment="haptic feedback on key press">Vibrate when typing</string>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View file

@ -49,6 +49,9 @@ Click on this to [adjust the keyboard height](adjust-keyboard-height).
Click on this to [adjust the delay time](adjust-longpress-delay) for a longpress gesture.
## Show On-Screen Keyboard
By default, Android 16 (Baklava) and later versions won't display the On-Screen keyboard if a physical keyboard is connected. When enabled, show the Keyman system keyboard even if a physical keyboard is connected.
## Spacebar Caption
Click on this to [change the displayed keyboard name](spacebar-caption) on the spacebar.