|
| 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 androidx.annotation.NonNull; |
| 8 | +import androidx.annotation.VisibleForTesting; |
| 9 | +import androidx.camera.core.resolutionselector.AspectRatioStrategy; |
| 10 | +import io.flutter.plugins.camerax.GeneratedCameraXLibrary.AspectRatioStrategyHostApi; |
| 11 | + |
| 12 | +/** |
| 13 | + * Host API implementation for {@link AspectRatioStrategy}. |
| 14 | + * |
| 15 | + * <p>This class handles instantiating and adding native object instances that are attached to a |
| 16 | + * Dart instance or handle method calls on the associated native class or an instance of the class. |
| 17 | + */ |
| 18 | +public class AspectRatioStrategyHostApiImpl implements AspectRatioStrategyHostApi { |
| 19 | + private final InstanceManager instanceManager; |
| 20 | + private final AspectRatioStrategyProxy proxy; |
| 21 | + |
| 22 | + /** Proxy for constructors and static method of {@link AspectRatioStrategy}. */ |
| 23 | + @VisibleForTesting |
| 24 | + public static class AspectRatioStrategyProxy { |
| 25 | + /** Creates an instance of {@link AspectRatioStrategy}. */ |
| 26 | + @NonNull |
| 27 | + public AspectRatioStrategy create( |
| 28 | + @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) { |
| 29 | + return new AspectRatioStrategy(preferredAspectRatio.intValue(), fallbackRule.intValue()); |
| 30 | + } |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Constructs an {@link AspectRatioStrategyHostApiImpl}. |
| 35 | + * |
| 36 | + * @param instanceManager maintains instances stored to communicate with attached Dart objects |
| 37 | + */ |
| 38 | + public AspectRatioStrategyHostApiImpl(@NonNull InstanceManager instanceManager) { |
| 39 | + this(instanceManager, new AspectRatioStrategyProxy()); |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Constructs an {@link AspectRatioStrategyHostApiImpl}. |
| 44 | + * |
| 45 | + * @param instanceManager maintains instances stored to communicate with attached Dart objects |
| 46 | + * @param proxy proxy for constructors and static method of {@link AspectRatioStrategy} |
| 47 | + */ |
| 48 | + @VisibleForTesting |
| 49 | + AspectRatioStrategyHostApiImpl( |
| 50 | + @NonNull InstanceManager instanceManager, @NonNull AspectRatioStrategyProxy proxy) { |
| 51 | + this.instanceManager = instanceManager; |
| 52 | + this.proxy = proxy; |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * Creates an {@link AspectRatioStrategy} instance with the preferred aspect ratio and fallback |
| 57 | + * rule specified. |
| 58 | + */ |
| 59 | + @Override |
| 60 | + public void create( |
| 61 | + @NonNull Long identifier, @NonNull Long preferredAspectRatio, @NonNull Long fallbackRule) { |
| 62 | + instanceManager.addDartCreatedInstance( |
| 63 | + proxy.create(preferredAspectRatio, fallbackRule), identifier); |
| 64 | + } |
| 65 | +} |
0 commit comments