Skip to content

Commit

Permalink
added zxing.maui sample ui - works on android simulator 30
Browse files Browse the repository at this point in the history
  • Loading branch information
gentledepp committed May 6, 2024
1 parent 33dc260 commit 5845acd
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<style name="MyTheme">
</style>

<style name="MyTheme.NoActionBar" parent="@style/Theme.AppCompat.NoActionBar">
<style name="MyTheme.NoActionBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">@null</item>
<item name="android:windowNoTitle">true</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<style name="MyTheme">
</style>

<style name="MyTheme.NoActionBar" parent="@style/Theme.AppCompat.DayNight.NoActionBar">
<style name="MyTheme.NoActionBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowBackground">@drawable/splash_screen</item>
<item name="android:windowNoTitle">true</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Microsoft.Maui;

namespace Avalonia.Maui.Controls;

public class MauiGridLengthExtension
{
private readonly double _value;
private readonly GridUnitType _type;


public MauiGridLengthExtension(double value, GridUnitType type)
{
_value = value;
_type = type;
}

public Microsoft.Maui.GridLength ProvideValue(IServiceProvider provider)
{
return new Microsoft.Maui.GridLength(_value, _type);
}
}
10 changes: 6 additions & 4 deletions POC_AvaloniaMauiApp01/POC_AvaloniaMauiApp01/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainViewModel />
</Design.DataContext>
<StackPanel Orientation="Vertical">
<Grid RowDefinitions="Auto,Auto,*">

<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

<Button Content="Next sample" Command="{Binding NavigateToNextCommand}" />
<Button Grid.Row="1" Content="Next sample" Command="{Binding NavigateToNextCommand}" />

<ContentControl Content="{Binding CurrentViewModel}" />
<ContentControl Grid.Row="2" Content="{Binding CurrentViewModel}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"/>

</StackPanel>
</Grid>

</UserControl>
59 changes: 50 additions & 9 deletions POC_AvaloniaMauiApp01/POC_AvaloniaMauiApp01/Views/QRCodeView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,59 @@
xmlns:viewModels="clr-namespace:POC_AvaloniaMauiApp01.ViewModels"
xmlns:controls="using:Avalonia.Maui.Controls"
xmlns:zxing="using:ZXing.Net.Maui.Controls"
xmlns:maui="using:Microsoft.Maui.Controls"
xmlns:mau="using:Microsoft.Maui"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="POC_AvaloniaMauiApp01.Views.QRCodeView"
x:DataType="viewModels:QRCodeViewModel">
<StackPanel Orientation="Vertical">
<TextBox Text="Scan a QR Code" />


<controls:MauiControlHost x:Name="ProgressBarHost"
Margin="10">
<!-- <zxing:CameraBarcodeReaderView -->
<!-- x:Name="CameraBarcodeReaderView" -->
<!-- BarcodesDetected="BarcodesDetected" /> -->
</controls:MauiControlHost>
Margin="0">
<maui:Grid >
<maui:Grid.RowDefinitions>
<maui:RowDefinition Height="{controls:MauiGridLengthExtension 1, Star}"/>
<maui:RowDefinition Height="{controls:MauiGridLengthExtension 3, Star}"/>
<maui:RowDefinition Height="{controls:MauiGridLengthExtension 1, Star}"/>
</maui:Grid.RowDefinitions>

</StackPanel>
<zxing:CameraBarcodeReaderView
maui:Grid.Row="0" maui:Grid.RowSpan="3"
BarcodesDetected="BarcodesDetected"
/>

<maui:Grid
maui:Grid.Row="0"
BackgroundColor="#aa000000">
<maui:Label maui:Grid.Row="2" Text="{Binding ScannedQRCodes}" HorizontalOptions="Center" VerticalOptions="Center" TextColor="White" />
</maui:Grid>

<maui:Grid
maui:Grid.Row="3"
BackgroundColor="#aa000000"
Padding="20">
<maui:Grid.ColumnDefinitions>
<maui:ColumnDefinition Width="{controls:MauiGridLengthExtension 0, Auto}"/>
<maui:ColumnDefinition Width="{controls:MauiGridLengthExtension 1, Star}"/>
<maui:ColumnDefinition Width="{controls:MauiGridLengthExtension 0, Auto}"/>
</maui:Grid.ColumnDefinitions>

<maui:Button Text="🔄️" maui:Grid.Column="0" BackgroundColor="#aa000000" CornerRadius="8" BorderColor="Black" Clicked="SwitchCameraButton_Clicked" />

<zxing:BarcodeGeneratorView
maui:Grid.Column="1"
HorizontalOptions="Center"
VerticalOptions="Center"
HeightRequest="100"
WidthRequest="100"
ForegroundColor="DarkBlue"
Format="QrCode"
Value="Bla"
BarcodeMargin="1" />

<maui:Button Text="💡" maui:Grid.Column="2" BackgroundColor="#aa000000" CornerRadius="8" BorderColor="Black" Clicked="TorchButton_Clicked" />
</maui:Grid>

</maui:Grid>

</controls:MauiControlHost>
</UserControl>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using POC_AvaloniaMauiApp01.ViewModels;
Expand All @@ -21,4 +22,14 @@ private void BarcodesDetected(object? sender, BarcodeDetectionEventArgs e)

((QRCodeViewModel)DataContext).ScannedQRCodes = string.Join("|", allResults);
}

private void SwitchCameraButton_Clicked(object? sender, EventArgs e)
{

}

private void TorchButton_Clicked(object? sender, EventArgs e)
{

}
}

0 comments on commit 5845acd

Please sign in to comment.