-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Nuget Packages & Remove ZXing.Net.Mobile Add MLKit + Camera2
- Loading branch information
Showing
17 changed files
with
151 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 56 additions & 57 deletions
113
src/ST.Client.Mobile.Droid/Extensions/ZXingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,56 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xamarin.Essentials; | ||
using ZXing; | ||
using ZXing.Mobile; | ||
using ZXingResult = ZXing.Result; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace System | ||
{ | ||
public static class ZXingExtensions | ||
{ | ||
// https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Sample.Android/MainActivity.cs | ||
|
||
public static async void StartScan(this MobileBarcodeScanner? scanner, Action<ZXingResult> handleScanResult) | ||
{ | ||
if (scanner == null) return; | ||
|
||
// Tell our scanner to use the default overlay | ||
scanner.UseCustomOverlay = false; | ||
|
||
// We can customize the top and bottom text of the default overlay | ||
scanner.TopText = "Hold the camera up to the barcode\nAbout 6 inches away"; | ||
scanner.BottomText = "Wait for the barcode to automatically scan!"; | ||
|
||
//Start scanning | ||
var result = await scanner.Scan(new() | ||
{ | ||
// https://github.com/Redth/ZXing.Net.Mobile/issues/808#issuecomment-835089415 | ||
PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE }, | ||
CameraResolutionSelector = new((List<CameraResolution> availableResolutions) => | ||
{ | ||
CameraResolution? result = null; | ||
|
||
double aspectTolerance = 0.1; | ||
var displayOrientationHeight = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? DeviceDisplay.MainDisplayInfo.Height : DeviceDisplay.MainDisplayInfo.Width; | ||
var displayOrientationWidth = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? DeviceDisplay.MainDisplayInfo.Width : DeviceDisplay.MainDisplayInfo.Height; | ||
|
||
var targetRatio = displayOrientationHeight / displayOrientationWidth; | ||
var targetHeight = displayOrientationHeight; | ||
var minDiff = double.MaxValue; | ||
|
||
foreach (var r in availableResolutions.Where(r => Math.Abs(((double)r.Width / r.Height) - targetRatio) < aspectTolerance)) | ||
{ | ||
if (Math.Abs(r.Height - targetHeight) < minDiff) | ||
minDiff = Math.Abs(r.Height - targetHeight); | ||
result = r; | ||
} | ||
return result; | ||
}) | ||
}); | ||
if (result == null) return; | ||
|
||
handleScanResult(result); | ||
} | ||
} | ||
} | ||
//using System.Collections.Generic; | ||
//using System.Linq; | ||
//using System.Threading.Tasks; | ||
//using Xamarin.Essentials; | ||
//using ZXing; | ||
//using ZXing.Mobile; | ||
//using ZXingResult = ZXing.Result; | ||
|
||
//// ReSharper disable once CheckNamespace | ||
//namespace System | ||
//{ | ||
// public static class ZXingExtensions | ||
// { | ||
// // https://github.com/Redth/ZXing.Net.Mobile/blob/master/Samples/Sample.Android/MainActivity.cs | ||
|
||
// public static async Task<ZXingResult?> StartScanAsync(this MobileBarcodeScanner? scanner, string? topText = null, string? bottomText = null) | ||
// { | ||
// if (scanner == null) return null; | ||
|
||
// // Tell our scanner to use the default overlay | ||
// scanner.UseCustomOverlay = false; | ||
|
||
// // We can customize the top and bottom text of the default overlay | ||
// scanner.TopText = topText ?? "Hold the camera up to the barcode\nAbout 6 inches away"; | ||
// scanner.BottomText = bottomText ?? "Wait for the barcode to automatically scan!"; | ||
|
||
// //Start scanning | ||
// var result = await scanner.Scan(new() | ||
// { | ||
// // https://github.com/Redth/ZXing.Net.Mobile/issues/808#issuecomment-835089415 | ||
// PossibleFormats = new List<BarcodeFormat>() { BarcodeFormat.QR_CODE }, | ||
// CameraResolutionSelector = new((List<CameraResolution> availableResolutions) => | ||
// { | ||
// CameraResolution? result = null; | ||
|
||
// double aspectTolerance = 0.1; | ||
// var displayOrientationHeight = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? DeviceDisplay.MainDisplayInfo.Height : DeviceDisplay.MainDisplayInfo.Width; | ||
// var displayOrientationWidth = DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Portrait ? DeviceDisplay.MainDisplayInfo.Width : DeviceDisplay.MainDisplayInfo.Height; | ||
|
||
// var targetRatio = displayOrientationHeight / displayOrientationWidth; | ||
// var targetHeight = displayOrientationHeight; | ||
// var minDiff = double.MaxValue; | ||
|
||
// foreach (var r in availableResolutions.Where(r => Math.Abs(((double)r.Width / r.Height) - targetRatio) < aspectTolerance)) | ||
// { | ||
// if (Math.Abs(r.Height - targetHeight) < minDiff) | ||
// minDiff = Math.Abs(r.Height - targetHeight); | ||
// result = r; | ||
// } | ||
// return result; | ||
// }) | ||
// }); | ||
// return result; | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...Mobile.Droid/UI/Fragments/LocalAuthPage/LocalAuthSteamToolsImportFragment.MLKitCameraX.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace System.Application.UI.Fragments | ||
{ | ||
partial class LocalAuthSteamToolsImportFragment | ||
{ | ||
internal sealed class MLKitCameraX : LocalAuthSteamToolsImportFragment | ||
{ | ||
protected override void OnBtnImportV2ByQRCodeClick() | ||
{ | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
....Mobile.Droid/UI/Fragments/LocalAuthPage/LocalAuthSteamToolsImportFragment.ZXingMobile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//using Android.Views; | ||
//using ZXing.Mobile; | ||
|
||
//namespace System.Application.UI.Fragments | ||
//{ | ||
// partial class LocalAuthSteamToolsImportFragment | ||
// { | ||
// internal sealed class ZXing : LocalAuthSteamToolsImportFragment | ||
// { | ||
// MobileBarcodeScanner? scanner; | ||
|
||
// public override void OnCreateView(View view) | ||
// { | ||
// base.OnCreateView(view); | ||
|
||
// //Create a new instance of our Scanner | ||
// scanner = new(); | ||
// } | ||
|
||
// protected override async void OnBtnImportV2ByQRCodeClick() | ||
// { | ||
// var result = await scanner.StartScanAsync(); | ||
// if (result == null) return; | ||
// if (!result.RawBytes.Any_Nullable()) return; | ||
// ViewModel!.ImportSteamPlusPlusV2(result.RawBytes!); | ||
// } | ||
// } | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.