Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the Controls Application #550

Merged
merged 32 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9a6a220
Implement IStartup
jsuarezruiz Mar 15, 2021
c79db26
Clean up code
jsuarezruiz Mar 15, 2021
b40bd60
Merge branch 'main' into startup
jsuarezruiz Mar 16, 2021
71bb51d
Merge branch 'main' into startup
jsuarezruiz Mar 16, 2021
f935032
Move the static Current into MauiApp
mattleibow Mar 16, 2021
accc1b3
Add missing SearchBar handler mapping
mattleibow Mar 17, 2021
36c8351
Don't need this anymore
mattleibow Mar 17, 2021
a1e163a
Pass the handler along on iOS
mattleibow Mar 17, 2021
9319bf5
Lots more perf fixes
mattleibow Mar 18, 2021
a3249b9
Remove App.SetHandlerContext
mattleibow Mar 18, 2021
f9b38a6
Fix tests
mattleibow Mar 18, 2021
9ab844f
Merge remote-tracking branch 'origin/main' into startup
mattleibow Mar 18, 2021
0913bdc
Fix catalyst
mattleibow Mar 18, 2021
615b220
revert
mattleibow Mar 18, 2021
d6d6c03
Using the Controls Application
mattleibow Mar 19, 2021
4f4e9b2
Use the XamlApp
mattleibow Mar 19, 2021
de8a0b6
This is no more!
mattleibow Mar 19, 2021
f2ec0f4
Merge remote-tracking branch 'origin/main' into startup
mattleibow Mar 19, 2021
9ee8f91
Merge branch 'main' into startup
jsuarezruiz Mar 19, 2021
3450d57
Fixed build errors
jsuarezruiz Mar 19, 2021
84c9108
Fix the updated SearchBar
mattleibow Mar 19, 2021
88a16e6
Merge branch 'startup' of https://github.com/dotnet/maui into startup
mattleibow Mar 19, 2021
0a08a7b
Merge remote-tracking branch 'origin/main' into startup
mattleibow Mar 19, 2021
c3bc181
Merge branch 'startup' into dev/new-applications
mattleibow Mar 19, 2021
6058543
rename ns
mattleibow Mar 19, 2021
1753ee9
gone!
mattleibow Mar 19, 2021
d3ce150
Merge remote-tracking branch 'origin/main' into dev/new-applications
mattleibow Mar 22, 2021
ddec1b7
reverts
mattleibow Mar 22, 2021
f2484d7
Fix iOS
mattleibow Mar 22, 2021
fb8a3e7
Merge remote-tracking branch 'origin/main' into dev/new-applications
mattleibow Mar 22, 2021
519a189
:|
mattleibow Mar 22, 2021
19794a6
sp
mattleibow Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 5 additions & 20 deletions src/Compatibility/ControlGallery/src/Android/CustomRenderers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,7 @@ public NativeListViewRenderer(Context context) : base(context)

protected override global::Android.Widget.ListView CreateNativeControl()
{
#pragma warning disable 618
// Disabled the warning so we have a test that this obsolete stuff still works
return new global::Android.Widget.ListView(Forms.Context);
#pragma warning restore 618
return new global::Android.Widget.ListView(Context);
}

