summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorE.Z. Hart <hartez@users.noreply.github.com>2017-05-04 09:44:13 -0600
committerkingces95 <kingces95@users.noreply.github.com>2017-05-04 11:44:13 -0400
commit1e1785016aef68fb36907d5b7662eda2aa403825 (patch)
tree1997401dc9f9d9b09d7ef3d80d0a6789c41a1602 /Xamarin.Forms.Platform.Android
parent34a1cc8d7323d3e83623333db4bc9966bf0703b0 (diff)
downloadxamarin-forms-1e1785016aef68fb36907d5b7662eda2aa403825.tar.gz
xamarin-forms-1e1785016aef68fb36907d5b7662eda2aa403825.tar.bz2
xamarin-forms-1e1785016aef68fb36907d5b7662eda2aa403825.zip
Remove status bar underlay view in Android AppCompat (#892)
* Remove status bar underlay and handle status bar color with theme colors * Fix layout gap when SoftInputMode is set to resize * Restore linker settings
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs96
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs6
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/Platform.cs25
3 files changed, 16 insertions, 111 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
index 8bba063b..e0bac30e 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/FormsAppCompatActivity.cs
@@ -45,8 +45,6 @@ namespace Xamarin.Forms.Platform.Android
AndroidApplicationLifecycleState _previousState;
bool _renderersAdded, _isFullScreen;
- int _statusBarHeight = -1;
- global::Android.Views.View _statusBarUnderlay;
// Override this if you want to handle the default Android behavior of restoring fragments on an application restart
protected virtual bool AllowFragmentRestore => false;
@@ -105,7 +103,10 @@ namespace Xamarin.Forms.Platform.Android
public void SetStatusBarColor(AColor color)
{
- _statusBarUnderlay.SetBackgroundColor(color);
+ if (Forms.IsLollipopOrNewer)
+ {
+ Window.SetStatusBarColor(color);
+ }
}
protected void LoadApplication(Application application)
@@ -171,7 +172,7 @@ namespace Xamarin.Forms.Platform.Android
}
else
bar = new AToolbar(this);
-
+
SetSupportActionBar(bar);
_layout = new ARelativeLayout(BaseContext);
@@ -184,7 +185,11 @@ namespace Xamarin.Forms.Platform.Android
OnStateChanged();
- AddStatusBarUnderlay();
+ if (Forms.IsLollipopOrNewer)
+ {
+ // Allow for the status bar color to be changed
+ Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
+ }
}
protected override void OnDestroy()
@@ -280,45 +285,6 @@ namespace Xamarin.Forms.Platform.Android
OnStateChanged();
}
- internal int GetStatusBarHeight()
- {
- if (_statusBarHeight >= 0)
- return _statusBarHeight;
-
- var result = 0;
- int resourceId = Resources.GetIdentifier("status_bar_height", "dimen", "android");
- if (resourceId > 0)
- result = Resources.GetDimensionPixelSize(resourceId);
- 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")
@@ -338,32 +304,6 @@ namespace Xamarin.Forms.Platform.Android
_application?.SendOnAppLinkRequestReceived(link);
}
- int GetColorPrimaryDark()
- {
- FormsAppCompatActivity context = this;
- int id = global::Android.Resource.Attribute.ColorPrimaryDark;
- using (var value = new TypedValue())
- {
- try
- {
- Resources.Theme theme = context.Theme;
- if (theme != null && theme.ResolveAttribute(id, value, true))
- {
- if (value.Type >= DataType.FirstInt && value.Type <= DataType.LastInt)
- return value.Data;
- if (value.Type == DataType.String)
- return ContextCompat.GetColor(context, value.ResourceId);
- }
- }
- catch (Exception ex)
- {
- Internals.Log.Warning("Xamarin.Forms.Platform.Android.FormsAppCompatActivity", "Error retrieving color resource: {0}", ex);
- }
-
- return -1;
- }
- }
-
void InternalSetPage(Page page)
{
if (!Forms.IsInitialized)
@@ -477,7 +417,6 @@ namespace Xamarin.Forms.Platform.Android
}
Window.SetSoftInputMode(adjust);
- SetStatusBarVisibility(adjust);
}
public override void OnWindowAttributesChanged(WindowManagerLayoutParams @params)
@@ -512,21 +451,6 @@ namespace Xamarin.Forms.Platform.Android
AppCompat.Platform.LayoutRootPage(this, Xamarin.Forms.Application.Current.MainPage, width, height);
}
- 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/AppCompat/MasterDetailPageRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs
index a1c4092e..5104800d 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs
@@ -113,23 +113,17 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
oldElement.Disappearing -= MasterDetailPageDisappearing;
}
- var statusBarHeight = 0;
- if (Forms.IsLollipopOrNewer)
- statusBarHeight = ((FormsAppCompatActivity)Context).GetStatusBarHeight();
-
if (newElement != null)
{
if (_detailLayout == null)
{
_detailLayout = new MasterDetailContainer(newElement, false, Context)
{
- TopPadding = HasAncestorNavigationPage(Element) ? 0 : statusBarHeight,
LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent)
};
_masterLayout = new MasterDetailContainer(newElement, true, Context)
{
- TopPadding = ((IMasterDetailPageController)newElement).ShouldShowSplitMode ? statusBarHeight : 0,
LayoutParameters = new LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Gravity = (int)GravityFlags.Start }
};
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs b/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
index 872bac77..be54ea0a 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/Platform.cs
@@ -8,7 +8,6 @@ using Android.Views;
using Android.Views.Animations;
using ARelativeLayout = Android.Widget.RelativeLayout;
using Xamarin.Forms.Internals;
-using Debug = System.Diagnostics.Debug;
namespace Xamarin.Forms.Platform.Android.AppCompat
{
@@ -196,7 +195,9 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
void IPlatformLayout.OnLayout(bool changed, int l, int t, int r, int b)
{
if (changed)
+ {
LayoutRootPage((FormsAppCompatActivity)_context, Page, r - l, b - t);
+ }
Android.Platform.GetRenderer(Page).UpdateLayout();
@@ -286,15 +287,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
internal static void LayoutRootPage(FormsAppCompatActivity activity, Page page, int width, int height)
{
- 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, activity.FromPixels(width), activity.FromPixels(height)));
- else
- {
- page.Layout(new Rectangle(0, activity.FromPixels(statusBarHeight), activity.FromPixels(width), activity.FromPixels(height - statusBarHeight)));
- }
+ page.Layout(new Rectangle(0, 0, activity.FromPixels(width), activity.FromPixels(height)));
}
Task PresentModal(Page modal, bool animated)
@@ -381,18 +374,12 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
protected override void OnLayout(bool changed, int l, int t, int r, int b)
{
- var activity = (FormsAppCompatActivity)Context;
- int statusBarHeight = Forms.IsLollipopOrNewer ? activity.GetStatusBarHeight() : 0;
if (changed)
{
- if (_modal is MasterDetailPage)
- _modal.Layout(new Rectangle(0, 0, activity.FromPixels(r - l), activity.FromPixels(b - t)));
- else
- {
- _modal.Layout(new Rectangle(0, activity.FromPixels(statusBarHeight), activity.FromPixels(r - l), activity.FromPixels(b - t - statusBarHeight)));
- }
+ var activity = (FormsAppCompatActivity)Context;
- _backgroundView.Layout(0, statusBarHeight, r - l, b - t);
+ _modal.Layout(new Rectangle(0, 0, activity.FromPixels(r - l), activity.FromPixels(b - t)));
+ _backgroundView.Layout(0, 0, r - l, b - t);
}
_renderer.UpdateLayout();