Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions CustomRenderers/View/CustomRenderer/CameraPreview.cs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

namespace CustomRenderer
{
public class CameraPreview : View
{
public static readonly BindableProperty CameraProperty = BindableProperty.Create (
propertyName: "Camera",
returnType: typeof(CameraOptions),
declaringType: typeof(CameraPreview),
defaultValue: CameraOptions.Rear);
public class CameraPreview : View
{
public static readonly BindableProperty CameraProperty = BindableProperty.Create(
propertyName: "Camera",
returnType: typeof(CameraOptions),
declaringType: typeof(CameraPreview),
defaultValue: CameraOptions.Rear);

public CameraOptions Camera {
get { return (CameraOptions)GetValue (CameraProperty); }
set { SetValue (CameraProperty, value); }
}
}
public CameraOptions Camera
{
get { return (CameraOptions)GetValue(CameraProperty); }
set { SetValue(CameraProperty, value); }
}
}
}
2 changes: 1 addition & 1 deletion CustomRenderers/View/CustomRenderer/CustomRenderer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
</EmbeddedResource>
</ItemGroup>

</Project>
</Project>
13 changes: 6 additions & 7 deletions CustomRenderers/View/CustomRenderer/MainPage.xaml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:CustomRenderer;assembly=CustomRenderer"
x:Class="CustomRenderer.MainPage"
Padding="0,20,0,0"
Title="Main Page">
<ContentPage.Content>
<StackLayout>
<Label Text="Camera Preview:" />
<local:CameraPreview Camera="Rear" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage.Content>
<StackLayout Margin="20,35,20,20">
<Label Text="Camera Preview:" />
<local:CameraPreview Camera="Rear"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" />
</StackLayout>
</ContentPage>
84 changes: 84 additions & 0 deletions CustomRenderers/View/Droid/AutoFitTextureView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System;
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Views;

namespace CustomRenderer.Droid
{
public class AutoFitTextureView : TextureView
{
int mRatioWidth = 0;
int mRatioHeight = 0;
readonly object locker = new object();

public AutoFitTextureView(Context context) : this(context, null)
{
}

public AutoFitTextureView(Context context, IAttributeSet attrs) : this(context, attrs, 0)
{
}

public AutoFitTextureView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
}

protected AutoFitTextureView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}

public void SetAspectRatio(int width, int height)
{
if (width == 0 || height == 0)
{
throw new ArgumentException("Size can't be negative.");
}

mRatioWidth = width;
mRatioHeight = height;
RequestLayout();
}

protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
base.OnMeasure(widthMeasureSpec, heightMeasureSpec);

int width = MeasureSpec.GetSize(widthMeasureSpec);
int height = MeasureSpec.GetSize(heightMeasureSpec);

if (mRatioWidth == 0 || mRatioHeight == 0)
{
SetMeasuredDimension(width, height);
}
else
{
if (width < (float)height * mRatioWidth / mRatioHeight)
{
SetMeasuredDimension(width, width * mRatioHeight / mRatioWidth);
}
else
{
SetMeasuredDimension(height * mRatioWidth / mRatioHeight, height);
}
}
}

public void ClearCanvas(Android.Graphics.Color color)
{
using var canvas = LockCanvas(null);
lock (locker)
{
try
{
canvas.DrawColor(color);
}
finally
{
UnlockCanvasAndPost(canvas);
}
Invalidate();
}
}
}
}
14 changes: 14 additions & 0 deletions CustomRenderers/View/Droid/CameraCaptureStateListener.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using Android.Hardware.Camera2;

namespace CustomRenderer.Droid
{
class CameraCaptureStateListener : CameraCaptureSession.StateCallback
{
public Action<CameraCaptureSession> OnConfigureFailedAction;
public Action<CameraCaptureSession> OnConfiguredAction;

public override void OnConfigureFailed(CameraCaptureSession session) => OnConfigureFailedAction?.Invoke(session);
public override void OnConfigured(CameraCaptureSession session) => OnConfiguredAction?.Invoke(session);
}
}
Loading