Bug fixes,

integration of new keyboard
This commit is contained in:
Philipp Crocoll
2014-01-24 11:29:34 -08:00
parent 9611622fb1
commit b437dceb70
10 changed files with 1487 additions and 1358 deletions

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.preference.PreferenceManager;
import android.util.Log;
import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodManager;
@@ -21,26 +22,31 @@ public class ImeSwitcher {
private static final String KP2A_SWITCHER = "KP2A_Switcher";
private static final String Tag = "KP2A_SWITCHER";
public static void switchToPreviousKeyboard(Context ctx)
public static void switchToPreviousKeyboard(Context ctx, boolean silent)
{
SharedPreferences prefs = ctx.getSharedPreferences(KP2A_SWITCHER, Context.MODE_PRIVATE);
switchToKeyboard(ctx, prefs.getString(PREVIOUS_KEYBOARD, null));
switchToKeyboard(ctx, prefs.getString(PREVIOUS_KEYBOARD, null), silent);
}
public static void switchToKeyboard(Context ctx, String newImeName)
//silent: if true, do not show picker, only switch in background. Don't do anything if switching fails.
public static void switchToKeyboard(Context ctx, String newImeName, boolean silent)
{
if (newImeName == null)
Log.d(Tag,"silent: "+silent);
if ((newImeName == null) || (!autoSwitchEnabled(ctx)))
{
showPicker(ctx);
return;
Log.d(Tag, "(newImeName == null): "+(newImeName == null));
Log.d(Tag, "autoSwitchEnabled(ctx)"+autoSwitchEnabled(ctx));
if (!silent)
{
showPicker(ctx);
}
return;
}
Intent qi = new Intent("com.twofortyfouram.locale.intent.action.FIRE_SETTING");
List<ResolveInfo> pkgAppsList = ctx.getPackageManager().queryBroadcastReceivers(qi, 0);
boolean sentBroadcast = false;
for (ResolveInfo ri: pkgAppsList)
{
if (ri.activityInfo.packageName.equals("com.intangibleobject.securesettings.plugin"))
{
@@ -57,32 +63,28 @@ public class ImeSwitcher {
Intent i=new Intent("com.twofortyfouram.locale.intent.action.FIRE_SETTING");
Bundle b = new Bundle();
b.putString("com.intangibleobject.securesettings.plugin.extra.BLURB", "Input Method/Switch IME");
b.putString("com.intangibleobject.securesettings.plugin.extra.BLURB", "Input Method/SwitchIME");
b.putString("com.intangibleobject.securesettings.plugin.extra.INPUT_METHOD", newImeName);
b.putString("com.intangibleobject.securesettings.plugin.extra.SETTING","default_input_method");
i.putExtra("com.twofortyfouram.locale.intent.extra.BUNDLE", b);
Log.d(Tag,"trying to switch by broadcast to SecureSettings");
ctx.sendBroadcast(i);
sentBroadcast = true;
break;
}
}
if (!sentBroadcast)
if ((!sentBroadcast) && (!silent))
{
//report that switch failed:
try
{
Toast.makeText(ctx, "SecureSettings not found on system!", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
Log.e(Tag, e.toString());
}
showPicker(ctx);
}
}
private static boolean autoSwitchEnabled(Context ctx) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ctx);
return sp.getBoolean("kp2a_switch_rooted", false);
}
private static void showPicker(Context ctx) {
((InputMethodManager) ctx.getSystemService(InputMethodService.INPUT_METHOD_SERVICE))
.showInputMethodPicker();

View File

@@ -170,7 +170,7 @@ public class KP2AKeyboard extends InputMethodService
private boolean mKp2aEnableSimpleKeyboard;
private boolean mKp2aSwitchKeyboardOnSendGoDone;
private boolean mKp2aLockOnSendGoDone;
private boolean mKp2aSwitchRooted;
private boolean mIsSendGoDone;
@@ -294,9 +294,10 @@ public class KP2AKeyboard extends InputMethodService
public void onReceive(Context context, Intent intent) {
mShowKp2aKeyboard = false;
updateKeyboardMode(getCurrentInputEditorInfo());
//switch back, but only "silently" (i.e. if automatic switching is enabled and available)
keepass2android.kbbridge.ImeSwitcher.switchToPreviousKeyboard(KP2AKeyboard.this, true);
}
}
@@ -494,8 +495,22 @@ public class KP2AKeyboard extends InputMethodService
public View onCreateInputView() {
mKeyboardSwitcher.recreateInputView();
mKeyboardSwitcher.makeKeyboards(true);
mKeyboardSwitcher.setKeyboardMode(
KeyboardSwitcher.MODE_TEXT, 0);
loadSettings();
updateShowKp2aMode();
Log.d("KP2AK", "onCreateInputView -> setKM");
if ((mShowKp2aKeyboard) && (mKp2aEnableSimpleKeyboard))
{
mKeyboardSwitcher.setKeyboardMode(
KeyboardSwitcher.MODE_KP2A, 0);
}
else
{
mKeyboardSwitcher.setKeyboardMode(
KeyboardSwitcher.MODE_TEXT, 0);
}
return mKeyboardSwitcher.getInputView();
}
@@ -517,6 +532,8 @@ public class KP2AKeyboard extends InputMethodService
if (inputView == null) {
return;
}
loadSettings();
if (mRefreshKeyboardRequired) {
mRefreshKeyboardRequired = false;
@@ -536,7 +553,7 @@ public class KP2AKeyboard extends InputMethodService
mIsSendGoDone = ((attribute.imeOptions&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) == EditorInfo.IME_ACTION_GO)
|| ((attribute.imeOptions&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) == EditorInfo.IME_ACTION_DONE)
|| ((attribute.imeOptions&(EditorInfo.IME_MASK_ACTION|EditorInfo.IME_FLAG_NO_ENTER_ACTION)) == EditorInfo.IME_ACTION_SEND);
loadSettings();
updateShiftKeyState(attribute);
setCandidatesViewShownInternal(isCandidateStripVisible() || mCompletionOn,
@@ -562,39 +579,17 @@ public class KP2AKeyboard extends InputMethodService
private void updateKeyboardMode(EditorInfo attribute) {
mInputTypeNoAutoCorrect = false;
mPredictionOn = false;
mCompletionOn = false;
mCompletions = null;
mCapsLock = false;
mEnteredText = null;
int variation = attribute.inputType & EditorInfo.TYPE_MASK_VARIATION;
if (!keepass2android.kbbridge.KeyboardData.hasData())
{
//data no longer available. hide kp2a keyboard:
mShowKp2aKeyboard = false;
mHadKp2aData = false;
}
else
{
if (!mHadKp2aData)
{
if (keepass2android.kbbridge.KeyboardData.hasData())
{
//new data available -> show kp2a keyboard:
mShowKp2aKeyboard = true;
}
}
mHadKp2aData = keepass2android.kbbridge.KeyboardData.hasData();
}
Log.d("KP2AK", "show: " + mShowKp2aKeyboard);
updateShowKp2aMode();
Log.d("KP2AK", "updateKeyboardMode -> setKM");
if ((mShowKp2aKeyboard) && (mKp2aEnableSimpleKeyboard))
{
mKeyboardSwitcher.setKeyboardMode(KeyboardSwitcher.MODE_KP2A, attribute.imeOptions);
@@ -678,6 +673,31 @@ public class KP2AKeyboard extends InputMethodService
}
}
private void updateShowKp2aMode() {
if (!keepass2android.kbbridge.KeyboardData.hasData())
{
//data no longer available. hide kp2a keyboard:
mShowKp2aKeyboard = false;
mHadKp2aData = false;
}
else
{
if (!mHadKp2aData)
{
if (keepass2android.kbbridge.KeyboardData.hasData())
{
//new data available -> show kp2a keyboard:
mShowKp2aKeyboard = true;
}
}
mHadKp2aData = keepass2android.kbbridge.KeyboardData.hasData();
}
Log.d("KP2AK", "show: " + mShowKp2aKeyboard);
}
private boolean tryKp2aAutoFill(final EditorInfo editorInfo) {
if (!mKp2aAutoFillOn)
@@ -1282,8 +1302,7 @@ public class KP2AKeyboard extends InputMethodService
{
if (mKp2aSwitchKeyboardOnSendGoDone)
{
//TODO auto switch
showInputMethodPicker();
keepass2android.kbbridge.ImeSwitcher.switchToPreviousKeyboard(this, false);
}
if (mKp2aLockOnSendGoDone)
{
@@ -1300,7 +1319,6 @@ public class KP2AKeyboard extends InputMethodService
}
private void onKp2aSwitchKeyboardPressed() {
showInputMethodPicker();
}
@@ -2223,6 +2241,7 @@ public class KP2AKeyboard extends InputMethodService
int currentKeyboardMode = mKeyboardSwitcher.getKeyboardMode();
reloadKeyboards();
mKeyboardSwitcher.makeKeyboards(true);
Log.d("KP2AK", "toggleLanguage -> setKM");
mKeyboardSwitcher.setKeyboardMode(currentKeyboardMode, 0);
initSuggest(mLanguageSwitcher.getInputLanguage());
mLanguageSwitcher.persist();
@@ -2433,7 +2452,7 @@ public class KP2AKeyboard extends InputMethodService
mKp2aEnableSimpleKeyboard = sp.getBoolean("kp2a_simple_keyboard", true);
mKp2aSwitchKeyboardOnSendGoDone = sp.getBoolean("kp2a_switch_on_sendgodone", false);
mKp2aLockOnSendGoDone = sp.getBoolean("kp2a_lock_on_sendgodone", false);
mKp2aSwitchRooted = sp.getBoolean("kp2a_switch_rooted", false);
mShowSuggestions = sp.getBoolean(PREF_SHOW_SUGGESTIONS, true);

View File

@@ -20,6 +20,7 @@ import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.InflateException;
import java.lang.ref.SoftReference;
@@ -244,6 +245,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha
public void setKeyboardMode(int mode, int imeOptions) {
Log.d("KP2AK", "Switcher.SetKeyboardMode: " + mode);
mAutoModeSwitchState = AUTO_MODE_SWITCH_STATE_ALPHA;
mPreferSymbols = mode == MODE_SYMBOLS;
if (mode == MODE_SYMBOLS) {