protected override void OnElementChanged(ElementChangedEventArgs<NativeListView> e)
Expand All @@ -289,10 +286,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<NativeListView>
{
// subscribe

#pragma warning disable 618
// Disabled the warning so we have a test that this obsolete stuff still works
Control.Adapter = new NativeListViewAdapter(Forms.Context.GetActivity(), e.NewElement);
#pragma warning restore 618
Control.Adapter = new NativeListViewAdapter(Context.GetActivity(), e.NewElement);
Control.ItemClick += Clicked;
}
}
Expand All @@ -309,10 +303,7 @@ protected override void OnElementPropertyChanged(object sender, System.Component
{
// update the Items list in the UITableViewSource

#pragma warning disable 618
// Disabled the warning so we have a test that this obsolete stuff still works
Control.Adapter = new NativeListViewAdapter(Forms.Context.GetActivity(), Element);
#pragma warning restore 618
Control.Adapter = new NativeListViewAdapter(Context.GetActivity(), Element);
}
}
}
Expand Down Expand Up @@ -471,10 +462,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<NativeListView2
if (e.NewElement != null)
{
// subscribe
#pragma warning disable 618
// Disabled the warning so we have a test that this obsolete stuff still works
Control.Adapter = new NativeAndroidListViewAdapter(Forms.Context.GetActivity(), e.NewElement);
#pragma warning restore 618
Control.Adapter = new NativeAndroidListViewAdapter(Context.GetActivity(), e.NewElement);
Control.ItemClick += Clicked;
}
}
Expand All @@ -496,10 +484,7 @@ protected override void OnElementPropertyChanged(object sender, System.Component
{
// update the Items list in the UITableViewSource

#pragma warning disable 618
// Disabled the warning so we have a test that this obsolete stuff still works
Control.Adapter = new NativeAndroidListViewAdapter(Forms.Context.GetActivity(), Element);
#pragma warning restore 618
Control.Adapter = new NativeAndroidListViewAdapter(Context.GetActivity(), Element);
}
}
}
Expand Down
12 changes: 0 additions & 12 deletions src/Compatibility/Core/src/Android/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ public static AColor ToAndroid(this Color self)
return new AColor((byte)(byte.MaxValue * self.R), (byte)(byte.MaxValue * self.G), (byte)(byte.MaxValue * self.B), (byte)(byte.MaxValue * self.A));
}

