Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #29 from rebuy-de/37651_add_command_to_scan
Browse files Browse the repository at this point in the history
refs #37651 add barcode command
  • Loading branch information
armintelker committed May 11, 2015
2 parents 588bdfa + 2e037ec commit aad7ffc
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 38 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ What | Type | Description
`BarcodeScanner.PreviewActive` | Property | If `true` the preview image gets updated. `false` no preview for you!
`BarcodeScanner.BarcodeDecoder` | Property | If `true` the decoder is active and tries to decode barcodes out of the image. `false` turns the decoder off, the preview is still active but barcodes will not be decoded.

Every event is also provided as `Command`. e.g. `BarcodeChanged` => `BarcodeChangedCommand`
### Configuration

Configuration can be applied by passing a `RbConfig` object to the `BarcodeScannerRenderer.Init()` method. As the available options are platform specific, the configuration has to be done in the according platform solution. The corresponding [Android](Rb.Forms.Barcode.Droid/RbConfig.cs) class documentation should give you a solid understanding of the available options.
Expand Down
10 changes: 5 additions & 5 deletions Rb.Forms.Barcode.Droid/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 116 additions & 2 deletions Rb.Forms.Barcode.Pcl/BarcodeScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,72 @@
using Xamarin.Forms;
using System.Diagnostics;
using Rb.Forms.Barcode.Pcl.Extensions;
using System.Windows.Input;

