summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authoradrianknight89 <adrianknight89@outlook.com>2016-09-30 19:22:02 (GMT)
committerJason Smith <jason.smith@xamarin.com>2016-09-30 19:22:02 (GMT)
commit4b06bc212f0ff9b813693d6acbeaf23ccac38091 (patch)
treeaa434e3bd982a7f33c91db1b83422ce79a2208c2 /Xamarin.Forms.Platform.Android
parent88c0da5791efa3ebdc3385aadf091b574a987d80 (diff)
downloadxamarin-forms-4b06bc212f0ff9b813693d6acbeaf23ccac38091.zip
xamarin-forms-4b06bc212f0ff9b813693d6acbeaf23ccac38091.tar.gz
xamarin-forms-4b06bc212f0ff9b813693d6acbeaf23ccac38091.tar.bz2
AppCompat should now be able to set title bar visibility programmatic… (#350)
* AppCompat should now be able to set title bar visibility programmatically * coding style changes * making sure page layout runs only on fullscreen flag changes
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs34
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/Platform.cs12
-rw-r--r--Xamarin.Forms.Platform.Android/Forms.cs21
3 files changed, 59 insertions, 8 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
index ab2fb61..83a2950 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
@@ -41,7 +41,7 @@ namespace Xamarin.Forms.Platform.Android
AndroidApplicationLifecycleState _previousState;
- bool _renderersAdded;
+ bool _renderersAdded, _isFullScreen;
int _statusBarHeight = -1;
global::Android.Views.View _statusBarUnderlay;
@@ -468,6 +468,38 @@ namespace Xamarin.Forms.Platform.Android
SetStatusBarVisibility(adjust);
}
+ public override void OnWindowAttributesChanged(WindowManagerLayoutParams @params)
+ {
+ base.OnWindowAttributesChanged(@params);
+
+ if (Xamarin.Forms.Application.Current == null || Xamarin.Forms.Application.Current.MainPage == null)
+ return;
+
+ if (@params.Flags.HasFlag(WindowManagerFlags.Fullscreen))
+ {
+ if (Forms.TitleBarVisibility != AndroidTitleBarVisibility.Never)
+ Forms.TitleBarVisibility = AndroidTitleBarVisibility.Never;
+
+ if (_isFullScreen)
+ return;
+ }
+ else
+ {
+ if (Forms.TitleBarVisibility != AndroidTitleBarVisibility.Default)
+ Forms.TitleBarVisibility = AndroidTitleBarVisibility.Default;
+
+ if (!_isFullScreen)
+ return;
+ }
+
+ _isFullScreen = !_isFullScreen;
+
+ var displayMetrics = Resources.DisplayMetrics;
+ var width = displayMetrics.WidthPixels;
+ var height = displayMetrics.HeightPixels;
+ AppCompat.Platform.LayoutRootPage(this, Xamarin.Forms.Application.Current.MainPage, width, height);
+ }
+
void SetStatusBarVisibility(SoftInput mode)
{
if (!Forms.IsLollipopOrNewer)
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs b/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
index f656ff8..eb23c4d 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
@@ -193,7 +193,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
void IPlatformLayout.OnLayout(bool changed, int l, int t, int r, int b)
{
if (changed)
- LayoutRootPage(Page, r - l, b - t);
+ LayoutRootPage((FormsAppCompatActivity)_context, Page, r - l, b - t);
Android.Platform.GetRenderer(Page).UpdateLayout();
@@ -251,7 +251,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
Android.Platform.SetRenderer(page, renderView);
if (layout)
- LayoutRootPage(page, _renderer.Width, _renderer.Height);
+ LayoutRootPage((FormsAppCompatActivity)_context, page, _renderer.Width, _renderer.Height);
_renderer.AddView(renderView.ViewGroup);
}
@@ -267,16 +267,16 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
return handled;
}
- void LayoutRootPage(Page page, int width, int height)
+ internal static void LayoutRootPage(FormsAppCompatActivity activity, Page page, int width, int height)
{
- var activity = (FormsAppCompatActivity)_context;
int statusBarHeight = Forms.IsLollipopOrNewer ? activity.GetStatusBarHeight() : 0;
+ statusBarHeight = activity.Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen) || Forms.TitleBarVisibility == AndroidTitleBarVisibility.Never ? 0 : statusBarHeight;
if (page is MasterDetailPage)
- page.Layout(new Rectangle(0, 0, _context.FromPixels(width), _context.FromPixels(height)));
+ page.Layout(new Rectangle(0, 0, activity.FromPixels(width), activity.FromPixels(height)));
else
{
- page.Layout(new Rectangle(0, _context.FromPixels(statusBarHeight), _context.FromPixels(width), _context.FromPixels(height - statusBarHeight)));
+ page.Layout(new Rectangle(0, activity.FromPixels(statusBarHeight), activity.FromPixels(width), activity.FromPixels(height - statusBarHeight)));
}
}
diff --git a/Xamarin.Forms.Platform.Android/Forms.cs b/Xamarin.Forms.Platform.Android/Forms.cs
index 6f3346f..fd74287 100644
--- a/Xamarin.Forms.Platform.Android/Forms.cs
+++ b/Xamarin.Forms.Platform.Android/Forms.cs
@@ -15,6 +15,7 @@ using Android.Content;
using Android.Content.Res;
using Android.OS;
using Android.Util;
+using Android.Views;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.Android;
using Resource = Android.Resource;
@@ -61,7 +62,7 @@ namespace Xamarin.Forms
}
}
- internal static AndroidTitleBarVisibility TitleBarVisibility { get; private set; }
+ internal static AndroidTitleBarVisibility TitleBarVisibility { get; set; }
// Provide backwards compat for Forms.Init and AndroidActivity
// Why is bundle a param if never used?
@@ -76,9 +77,27 @@ namespace Xamarin.Forms
SetupInit(activity, resourceAssembly);
}
+ /// <summary>
+ /// Sets title bar visibility programmatically. Must be called after Xamarin.Forms.Forms.Init() method
+ /// </summary>
+ /// <param name="visibility">Title bar visibility enum</param>
public static void SetTitleBarVisibility(AndroidTitleBarVisibility visibility)
{
+ if((Activity)Context == null)
+ throw new NullReferenceException("Must be called after Xamarin.Forms.Forms.Init() method");
+
TitleBarVisibility = visibility;
+
+ if (TitleBarVisibility == AndroidTitleBarVisibility.Never)
+ {
+ if (!((Activity)Context).Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen))
+ ((Activity)Context).Window.AddFlags(WindowManagerFlags.Fullscreen);
+ }
+ else
+ {
+ if (((Activity)Context).Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen))
+ ((Activity)Context).Window.ClearFlags(WindowManagerFlags.Fullscreen);
+ }
}
public static event EventHandler<ViewInitializedEventArgs> ViewInitialized;