Skip to content

Commit

Permalink
Merge pull request #19 from muak/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
muak authored Jul 20, 2020
2 parents 7ef8672 + 6643087 commit 7640ab0
Show file tree
Hide file tree
Showing 21 changed files with 438 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<DocumentationFile>bin\Release\netstandard2.0\AiForms.Dialogs.Abstractions.xml</DocumentationFile>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Class1.cs" />
Expand Down
28 changes: 28 additions & 0 deletions AiForms.Dialogs.Abstractions/ExtraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ public float CornerRadius
set { SetValue(CornerRadiusProperty, value); }
}

public static BindableProperty BorderColorProperty = BindableProperty.Create(
nameof(BorderColor),
typeof(Color),
typeof(ExtraView),
default(Color),
defaultBindingMode: BindingMode.OneWay
);

public Color BorderColor
{
get { return (Color)GetValue(BorderColorProperty); }
set { SetValue(BorderColorProperty, value); }
}

public static BindableProperty BorderWidthProperty = BindableProperty.Create(
nameof(BorderWidth),
typeof(double),
typeof(ExtraView),
default(double),
defaultBindingMode: BindingMode.OneWay
);

public double BorderWidth
{
get { return (double)GetValue(BorderWidthProperty); }
set { SetValue(BorderWidthProperty, value); }
}

public virtual void RunPresentationAnimation() {}
public virtual void RunDismissalAnimation() {}
public virtual void Destroy() {}
Expand Down
6 changes: 5 additions & 1 deletion AiForms.Dialogs.Android/AiForms.Dialogs.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
<JavaMaximumHeapSize></JavaMaximumHeapSize>
<AndroidEnableSGenConcurrent>false</AndroidEnableSGenConcurrent>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -37,6 +40,7 @@
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
<JavaMaximumHeapSize></JavaMaximumHeapSize>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand Down Expand Up @@ -161,7 +165,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AiForms.Dialogs.Abstractions\AiForms.Dialogs.Abstractions.csproj">
<Project>{0BDF7090-FE73-49E6-B554-B2DA240768BB}</Project>
<Project>{08703C66-119B-47EC-9407-134D36D85C81}</Project>
<Name>AiForms.Dialogs.Abstractions</Name>
</ProjectReference>
</ItemGroup>
Expand Down
137 changes: 121 additions & 16 deletions AiForms.Dialogs.Android/Dialogs.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using System.Drawing;
using AiForms.Dialogs.Abstractions;
using Android.App;
using Android.Content;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Support.V7.Widget;
using Android.Views;
using Android.Widget;
using Xamarin.Forms.Platform.Android;
Expand All @@ -22,6 +24,33 @@ public static void Init(Context context)

internal static FragmentManager FragmentManager => (Context as Activity)?.FragmentManager;

static int? _statusbarHeight;
internal static int StatusBarHeight => _statusbarHeight ??=
Context.Resources.GetDimensionPixelSize(Context.Resources.GetIdentifier("status_bar_height", "dimen", "android"));

static int? _navigationBarHeight;
internal static int NavigationBarHeight => _navigationBarHeight ??=
Context.Resources.GetDimensionPixelSize(Context.Resources.GetIdentifier("navigation_bar_height", "dimen", "android"));

static Size? _contentSize;
internal static Size ContentSize
{
get
{
if(_contentSize != null)
{
return _contentSize.Value;
}

Rect contentSize = new Rect();
(Context as Activity)?.Window.DecorView.GetWindowVisibleDisplayFrame(contentSize);
_contentSize = new Size(contentSize.Width(), contentSize.Height());
return _contentSize.Value;
}
}

internal static int DisplayHeight => StatusBarHeight + ContentSize.Height;

