@capgo/camera-preview 7.4.0-alpha.11 → 7.4.0-alpha.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -288,15 +288,17 @@ public class CameraPreview
|
|
|
288
288
|
List<CameraDevice> devices = CameraXView.getAvailableDevicesStatic(
|
|
289
289
|
getContext()
|
|
290
290
|
);
|
|
291
|
+
ZoomFactors zoomFactors = cameraXView.getZoomFactors();
|
|
291
292
|
boolean hasUltraWide = false;
|
|
292
293
|
boolean hasTelephoto = false;
|
|
293
294
|
float minUltra = 0.5f;
|
|
295
|
+
|
|
294
296
|
for (CameraDevice device : devices) {
|
|
295
297
|
for (com.ahm.capacitor.camera.preview.model.LensInfo lens : device.getLenses()) {
|
|
296
298
|
if ("ultraWide".equals(lens.getDeviceType())) {
|
|
297
299
|
hasUltraWide = true;
|
|
298
300
|
// Use overall minZoom for that device as the button value to represent UW
|
|
299
|
-
minUltra = Math.
|
|
301
|
+
minUltra = Math.max(minUltra, zoomFactors.getMin());
|
|
300
302
|
} else if ("telephoto".equals(lens.getDeviceType())) {
|
|
301
303
|
hasTelephoto = true;
|
|
302
304
|
}
|
|
@@ -332,9 +334,8 @@ public class CameraPreview
|
|
|
332
334
|
call.reject("level parameter is required");
|
|
333
335
|
return;
|
|
334
336
|
}
|
|
335
|
-
Boolean autoFocus = call.getBoolean("autoFocus", true);
|
|
336
337
|
try {
|
|
337
|
-
cameraXView.setZoom(level
|
|
338
|
+
cameraXView.setZoom(level);
|
|
338
339
|
call.resolve();
|
|
339
340
|
} catch (Exception e) {
|
|
340
341
|
call.reject("Failed to set zoom: " + e.getMessage());
|
|
@@ -727,7 +727,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
727
727
|
}
|
|
728
728
|
}
|
|
729
729
|
|
|
730
|
-
|
|
730
|
+
setZoom(initialZoom);
|
|
731
731
|
}
|
|
732
732
|
|
|
733
733
|
isRunning = true;
|
|
@@ -1634,7 +1634,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1634
1634
|
}
|
|
1635
1635
|
}
|
|
1636
1636
|
|
|
1637
|
-
public void setZoom(float zoomRatio
|
|
1637
|
+
public void setZoom(float zoomRatio) throws Exception {
|
|
1638
1638
|
if (camera == null) {
|
|
1639
1639
|
throw new Exception("Camera not initialized");
|
|
1640
1640
|
}
|
|
@@ -1643,26 +1643,16 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1643
1643
|
|
|
1644
1644
|
// Just let CameraX handle everything - it should automatically switch lenses
|
|
1645
1645
|
try {
|
|
1646
|
-
|
|
1647
|
-
.getCameraControl()
|
|
1648
|
-
.setZoomRatio(zoomRatio);
|
|
1646
|
+
ZoomFactors zoomFactors = getZoomFactors();
|
|
1649
1647
|
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
triggerAutoFocus();
|
|
1659
|
-
}
|
|
1660
|
-
} catch (Exception e) {
|
|
1661
|
-
Log.e(TAG, "Error setting zoom: " + e.getMessage());
|
|
1662
|
-
}
|
|
1663
|
-
},
|
|
1664
|
-
ContextCompat.getMainExecutor(context)
|
|
1665
|
-
);
|
|
1648
|
+
if (zoomRatio < zoomFactors.getMin()) {
|
|
1649
|
+
zoomRatio = zoomFactors.getMin();
|
|
1650
|
+
} else if (zoomRatio > zoomFactors.getMax()) {
|
|
1651
|
+
zoomRatio = zoomFactors.getMax();
|
|
1652
|
+
}
|
|
1653
|
+
|
|
1654
|
+
camera.getCameraControl().setZoomRatio(zoomRatio);
|
|
1655
|
+
// Note: autofocus is intentionally not triggered on zoom because it's done by CameraX
|
|
1666
1656
|
} catch (Exception e) {
|
|
1667
1657
|
Log.e(TAG, "Failed to set zoom: " + e.getMessage());
|
|
1668
1658
|
throw e;
|
|
@@ -1821,8 +1811,8 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1821
1811
|
|
|
1822
1812
|
// Set initial state for smooth animation
|
|
1823
1813
|
focusIndicatorView.setAlpha(1f); // Start visible
|
|
1824
|
-
focusIndicatorView.setScaleX(1.
|
|
1825
|
-
focusIndicatorView.setScaleY(1.
|
|
1814
|
+
focusIndicatorView.setScaleX(1.4f); // Start slightly larger for a quick scale-in
|
|
1815
|
+
focusIndicatorView.setScaleY(1.4f);
|
|
1826
1816
|
focusIndicatorView.setVisibility(View.VISIBLE);
|
|
1827
1817
|
|
|
1828
1818
|
// Ensure container doesn't intercept touch events
|
|
@@ -1848,16 +1838,16 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1848
1838
|
|
|
1849
1839
|
// Smooth scale down animation with easing (no fade needed since we start visible)
|
|
1850
1840
|
ScaleAnimation scaleAnimation = new ScaleAnimation(
|
|
1851
|
-
1.
|
|
1841
|
+
1.4f,
|
|
1852
1842
|
1.0f,
|
|
1853
|
-
1.
|
|
1843
|
+
1.4f,
|
|
1854
1844
|
1.0f,
|
|
1855
1845
|
Animation.RELATIVE_TO_SELF,
|
|
1856
1846
|
0.5f,
|
|
1857
1847
|
Animation.RELATIVE_TO_SELF,
|
|
1858
1848
|
0.5f
|
|
1859
1849
|
);
|
|
1860
|
-
scaleAnimation.setDuration(
|
|
1850
|
+
scaleAnimation.setDuration(120);
|
|
1861
1851
|
scaleAnimation.setInterpolator(
|
|
1862
1852
|
new android.view.animation.OvershootInterpolator(1.2f)
|
|
1863
1853
|
);
|
|
@@ -1865,7 +1855,7 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1865
1855
|
// Start the animation
|
|
1866
1856
|
focusIndicatorView.startAnimation(scaleAnimation);
|
|
1867
1857
|
|
|
1868
|
-
// Schedule fade out and removal
|
|
1858
|
+
// Schedule fast fade out and removal
|
|
1869
1859
|
focusIndicatorView.postDelayed(
|
|
1870
1860
|
new Runnable() {
|
|
1871
1861
|
@Override
|
|
@@ -1876,121 +1866,39 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
1876
1866
|
thisIndicatorView == focusIndicatorView &&
|
|
1877
1867
|
thisAnimationId == focusIndicatorAnimationId
|
|
1878
1868
|
) {
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
@Override
|
|
1894
|
-
public void onAnimationEnd(Animation animation) {
|
|
1895
|
-
Log.d(
|
|
1896
|
-
TAG,
|
|
1897
|
-
"showFocusIndicator: Fade to transparent ended, starting final fade out"
|
|
1898
|
-
);
|
|
1899
|
-
// Final smooth fade out and scale down
|
|
1900
|
-
if (
|
|
1901
|
-
focusIndicatorView != null &&
|
|
1902
|
-
thisIndicatorView == focusIndicatorView &&
|
|
1903
|
-
thisAnimationId == focusIndicatorAnimationId
|
|
1904
|
-
) {
|
|
1905
|
-
AnimationSet finalAnimation = new AnimationSet(false);
|
|
1906
|
-
|
|
1907
|
-
AlphaAnimation finalFadeOut = new AlphaAnimation(0.4f, 0f);
|
|
1908
|
-
finalFadeOut.setDuration(500);
|
|
1909
|
-
finalFadeOut.setStartOffset(300);
|
|
1910
|
-
finalFadeOut.setInterpolator(
|
|
1911
|
-
new android.view.animation.AccelerateInterpolator()
|
|
1912
|
-
);
|
|
1913
|
-
|
|
1914
|
-
ScaleAnimation finalScaleDown = new ScaleAnimation(
|
|
1915
|
-
1.0f,
|
|
1916
|
-
0.9f,
|
|
1917
|
-
1.0f,
|
|
1918
|
-
0.9f,
|
|
1919
|
-
Animation.RELATIVE_TO_SELF,
|
|
1920
|
-
0.5f,
|
|
1921
|
-
Animation.RELATIVE_TO_SELF,
|
|
1922
|
-
0.5f
|
|
1923
|
-
);
|
|
1924
|
-
finalScaleDown.setDuration(500);
|
|
1925
|
-
finalScaleDown.setStartOffset(300);
|
|
1926
|
-
finalScaleDown.setInterpolator(
|
|
1927
|
-
new android.view.animation.AccelerateInterpolator()
|
|
1928
|
-
);
|
|
1929
|
-
|
|
1930
|
-
finalAnimation.addAnimation(finalFadeOut);
|
|
1931
|
-
finalAnimation.addAnimation(finalScaleDown);
|
|
1932
|
-
|
|
1933
|
-
finalAnimation.setAnimationListener(
|
|
1934
|
-
new Animation.AnimationListener() {
|
|
1935
|
-
@Override
|
|
1936
|
-
public void onAnimationStart(Animation animation) {
|
|
1937
|
-
Log.d(
|
|
1938
|
-
TAG,
|
|
1939
|
-
"showFocusIndicator: Final animation started"
|
|
1940
|
-
);
|
|
1941
|
-
}
|
|
1942
|
-
|
|
1943
|
-
@Override
|
|
1944
|
-
public void onAnimationEnd(Animation animation) {
|
|
1945
|
-
Log.d(
|
|
1946
|
-
TAG,
|
|
1947
|
-
"showFocusIndicator: Final animation ended, removing indicator"
|
|
1948
|
-
);
|
|
1949
|
-
// Remove the focus indicator
|
|
1950
|
-
if (
|
|
1951
|
-
focusIndicatorView != null &&
|
|
1952
|
-
previewContainer != null &&
|
|
1953
|
-
thisIndicatorView == focusIndicatorView &&
|
|
1954
|
-
thisAnimationId == focusIndicatorAnimationId
|
|
1955
|
-
) {
|
|
1956
|
-
try {
|
|
1957
|
-
focusIndicatorView.clearAnimation();
|
|
1958
|
-
} catch (Exception ignore) {}
|
|
1959
|
-
previewContainer.removeView(focusIndicatorView);
|
|
1960
|
-
focusIndicatorView = null;
|
|
1961
|
-
}
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
@Override
|
|
1965
|
-
public void onAnimationRepeat(Animation animation) {}
|
|
1966
|
-
}
|
|
1967
|
-
);
|
|
1968
|
-
|
|
1869
|
+
focusIndicatorView
|
|
1870
|
+
.animate()
|
|
1871
|
+
.alpha(0f)
|
|
1872
|
+
.scaleX(0.9f)
|
|
1873
|
+
.scaleY(0.9f)
|
|
1874
|
+
.setDuration(180)
|
|
1875
|
+
.setInterpolator(
|
|
1876
|
+
new android.view.animation.AccelerateInterpolator()
|
|
1877
|
+
)
|
|
1878
|
+
.withEndAction(
|
|
1879
|
+
new Runnable() {
|
|
1880
|
+
@Override
|
|
1881
|
+
public void run() {
|
|
1969
1882
|
if (
|
|
1883
|
+
focusIndicatorView != null &&
|
|
1884
|
+
previewContainer != null &&
|
|
1970
1885
|
thisIndicatorView == focusIndicatorView &&
|
|
1971
1886
|
thisAnimationId == focusIndicatorAnimationId
|
|
1972
1887
|
) {
|
|
1973
|
-
|
|
1888
|
+
try {
|
|
1889
|
+
focusIndicatorView.clearAnimation();
|
|
1890
|
+
} catch (Exception ignore) {}
|
|
1891
|
+
previewContainer.removeView(focusIndicatorView);
|
|
1892
|
+
focusIndicatorView = null;
|
|
1974
1893
|
}
|
|
1975
1894
|
}
|
|
1976
1895
|
}
|
|
1977
|
-
|
|
1978
|
-
@Override
|
|
1979
|
-
public void onAnimationRepeat(Animation animation) {}
|
|
1980
|
-
}
|
|
1981
|
-
);
|
|
1982
|
-
|
|
1983
|
-
if (
|
|
1984
|
-
thisIndicatorView == focusIndicatorView &&
|
|
1985
|
-
thisAnimationId == focusIndicatorAnimationId
|
|
1986
|
-
) {
|
|
1987
|
-
focusIndicatorView.startAnimation(fadeToTransparent);
|
|
1988
|
-
}
|
|
1896
|
+
);
|
|
1989
1897
|
}
|
|
1990
1898
|
}
|
|
1991
1899
|
},
|
|
1992
|
-
|
|
1993
|
-
); //
|
|
1900
|
+
250
|
|
1901
|
+
); // Faster feedback
|
|
1994
1902
|
}
|
|
1995
1903
|
|
|
1996
1904
|
public static List<Size> getSupportedPictureSizes(String facing) {
|
|
@@ -2016,89 +1924,6 @@ public class CameraXView implements LifecycleOwner, LifecycleObserver {
|
|
|
2016
1924
|
return sizes;
|
|
2017
1925
|
}
|
|
2018
1926
|
|
|
2019
|
-
private void setZoomInternal(float zoomRatio) {
|
|
2020
|
-
if (camera != null) {
|
|
2021
|
-
try {
|
|
2022
|
-
float minZoom = Objects.requireNonNull(
|
|
2023
|
-
camera.getCameraInfo().getZoomState().getValue()
|
|
2024
|
-
).getMinZoomRatio();
|
|
2025
|
-
float maxZoom = camera
|
|
2026
|
-
.getCameraInfo()
|
|
2027
|
-
.getZoomState()
|
|
2028
|
-
.getValue()
|
|
2029
|
-
.getMaxZoomRatio();
|
|
2030
|
-
float currentZoom = camera
|
|
2031
|
-
.getCameraInfo()
|
|
2032
|
-
.getZoomState()
|
|
2033
|
-
.getValue()
|
|
2034
|
-
.getZoomRatio();
|
|
2035
|
-
|
|
2036
|
-
Log.d(
|
|
2037
|
-
TAG,
|
|
2038
|
-
"setZoomInternal: Current camera range: " +
|
|
2039
|
-
minZoom +
|
|
2040
|
-
"-" +
|
|
2041
|
-
maxZoom +
|
|
2042
|
-
", current: " +
|
|
2043
|
-
currentZoom
|
|
2044
|
-
);
|
|
2045
|
-
Log.d(TAG, "setZoomInternal: Requesting zoom: " + zoomRatio);
|
|
2046
|
-
|
|
2047
|
-
// Try to set zoom directly - let CameraX handle lens switching
|
|
2048
|
-
ListenableFuture<Void> zoomFuture = camera
|
|
2049
|
-
.getCameraControl()
|
|
2050
|
-
.setZoomRatio(zoomRatio);
|
|
2051
|
-
|
|
2052
|
-
zoomFuture.addListener(
|
|
2053
|
-
() -> {
|
|
2054
|
-
try {
|
|
2055
|
-
zoomFuture.get(); // Check if zoom was successful
|
|
2056
|
-
float newZoom = Objects.requireNonNull(
|
|
2057
|
-
camera.getCameraInfo().getZoomState().getValue()
|
|
2058
|
-
).getZoomRatio();
|
|
2059
|
-
Log.d(
|
|
2060
|
-
TAG,
|
|
2061
|
-
"setZoomInternal: Zoom set successfully to " +
|
|
2062
|
-
newZoom +
|
|
2063
|
-
" (requested: " +
|
|
2064
|
-
zoomRatio +
|
|
2065
|
-
")"
|
|
2066
|
-
);
|
|
2067
|
-
|
|
2068
|
-
// Check if CameraX switched cameras
|
|
2069
|
-
String newCameraId = getCameraId(camera.getCameraInfo());
|
|
2070
|
-
if (!newCameraId.equals(currentDeviceId)) {
|
|
2071
|
-
currentDeviceId = newCameraId;
|
|
2072
|
-
Log.d(
|
|
2073
|
-
TAG,
|
|
2074
|
-
"setZoomInternal: CameraX switched to camera: " + newCameraId
|
|
2075
|
-
);
|
|
2076
|
-
}
|
|
2077
|
-
} catch (Exception e) {
|
|
2078
|
-
Log.w(
|
|
2079
|
-
TAG,
|
|
2080
|
-
"setZoomInternal: Zoom operation failed: " + e.getMessage()
|
|
2081
|
-
);
|
|
2082
|
-
// Fallback: clamp to current camera's range
|
|
2083
|
-
float clampedZoom = Math.max(
|
|
2084
|
-
minZoom,
|
|
2085
|
-
Math.min(zoomRatio, maxZoom)
|
|
2086
|
-
);
|
|
2087
|
-
camera.getCameraControl().setZoomRatio(clampedZoom);
|
|
2088
|
-
Log.d(
|
|
2089
|
-
TAG,
|
|
2090
|
-
"setZoomInternal: Fallback - clamped zoom to " + clampedZoom
|
|
2091
|
-
);
|
|
2092
|
-
}
|
|
2093
|
-
},
|
|
2094
|
-
mainExecutor
|
|
2095
|
-
);
|
|
2096
|
-
} catch (Exception e) {
|
|
2097
|
-
Log.e(TAG, "setZoomInternal: Error setting zoom", e);
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
}
|
|
2101
|
-
|
|
2102
1927
|
public static List<String> getSupportedFlashModesStatic() {
|
|
2103
1928
|
try {
|
|
2104
1929
|
// For static method, we can return common flash modes
|