From 7c292ebd57af46892dba7ec816f84c2b3cfe64e6 Mon Sep 17 00:00:00 2001 From: Philipp Crocoll Date: Wed, 22 May 2013 06:37:59 +0200 Subject: [PATCH] automatically bring up keyboard selection --- .../Resources/Resource.designer.cs | 21 +++- src/keepass2android/EntryActivity.cs | 1 + .../Resources/Resource.designer.cs | 76 ++++++++++++++- .../services/CopyToClipboardService.cs | 96 +++++++++++-------- 4 files changed, 146 insertions(+), 48 deletions(-) diff --git a/src/KeePassLib2Android/Resources/Resource.designer.cs b/src/KeePassLib2Android/Resources/Resource.designer.cs index ee0b9514..26dea8fd 100644 --- a/src/KeePassLib2Android/Resources/Resource.designer.cs +++ b/src/KeePassLib2Android/Resources/Resource.designer.cs @@ -2,26 +2,36 @@ //------------------------------------------------------------------------------ // // Dieser Code wurde von einem Tool generiert. -// Laufzeitversion:4.0.30319.296 +// Laufzeitversion:4.0.30319.18033 // // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn // der Code erneut generiert wird. // //------------------------------------------------------------------------------ -[assembly: Android.Runtime.ResourceDesignerAttribute("KeePassLib2Android.Resource", IsApplication=false)] +[assembly: global::Android.Runtime.ResourceDesignerAttribute("KeePassLib2Android.Resource", IsApplication=false)] namespace KeePassLib2Android { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Novell.MonoDroid.Build.Tasks", "1.0.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] public partial class Resource { + static Resource() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + public partial class Attribute { + static Attribute() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Attribute() { } @@ -33,6 +43,11 @@ namespace KeePassLib2Android // aapt resource value: 0x7f020000 public static int library_name = 2130837504; + static String() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private String() { } diff --git a/src/keepass2android/EntryActivity.cs b/src/keepass2android/EntryActivity.cs index 561eb7ac..cfd06273 100644 --- a/src/keepass2android/EntryActivity.cs +++ b/src/keepass2android/EntryActivity.cs @@ -147,6 +147,7 @@ namespace keepass2android Intent showNotIntent = new Intent(this, typeof(CopyToClipboardService)); Intent.SetAction(Intents.SHOW_NOTIFICATION); showNotIntent.PutExtra(KEY_ENTRY, mEntry.Uuid.ToHexString()); + showNotIntent.PutExtra(KEY_CLOSE_AFTER_CREATE, closeAfterCreate); StartService(showNotIntent); diff --git a/src/keepass2android/Resources/Resource.designer.cs b/src/keepass2android/Resources/Resource.designer.cs index 4f450f46..8bf958a7 100644 --- a/src/keepass2android/Resources/Resource.designer.cs +++ b/src/keepass2android/Resources/Resource.designer.cs @@ -2,23 +2,28 @@ //------------------------------------------------------------------------------ // // Dieser Code wurde von einem Tool generiert. -// Laufzeitversion:4.0.30319.296 +// Laufzeitversion:4.0.30319.18033 // // Änderungen an dieser Datei können falsches Verhalten verursachen und gehen verloren, wenn // der Code erneut generiert wird. // //------------------------------------------------------------------------------ -[assembly: Android.Runtime.ResourceDesignerAttribute("keepass2android.Resource", IsApplication=true)] +[assembly: global::Android.Runtime.ResourceDesignerAttribute("keepass2android.Resource", IsApplication=true)] namespace keepass2android { - [System.CodeDom.Compiler.GeneratedCodeAttribute("Novell.MonoDroid.Build.Tasks", "1.0.0.0")] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")] public partial class Resource { + static Resource() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + public static void UpdateIdValues() { KeePassLib2Android.Resource.String.library_name = keepass2android.Resource.String.library_name; @@ -39,6 +44,11 @@ namespace keepass2android // aapt resource value: 0x7f040003 public const int anim_leave_back = 2130968579; + static Animation() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Animation() { } @@ -62,6 +72,11 @@ namespace keepass2android // aapt resource value: 0x7f0a0001 public const int list_size_values = 2131361793; + static Array() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Array() { } @@ -70,6 +85,11 @@ namespace keepass2android public partial class Attribute { + static Attribute() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Attribute() { } @@ -102,6 +122,11 @@ namespace keepass2android // aapt resource value: 0x7f090002 public const int sort_default = 2131296258; + static Boolean() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Boolean() { } @@ -152,6 +177,11 @@ namespace keepass2android // aapt resource value: 0x7f06000c public const int light_gray = 2131099660; + static Color() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Color() { } @@ -169,6 +199,11 @@ namespace keepass2android // aapt resource value: 0x7f070000 public const int key_height = 2131165184; + static Dimension() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Dimension() { } @@ -504,6 +539,11 @@ namespace keepass2android // aapt resource value: 0x7f02006c public const int YellowButton = 2130837612; + static Drawable() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Drawable() { } @@ -1010,6 +1050,11 @@ namespace keepass2android // aapt resource value: 0x7f0d0002 public const int version_title = 2131558402; + static Id() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Id() { } @@ -1123,6 +1168,11 @@ namespace keepass2android // aapt resource value: 0x7f030022 public const int url_credentials = 2130903074; + static Layout() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Layout() { } @@ -1146,6 +1196,11 @@ namespace keepass2android // aapt resource value: 0x7f0c0004 public const int password = 2131492868; + static Menu() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Menu() { } @@ -2012,6 +2067,11 @@ namespace keepass2android // aapt resource value: 0x7f0800b1 public const int yes = 2131230897; + static String() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private String() { } @@ -2101,6 +2161,11 @@ namespace keepass2android // aapt resource value: 0x7f0b000c public const int WhiteOnDarkSmall = 2131427340; + static Style() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Style() { } @@ -2127,6 +2192,11 @@ namespace keepass2android // aapt resource value: 0x7f050005 public const int symbols_shift = 2131034117; + static Xml() + { + global::Android.Runtime.ResourceIdManager.UpdateIdValues(); + } + private Xml() { } diff --git a/src/keepass2android/services/CopyToClipboardService.cs b/src/keepass2android/services/CopyToClipboardService.cs index 05f16b97..70312691 100644 --- a/src/keepass2android/services/CopyToClipboardService.cs +++ b/src/keepass2android/services/CopyToClipboardService.cs @@ -74,18 +74,12 @@ namespace keepass2android Android.Util.Log.Debug("DEBUG","Received intent to provide access to entry"); String uuidBytes = intent.GetStringExtra(EntryActivity.KEY_ENTRY); + bool closeAfterCreate = intent.GetBooleanExtra(EntryActivity.KEY_CLOSE_AFTER_CREATE, false); PwUuid entryId = PwUuid.Zero; if (uuidBytes != null) entryId = new KeePassLib.PwUuid(MemUtil.HexStringToByteArray(uuidBytes)); - /*Android.Util.Log.Debug("DEBUG","Uuid="+uuidBytes); - - - foreach (PwUuid key in App.getDB().entries.Keys) - { - Android.Util.Log.Debug("DEBUG",key.ToHexString() + " -> " + App.getDB().entries[key].Uuid.ToHexString()); - }*/ PwEntry entry; try { @@ -98,7 +92,7 @@ namespace keepass2android return StartCommandResult.NotSticky; } - displayAccessNotifications(entry); + displayAccessNotifications(entry, closeAfterCreate); return StartCommandResult.RedeliverIntent; @@ -143,7 +137,7 @@ namespace keepass2android return PendingIntent.GetBroadcast(this, requestCode, intent, PendingIntentFlags.CancelCurrent); } - public void displayAccessNotifications(PwEntry entry) + public void displayAccessNotifications(PwEntry entry, bool closeAfterCreate) { // Notification Manager mNM = (NotificationManager)GetSystemService(NotificationService); @@ -190,6 +184,13 @@ namespace keepass2android keyboard.DeleteIntent = createDeleteIntent(NOTIFY_KEYBOARD); mNumElementsToWaitFor++; mNM.Notify(NOTIFY_KEYBOARD, keyboard); + + //if the app is about to be closed again (e.g. after searching for a URL and returning to the browser: + // automatically bring up the Keyboard selection dialog + if (closeAfterCreate) + { + ActivateKp2aKeyboard(this); + } } } @@ -347,7 +348,6 @@ namespace keepass2android - class CopyToClipboardBroadcastReceiver: BroadcastReceiver { CopyToClipboardService mService; @@ -379,39 +379,10 @@ namespace keepass2android } } else if (action.Equals(Intents.CHECK_KEYBOARD)) { - string currentIme = Android.Provider.Settings.Secure.GetString( - mService.ContentResolver, - Android.Provider.Settings.Secure.DefaultInputMethod); - - string kp2aIme = mService.PackageName+"/keepass2android.softkeyboard.KP2AKeyboard"; - - InputMethodManager imeManager = (InputMethodManager)mService.ApplicationContext.GetSystemService(Context.InputMethodService); - - if (currentIme == kp2aIme) - { - imeManager.ToggleSoftInput(ShowSoftInputFlags.Explicit, HideSoftInputFlags.None); - return; - } - - IList inputMethodProperties = imeManager.EnabledInputMethodList; - - if (!inputMethodProperties.Any(imi => imi.Id.Equals(kp2aIme))) - { - Toast.MakeText(mService, Resource.String.please_activate_keyboard, ToastLength.Long).Show(); - Intent settingsIntent = new Intent(Android.Provider.Settings.ActionInputMethodSettings); - settingsIntent.SetFlags(ActivityFlags.NewTask); - mService.StartActivity(settingsIntent); - } - else - { - if (imeManager != null) { - imeManager.ShowInputMethodPicker(); - } else { - Toast.MakeText(mService, Resource.String.not_possible_im_picker, ToastLength.Long).Show(); - } - } + CopyToClipboardService.ActivateKp2aKeyboard(mService); } } + }; class NotificationDeletedBroadcastReceiver: BroadcastReceiver @@ -432,6 +403,47 @@ namespace keepass2android } #endregion } - } + + internal static void ActivateKp2aKeyboard(CopyToClipboardService service) + { + string currentIme = Android.Provider.Settings.Secure.GetString( + service.ContentResolver, + Android.Provider.Settings.Secure.DefaultInputMethod); + + string kp2aIme = service.PackageName + "/keepass2android.softkeyboard.KP2AKeyboard"; + + InputMethodManager imeManager = (InputMethodManager)service.ApplicationContext.GetSystemService(Context.InputMethodService); + + if (currentIme == kp2aIme) + { + imeManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.None); + } + else + { + + IList inputMethodProperties = imeManager.EnabledInputMethodList; + + if (!inputMethodProperties.Any(imi => imi.Id.Equals(kp2aIme))) + { + Toast.MakeText(service, Resource.String.please_activate_keyboard, ToastLength.Long).Show(); + Intent settingsIntent = new Intent(Android.Provider.Settings.ActionInputMethodSettings); + settingsIntent.SetFlags(ActivityFlags.NewTask); + service.StartActivity(settingsIntent); + } + else + { + if (imeManager != null) + { + imeManager.ShowInputMethodPicker(); + } + else + { + Toast.MakeText(service, Resource.String.not_possible_im_picker, ToastLength.Long).Show(); + } + } + } + } + + } }