Skip to content

Commit

Permalink
Fix problems in some Android Devices
Browse files Browse the repository at this point in the history
  • Loading branch information
hjam40 committed May 19, 2023
1 parent a44a7c4 commit ea0c680
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Camera.MAUI.Test/SizedPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
<CheckBox CheckedChanged="CheckBox3_CheckedChanged" VerticalOptions="Center" Color="Black"/>
</HorizontalStackLayout>
<HorizontalStackLayout HorizontalOptions="Center">
<Label Text="AutoSnap freq: " VerticalOptions="Center" TextColor="Black"/>
<Entry WidthRequest="20" TextChanged="Entry_TextChanged" Keyboard="Numeric" TextColor="Black" />
<Label Text="Take Autosnap" VerticalOptions="Center" TextColor="Black"/>
<Label Text="Flash" VerticalOptions="Center" TextColor="Black"/>
<CheckBox CheckedChanged="CheckBox_CheckedChanged_1" VerticalOptions="Center" Color="Black"/>
<Label Text="As ISource" VerticalOptions="Center" TextColor="Black"/>
<CheckBox BindingContext="{x:Reference cameraView}" IsChecked="{Binding AutoSnapShotAsImageSource}" VerticalOptions="Center" Color="Black"/>
Expand Down
6 changes: 1 addition & 5 deletions Camera.MAUI.Test/SizedPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ private void Entry_TextChanged(object sender, TextChangedEventArgs e)

private void CheckBox_CheckedChanged_1(object sender, CheckedChangedEventArgs e)
{
if (e.Value && cameraView.AutoSnapShotSeconds <= 0 || !cameraView.AutoSnapShotAsImageSource)
snapPreview.SetBinding(Image.SourceProperty, nameof(cameraView.SnapShot));
else if (cameraView.AutoSnapShotSeconds <= 0)
snapPreview.RemoveBinding(Image.SourceProperty);
cameraView.TakeAutoSnapShot = e.Value;
cameraView.FlashMode = e.Value ? FlashMode.Enabled : FlashMode.Disabled;
}

private void MicroPicker_SelectedIndexChanged(object sender, EventArgs e)
Expand Down
2 changes: 1 addition & 1 deletion Camera.MAUI/Apple/MauiCameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void InitDevices()
AVCaptureDevicePosition.Back => CameraPosition.Back,
AVCaptureDevicePosition.Front => CameraPosition.Front,
_ => CameraPosition.Unknow
};
};
cameraView.Cameras.Add(new CameraInfo
{
Name = device.LocalizedName,
Expand Down
4 changes: 2 additions & 2 deletions Camera.MAUI/Camera.MAUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<Authors>hjam40</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<Version>1.4.1</Version>
<PackageReleaseNotes>Compatibility with Android 8
<Version>1.4.2</Version>
<PackageReleaseNotes>Fix problems in some Android Devices
</PackageReleaseNotes>
</PropertyGroup>

Expand Down
3 changes: 3 additions & 0 deletions Camera.MAUI/CameraInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public class CameraInfo
public bool HasFlashUnit { get; internal set; }
public float MinZoomFactor { get; internal set; }
public float MaxZoomFactor { get; internal set; }
public float HorizontalViewAngle { get; internal set; }
public float VerticalViewAngle { get; internal set; }

public List<Size> AvailableResolutions { get; internal set; }
public override string ToString()
{
Expand Down
29 changes: 24 additions & 5 deletions Camera.MAUI/Platforms/Android/MauiCameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
using Size = Android.Util.Size;
using Class = Java.Lang.Class;
using Rect = Android.Graphics.Rect;
using SizeF = Android.Util.SizeF;
using Android.Runtime;
using Android.OS;
using Microsoft.Maui.Controls.PlatformConfiguration;

namespace Camera.MAUI.Platforms.Android;

Expand Down Expand Up @@ -95,12 +95,31 @@ private void InitDevices()
}
cameraInfo.MaxZoomFactor = (float)(chars.Get(CameraCharacteristics.ScalerAvailableMaxDigitalZoom) as Java.Lang.Number);
cameraInfo.HasFlashUnit = (bool)(chars.Get(CameraCharacteristics.FlashInfoAvailable) as Java.Lang.Boolean);
StreamConfigurationMap map = (StreamConfigurationMap)chars.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
cameraInfo.AvailableResolutions = new();
foreach(var s in map.GetOutputSizes(Class.FromType(typeof(ImageReader))))
cameraInfo.AvailableResolutions.Add(new(s.Width, s.Height));
try
{
float[] maxFocus = (float[])chars.Get(CameraCharacteristics.LensInfoAvailableFocalLengths);
SizeF size = (SizeF)chars.Get(CameraCharacteristics.SensorInfoPhysicalSize);
cameraInfo.HorizontalViewAngle = (float)(2 * Math.Atan(size.Width / (maxFocus[0] * 2)));
cameraInfo.VerticalViewAngle = (float)(2 * Math.Atan(size.Height / (maxFocus[0] * 2)));
}
catch { }
try
{
StreamConfigurationMap map = (StreamConfigurationMap)chars.Get(CameraCharacteristics.ScalerStreamConfigurationMap);
foreach (var s in map.GetOutputSizes(Class.FromType(typeof(ImageReader))))
cameraInfo.AvailableResolutions.Add(new(s.Width, s.Height));
}
catch
{
if (cameraInfo.Position == CameraPosition.Back)
cameraInfo.AvailableResolutions.Add(new(1920, 1080));
cameraInfo.AvailableResolutions.Add(new(1280, 720));
cameraInfo.AvailableResolutions.Add(new(640, 480));
cameraInfo.AvailableResolutions.Add(new(352, 288));
}
cameraView.Cameras.Add(cameraInfo);
}
}
if (OperatingSystem.IsAndroidVersionAtLeast(30))
{
cameraView.Microphones.Clear();
Expand Down

0 comments on commit ea0c680

Please sign in to comment.