diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/Assets/AboutAssets.txt b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Assets/AboutAssets.txt new file mode 100755 index 000000000..a9b0638eb --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Assets/AboutAssets.txt @@ -0,0 +1,19 @@ +Any raw assets you want to be deployed with your application can be placed in +this directory (and child directories) and given a Build Action of "AndroidAsset". + +These files will be deployed with your package and will be accessible using Android's +AssetManager, like this: + +public class ReadAsset : Activity +{ + protected override void OnCreate (Bundle bundle) + { + base.OnCreate (bundle); + + InputStream input = Assets.Open ("my_asset.txt"); + } +} + +Additionally, some Android functions will automatically load asset files: + +Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/CustomRenderer.Android.csproj b/Upgrading/CustomRenderer/MultiProject/Entry/Android/CustomRenderer.Android.csproj new file mode 100644 index 000000000..99c0bc149 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/CustomRenderer.Android.csproj @@ -0,0 +1,24 @@ + + + Exe + enable + true + + + false + + + false + + + net8.0-android + + + + + + + all + + + diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/MainActivity.cs b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MainActivity.cs new file mode 100755 index 000000000..1f0ba0641 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MainActivity.cs @@ -0,0 +1,24 @@ +using System; + +using Android.App; +using Android.Content; +using Android.Runtime; +using Android.Views; +using Android.Widget; +using Android.OS; +using Android.Content.PM; +using Microsoft.Maui; +using Microsoft.Maui.Controls; + + +namespace CustomRenderer.Android +{ + [Activity (Label = "CustomRenderer.Android.Android", Icon = "@drawable/icon", + Theme = "@style/MainTheme", MainLauncher = true, + ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)] + public class MainActivity : MauiAppCompatActivity + { + } + +} + diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/MainApplication.cs b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MainApplication.cs new file mode 100644 index 000000000..1173ec6f2 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MainApplication.cs @@ -0,0 +1,19 @@ +using System; +using Android.App; +using Android.Runtime; +using Microsoft.Maui; +using Microsoft.Maui.Hosting; + +namespace CustomRenderer.Android +{ + [Application] + public class MainApplication : MauiApplication + { + public MainApplication(IntPtr handle, JniHandleOwnership ownership) + : base(handle, ownership) + { + } + + protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); + } +} diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/MauiProgram.cs b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MauiProgram.cs new file mode 100644 index 000000000..f3a0c3f66 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MauiProgram.cs @@ -0,0 +1,37 @@ +using Microsoft.Maui.Hosting; +using Microsoft.Maui.Handlers; +using Microsoft.Maui.Controls.Compatibility.Hosting; + +namespace CustomRenderer.Android; + +public static class MauiProgram +{ + public static MauiAppBuilder builder; + public static MauiAppBuilder Builder + { + get + { + if (builder == null) + { + builder = MauiApp.CreateBuilder(); + } + + return builder; + } + } + public static MauiApp CreateMauiApp() + { + var builder = Builder; + builder + .UseMauiCompatibility() + .UseMauiApp(); + + builder.ConfigureMauiHandlers(handlers => { +#if ANDROID + handlers.AddCompatibilityRenderer(typeof(MyEntry), typeof(CustomRenderer.Android.MyEntryRenderer)); +#endif + }); + + return builder.Build(); + } +} diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/MyEntryRenderer.cs b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MyEntryRenderer.cs new file mode 100755 index 000000000..3520c605c --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/MyEntryRenderer.cs @@ -0,0 +1,29 @@ +using CustomRenderer; +using CustomRenderer.Android; +using Android.Content; +using Microsoft.Maui; +using Microsoft.Maui.Controls; +using Microsoft.Maui.Controls.Compatibility.Platform.Android; +using Microsoft.Maui.Controls.Platform; + + +namespace CustomRenderer.Android +{ + class MyEntryRenderer : EntryRenderer + { + public MyEntryRenderer(Context context) : base(context) + { + } + + protected override void OnElementChanged(ElementChangedEventArgs e) + { + base.OnElementChanged(e); + + if (Control != null) + { + Control.SetBackgroundColor(global::Android.Graphics.Color.LightGreen); + } + } + } +} + diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/Properties/AndroidManifest.xml b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Properties/AndroidManifest.xml new file mode 100755 index 000000000..baf87db76 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Properties/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/AboutResources.txt b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/AboutResources.txt new file mode 100755 index 000000000..10f52d460 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/AboutResources.txt @@ -0,0 +1,44 @@ +Images, layout descriptions, binary blobs and string dictionaries can be included +in your application as resource files. Various Android APIs are designed to +operate on the resource IDs instead of dealing with images, strings or binary blobs +directly. + +For example, a sample Android app that contains a user interface layout (main.axml), +an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) +would keep its resources in the "Resources" directory of the application: + +Resources/ + drawable/ + icon.png + + layout/ + main.axml + + values/ + strings.xml + +In order to get the build system to recognize Android resources, set the build action to +"AndroidResource". The native Android APIs do not operate directly with filenames, but +instead operate on resource IDs. When you compile an Android application that uses resources, +the build system will package the resources for distribution and generate a class called "R" +(this is an Android convention) that contains the tokens for each one of the resources +included. For example, for the above Resources layout, this is what the R class would expose: + +public class R { + public class drawable { + public const int icon = 0x123; + } + + public class layout { + public const int main = 0x456; + } + + public class strings { + public const int first_string = 0xabc; + public const int second_string = 0xbcd; + } +} + +You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main +to reference the layout/main.axml file, or R.strings.first_string to reference the first +string in the dictionary file values/strings.xml. diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/drawable/Icon.png b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/drawable/Icon.png new file mode 100755 index 000000000..fae80caf4 Binary files /dev/null and b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/drawable/Icon.png differ diff --git a/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/layout/Main.axml b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/layout/Main.axml new file mode 100755 index 000000000..bd890ffb7 --- /dev/null +++ b/Upgrading/CustomRenderer/MultiProject/Entry/Android/Resources/layout/Main.axml @@ -0,0 +1,14 @@ + + +