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

2
.gitignore vendored
View File

@ -178,3 +178,5 @@ Thumbs.db
/src/JavaFileStorageBindings/obj/ReleaseNoNet
/src/AppCompatV7Binding/bin/ReleaseNoNet
/src/java/KP2ASoftKeyboard2/java/projectzip

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="8" />
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
<application></application>
</manifest>

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) {

View File

@ -36,6 +36,15 @@
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/method" />
</service>
<activity android:name="keepass2android.softkeyboard.LatinIMESettings" android:label="@string/english_ime_settings">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
<activity android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" android:theme="@style/Base" android:name="keepass2android.PasswordActivity">
<intent-filter android:label="@string/app_name">
<action android:name="android.intent.action.VIEW" />

View File

@ -54,6 +54,12 @@
</intent-filter>
<meta-data android:name="android.view.im" android:resource="@xml/method" />
</service>
<activity android:name="keepass2android.softkeyboard.LatinIMESettings" android:label="@string/english_ime_settings">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,9 @@ namespace keepass2android
/// <summary>This intent will be broadcast once the database has been locked. Sensitive information displayed should be hidden and unloaded.</summary>
public const String DatabaseLocked = "keepass2android.database_locked";
/// <summary>This intent will be broadcast once the keyboard data has been cleared</summary>
public const String KeyboardCleared = "keepass2android.keyboard_cleared";
public const String CopyUsername = "keepass2android.copy_username";
public const String CopyPassword = "keepass2android.copy_password";
public const String CheckKeyboard = "keepass2android.check_keyboard";

View File

@ -137,7 +137,7 @@ namespace keepass2android
_notificationManager.Cancel(NotifyKeyboard);
_numElementsToWaitFor= 0;
clearKeyboard();
ClearKeyboard(true);
}
Kp2aLog.Log("Destroyed Show-Notification-Receiver.");
@ -168,7 +168,7 @@ namespace keepass2android
_notificationManager.Cancel(NotifyUsername);
_notificationManager.Cancel(NotifyKeyboard);
_numElementsToWaitFor = 0;
clearKeyboard();
bool hadKeyboardData = ClearKeyboard(false); //do not broadcast if the keyboard was changed
String entryName = entry.Strings.ReadSafe(PwDefs.TitleField);
@ -197,11 +197,13 @@ namespace keepass2android
}
}
bool hasKeyboardDataNow = false;
if (prefs.GetBoolean(GetString(Resource.String.UseKp2aKeyboard_key), Resources.GetBoolean(Resource.Boolean.UseKp2aKeyboard_default)))
{
//keyboard
if (MakeAccessibleForKeyboard(entry))
hasKeyboardDataNow = MakeAccessibleForKeyboard(entry);
if (hasKeyboardDataNow)
{
// only show notification if username is available
Notification keyboard = GetNotification(Intents.CheckKeyboard, Resource.String.available_through_keyboard, Resource.Drawable.notify_keyboard, entryName);
@ -219,6 +221,11 @@ namespace keepass2android
}
if ((!hasKeyboardDataNow) && (hadKeyboardData))
{
ClearKeyboard(true); //this clears again and then (this is the point) broadcasts that we no longer have keyboard data
}
if (_numElementsToWaitFor == 0)
{
StopSelf();
@ -268,7 +275,7 @@ namespace keepass2android
if (value.Length > 0)
{
kbdataBuilder.AddPair(GetString(resIds[i]), value);
kbdataBuilder.AddString(key, GetString(resIds[i]), value);
hasData = true;
}
i++;
@ -282,13 +289,15 @@ namespace keepass2android
if (!PwDefs.IsStandardField(key)) {
kbdataBuilder.AddPair(pair.Key, value);
kbdataBuilder.AddString(pair.Key, pair.Key, value);
hasData = true;
}
}
kbdataBuilder.Commit();
Keepass2android.Kbbridge.KeyboardData.EntryName = entry.Strings.ReadSafe(PwDefs.TitleField);
Keepass2android.Kbbridge.KeyboardData.EntryId = entry.Uuid.ToHexString();
return hasData;
#endif
@ -311,15 +320,22 @@ namespace keepass2android
if (itemId == NotifyKeyboard)
{
//keyboard notification was deleted -> clear entries in keyboard
clearKeyboard();
ClearKeyboard(true);
}
}
void clearKeyboard()
bool ClearKeyboard(bool broadcastClear)
{
#if !EXCLUDE_KEYBOARD
Keepass2android.Kbbridge.KeyboardData.AvailableFields.Clear();
Keepass2android.Kbbridge.KeyboardData.EntryName = null;
bool hadData = Keepass2android.Kbbridge.KeyboardData.EntryId != null;
Keepass2android.Kbbridge.KeyboardData.EntryId = null;
if ((hadData) && broadcastClear)
SendBroadcast(new Intent(Intents.KeyboardCleared));
return hadData;
#endif
}
@ -471,6 +487,11 @@ namespace keepass2android
string kp2aIme = service.PackageName + "/keepass2android.softkeyboard.KP2AKeyboard";
InputMethodManager imeManager = (InputMethodManager)service.ApplicationContext.GetSystemService(InputMethodService);
if (imeManager == null)
{
Toast.MakeText(service, Resource.String.not_possible_im_picker, ToastLength.Long).Show();
return;
}
if (currentIme == kp2aIme)
{
@ -490,14 +511,7 @@ namespace keepass2android
}
else
{
if (imeManager != null)
{
imeManager.ShowInputMethodPicker();
}
else
{
Toast.MakeText(service, Resource.String.not_possible_im_picker, ToastLength.Long).Show();
}
Keepass2android.Kbbridge.ImeSwitcher.SwitchToKeyboard(service, kp2aIme, false);
}
}
}