-
Notifications
You must be signed in to change notification settings - Fork 208
Fix need to rotate android device to landscape to scan 1D barcodes, also fix focus and auto focus not being implemented #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
910e35d
cc715e5
e8386ac
d6eb72e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,10 +39,12 @@ internal partial class CameraManager | |
| ProcessCameraProvider cameraProvider; | ||
| ICamera camera; | ||
|
|
||
| Timer timer; | ||
|
|
||
| public NativePlatformCameraPreviewView CreateNativeView() | ||
| { | ||
| previewView = new PreviewView(Context.Context); | ||
| cameraExecutor = Executors.NewSingleThreadExecutor(); | ||
| cameraExecutor = Executors.NewSingleThreadExecutor(); | ||
|
|
||
| return previewView; | ||
| } | ||
|
|
@@ -63,6 +65,7 @@ public void Connect() | |
| // Frame by frame analyze | ||
| imageAnalyzer = new ImageAnalysis.Builder() | ||
| .SetDefaultResolution(new Android.Util.Size(640, 480)) | ||
| .SetOutputImageRotationEnabled(true) | ||
| .SetBackpressureStrategy(ImageAnalysis.StrategyKeepOnlyLatest) | ||
| .Build(); | ||
|
|
||
|
|
@@ -71,9 +74,64 @@ public void Connect() | |
|
|
||
| UpdateCamera(); | ||
|
|
||
| }), ContextCompat.GetMainExecutor(Context.Context)); //GetMainExecutor: returns an Executor that runs on the main thread. | ||
| AutoFocus(); | ||
| setupAutoFocusTimer(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like it adds a continuous autofocus that's never canceled, even when you explicitly call one of the other functions. |
||
| ((View)previewView.Parent).SetOnTouchListener(new TapFocusTouchListener(this)); | ||
|
|
||
|
|
||
| }), ContextCompat.GetMainExecutor(Context.Context)); //GetMainExecutor: returns an Executor that runs on the main thread. | ||
| } | ||
|
|
||
| private class TapFocusTouchListener : Java.Lang.Object, View.IOnTouchListener { | ||
|
|
||
| private CameraManager cameraManager; | ||
|
|
||
| public TapFocusTouchListener(CameraManager cameraManager) | ||
| { | ||
| this.cameraManager = cameraManager; | ||
| } | ||
|
|
||
| public bool OnTouch(View v, MotionEvent e) | ||
| { | ||
|
|
||
| if (e.Action == MotionEventActions.Down) | ||
| { | ||
| Point point = new Point(((int)e.GetX()), ((int)e.GetY())); | ||
| cameraManager.Focus(point); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| private void setupAutoFocusTimer() | ||
| { | ||
| if(timer != null) | ||
| { | ||
| timer.Cancel(); | ||
| timer.Dispose(); | ||
| timer = null; | ||
| } | ||
| timer = new Timer(); | ||
| var task = new AFTimerTask(this); | ||
| timer.ScheduleAtFixedRate(task, 5000, 5000); | ||
| } | ||
|
|
||
| private class AFTimerTask : TimerTask | ||
| { | ||
| private CameraManager cameraManager; | ||
|
|
||
| public AFTimerTask(CameraManager manager) | ||
| { | ||
| this.cameraManager = manager; | ||
| } | ||
|
|
||
| public override void Run() | ||
| { | ||
| cameraManager.AutoFocus(); | ||
| } | ||
| } | ||
|
|
||
| public void Disconnect() | ||
| { } | ||
|
|
||
|
|
@@ -110,13 +168,30 @@ public void UpdateTorch(bool on) | |
|
|
||
| public void Focus(Point point) | ||
| { | ||
| camera?.CameraControl?.CancelFocusAndMetering(); | ||
|
|
||
| } | ||
| var factory = new SurfaceOrientedMeteringPointFactory(previewView.LayoutParameters.Width, previewView.LayoutParameters.Height); | ||
| var fpoint = factory.CreatePoint(point.X, point.Y); | ||
| var action = new FocusMeteringAction.Builder(fpoint, FocusMeteringAction.FlagAf) | ||
| .DisableAutoCancel() | ||
| .Build(); | ||
|
|
||
| camera?.CameraControl?.StartFocusAndMetering(action); | ||
|
|
||
| } | ||
|
|
||
| public void AutoFocus() | ||
| { | ||
| camera?.CameraControl?.CancelFocusAndMetering(); | ||
| var factory = new SurfaceOrientedMeteringPointFactory(1f, 1f); | ||
| var fpoint = factory.CreatePoint(.5f, .5f); | ||
| var action = new FocusMeteringAction.Builder(fpoint,FocusMeteringAction.FlagAf) | ||
| //.DisableAutoCancel() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either remove this or uncomment it. |
||
| .Build(); | ||
|
|
||
| } | ||
| camera?.CameraControl?.StartFocusAndMetering(action); | ||
|
|
||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be set based on some input?
I don't want it to auto-rotate if I initialise this: