barcode reader

main
syneffort 2 years ago
parent 87d8ee83f6
commit ce8dd822fb
  1. 35
      BarcodeReader/BarcodeReader.sln
  2. 19
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Assets/AboutAssets.txt
  3. 97
      BarcodeReader/BarcodeReader/BarcodeReader.Android/BarcodeReader.Android.csproj
  4. 28
      BarcodeReader/BarcodeReader/BarcodeReader.Android/MainActivity.cs
  5. 6
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Properties/AndroidManifest.xml
  6. 30
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Properties/AssemblyInfo.cs
  7. 50
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/AboutResources.txt
  8. 34789
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/Resource.designer.cs
  9. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/drawable/icon_barcode.png
  10. 5
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-anydpi-v26/icon.xml
  11. 5
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-anydpi-v26/icon_round.xml
  12. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-hdpi/icon.png
  13. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-hdpi/launcher_foreground.png
  14. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-mdpi/icon.png
  15. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-mdpi/launcher_foreground.png
  16. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-xhdpi/icon.png
  17. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-xhdpi/launcher_foreground.png
  18. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-xxhdpi/icon.png
  19. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-xxhdpi/launcher_foreground.png
  20. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-xxxhdpi/icon.png
  21. BIN
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/mipmap-xxxhdpi/launcher_foreground.png
  22. 7
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/values/colors.xml
  23. 18
      BarcodeReader/BarcodeReader/BarcodeReader.Android/Resources/values/styles.xml
  24. 8
      BarcodeReader/BarcodeReader/BarcodeReader/App.xaml
  25. 28
      BarcodeReader/BarcodeReader/BarcodeReader/App.xaml.cs
  26. 3
      BarcodeReader/BarcodeReader/BarcodeReader/AssemblyInfo.cs
  27. 18
      BarcodeReader/BarcodeReader/BarcodeReader/BarcodeReader.csproj
  28. 16
      BarcodeReader/BarcodeReader/BarcodeReader/MainPage.xaml
  29. 58
      BarcodeReader/BarcodeReader/BarcodeReader/MainPage.xaml.cs