internal static IVisualElementRenderer CreateNativeView(XF.View view)
{
IVisualElementRenderer renderer = Platform.GetRenderer(view);
Expand Down Expand Up @@ -49,20 +78,49 @@ internal static Android.App.Dialog CreateFullScreenTransparentDialog(View conten

internal static Xamarin.Forms.Size Measure(ExtraView view)
{
var display = (Context as Activity)?.WindowManager.DefaultDisplay;
var dWidth = Context.FromPixels(ContentSize.Width);
var dHeight = Context.FromPixels(ContentSize.Height);

Point size = new Point();
display.GetSize(size);
double fWidth = dWidth;
if (view.ProportionalWidth >= 0)
{
fWidth = dWidth * view.ProportionalWidth;
}
else if (view.HorizontalLayoutAlignment == XF.LayoutAlignment.Fill)
{
fWidth = dWidth;
}
else if (view.WidthRequest == -1)
{
fWidth = double.PositiveInfinity;
}
else if (view.WidthRequest >= 0)
{
fWidth = view.WidthRequest;
}

var dWidth = Context.FromPixels(size.X);
var dHeight = Context.FromPixels(size.Y);
double fHeight = dHeight;
if (view.ProportionalHeight >= 0)
{
fHeight = dHeight * view.ProportionalHeight;
}
else if (view.VerticalLayoutAlignment == XF.LayoutAlignment.Fill)
{
fHeight = dHeight;
}
else if (view.HeightRequest == -1)
{
fHeight = double.PositiveInfinity;
}
else if (view.HeightRequest >= 0)
{
fHeight = view.HeightRequest;
}

var fWidth = view.ProportionalWidth >= 0 ? dWidth * view.ProportionalWidth : dWidth;
var fHeight = view.ProportionalHeight >= 0 ? dHeight * view.ProportionalHeight : dHeight;

if (view.ProportionalWidth < 0 || view.ProportionalHeight < 0)
{
var sizeRequest = view.Measure(fWidth, fHeight);
var sizeRequest = view.Measure(fWidth, fHeight, XF.MeasureFlags.IncludeMargins);

var reqWidth = view.ProportionalWidth >= 0 ? fWidth : sizeRequest.Request.Width;
var reqHeight = view.ProportionalHeight >= 0 ? fHeight : sizeRequest.Request.Height;
Expand Down Expand Up @@ -104,6 +162,60 @@ internal static void SetOffsetMargin(FrameLayout.LayoutParams layoutParams, int
layoutParams.TopMargin = (int)Context.ToPixels(offsetY);
}

internal static ViewGroup SetViewAppearance(ExtraView formsView,ViewGroup nativeView)
{
if (formsView.CornerRadius > 0 && formsView.BorderWidth > 0)
{
var wrapper = new CardView(Context);
wrapper.Radius = Context.ToPixels(formsView.CornerRadius);
wrapper.SetCardBackgroundColor(formsView.BorderColor.ToAndroid());
wrapper.CardElevation = 0;
var borderW = (int)Context.ToPixels(formsView.BorderWidth);
wrapper.SetContentPadding(borderW, borderW, borderW, borderW);
wrapper.SetClipChildren(true);

var inner = nativeView;
var border = new GradientDrawable();
var innerRadius = Math.Max(formsView.CornerRadius - formsView.BorderWidth, 0);
border.SetCornerRadius(Context.ToPixels(innerRadius));
if (!formsView.BackgroundColor.IsDefault)
{
border.SetColor(formsView.BackgroundColor.ToAndroid());
}

inner.SetBackground(border);
inner.ClipToOutline = true;

wrapper.AddView(inner);
return wrapper;
}

if(formsView.CornerRadius > 0 || formsView.BorderWidth > 0)
{
var border = new GradientDrawable();
if (formsView.CornerRadius > 0)
{
border.SetCornerRadius(Context.ToPixels(formsView.CornerRadius));
}
if (!formsView.BackgroundColor.IsDefault)
{
border.SetColor(formsView.BackgroundColor.ToAndroid());
}

if (formsView.BorderWidth > 0)
{
var borderW = (int)Context.ToPixels(formsView.BorderWidth);
border.SetStroke(borderW, formsView.BorderColor.ToAndroid());
nativeView.SetPadding(borderW, borderW, borderW, borderW);
}

nativeView.SetBackground(border);
nativeView.ClipToOutline = true;
}

return nativeView;
}

internal static GravityFlags GetGravity(ExtraView view)
{
GravityFlags gravity = GravityFlags.NoGravity;
Expand Down Expand Up @@ -138,20 +250,13 @@ internal static GravityFlags GetGravity(ExtraView view)

internal static (int top, int bottom) CalcWindowPadding()
{
var display = (Context as Activity)?.WindowManager.DefaultDisplay;

Point size = new Point();
display.GetSize(size);

var activePage = XF.Application.Current.MainPage.GetActivePage();
var activeRenderer = Platform.GetRenderer(activePage);

var rect = new Rect();
activeRenderer.View.GetGlobalVisibleRect(rect);

activeRenderer = null;

return (rect.Top, size.Y - rect.Bottom);
return (rect.Top, DisplayHeight - rect.Bottom);
}
}
}
31 changes: 18 additions & 13 deletions AiForms.Dialogs.Android/ExtraPlatformDialog.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
using System;
using AiForms.Dialogs.Abstractions;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using Xamarin.Forms.Platform.Android;
using Android.Runtime;
using Android.Views;
using Android.Views.Animations;
using Android.Graphics;

namespace AiForms.Dialogs
{
[Android.Runtime.Preserve(AllMembers = true)]
public class ExtraPlatformDialog : Android.App.DialogFragment
public class ExtraPlatformDialog : Android.App.DialogFragment, IDialogInterfaceOnKeyListener
{
DialogView _dialogView;
ViewGroup _contentView;
Expand All @@ -37,16 +33,14 @@ public override Android.App.Dialog OnCreateDialog(Bundle savedInstanceState)
// Because it avoids the status bar color turning dark.
if (_dialogView.OverlayColor.IsTransparentOrDefault())
{
Display display = (Dialogs.Context as Activity).WindowManager.DefaultDisplay;
Point size = new Point();
display.GetSize(size);

var height = size.Y - (int)Dialogs.Context.ToPixels(24);
var height = Dialogs.ContentSize.Height;

dialog.Window.SetGravity(GravityFlags.CenterHorizontal | GravityFlags.Bottom);
dialog.Window.SetLayout(ViewGroup.LayoutParams.MatchParent, height);
}

dialog.SetOnKeyListener(this);

return dialog;
}

Expand All @@ -59,10 +53,21 @@ public override void OnStart()
public override void OnDestroyView()
{
base.OnDestroyView();

_contentView = null;
_dialogView = null;
Dialog?.Dispose();
}

public bool OnKey(IDialogInterface dialog, [GeneratedEnum] Keycode keyCode, KeyEvent e)
{
// Back Button handling
if (keyCode == Keycode.Back && e.Action == KeyEventActions.Up)
{
_dialogView.DialogNotifierInternal.Cancel();
return true;
}

return false;
}
}
}
Loading

0 comments on commit 7640ab0

Please sign in to comment.