зеркало из https://github.com/DeGsoft/maui-linux.git
Fix android tests (#13874)
* check when using new APIs * add the view to the hierarchy to make sure everything is complete
This commit is contained in:
Родитель
e81949278a
Коммит
d14a302c91
|
@ -12,6 +12,7 @@ using AFragmentManager = AndroidX.Fragment.App.FragmentManager;
|
|||
using Size = Microsoft.Maui.Size;
|
||||
using AColor = Android.Graphics.Color;
|
||||
using AAttribute = Android.Resource.Attribute;
|
||||
using Android.OS;
|
||||
|
||||
namespace Microsoft.Maui
|
||||
{
|
||||
|
@ -112,17 +113,21 @@ namespace Microsoft.Maui
|
|||
{
|
||||
if (context.Theme?.ResolveAttribute(attr, mTypedValue, true) == true)
|
||||
{
|
||||
if (mTypedValue.Type >= DataType.FirstInt
|
||||
&& mTypedValue.Type <= DataType.LastInt)
|
||||
if (mTypedValue.Type >= DataType.FirstInt && mTypedValue.Type <= DataType.LastInt)
|
||||
{
|
||||
return mTypedValue.Data;
|
||||
}
|
||||
else if (mTypedValue.Type == DataType.String)
|
||||
{
|
||||
if (context.Resources == null)
|
||||
return 0;
|
||||
|
||||
return context.Resources.GetColor(mTypedValue.ResourceId, context.Theme);
|
||||
if (context.Resources != null)
|
||||
{
|
||||
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
|
||||
return context.Resources.GetColor(mTypedValue.ResourceId, context.Theme);
|
||||
else
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
return context.Resources.GetColor(mTypedValue.ResourceId);
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,11 +57,19 @@ namespace Microsoft.Maui.DeviceTests
|
|||
layout.AddView(view);
|
||||
layout.Measure(500, 500);
|
||||
layout.Layout(0, 0, 500, 500);
|
||||
|
||||
var act = view.Context.GetActivity();
|
||||
var rootView = act.FindViewById<FrameLayout>(Android.Resource.Id.Content);
|
||||
|
||||
rootView.AddView(layout);
|
||||
|
||||
var bitmap = Bitmap.CreateBitmap(view.Width, view.Height, Bitmap.Config.Argb8888);
|
||||
Canvas canvas = new Canvas(bitmap);
|
||||
view.Layout(0, 0, view.Width, view.Height);
|
||||
view.Draw(canvas);
|
||||
|
||||
rootView.RemoveView(layout);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче