improved "switch back IME" implementation, now makes use of android switchToLastIME method -> works even without root/Secure Settings

This commit is contained in:
Philipp Crocoll 2015-02-11 08:30:36 +01:00
parent 8de5588cff
commit c9863b3178
4 changed files with 18 additions and 14 deletions

View File

@ -2,7 +2,7 @@
package="keepass2android.softkeyboard">
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="9"/>
<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="14"/>
<application android:label="MyKeyboard"
android:killAfterRestore="false">

View File

@ -11,6 +11,7 @@ import android.content.pm.ActivityInfo;
import android.content.pm.ResolveInfo;
import android.inputmethodservice.InputMethodService;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.inputmethod.InputMethod;
@ -23,10 +24,20 @@ public class ImeSwitcher {
private static final String KP2A_SWITCHER = "KP2A_Switcher";
private static final String Tag = "KP2A_SWITCHER";
public static void switchToPreviousKeyboard(Context ctx, boolean silent)
public static void switchToPreviousKeyboard(InputMethodService ims, boolean silent)
{
SharedPreferences prefs = ctx.getSharedPreferences(KP2A_SWITCHER, Context.MODE_PRIVATE);
switchToKeyboard(ctx, prefs.getString(PREVIOUS_KEYBOARD, null), silent);
try {
InputMethodManager imm = (InputMethodManager) ims.getSystemService(Context.INPUT_METHOD_SERVICE);
final IBinder token = ims.getWindow().getWindow().getAttributes().token;
//imm.setInputMethod(token, LATIN);
imm.switchToLastInputMethod(token);
} catch (Throwable t) { // java.lang.NoSuchMethodError if API_level<11
Log.e("KP2A","cannot set the previous input method:");
t.printStackTrace();
SharedPreferences prefs = ims.getSharedPreferences(KP2A_SWITCHER, Context.MODE_PRIVATE);
switchToKeyboard(ims, prefs.getString(PREVIOUS_KEYBOARD, null), silent);
}
}
//silent: if true, do not show picker, only switch in background. Don't do anything if switching fails.

View File

@ -256,7 +256,9 @@
android:title="@string/OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_title"
android:key="@string/OpenKp2aKeyboardAutomaticallyOnlyAfterSearch_key" />
<CheckBoxPreference
<!-- with and without autoswitch on root-->
<CheckBoxPreference
android:enabled="true"
android:persistent="true"
android:summary="@string/AutoSwitchBackKeyboard_summary"
@ -264,7 +266,6 @@
android:title="@string/AutoSwitchBackKeyboard_title"
android:key="@string/AutoSwitchBackKeyboard_key" />
<!-- with and without autoswitch on root-->
<CheckBoxPreference
android:key="kp2a_switch_on_sendgodone"
android:title="@string/kp2a_switch_on_sendgodone"

View File

@ -182,10 +182,6 @@ namespace keepass2android
{
_screen.RemovePreference(_openOnlyOnSearchPref);
}
if (_act.FindPreference(_act.GetString(Resource.String.AutoSwitchBackKeyboard_key)) != null)
{
_screen.RemovePreference(_switchBackPref);
}
}
else
{
@ -197,10 +193,6 @@ namespace keepass2android
{
_screen.AddPreference(_openOnlyOnSearchPref);
}
if (_act.FindPreference(_act.GetString(Resource.String.AutoSwitchBackKeyboard_key)) == null)
{
_screen.AddPreference(_switchBackPref);
}
}
/*_openKp2aAutoPref.Enabled = !switchOnRooted;