Skip to content

Commit

Permalink
Android Forms: Fix camera orientation after rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
Redth committed Nov 15, 2016
1 parent 81a74a7 commit 858d1a5
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions Source/ZXing.Net.Mobile.Android/ZXingSurfaceView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,30 @@ public void SurfaceCreated (ISurfaceHolder holder)

}

int lastSurfaceWx = -1;
int lastSurfaceHx = -1;

public void SurfaceChanged (ISurfaceHolder holder, Format format, int wx, int hx)
{
tcsSurfaceReady.TrySetResult (null);

if (wasStarted) {
SetupCamera ().ContinueWith (t => {
MobileBarcodeScanner.LogError ("SetupCamera Failed: {0}", t.Exception);
}, TaskContinuationOptions.OnlyOnFaulted);
if (camera == null)
{
SetupCamera().ContinueWith(t =>
{
MobileBarcodeScanner.LogError("SetupCamera Failed: {0}", t.Exception);
}, TaskContinuationOptions.OnlyOnFaulted);
}
else
{
if (this.activity != null && (lastSurfaceHx != hx || lastSurfaceWx != wx))
{
lastSurfaceHx = hx;
lastSurfaceWx = wx;
SetCameraDisplayOrientation(this.activity);
}
}
}
}

Expand All @@ -103,6 +119,9 @@ public void SurfaceDestroyed (ISurfaceHolder holder)
theCamera.SetPreviewCallback (null);
theCamera.StopPreview ();
theCamera.Release ();

lastSurfaceHx = -1;
lastSurfaceWx = -1;
}
tcsSurfaceReady = new TaskCompletionSource<object> ();
ReleaseExclusiveAccess ();
Expand Down

0 comments on commit 858d1a5

Please sign in to comment.