[Obsolete("ToAndroid(this Color, int) is obsolete as of version 2.5. Please use ToAndroid(this Color, int, Context) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static AColor ToAndroid(this Color self, int defaultColorResourceId)
{
if (self == Color.Default)
{
return new AColor(ContextCompat.GetColor(Forms.Context, defaultColorResourceId));
}

return ToAndroid(self);
}

public static AColor ToAndroid(this Color self, int defaultColorResourceId, Context context)
{
if (self == Color.Default)
Expand Down
45 changes: 6 additions & 39 deletions src/Compatibility/Core/src/Android/Forms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,8 @@ public static class Forms
static bool? s_isPieOrNewer;
static FontManager s_fontManager;

[Obsolete("Context is obsolete as of version 2.5. Please use a local context instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Context Context { get; internal set; }

// One per process; does not change, suitable for loading resources (e.g., ResourceProvider)
internal static Context ApplicationContext { get; private set; }
internal static Context ApplicationContext { get; private set; } = global::Android.App.Application.Context;
internal static IMauiContext MauiContext { get; private set; }

public static bool IsInitialized { get; private set; }
Expand Down Expand Up @@ -232,30 +228,6 @@ public static void Init(InitializationOptions options)
Profile.FrameEnd();
}

/// <summary>
/// Sets title bar visibility programmatically. Must be called after Microsoft.Maui.Controls.Compatibility.Forms.Init() method
/// </summary>
/// <param name="visibility">Title bar visibility enum</param>
[Obsolete("SetTitleBarVisibility(AndroidTitleBarVisibility) is obsolete as of version 2.5. "
+ "Please use SetTitleBarVisibility(Activity, AndroidTitleBarVisibility) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void SetTitleBarVisibility(AndroidTitleBarVisibility visibility)
{
if (Context.GetActivity() == null)
throw new NullReferenceException("Must be called after Microsoft.Maui.Controls.Compatibility.Forms.Init() method");

if (visibility == AndroidTitleBarVisibility.Never)
{
if (!Context.GetActivity().Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen))
Context.GetActivity().Window.AddFlags(WindowManagerFlags.Fullscreen);
}
else
{
if (Context.GetActivity().Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen))
Context.GetActivity().Window.ClearFlags(WindowManagerFlags.Fullscreen);
}
}

public static void SetTitleBarVisibility(Activity activity, AndroidTitleBarVisibility visibility)
{
if (visibility == AndroidTitleBarVisibility.Never)
Expand Down Expand Up @@ -358,16 +330,10 @@ static void SetupInit(
var activity = context.Context;
Profile.FrameBegin();
Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim);
if (!IsInitialized)
{
// Only need to get this once; it won't change
ApplicationContext = activity.ApplicationContext;
MauiContext = context;
}

#pragma warning disable 618 // Still have to set this up so obsolete code can function
Context = activity;
#pragma warning restore 618
// Allow this multiple times to support the app and then the activity
ApplicationContext = activity.ApplicationContext;
MauiContext = context;

if (!IsInitialized)
{
Expand Down Expand Up @@ -418,7 +384,8 @@ static void SetupInit(

Profile.FramePartition("RegisterAll");

RegisterCompatRenderers(maybeOptions);
if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true)
RegisterCompatRenderers(maybeOptions);

Profile.FramePartition("Epilog");

Expand Down

This file was deleted.

51 changes: 0 additions & 51 deletions src/Compatibility/Core/src/Android/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,29 +321,6 @@ public static Task<Bitmap> GetBitmapAsync(this Resources resource, string name,
return BitmapFactory.DecodeResourceAsync(resource, IdFromTitle(name, DrawableClass, _drawableDefType, resource, context.PackageName));
}

[Obsolete("GetDrawable(this Resources, string) is obsolete as of version 2.5. "
+ "Please use GetDrawable(this Context, string) instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public static Drawable GetDrawable(this Resources resource, string name)
{
int id = IdFromTitle(name, DrawableClass, _drawableDefType, resource);
if (id == 0)
{
Log.Warning("Could not load image named: {0}", name);
return null;
}

return AndroidAppCompat.GetDrawable(Forms.Context, id);
}

[EditorBrowsable(EditorBrowsableState.Never)]
static void LogInfoToPreviewer(string message)
{
Java.Lang.Class designerHost = Java.Lang.Class.FromType(typeof(ImageRenderer)).ClassLoader.LoadClass("mono.android.HostProcessConnection");
Java.Lang.Reflect.Method reportMethod = designerHost.GetMethod("logInfo", Java.Lang.Class.FromType(typeof(Java.Lang.String)));
reportMethod.Invoke(null, message);
}

public static Drawable GetDrawable(this Context context, string name)
{
int id = IdFromTitle(name, DrawableClass, _drawableDefType, context);
Expand All @@ -362,44 +339,16 @@ public static int GetDrawableId(this Context context, string title)
return IdFromTitle(title, DrawableClass, _drawableDefType, context);
}

[Obsolete("GetDrawableByName(string) is obsolete as of version 4.8. "
+ "Please use GetDrawableId(string, context) instead.")]
public static int GetDrawableByName(string name)
{
return IdFromTitle(name, DrawableClass, _drawableDefType, Forms.ApplicationContext);
}

[Obsolete("GetResourceByName(string) is obsolete as of version 4.8. "
+ "Please use GetResource(string, context) instead.")]
public static int GetResourceByName(string name)
{
return IdFromTitle(name, ResourceClass, "id", Forms.ApplicationContext);
}

public static int GetResource(this Context context, string title)
{
return IdFromTitle(title, ResourceClass, "id", context);
}

[Obsolete("GetLayoutByName(string) is obsolete as of version 4.8. "
+ "Please use GetLayout(string, context) instead.")]
public static int GetLayoutByName(string name)
{
return IdFromTitle(name, LayoutClass, "layout", Forms.ApplicationContext);
}

public static int GetLayout(this Context context, string name)
{
return IdFromTitle(name, LayoutClass, "layout", context);
}

[Obsolete("GetStyleByName(string) is obsolete as of version 4.8. "
+ "Please use GetStyle(string, context) instead.")]
public static int GetStyleByName(string name)
{
return IdFromTitle(name, StyleClass, "style", Forms.ApplicationContext);
}

public static int GetStyle(this Context context, string name)
{
return IdFromTitle(name, StyleClass, "style", context);
Expand Down
15 changes: 15 additions & 0 deletions src/Compatibility/Core/src/AppHostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ namespace Microsoft.Maui.Controls.Compatibility
{
public static class AppHostBuilderExtensions
{
public static IAppHostBuilder RegisterCompatibilityForms(this IAppHostBuilder builder)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the special place for now since we used to init things like Device.Info and PlatformServices in the Forms.Init but that is currently running inside the Activity. However, we are now creating apps form the Application area.

Once we split all this stuff out of Forms and into services then this can be removed.

{
#if __ANDROID__
var options = new InitializationOptions(global::Android.App.Application.Context, null, null);
#elif __IOS__
var options = new InitializationOptions();
#endif

options.Flags |= InitializationFlags.SkipRenderers;

Forms.Init(options);

return builder;
}

public static IAppHostBuilder RegisterCompatibilityRenderers(this IAppHostBuilder builder)
{
// This won't really be a thing once we have all the handlers built
Expand Down
Loading