Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): fix Android camera with overlay issues (12_2_X) #13914

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* TiDev Titanium Mobile
* Titanium SDK
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
Expand Down Expand Up @@ -93,7 +93,8 @@ public class MediaModule extends KrollModule implements Handler.Callback
public static final int NO_CAMERA = 2;
@Kroll.constant
public static final int NO_VIDEO = 3;

@Kroll.constant
public static final int NO_FOCUS = 4;
@Kroll.constant
public static final int IMAGE_SCALING_AUTO = -1;
@Kroll.constant
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* TiDev Titanium Mobile
* Titanium SDK
* Copyright TiDev, Inc. 04/07/2022-Present. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
Expand All @@ -20,6 +20,7 @@
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.io.TiContentFile;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.view.TiUIView;

import android.Manifest;
import android.app.Activity;
Expand Down Expand Up @@ -246,14 +247,23 @@ protected void onResume()
cameraActivity = this;
previewLayout.addView(preview,
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
View overlayView = localOverlayProxy.getOrCreateView().getNativeView();
ViewGroup parent = (ViewGroup) overlayView.getParent();
// Detach from the parent if applicable
if (parent != null) {
parent.removeView(overlayView);
}
cameraLayout.addView(overlayView,
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
if (localOverlayProxy != null) {
TiUIView localView = localOverlayProxy.getOrCreateView();
if (localView != null) {
View overlayView = localView.getNativeView();
ViewGroup parent = (ViewGroup) overlayView.getParent();
// Detach from the parent if applicable
if (parent != null) {
parent.removeView(overlayView);
}
cameraLayout.addView(overlayView,
new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
} else {
Log.e(TAG, "Overlay view is null");
}
} else {
Log.e(TAG, "Overlay is null");
}
}

public static void setFlashMode(int cameraFlashMode)
Expand Down Expand Up @@ -729,6 +739,18 @@ public void onAutoFocus(boolean success, Camera camera)
}
} else {
Log.w(TAG, "Unable to focus.");
if (errorCallback != null) {
KrollDict response = new KrollDict();
response.putCodeAndMessage(MediaModule.NO_FOCUS, "Couldn't focus");
errorCallback.callAsync(callbackContext, response);
}
try {
camera.cancelAutoFocus();
camera.autoFocus(null);
} catch (Exception e) {
Log.w(TAG, "Failed to cancel auto focus: " + e.toString());
}
takingPicture = false;
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion apidoc/Titanium/Media/Media.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,13 @@ properties:
type: Number
permission: read-only

- name: NO_FOCUS
summary: Constant for camera didn't focus when taking a trying to take a picture.
type: Number
permission: read-only
since:
android: "12.2.1"

- name: VIDEO_CONTROL_DEFAULT
deprecated:
since: "7.0.0"
Expand Down Expand Up @@ -2370,7 +2377,7 @@ properties:
- name: code
summary: Error code, if applicable.
type: Number
constants: [Titanium.Media.DEVICE_BUSY, Titanium.Media.NO_CAMERA, Titanium.Media.UNKNOWN_ERROR]
constants: [Titanium.Media.DEVICE_BUSY, Titanium.Media.NO_CAMERA, Titanium.Media.UNKNOWN_ERROR, Titanium.Media.NO_FOCUS]
accessors: false

- name: success
Expand Down
Loading