Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
moving android support to a separate binding packages
[#249] Make assembly names in NuGet package consistent
  • Loading branch information
micjahn committed Sep 30, 2020
1 parent 1fa53d7 commit 0b93f8e
Show file tree
Hide file tree
Showing 15 changed files with 740 additions and 10 deletions.
76 changes: 76 additions & 0 deletions Source/Bindings/ZXing.Android/BarcodeReader.AndroidBitmap.cs
@@ -0,0 +1,76 @@
/*
* Copyright 2012 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern alias Android;

using System;
using Android::Android.Graphics;

namespace ZXing.Android
{
/// <summary>
/// A smart class to decode the barcode inside a bitmap object
/// </summary>
[CLSCompliant(false)]
public class BarcodeReader : BarcodeReader<Bitmap>, IBarcodeReader
{
private static readonly Func<Bitmap, LuminanceSource> defaultCreateLuminanceSource =
(bitmap) => new BitmapLuminanceSource(bitmap);

/// <summary>
/// Initializes a new instance of the <see cref="BarcodeReader"/> class.
/// </summary>
public BarcodeReader()
: this(null, defaultCreateLuminanceSource, null)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BarcodeReader"/> class.
/// </summary>
/// <param name="reader">Sets the reader which should be used to find and decode the barcode.
/// If null then MultiFormatReader is used</param>
/// <param name="createLuminanceSource">Sets the function to create a luminance source object for a bitmap.
/// If null, an exception is thrown when Decode is called</param>
/// <param name="createBinarizer">Sets the function to create a binarizer object for a luminance source.
/// If null then HybridBinarizer is used</param>
public BarcodeReader(Reader reader,
Func<Bitmap, LuminanceSource> createLuminanceSource,
Func<LuminanceSource, Binarizer> createBinarizer
)
: base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="BarcodeReader"/> class.
/// </summary>
/// <param name="reader">Sets the reader which should be used to find and decode the barcode.
/// If null then MultiFormatReader is used</param>
/// <param name="createLuminanceSource">Sets the function to create a luminance source object for a bitmap.
/// If null, an exception is thrown when Decode is called</param>
/// <param name="createBinarizer">Sets the function to create a binarizer object for a luminance source.
/// If null then HybridBinarizer is used</param>
/// <param name="createRGBLuminanceSource">Sets the function to create a luminance source object for a rgb raw byte array.</param>
public BarcodeReader(Reader reader,
Func<Bitmap, LuminanceSource> createLuminanceSource,
Func<LuminanceSource, Binarizer> createBinarizer,
Func<byte[], int, int, RGBLuminanceSource.BitmapFormat, LuminanceSource> createRGBLuminanceSource
)
: base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer, createRGBLuminanceSource)
{
}
}
}
50 changes: 50 additions & 0 deletions Source/Bindings/ZXing.Android/BarcodeReader.Extensions.cs
@@ -0,0 +1,50 @@
/*
* Copyright 2017 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

extern alias Android;

namespace ZXing
{
/// <summary>
/// extensions methods which are working directly on any IBarcodeReaderGeneric implementation
/// </summary>
public static class BarcodeReaderExtensions
{
/// <summary>
/// uses the IBarcodeReaderGeneric implementation and the <see cref="BitmapLuminanceSource"/> class for decoding
/// </summary>
/// <param name="reader"></param>
/// <param name="bitmap"></param>
/// <returns></returns>
public static Result Decode(this IBarcodeReaderGeneric reader, Android::Android.Graphics.Bitmap bitmap)
{
var luminanceSource = new BitmapLuminanceSource(bitmap);
return reader.Decode(luminanceSource);
}

/// <summary>
/// uses the IBarcodeReaderGeneric implementation and the <see cref="BitmapLuminanceSource"/> class for decoding
/// </summary>
/// <param name="reader"></param>
/// <param name="bitmap"></param>
/// <returns></returns>
public static Result[] DecodeMultiple(this IBarcodeReaderGeneric reader, Android::Android.Graphics.Bitmap bitmap)
{
var luminanceSource = new BitmapLuminanceSource(bitmap);
return reader.DecodeMultiple(luminanceSource);
}
}
}
37 changes: 37 additions & 0 deletions Source/Bindings/ZXing.Android/BarcodeWriter.AndroidBitmap.cs
@@ -0,0 +1,37 @@
/*
* Copyright 2012 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

extern alias Android;

namespace ZXing.Android
{
using Rendering;

/// <summary>
/// A smart class to encode some content to a barcode image
/// </summary>
[System.CLSCompliant(false)]
public class BarcodeWriter : BarcodeWriter<Android::Android.Graphics.Bitmap>, IBarcodeWriter
{
/// <summary>
/// Initializes a new instance of the <see cref="BarcodeWriter"/> class.
/// </summary>
public BarcodeWriter()
{
Renderer = new BitmapRenderer();
}
}
}
41 changes: 41 additions & 0 deletions Source/Bindings/ZXing.Android/BarcodeWriter.Extensions.cs
@@ -0,0 +1,41 @@
/*
* Copyright 2017 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

extern alias Android;

namespace ZXing
{
using Android.Rendering;

/// <summary>
/// extensions methods which are working directly on any BarcodeWriterGeneric implementation
/// </summary>
public static class BarcodeWriterExtensions
{
/// <summary>
/// uses the BarcodeWriterGeneric implementation and the <see cref="BitmapRenderer"/> class for decoding
/// </summary>
/// <param name="writer"></param>
/// <param name="content"></param>
/// <returns></returns>
public static Android::Android.Graphics.Bitmap WriteAsBitmap(this IBarcodeWriterGeneric writer, string content)
{
var bitmatrix = writer.Encode(content);
var renderer = new BitmapRenderer();
return renderer.Render(bitmatrix, writer.Format, content, writer.Options);
}
}
}
34 changes: 34 additions & 0 deletions Source/Bindings/ZXing.Android/IBarcodeReader.AndroidBitmap.cs
@@ -0,0 +1,34 @@
/*
* Copyright 2012 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

extern alias Android;

namespace ZXing.Android
{
/// <summary>
/// Interface for a smart class to decode the barcode inside a bitmap object
/// </summary>
[System.CLSCompliant(false)]
public partial interface IBarcodeReader
{
/// <summary>
/// Decodes the specified barcode bitmap.
/// </summary>
/// <param name="barcodeImage">The barcode bitmap.</param>
/// <returns>the result data or null</returns>
Result Decode(Android::Android.Graphics.Bitmap barcodeImage);
}
}
@@ -0,0 +1,33 @@
/*
* Copyright 2012 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

extern alias Android;

namespace ZXing.Android
{
/// <summary>
/// Interface for a smart class to decode multiple barcodes inside a bitmap object
/// </summary>
public partial interface IBarcodeReader
{
/// <summary>
/// Decodes the specified barcode bitmap.
/// </summary>
/// <param name="barcodeImage">The barcode bitmap.</param>
/// <returns>the result data or null</returns>
Result[] DecodeMultiple(Android::Android.Graphics.Bitmap barcodeImage);
}
}
38 changes: 38 additions & 0 deletions Source/Bindings/ZXing.Android/IBarcodeWriter.AndroidBitmap.cs
@@ -0,0 +1,38 @@
/*
* Copyright 2012 ZXing.Net authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

extern alias Android;

using ZXing.Common;

namespace ZXing.Android
{
/// <summary>
/// Interface for a smart class to encode some content into a barcode
/// </summary>
public interface IBarcodeWriter
{
/// <summary>
/// Creates a visual representation of the contents
/// </summary>
Android::Android.Graphics.Bitmap Write(string contents);

/// <summary>
/// Returns a rendered instance of the barcode which is given by a BitMatrix.
/// </summary>
Android::Android.Graphics.Bitmap Write(BitMatrix matrix);
}
}

0 comments on commit 0b93f8e

Please sign in to comment.