|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +package io.flutter.plugins.camerax; |
| 6 | + |
| 7 | +import android.util.Size; |
| 8 | +import androidx.annotation.NonNull; |
| 9 | +import androidx.annotation.Nullable; |
| 10 | +import androidx.annotation.VisibleForTesting; |
| 11 | +import androidx.camera.core.MeteringPoint; |
| 12 | +import androidx.camera.core.MeteringPointFactory; |
| 13 | +import androidx.camera.core.SurfaceMeteringPointFactory; |
| 14 | +import io.flutter.plugins.camerax.GeneratedCameraXLibrary.MeteringPointHostApi; |
| 15 | + |
| 16 | +/** |
| 17 | + * Host API implementation for {@link MeteringPoint}. |
| 18 | + * |
| 19 | + * <p>This class handles instantiating and adding native object instances that are attached to a |
| 20 | + * Dart instance or handle method calls on the associated native class or an instance of the class. |
| 21 | + */ |
| 22 | +public class MeteringPointHostApiImpl implements MeteringPointHostApi { |
| 23 | + private final InstanceManager instanceManager; |
| 24 | + private final MeteringPointProxy proxy; |
| 25 | + |
| 26 | + /** Proxy for constructors and static method of {@link MeteringPoint}. */ |
| 27 | + @VisibleForTesting |
| 28 | + public static class MeteringPointProxy { |
| 29 | + |
| 30 | + public void create(@NonNull Double x, @NonNull Double y, @Nullable Double size) { |
| 31 | + SurfaceOrientedMeteringPointFactory factory = new SurfaceOrientedMeteringPointFactory(1f, 1f); // TODO(camsim99): get feedback on using this default instead of exposing |
| 32 | + if (size == null) { |
| 33 | + return factory.createPoint(x, y); |
| 34 | + } else { |
| 35 | + return factory.createPoint(x, y, size); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @NonNull |
| 40 | + public float getDefaultPointSize() { |
| 41 | + return MeteringPointFactory.getDefaultPointSize(); |
| 42 | + } |
| 43 | + } |
| 44 | + /** |
| 45 | + * Constructs a {@link MeteringPointHostApiImpl}. |
| 46 | + * |
| 47 | + * @param instanceManager maintains instances stored to communicate with attached Dart objects |
| 48 | + */ |
| 49 | + public MeteringPointHostApiImpl(@NonNull InstanceManager instanceManager) { |
| 50 | + this(instanceManager, new MeteringPointProxy()); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Constructs a {@link MeteringPointHostApiImpl}. |
| 55 | + * |
| 56 | + * @param instanceManager maintains instances stored to communicate with attached Dart objects |
| 57 | + * @param proxy proxy for constructors and static method of {@link MeteringPoint} |
| 58 | + */ |
| 59 | + @VisibleForTesting |
| 60 | + MeteringPointHostApiImpl( |
| 61 | + @NonNull InstanceManager instanceManager, @NonNull MeteringPointProxy proxy) { |
| 62 | + this.instanceManager = instanceManager; |
| 63 | + this.proxy = proxy; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void create(@NonNull Long identifier, @NonNull Double x, @NonNull Double y, @Nullable Double size) { |
| 68 | + MeteringPoint meteringPoint = proxy.create(x, y, size); |
| 69 | + instanceManager.addDartCreatedInstance(meteringPoint, identifier); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + @NonNull |
| 74 | + public Double getDefaultPointSize() { |
| 75 | + return (Double) proxy.getDefaultPointSize; |
| 76 | + } |
| 77 | +} |
0 commit comments