init
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
.idea/
|
||||||
|
obj/
|
||||||
|
bin/
|
18
DemoAndroid.sln
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoAndroid", "DemoAndroid\DemoAndroid.csproj", "{2A2871F0-6043-40CD-8249-3B20E56B8EF4}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{2A2871F0-6043-40CD-8249-3B20E56B8EF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{2A2871F0-6043-40CD-8249-3B20E56B8EF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{2A2871F0-6043-40CD-8249-3B20E56B8EF4}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||||
|
{2A2871F0-6043-40CD-8249-3B20E56B8EF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{2A2871F0-6043-40CD-8249-3B20E56B8EF4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{2A2871F0-6043-40CD-8249-3B20E56B8EF4}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
6
DemoAndroid/AndroidManifest.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:label="@string/app_name" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true">
|
||||||
|
</application>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
</manifest>
|
18
DemoAndroid/DemoAndroid.csproj
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0-android</TargetFramework>
|
||||||
|
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<ApplicationId>com.maurict.androiddemo</ApplicationId>
|
||||||
|
<ApplicationVersion>1</ApplicationVersion>
|
||||||
|
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
|
||||||
|
|
||||||
|
<!-- With AOT, our app is crashing in Release mode -->
|
||||||
|
<AotAssemblies>False</AotAssemblies>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="QRCoder-ImageSharp" Version="0.10.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
44
DemoAndroid/MainActivity.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using Android.Graphics;
|
||||||
|
using QRCoder;
|
||||||
|
using Exception = Java.Lang.Exception; // QRCoder-ImageSharp else it crashes
|
||||||
|
|
||||||
|
namespace DemoAndroid;
|
||||||
|
|
||||||
|
[Activity(Label = "@string/app_name", MainLauncher = true)]
|
||||||
|
public class MainActivity : Activity
|
||||||
|
{
|
||||||
|
private string _text = "";
|
||||||
|
private ImageView? _ivQr;
|
||||||
|
|
||||||
|
protected override void OnCreate(Bundle? savedInstanceState)
|
||||||
|
{
|
||||||
|
base.OnCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Set our view from the "main" layout resource
|
||||||
|
SetContentView(Resource.Layout.activity_main);
|
||||||
|
|
||||||
|
var etInput = FindViewById<EditText>(Resource.Id.etInput) ?? throw new Exception("EditText #etInput not found");
|
||||||
|
_ivQr = FindViewById<ImageView>(Resource.Id.ivQR) ?? throw new Exception("ImageView #ivQR not found");;
|
||||||
|
|
||||||
|
etInput.TextChanged += (sender, args) =>
|
||||||
|
{
|
||||||
|
_text = args.Text?.ToString() ?? string.Empty;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(_text))
|
||||||
|
{
|
||||||
|
CreateQr();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateQr()
|
||||||
|
{
|
||||||
|
using var qrGenerator = new QRCodeGenerator();
|
||||||
|
using var qrCodeData = qrGenerator.CreateQrCode(_text, QRCodeGenerator.ECCLevel.Q);
|
||||||
|
using var qrCode = new PngByteQRCode(qrCodeData);
|
||||||
|
|
||||||
|
var qrCodeImage = qrCode.GetGraphic(20);
|
||||||
|
var javaBitmap = BitmapFactory.DecodeByteArray(qrCodeImage, 0, qrCodeImage.Length);
|
||||||
|
_ivQr?.SetImageBitmap(javaBitmap);
|
||||||
|
}
|
||||||
|
}
|
44
DemoAndroid/Resources/AboutResources.txt
Normal file
@ -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.xml),
|
||||||
|
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.xml
|
||||||
|
|
||||||
|
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 "Resource"
|
||||||
|
(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 Resource class would expose:
|
||||||
|
|
||||||
|
public class Resource {
|
||||||
|
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 Resource.Drawable.icon to reference the drawable/icon.png file, or
|
||||||
|
Resource.Layout.main to reference the layout/main.xml file, or Resource.Strings.first_string
|
||||||
|
to reference the first string in the dictionary file values/strings.xml.
|
15
DemoAndroid/Resources/layout/activity_main.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<EditText android:id="@+id/etInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Enter text here to create QR"/>
|
||||||
|
|
||||||
|
<ImageView android:id="@+id/ivQR"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
4
DemoAndroid/Resources/mipmap-anydpi-v26/appicon.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@mipmap/appicon_background" />
|
||||||
|
<foreground android:drawable="@mipmap/appicon_foreground" />
|
||||||
|
</adaptive-icon>
|
@ -0,0 +1,4 @@
|
|||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<background android:drawable="@mipmap/appicon_background" />
|
||||||
|
<foreground android:drawable="@mipmap/appicon_foreground" />
|
||||||
|
</adaptive-icon>
|
BIN
DemoAndroid/Resources/mipmap-hdpi/appicon.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
DemoAndroid/Resources/mipmap-hdpi/appicon_background.png
Normal file
After Width: | Height: | Size: 97 B |
BIN
DemoAndroid/Resources/mipmap-hdpi/appicon_foreground.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
DemoAndroid/Resources/mipmap-mdpi/appicon.png
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
DemoAndroid/Resources/mipmap-mdpi/appicon_background.png
Normal file
After Width: | Height: | Size: 92 B |
BIN
DemoAndroid/Resources/mipmap-mdpi/appicon_foreground.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
DemoAndroid/Resources/mipmap-xhdpi/appicon.png
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
DemoAndroid/Resources/mipmap-xhdpi/appicon_background.png
Normal file
After Width: | Height: | Size: 100 B |
BIN
DemoAndroid/Resources/mipmap-xhdpi/appicon_foreground.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
DemoAndroid/Resources/mipmap-xxhdpi/appicon.png
Normal file
After Width: | Height: | Size: 4.6 KiB |
BIN
DemoAndroid/Resources/mipmap-xxhdpi/appicon_background.png
Normal file
After Width: | Height: | Size: 108 B |
BIN
DemoAndroid/Resources/mipmap-xxhdpi/appicon_foreground.png
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
DemoAndroid/Resources/mipmap-xxxhdpi/appicon.png
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
DemoAndroid/Resources/mipmap-xxxhdpi/appicon_background.png
Normal file
After Width: | Height: | Size: 117 B |
BIN
DemoAndroid/Resources/mipmap-xxxhdpi/appicon_foreground.png
Normal file
After Width: | Height: | Size: 2.7 KiB |
5
DemoAndroid/Resources/values/colors.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="blue">#4287f5</color>
|
||||||
|
<color name="white">#FFFFFF</color>
|
||||||
|
</resources>
|
4
DemoAndroid/Resources/values/ic_launcher_background.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="ic_launcher_background">#2C3E50</color>
|
||||||
|
</resources>
|
4
DemoAndroid/Resources/values/strings.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">DemoAndroid</string>
|
||||||
|
<string name="app_text">Hello, Android!</string>
|
||||||
|
</resources>
|