Hello,
Welcome to our Microsoft Q&A platform!
how to draw the circle on focus and dismiss it when the view becomes unfocused as well keep redrawing it when the camera is focused.
Try to get the circle view in the renderer class and then change the visibility of the view to hide/show the circle. Here is the related code, you could refer to it.
ImageView focus_circle;
void SetupUserInterface()
{
activity = this.Context as Activity;
view = activity.LayoutInflater.Inflate(Resource.Layout.CameraLayout, this, false);
textureView = view.FindViewById<TextureView>(Resource.Id.textureView);
...
textureView.Touch += TextureView_Touch; ;
focus_circle = view.FindViewById<ImageView>(Resource.Id.focus_circle);
}
private void TextureView_Touch(object sender, TouchEventArgs e)
{
if (camera != null)
{
var parameters = camera.GetParameters();
camera.CancelAutoFocus();
Android.Graphics.Rect focusRect = CalculateTapArea(e.Event.GetX(), e.Event.GetY(), 1f);
if (parameters.FocusMode != Android.Hardware.Camera.Parameters.FocusModeAuto)
{
parameters.FocusMode = Android.Hardware.Camera.Parameters.FocusModeAuto;
}
if (parameters.MaxNumFocusAreas > 0)
{
List<Area> mylist = new List<Area>();
mylist.Add(new Android.Hardware.Camera.Area(focusRect, 1000));
parameters.FocusAreas = mylist;
}
try
{
camera.CancelAutoFocus();
camera.SetParameters(parameters);
camera.StartPreview();
camera.AutoFocus(this);
//you could define the layoutParameters of the circle and then set the visibility to visible
focus_circle.Visibility = ViewStates.Visible;
}
catch (System.Exception ex)
{
Console.WriteLine(ex.ToString());
Console.Write(ex.StackTrace);
}
}
else
{
//return false;
}
}
public void OnAutoFocus(bool success, Android.Hardware.Camera camera)
{
...
//hide the circle
if (success)
{
Task.Delay(1000);
focus_circle.Visibility = ViewStates.Invisible;
}
}
For more details, you could refer to this thread: https://stackoverflow.com/a/41053193/11083277
Best Regards,
Jarvan Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.