@ -0,0 +1,35 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32929.385
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarcodeReader.Android", "BarcodeReader\BarcodeReader.Android\BarcodeReader.Android.csproj", "{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarcodeReader", "BarcodeReader\BarcodeReader\BarcodeReader.csproj", "{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}.Release|Any CPU.Build.0 = Release|Any CPU
{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}.Release|Any CPU.Deploy.0 = Release|Any CPU
{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}.Release|Any CPU.Build.0 = Release|Any CPU
{ECB61F21-EBE2-4F35-80D8-81F00F0B8D03}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {790058EA-1CB7-4C43-A14D-6EF97082CE18}
EndGlobalSection
EndGlobal

@ -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");

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{ED6E23C4-2F22-498B-826B-4C1C0B9F8D49}</ProjectGuid>
<ProjectTypeGuids>{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TemplateGuid>{c9e5eea5-ca05-42a1-839b-61506e0a37df}</TemplateGuid>
<OutputType>Library</OutputType>
<RootNamespace>BarcodeReader.Droid</RootNamespace>
<AssemblyName>BarcodeReader.Android</AssemblyName>
<Deterministic>True</Deterministic>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v12.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidLinkMode>None</AndroidLinkMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>portable</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidManagedSymbols>true</AndroidManagedSymbols>
<AndroidUseSharedRuntime>false</AndroidUseSharedRuntime>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2196" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainActivity.cs" />
<Compile Include="Resources\Resource.designer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\AboutResources.txt" />
<None Include="Assets\AboutAssets.txt" />
<None Include="Properties\AndroidManifest.xml" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon.xml" />
<AndroidResource Include="Resources\mipmap-anydpi-v26\icon_round.xml" />
<AndroidResource Include="Resources\mipmap-hdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-hdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-mdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-mdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xxhdpi\launcher_foreground.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\icon.png" />
<AndroidResource Include="Resources\mipmap-xxxhdpi\launcher_foreground.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<ProjectReference Include="..\BarcodeReader\BarcodeReader.csproj">
<Project>{C7ED0914-70B7-4EB7-A7F0-D2F996C2E3AB}</Project>
<Name>BarcodeReader</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\drawable\icon_barcode.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>

@ -0,0 +1,28 @@
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.OS;
namespace BarcodeReader.Droid
{
[Activity(Label = "BarcodeReader", Icon = "@drawable/icon_barcode", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize )]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
{
Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
}

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.companyname.barcodereader">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />
<application android:label="BarcodeReader.Android" android:theme="@style/MainTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

@ -0,0 +1,30 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Android.App;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BarcodeReader.Android")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BarcodeReader.Android")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
// Add some common permissions, these can be removed if not needed
[assembly: UsesPermission(Android.Manifest.Permission.Internet)]
[assembly: UsesPermission(Android.Manifest.Permission.WriteExternalStorage)]

@ -0,0 +1,50 @@
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-hdpi/
icon.png
drawable-ldpi/
icon.png
drawable-mdpi/
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" 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 R.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.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/launcher_background" />
<foreground android:drawable="@mipmap/launcher_foreground" />
</adaptive-icon>

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@color/launcher_background" />
<foreground android:drawable="@mipmap/launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="launcher_background">#FFFFFF</color>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="MainTheme" parent="MainTheme.Base">
<!-- As of Xamarin.Forms 4.6 the theme has moved into the Forms binary -->
<!-- If you want to override anything you can do that here. -->
<!-- Underneath are a couple of entries to get you started. -->
<!-- Set theme colors from https://aka.ms/material-colors -->
<!-- colorPrimary is used for the default action bar background -->
<!--<item name="colorPrimary">#2196F3</item>-->
<!-- colorPrimaryDark is used for the status bar -->
<!--<item name="colorPrimaryDark">#1976D2</item>-->
<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<!--<item name="colorAccent">#FF4081</item>-->
</style>
</resources>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BarcodeReader.App">
<Application.Resources>
</Application.Resources>
</Application>

@ -0,0 +1,28 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace BarcodeReader
{
public partial class App : Application
{
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
protected override void OnStart()
{
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
}
}
}

@ -0,0 +1,3 @@
using Xamarin.Forms.Xaml;
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2196" />
<PackageReference Include="Xamarin.Essentials" Version="1.7.0" />
<PackageReference Include="ZXing.Net.Mobile.Forms" Version="3.1.0-beta2" />
</ItemGroup>
</Project>

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="BarcodeReader.MainPage"
Title="바코드 리더">
<StackLayout>
<Label Text="어떻게 사용하나요?" FontSize="Title" Padding="30,10,30,10"/>
<Label Text="아래 버튼을 탭하고 붉은선에 맞추어 바코드를 읽으세요. 읽은 바코드를 탭하면 클립보드에 복사할 수 있습니다." FontSize="16" Padding="30,0,30,0"/>
<Label x:Name="timeStampLabel" FontSize="Medium" HorizontalTextAlignment="Center" Padding="30,50,30,0"/>
<Label x:Name="formatLabel" FontSize="Medium" HorizontalTextAlignment="Center" Padding="30,0,30,0"/>
<Label x:Name="codeLabel" FontSize="Large" HorizontalTextAlignment="Center" FontAttributes="Bold" TextColor="OrangeRed" Padding="30,0,30,0" />
<Button x:Name="barcodeReadButton" Text="Barcode read" TextColor="White" BackgroundColor="#4A76B0" VerticalOptions="EndAndExpand" CornerRadius="5" Margin="30,0,30,30"
Clicked="barcodeReadButton_Clicked"/>
</StackLayout>
</ContentPage>

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
using ZXing.Net.Mobile.Forms;
namespace BarcodeReader
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
InitInstance();
}
private void InitInstance()
{
TapGestureRecognizer copyClipbaordTap = new TapGestureRecognizer();
copyClipbaordTap.Tapped += CopyClipbaordTap_Tapped;
codeLabel.GestureRecognizers.Add(copyClipbaordTap);
}
private void CopyClipbaordTap_Tapped(object sender, EventArgs e)
{
Label label = sender as Label;
if (label == null)
return;
Clipboard.SetTextAsync(label.Text);
DisplayAlert("알림", $"바코드가 클립보드에 복사되었습니다.", "확인");
}
private async void barcodeReadButton_Clicked(object sender, EventArgs e)
{
ZXingScannerPage scannerPage = new ZXingScannerPage();
await Navigation.PushAsync(scannerPage);
scannerPage.OnScanResult += ScannerPage_OnScanResult;
}
private void ScannerPage_OnScanResult(ZXing.Result result)
{
Device.BeginInvokeOnMainThread(async () =>
{
timeStampLabel.Text = $"타임스탬프: {DateTime.FromBinary(result.Timestamp)}";
formatLabel.Text = $"바코드 포맷: {result.BarcodeFormat}";
codeLabel.Text = result.Text;
await Navigation.PopAsync();
});
}
}
}
Loading…
Cancel
Save