summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorSamantha Houts <samantha@teamredwall.com>2016-08-30 17:46:14 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-08-30 17:46:14 (GMT)
commit5e553f6195e66e48688b8ab324f1bab1e9251f0a (patch)
treef8843e5e9e8afe89a05a1cc91c3b7fa05588bac7 /Xamarin.Forms.Platform.Android
parentf551654b1cfe654c579ca50978445e7cb93f287d (diff)
downloadxamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.zip
xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.gz
xamarin-forms-5e553f6195e66e48688b8ab324f1bab1e9251f0a.tar.bz2
Platform Specifics (#301)
* Playing around with how the platform specifics interfaces etc. might work * Sample implementation of iOS navigation translucency * Very slightly reduced code * Better vendor stuff * Drop single-implemenation interfaces * Generics on NavigationPage * On-demand vendor stuff * Remove functionally duplicate classes and make ControlGallery work again * Namespace all the things. XAML test. * Can use Effect to attach platform specific * Attach Effect on PropertyChanging for XAML support! * Rename IConfigPlatform interfaces for readability * Some renaming to match the documents * Split class files * Clear out test-only code * Re-namespace * Added On method to rendered Elements * Allow for removal of platform suffix, convenience methods on specific platforms * Creating a gallery page for specifics * Add rudimentary Platform Specifics gallery; make CollapseStyle work on UWP; Add CollapsedPaneWidth specific property * Toolbar now working with both collapse styles * MDP now displaying Content title; toolbar routing around title * Add a gallery for the iOS NavigationPage stuff * Add Navigation Page as detail page to verify it works with new Toolbar options * Make titlebar/toolbar background colors consistent * ToolbarPlacement now working on NavigationPage * Toolbar Placement working for tabbed and nav pages * Fix bug where phone doesn't get default toolbar placement on start * [Core] Add PS WindowSoftInputModeAdjust [Core] Make Application extendable * Toolbar placement now working on Nav, Tabbed, and Master pages on desktop/phone Remove unnecessary style indirection Fix build errors * [A] Add PlatformConfigurationExtensions * SetSoftInputMode test page * [A] SetSoftInputMode Known issue: Status bar color does not work in AdjustResize mode * [Core] Add PS Blur * [iOS] Configure renderer for blur * Add test page * Move to blur VisualElement for broader support * Move test pages to gallery * Update docs * Use lazy initializer for PlatformConfigurationRegistry
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs96
-rw-r--r--Xamarin.Forms.Platform.Android/FormsApplicationActivity.cs27
-rw-r--r--Xamarin.Forms.Platform.Android/PlatformConfigurationExtensions.cs11
-rw-r--r--Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj1
4 files changed, 110 insertions, 25 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
index b6736df..b200e27 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
@@ -14,6 +14,7 @@ using Android.Util;
using Android.Views;
using Android.Widget;
using Xamarin.Forms.Platform.Android.AppCompat;
+using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using AToolbar = Android.Support.V7.Widget.Toolbar;
using AColor = Android.Graphics.Color;
using AlertDialog = Android.Support.V7.App.AlertDialog;
@@ -142,7 +143,6 @@ namespace Xamarin.Forms.Platform.Android
callback(resultCode, data);
}
-
protected override void OnCreate(Bundle savedInstanceState)
{
if (!AllowFragmentRestore)
@@ -167,7 +167,7 @@ namespace Xamarin.Forms.Platform.Android
SetSupportActionBar(bar);
- Window.SetSoftInputMode(SoftInput.AdjustPan);
+ SetSoftInputMode();
_layout = new ARelativeLayout(BaseContext);
SetContentView(_layout);
@@ -179,29 +179,7 @@ namespace Xamarin.Forms.Platform.Android
OnStateChanged();
- _statusBarUnderlay = new global::Android.Views.View(this);
- var layoutParameters = new ARelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, GetStatusBarHeight()) { AlignWithParent = true };
- layoutParameters.AddRule(LayoutRules.AlignTop);
- _statusBarUnderlay.LayoutParameters = layoutParameters;
- _layout.AddView(_statusBarUnderlay);
-
- if (Forms.IsLollipopOrNewer)
- {
- Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable);
- Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
- Window.SetStatusBarColor(AColor.Transparent);
-
- int primaryColorDark = GetColorPrimaryDark();
-
- if (primaryColorDark != 0)
- {
- int r = AColor.GetRedComponent(primaryColorDark);
- int g = AColor.GetGreenComponent(primaryColorDark);
- int b = AColor.GetBlueComponent(primaryColorDark);
- int a = AColor.GetAlphaComponent(primaryColorDark);
- SetStatusBarColor(AColor.Argb(a, r, g, b));
- }
- }
+ AddStatusBarUnderlay();
}
protected override void OnDestroy()
@@ -302,10 +280,39 @@ namespace Xamarin.Forms.Platform.Android
return _statusBarHeight = result;
}
+ void AddStatusBarUnderlay()
+ {
+ _statusBarUnderlay = new global::Android.Views.View(this);
+
+ var layoutParameters = new ARelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, GetStatusBarHeight()) { AlignWithParent = true };
+ layoutParameters.AddRule(LayoutRules.AlignTop);
+ _statusBarUnderlay.LayoutParameters = layoutParameters;
+ _layout.AddView(_statusBarUnderlay);
+
+ if (Forms.IsLollipopOrNewer)
+ {
+ Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
+ Window.SetStatusBarColor(AColor.Transparent);
+
+ int primaryColorDark = GetColorPrimaryDark();
+
+ if (primaryColorDark != 0)
+ {
+ int r = AColor.GetRedComponent(primaryColorDark);
+ int g = AColor.GetGreenComponent(primaryColorDark);
+ int b = AColor.GetBlueComponent(primaryColorDark);
+ int a = AColor.GetAlphaComponent(primaryColorDark);
+ SetStatusBarColor(AColor.Argb(a, r, g, b));
+ }
+ }
+ }
+
void AppOnPropertyChanged(object sender, PropertyChangedEventArgs args)
{
if (args.PropertyName == "MainPage")
InternalSetPage(_application.MainPage);
+ if (args.PropertyName == PlatformConfiguration.AndroidSpecific.Application.WindowSoftInputModeAdjustProperty.PropertyName)
+ SetSoftInputMode();
}
void CheckForAppLink(Intent intent)
@@ -441,6 +448,45 @@ namespace Xamarin.Forms.Platform.Android
InternalSetPage(_application.MainPage);
}
+ void SetSoftInputMode()
+ {
+ SoftInput adjust = SoftInput.AdjustPan;
+
+ if (Xamarin.Forms.Application.Current != null)
+ {
+ var elementValue = Xamarin.Forms.Application.Current.OnThisPlatform().GetWindowSoftInputModeAdjust();
+ switch (elementValue)
+ {
+ default:
+ case WindowSoftInputModeAdjust.Pan:
+ adjust = SoftInput.AdjustPan;
+ break;
+
+ case WindowSoftInputModeAdjust.Resize:
+ adjust = SoftInput.AdjustResize;
+ break;
+ }
+ }
+
+ Window.SetSoftInputMode(adjust);
+ SetStatusBarVisibility(adjust);
+ }
+
+ void SetStatusBarVisibility(SoftInput mode)
+ {
+ if (!Forms.IsLollipopOrNewer)
+ return;
+
+ if (mode == SoftInput.AdjustResize)
+ {
+ Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.Immersive);
+ }
+ else
+ Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(SystemUiFlags.LayoutFullscreen | SystemUiFlags.LayoutStable);
+
+ _layout?.Invalidate();
+ }
+
void UpdateProgressBarVisibility(bool isBusy)
{
if (!Forms.SupportsProgress)
diff --git a/Xamarin.Forms.Platform.Android/FormsApplicationActivity.cs b/Xamarin.Forms.Platform.Android/FormsApplicationActivity.cs
index ca862d1..adb27f7 100644
--- a/Xamarin.Forms.Platform.Android/FormsApplicationActivity.cs
+++ b/Xamarin.Forms.Platform.Android/FormsApplicationActivity.cs
@@ -7,6 +7,7 @@ using Android.Content.Res;
using Android.OS;
using Android.Views;
using Android.Widget;
+using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace Xamarin.Forms.Platform.Android
{
@@ -126,6 +127,8 @@ namespace Xamarin.Forms.Platform.Android
base.OnCreate(savedInstanceState);
+ SetSoftInputMode();
+
_layout = new LinearLayout(BaseContext);
SetContentView(_layout);
@@ -221,6 +224,8 @@ namespace Xamarin.Forms.Platform.Android
{
if (args.PropertyName == "MainPage")
InternalSetPage(_application.MainPage);
+ if (args.PropertyName == PlatformConfiguration.AndroidSpecific.Application.WindowSoftInputModeAdjustProperty.PropertyName)
+ SetSoftInputMode();
}
void InternalSetPage(Page page)
@@ -307,6 +312,28 @@ namespace Xamarin.Forms.Platform.Android
InternalSetPage(_application.MainPage);
}
+ void SetSoftInputMode()
+ {
+ SoftInput adjust = SoftInput.AdjustPan;
+
+ if (Xamarin.Forms.Application.Current != null)
+ {
+ var elementValue = Xamarin.Forms.Application.Current.OnThisPlatform().GetWindowSoftInputModeAdjust();
+ switch (elementValue)
+ {
+ default:
+ case WindowSoftInputModeAdjust.Pan:
+ adjust = SoftInput.AdjustPan;
+ break;
+ case WindowSoftInputModeAdjust.Resize:
+ adjust = SoftInput.AdjustResize;
+ break;
+ }
+ }
+
+ Window.SetSoftInputMode(adjust);
+ }
+
void UpdateProgressBarVisibility(bool isBusy)
{
if (!Forms.SupportsProgress)
diff --git a/Xamarin.Forms.Platform.Android/PlatformConfigurationExtensions.cs b/Xamarin.Forms.Platform.Android/PlatformConfigurationExtensions.cs
new file mode 100644
index 0000000..49db473
--- /dev/null
+++ b/Xamarin.Forms.Platform.Android/PlatformConfigurationExtensions.cs
@@ -0,0 +1,11 @@
+namespace Xamarin.Forms.Platform.Android
+{
+ public static class PlatformConfigurationExtensions
+ {
+ public static IPlatformElementConfiguration<PlatformConfiguration.Android, T> OnThisPlatform<T>(this T element)
+ where T : Element, IElementConfiguration<T>
+ {
+ return (element).On<PlatformConfiguration.Android>();
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
index 3536739..33bfa03 100644
--- a/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
+++ b/Xamarin.Forms.Platform.Android/Xamarin.Forms.Platform.Android.csproj
@@ -147,6 +147,7 @@
<Compile Include="OnMeasureDelegate.cs" />
<Compile Include="PanGestureHandler.cs" />
<Compile Include="PinchGestureHandler.cs" />
+ <Compile Include="PlatformConfigurationExtensions.cs" />
<Compile Include="PlatformEffect.cs" />
<Compile Include="LayoutExtensions.cs" />
<Compile Include="Renderers\AHorizontalScrollView.cs" />