summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorAlan McGovern <alanmcgovern@users.noreply.github.com>2016-11-03 11:08:30 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-11-03 11:08:30 (GMT)
commita2fae62d8384f78c1b5f0ba3dc088000946479bc (patch)
tree45554567b06d192e98692a4294827c198f6f0126 /Xamarin.Forms.Platform.Android
parent7afe69e932543e96fd9557f8a6d4bf75b36b4489 (diff)
downloadxamarin-forms-a2fae62d8384f78c1b5f0ba3dc088000946479bc.zip
xamarin-forms-a2fae62d8384f78c1b5f0ba3dc088000946479bc.tar.gz
xamarin-forms-a2fae62d8384f78c1b5f0ba3dc088000946479bc.tar.bz2
Update ContextExtensions.cs (#502)
* [Android] Handle missing android services gracefully When rendering inside layoutlib, like the Android Designer does, we will not have access to the normal android services. * [Android] Handle null InputManagers here too Just in case this codepath is hit at some point during the android designer's rendering codepath.
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/ContextExtensions.cs6
-rw-r--r--Xamarin.Forms.Platform.Android/KeyboardManager.cs8
2 files changed, 9 insertions, 5 deletions
diff --git a/Xamarin.Forms.Platform.Android/ContextExtensions.cs b/Xamarin.Forms.Platform.Android/ContextExtensions.cs
index b3a219f..d3b0217 100644
--- a/Xamarin.Forms.Platform.Android/ContextExtensions.cs
+++ b/Xamarin.Forms.Platform.Android/ContextExtensions.cs
@@ -21,7 +21,9 @@ namespace Xamarin.Forms.Platform.Android
public static void HideKeyboard(this Context self, global::Android.Views.View view)
{
var service = (InputMethodManager)self.GetSystemService(Context.InputMethodService);
- service.HideSoftInputFromWindow(view.WindowToken, 0);
+ // Can happen in the context of the Android Designer
+ if (service != null)
+ service.HideSoftInputFromWindow(view.WindowToken, 0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -55,4 +57,4 @@ namespace Xamarin.Forms.Platform.Android
s_displayDensity = metrics.Density;
}
}
-} \ No newline at end of file
+}
diff --git a/Xamarin.Forms.Platform.Android/KeyboardManager.cs b/Xamarin.Forms.Platform.Android/KeyboardManager.cs
index eb89731..e89ed9e 100644
--- a/Xamarin.Forms.Platform.Android/KeyboardManager.cs
+++ b/Xamarin.Forms.Platform.Android/KeyboardManager.cs
@@ -23,7 +23,7 @@ namespace Xamarin.Forms.Platform.Android
throw new ArgumentException("inputView should be of type EditText, SearchView, or TextView");
IBinder windowToken = inputView.WindowToken;
- if (windowToken != null)
+ if (windowToken != null && inputMethodManager != null)
inputMethodManager.HideSoftInputFromWindow(windowToken, HideSoftInputFlags.None);
}
}
@@ -40,8 +40,10 @@ namespace Xamarin.Forms.Platform.Android
{
if (inputView is EditText || inputView is TextView || inputView is SearchView)
{
- inputMethodManager.ShowSoftInput(inputView, ShowFlags.Forced);
- inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
+ if (inputMethodManager != null) {
+ inputMethodManager.ShowSoftInput(inputView, ShowFlags.Forced);
+ inputMethodManager.ToggleSoftInput(ShowFlags.Forced, HideSoftInputFlags.ImplicitOnly);
+ }
}
else
throw new ArgumentException("inputView should be of type EditText, SearchView, or TextView");