You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
135 lines
4.1 KiB
135 lines
4.1 KiB
using CameraPreview;
|
|
using Xamarin.Forms;
|
|
|
|
namespace Demo
|
|
{
|
|
public partial class FacePage : ContentPage
|
|
{
|
|
private ScannerView _scannerView;
|
|
|
|
public FacePage(ScanningOptionsBase options = null, View customOverlay = null) : base()
|
|
{
|
|
_scannerView = new ScannerView
|
|
{
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
|
Options = options,
|
|
};
|
|
|
|
_scannerView.SetBinding(ScannerView.IsAnalyzingProperty, new Binding(nameof(IsAnalyzing)));
|
|
_scannerView.SetBinding(ScannerView.IsScanningProperty, new Binding(nameof(IsScanning)));
|
|
_scannerView.SetBinding(ScannerView.ResultProperty, new Binding(nameof(Result)));
|
|
|
|
_scannerView.OnScanResult += (result) =>
|
|
{
|
|
this.OnScanResult?.Invoke(result);
|
|
};
|
|
|
|
var grid = new Grid
|
|
{
|
|
VerticalOptions = LayoutOptions.FillAndExpand,
|
|
HorizontalOptions = LayoutOptions.FillAndExpand,
|
|
};
|
|
|
|
grid.Children.Add(_scannerView);
|
|
|
|
if (customOverlay != null)
|
|
{
|
|
Overlay = customOverlay;
|
|
grid.Children.Add(Overlay);
|
|
}
|
|
|
|
// The root page of your application
|
|
Content = grid;
|
|
}
|
|
|
|
#region Default Overlay Properties
|
|
|
|
public static readonly BindableProperty DefaultOverlayTopTextProperty =
|
|
BindableProperty.Create(nameof(DefaultOverlayTopText), typeof(string), typeof(FacePage), string.Empty);
|
|
|
|
public string DefaultOverlayTopText
|
|
{
|
|
get { return (string)GetValue(DefaultOverlayTopTextProperty); }
|
|
set { SetValue(DefaultOverlayTopTextProperty, value); }
|
|
}
|
|
|
|
public static readonly BindableProperty DefaultOverlayBottomTextProperty =
|
|
BindableProperty.Create(nameof(DefaultOverlayBottomText), typeof(string), typeof(FacePage), string.Empty);
|
|
|
|
public string DefaultOverlayBottomText
|
|
{
|
|
get { return (string)GetValue(DefaultOverlayBottomTextProperty); }
|
|
set { SetValue(DefaultOverlayBottomTextProperty, value); }
|
|
}
|
|
|
|
#endregion Default Overlay Properties
|
|
|
|
public delegate void ScanResultDelegate(IScanResult result);
|
|
|
|
public event ScanResultDelegate OnScanResult;
|
|
|
|
public View Overlay
|
|
{
|
|
get;
|
|
private set;
|
|
}
|
|
|
|
#region Functions
|
|
|
|
protected override void OnAppearing()
|
|
{
|
|
base.OnAppearing();
|
|
|
|
_scannerView.IsScanning = true;
|
|
}
|
|
|
|
protected override void OnDisappearing()
|
|
{
|
|
_scannerView.IsScanning = false;
|
|
|
|
base.OnDisappearing();
|
|
}
|
|
|
|
public void PauseAnalysis()
|
|
{
|
|
if (_scannerView != null)
|
|
_scannerView.IsAnalyzing = false;
|
|
}
|
|
|
|
public void ResumeAnalysis()
|
|
{
|
|
if (_scannerView != null)
|
|
_scannerView.IsAnalyzing = true;
|
|
}
|
|
|
|
#endregion Functions
|
|
|
|
public static readonly BindableProperty IsAnalyzingProperty =
|
|
BindableProperty.Create(nameof(IsAnalyzing), typeof(bool), typeof(FacePage), false);
|
|
|
|
public bool IsAnalyzing
|
|
{
|
|
get { return (bool)GetValue(IsAnalyzingProperty); }
|
|
set { SetValue(IsAnalyzingProperty, value); }
|
|
}
|
|
|
|
public static readonly BindableProperty IsScanningProperty =
|
|
BindableProperty.Create(nameof(IsScanning), typeof(bool), typeof(FacePage), false);
|
|
|
|
public bool IsScanning
|
|
{
|
|
get { return (bool)GetValue(IsScanningProperty); }
|
|
set { SetValue(IsScanningProperty, value); }
|
|
}
|
|
|
|
public static readonly BindableProperty ResultProperty =
|
|
BindableProperty.Create(nameof(Result), typeof(IScanResult), typeof(FacePage), default(IScanResult));
|
|
|
|
public IScanResult Result
|
|
{
|
|
get { return (IScanResult)GetValue(ResultProperty); }
|
|
set { SetValue(ResultProperty, value); }
|
|
}
|
|
}
|
|
} |