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 +