namespace Rb.Forms.Barcode.Pcl
{
public class BarcodeScanner : View
{
{
/// <summary>
/// Command property gets called only when the barcode text changes.
/// </summary>
public static BindableProperty BarcodeChangedCommandProperty = BindableProperty.Create(
propertyName: "BarcodeChangedCommand",
returnType: typeof(ICommand),
declaringType: typeof(BarcodeScanner),
defaultValue: null
);

/// <summary>
/// Command property gets called every time when a barcode is decoded from the preview, even if the value is the same as the previews one.
/// </summary>
public static BindableProperty BarcodeDecodedCommandProperty = BindableProperty.Create(
propertyName: "BarcodeDecodedCommand",
returnType: typeof(ICommand),
declaringType: typeof(BarcodeScanner),
defaultValue: null
);

/// <summary>
/// Command property gets called as soon as the surfaces starts previewing.
/// </summary>
public static BindableProperty PreviewActivatedCommandProperty = BindableProperty.Create(
propertyName: "PreviewActivatedCommand",
returnType: typeof(ICommand),
declaringType: typeof(BarcodeScanner),
defaultValue: null
);

/// <summary>
/// Command property gets called when the surfaces stops previewing.
/// </summary>
public static BindableProperty PreviewDeactivatedCommandProperty = BindableProperty.Create(
propertyName: "PreviewDeactivatedCommand",
returnType: typeof(ICommand),
declaringType: typeof(BarcodeScanner),
defaultValue: null
);

/// <summary>
/// Command property gets called after the camera was opened.
/// </summary>
public static BindableProperty CameraOpenedCommandProperty = BindableProperty.Create(
propertyName: "CameraOpenedCommand",
returnType: typeof(ICommand),
declaringType: typeof(BarcodeScanner),
defaultValue: null
);

/// <summary>
/// Command property gets called after the camera was released.
/// </summary>
public static BindableProperty CameraReleasedCommandProperty = BindableProperty.Create(
propertyName: "CameraReleasedCommand",
returnType: typeof(ICommand),
declaringType: typeof(BarcodeScanner),
defaultValue: null
);

/// <summary>
/// OneWay source to target binding for the current barcode.
/// </summary>
Expand Down Expand Up @@ -57,6 +118,54 @@ public bool PreviewActive
p => p.BarcodeDecoder, true, BindingMode.TwoWay
);

/// <summary>
/// Command gets called only when the barcode text changes.
/// </summary>
public ICommand BarcodeChangedCommand {
get { return (ICommand) GetValue(BarcodeChangedCommandProperty); }
set { SetValue(BarcodeChangedCommandProperty, value); }
}

/// <summary>
/// Command gets called every time when a barcode is decoded from the preview, even if the value is the same as the previews one.
/// </summary>
public ICommand BarcodeDecodedCommand {
get { return (ICommand) GetValue(BarcodeDecodedCommandProperty); }
set { SetValue(BarcodeDecodedCommandProperty, value); }
}

/// <summary>
/// Command gets called as soon as the surfaces starts previewing.
/// </summary>
public ICommand PreviewActivatedCommand {
get { return (ICommand) GetValue(PreviewActivatedCommandProperty); }
set { SetValue(PreviewActivatedCommandProperty, value); }
}

/// <summary>
/// Command gets called when the surfaces stops previewing.
/// </summary>
public ICommand PreviewDeactivatedCommand {
get { return (ICommand) GetValue(PreviewDeactivatedCommandProperty); }
set { SetValue(PreviewDeactivatedCommandProperty, value); }
}

/// <summary>
/// Command gets called after the camera was opened.
/// </summary>
public ICommand CameraOpenedCommand {
get { return (ICommand) GetValue(CameraOpenedCommandProperty); }
set { SetValue(CameraOpenedCommandProperty, value); }
}

/// <summary>
/// Command gets called after the camera was released.
/// </summary>
public ICommand CameraReleasedCommand {
get { return (ICommand) GetValue(CameraReleasedCommandProperty); }
set { SetValue(CameraReleasedCommandProperty, value); }
}

/// <summary>
/// Gets or controlls the decoder state.
/// </summary>
Expand Down Expand Up @@ -99,36 +208,41 @@ public bool BarcodeDecoder

public void OnCameraOpened()
{
CameraOpenedCommand.Raise();
CameraOpened.Raise(this, EventArgs.Empty);
}

public void OnCameraReleased()
{
CameraReleasedCommand.Raise();
CameraReleased.Raise(this, EventArgs.Empty);
}

private static void OnBarcodeChanged(BindableObject bindable, String oldValue, String newBarcode)
{
Debug.WriteLine("[ScannerView] OnBarcodeChanged [{0}]", newBarcode, null);
var b = (BarcodeScanner) bindable;

b.BarcodeChangedCommand.Raise(newBarcode);
b.BarcodeChanged.Raise(b, new BarcodeEventArgs(newBarcode));
}

private void OnBarcodeDecoded(String barcode)
{
Debug.WriteLine("[ScannerView] OnBarcodeDecoded [{0}]", barcode, null);

BarcodeDecodedCommand.Raise(barcode);
BarcodeDecoded.Raise(this, new BarcodeEventArgs(barcode));
}

public void OnPreviewActivated()
{
PreviewActivatedCommand.Raise();
PreviewActivated.Raise(this, EventArgs.Empty);
}

public void OnPreviewDeactivated()
{
PreviewDeactivatedCommand.Raise();
PreviewDeactivated.Raise(this, EventArgs.Empty);
}
}
Expand Down
21 changes: 21 additions & 0 deletions Rb.Forms.Barcode.Pcl/Extensions/CommandExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Windows.Input;

namespace Rb.Forms.Barcode.Pcl
{
public static class CommandExtension
{
public static void Raise(this ICommand comand, object parameter)
{
if (comand != null && comand.CanExecute(parameter)) {
comand.Execute(parameter);
}
}

public static void Raise(this ICommand comand)
{
Raise(comand, EventArgs.Empty);
}
}
}

1 change: 1 addition & 0 deletions Rb.Forms.Barcode.Pcl/Rb.Forms.Barcode.Pcl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<Compile Include="Extensions\EventExtension.cs" />
<Compile Include="BarcodeEventArgs.cs" />
<Compile Include="OutOfBoundsException.cs" />
<Compile Include="Extensions\CommandExtension.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Import Project="..\packages\Xamarin.Forms.1.4.2.6355\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\packages\Xamarin.Forms.1.4.2.6355\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
Expand Down
25 changes: 3 additions & 22 deletions Rb.Forms.Barcode.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>Rb.Forms.Barcode</id>
<title>Barcode scanner plugin for Xamarin.Forms</title>
<version>0.3.5-beta</version>
<version>0.4.0-beta</version>
<authors>Ota Mares</authors>
<owners>reBuy reCommerce GmbH</owners>
<licenseUrl>https://github.com/rebuy-de/rb-forms-barcode/blob/master/LICENSE</licenseUrl>
Expand All @@ -14,27 +14,8 @@ Please check the website for further details.

Beta notice: Currently only android is supported.</description>
<summary>Rb.Forms.Barcode is a Xamarin.Forms view for scanning barcodes.</summary>
<releaseNotes>0.3.5-beta:
* Fixed: Prevent dispose if object is null.

0.3.4-beta:
* Fixed: Surface changed does not start preview anymore.
* Improved: Dispose all buffers.
* Improved: Update to Xamarin.Forms to 1.4.2.6355 version.

0.3.3-beta:
* Fixed: UPC-A codes are not padded to 13 signs.

0.3.2-beta:
* Fixed: Even more oom issues.

0.3.1-beta:
* Fixed: Memory issue when restarting camera.

0.3.0-beta:
* New: Improved performance by using buffers and FastAndroidCamera.
* New: Added plenty configuration options!
* Fixed: Various preview halting and runtime issues.
<releaseNotes>0.4.0-beta:
* New: Add every event as command
</releaseNotes>
<tags>barcode scanner scanning scan zxing xamarin xamarin.forms rebuy unicorns</tags>
<dependencies>
Expand Down
18 changes: 9 additions & 9 deletions Sample/Sample.Droid/Resources/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aad7ffc

Please sign in to comment.