From 034cbcf224d207373b040bfcb68a0fb825a50810 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Oct 2025 07:13:38 +0000 Subject: [PATCH 1/3] Initial plan From 51bd82baf701b5cbdaa6b4202b392c7344e9ccae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Oct 2025 07:18:29 +0000 Subject: [PATCH 2/3] Initial plan for fixing CI/CD pipeline errors Co-authored-by: cail <153030+cail@users.noreply.github.com> --- .github/workflows/build-dotnet-android.yml | 36 +++++++++ .gitignore | 11 ++- examples/CanvasExample/AndroidManifest.xml | 6 ++ examples/CanvasExample/CanvasExample.csproj | 24 ++++++ examples/CanvasExample/MainActivity.cs | 81 +++++++++++++++++++ examples/CanvasExample/README.md | 32 ++++++++ .../Resources/values/strings.xml | 4 + 7 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-dotnet-android.yml create mode 100644 examples/CanvasExample/AndroidManifest.xml create mode 100644 examples/CanvasExample/CanvasExample.csproj create mode 100644 examples/CanvasExample/MainActivity.cs create mode 100644 examples/CanvasExample/README.md create mode 100644 examples/CanvasExample/Resources/values/strings.xml diff --git a/.github/workflows/build-dotnet-android.yml b/.github/workflows/build-dotnet-android.yml new file mode 100644 index 0000000..e7492e6 --- /dev/null +++ b/.github/workflows/build-dotnet-android.yml @@ -0,0 +1,36 @@ +name: Build .NET Android + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: '9.0.x' + + - name: Install .NET Android workload + run: dotnet workload install android + + - name: Restore dependencies + run: dotnet restore AndroidDrawing.dotnet.csproj + + - name: Build library + run: dotnet build AndroidDrawing.dotnet.csproj --configuration Release --no-restore + + - name: Restore example app dependencies + run: dotnet restore examples/CanvasExample/CanvasExample.csproj + + - name: Build example app + run: dotnet build examples/CanvasExample/CanvasExample.csproj --configuration Release --no-restore diff --git a/.gitignore b/.gitignore index dafa7bb..bfadbc4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ -bin/* -obj/* -*.pidb \ No newline at end of file +bin/ +obj/ +*.pidb +*.user +*.suo +.vs/ +*.apk +*.aab \ No newline at end of file diff --git a/examples/CanvasExample/AndroidManifest.xml b/examples/CanvasExample/AndroidManifest.xml new file mode 100644 index 0000000..8a313e3 --- /dev/null +++ b/examples/CanvasExample/AndroidManifest.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/examples/CanvasExample/CanvasExample.csproj b/examples/CanvasExample/CanvasExample.csproj new file mode 100644 index 0000000..59ea60f --- /dev/null +++ b/examples/CanvasExample/CanvasExample.csproj @@ -0,0 +1,24 @@ + + + + net9.0-android + Exe + CanvasExample + true + disable + enable + com.hobdrive.canvasexample + 1 + 1.0 + 23.0 + + + + + + + + + + + diff --git a/examples/CanvasExample/MainActivity.cs b/examples/CanvasExample/MainActivity.cs new file mode 100644 index 0000000..39805c8 --- /dev/null +++ b/examples/CanvasExample/MainActivity.cs @@ -0,0 +1,81 @@ +using Android.App; +using Android.OS; +using Android.Views; +using Android.Content; +using System.Drawing; + +namespace CanvasExample +{ + [Activity(Label = "Canvas Example", MainLauncher = true)] + public class MainActivity : Activity + { + protected override void OnCreate(Bundle? savedInstanceState) + { + base.OnCreate(savedInstanceState); + + // Create a custom view to demonstrate canvas operations + var canvasView = new CanvasView(this); + SetContentView(canvasView); + } + } + + public class CanvasView : View + { + public CanvasView(Context context) : base(context) + { + } + + protected override void OnDraw(Android.Graphics.Canvas? canvas) + { + base.OnDraw(canvas); + + if (canvas == null) + return; + + // Use AndroidDrawing Graphics wrapper + var g = new Graphics(canvas); + + // Set DPI for proper scaling + Graphics.DeviceDPI = (int)Resources!.DisplayMetrics!.Density * 160; + + // Set line width and flags + g.LineWidth = 2; + g.Flags = Android.Graphics.PaintFlags.AntiAlias; + + // Draw background + g.FillRectangle(new Brush(Color.White), 0, 0, Width, Height); + + // Draw various shapes to demonstrate canvas operations + + // Draw a red line + g.DrawLine(new Pen(Color.Red), 50, 50, 350, 50); + + // Draw a blue rectangle + g.DrawRectangle(new Pen(Color.Blue), 50, 100, 300, 100); + + // Fill a green rectangle + g.FillRectangle(new Brush(Color.Green), 70, 120, 260, 60); + + // Draw an orange ellipse + g.DrawEllipse(new Pen(Color.Orange), 50, 250, 300, 150); + + // Fill a purple ellipse + g.FillEllipse(new Brush(Color.Purple), 100, 280, 200, 90); + + // Draw text + g.DrawString("AndroidDrawing Example", + new Font("serif", 20, FontStyle.Bold), + new Brush(Color.Black), + new RectangleF(50, 450, 300, 50)); + + // Draw multiline text in a rectangle + g.DrawString("This demonstrates various canvas operations:\n• Lines\n• Rectangles\n• Ellipses\n• Text rendering", + new Font("serif", 14, FontStyle.Regular), + new Brush(Color.DarkBlue), + new RectangleF(50, 520, 300, 200)); + + // Flush to complete drawing + g.Flush(); + } + } +} diff --git a/examples/CanvasExample/README.md b/examples/CanvasExample/README.md new file mode 100644 index 0000000..2b6f89c --- /dev/null +++ b/examples/CanvasExample/README.md @@ -0,0 +1,32 @@ +# Canvas Example + +This is a simple Android application that demonstrates the usage of AndroidDrawing library. + +## Features + +The example demonstrates various canvas operations: +- Drawing lines with different colors +- Drawing and filling rectangles +- Drawing and filling ellipses +- Text rendering (single and multiline) +- Anti-aliasing support + +## Building + +To build the example: + +```bash +dotnet build CanvasExample.csproj +``` + +## Running + +To run on an Android device or emulator: + +```bash +dotnet build -t:Run -f net9.0-android +``` + +## Code Overview + +The example creates a simple `MainActivity` with a custom `CanvasView` that overrides the `OnDraw` method to demonstrate various drawing operations using the AndroidDrawing `Graphics` class. diff --git a/examples/CanvasExample/Resources/values/strings.xml b/examples/CanvasExample/Resources/values/strings.xml new file mode 100644 index 0000000..736b2ab --- /dev/null +++ b/examples/CanvasExample/Resources/values/strings.xml @@ -0,0 +1,4 @@ + + + Canvas Example + From 0195b9eaf78db70eee791d2dbe8e2699e2a45722 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 20 Oct 2025 07:26:55 +0000 Subject: [PATCH 3/3] Fix CI/CD pipeline: workload install and project versions Co-authored-by: cail <153030+cail@users.noreply.github.com> --- .github/workflows/build-dotnet-android.yml | 1 + AndroidDrawing.dotnet.csproj | 2 +- examples/CanvasExample/AndroidManifest.xml | 2 +- examples/CanvasExample/CanvasExample.csproj | 2 +- examples/CanvasExample/MainActivity.cs | 6 +++--- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-dotnet-android.yml b/.github/workflows/build-dotnet-android.yml index e7492e6..995cc1e 100644 --- a/.github/workflows/build-dotnet-android.yml +++ b/.github/workflows/build-dotnet-android.yml @@ -21,6 +21,7 @@ jobs: dotnet-version: '9.0.x' - name: Install .NET Android workload + working-directory: ${{ github.workspace }}/examples/CanvasExample run: dotnet workload install android - name: Restore dependencies diff --git a/AndroidDrawing.dotnet.csproj b/AndroidDrawing.dotnet.csproj index a8f7080..00fb5b0 100644 --- a/AndroidDrawing.dotnet.csproj +++ b/AndroidDrawing.dotnet.csproj @@ -14,7 +14,7 @@ - + diff --git a/examples/CanvasExample/AndroidManifest.xml b/examples/CanvasExample/AndroidManifest.xml index 8a313e3..e05ce67 100644 --- a/examples/CanvasExample/AndroidManifest.xml +++ b/examples/CanvasExample/AndroidManifest.xml @@ -2,5 +2,5 @@ - + diff --git a/examples/CanvasExample/CanvasExample.csproj b/examples/CanvasExample/CanvasExample.csproj index 59ea60f..2af6ddf 100644 --- a/examples/CanvasExample/CanvasExample.csproj +++ b/examples/CanvasExample/CanvasExample.csproj @@ -18,7 +18,7 @@ - + diff --git a/examples/CanvasExample/MainActivity.cs b/examples/CanvasExample/MainActivity.cs index 39805c8..b422c60 100644 --- a/examples/CanvasExample/MainActivity.cs +++ b/examples/CanvasExample/MainActivity.cs @@ -14,14 +14,14 @@ protected override void OnCreate(Bundle? savedInstanceState) base.OnCreate(savedInstanceState); // Create a custom view to demonstrate canvas operations - var canvasView = new CanvasView(this); + var canvasView = new DrawingView(this); SetContentView(canvasView); } } - public class CanvasView : View + public class DrawingView : View { - public CanvasView(Context context) : base(context) + public DrawingView(Context context) : base(context) { }