|
15 | 15 | * limitations under the License. |
16 | 16 | */ |
17 | 17 |
|
| 18 | +#include <base/macros.h> |
18 | 19 | #include <ndksamples/camera/native_debug.h> |
19 | 20 |
|
20 | 21 | #include "camera_engine.h" |
@@ -126,30 +127,46 @@ void CameraEngine::OnCameraPermission(jboolean granted) { |
126 | 127 | * exposure and sensitivity SeekBars |
127 | 128 | * takePhoto button |
128 | 129 | */ |
129 | | -extern "C" JNIEXPORT void JNICALL |
130 | | -Java_com_sample_camera_basic_CameraActivity_notifyCameraPermission( |
131 | | - JNIEnv*, jclass, jboolean permission) { |
| 130 | +void notifyCameraPermission(JNIEnv*, jclass, jboolean permission) { |
132 | 131 | std::thread permissionHandler(&CameraEngine::OnCameraPermission, |
133 | 132 | GetAppEngine(), permission); |
134 | 133 | permissionHandler.detach(); |
135 | 134 | } |
136 | 135 |
|
137 | | -extern "C" JNIEXPORT void JNICALL |
138 | | -Java_com_sample_camera_basic_CameraActivity_TakePhoto(JNIEnv*, jclass) { |
| 136 | +void TakePhoto(JNIEnv*, jclass) { |
139 | 137 | std::thread takePhotoHandler(&CameraEngine::OnTakePhoto, GetAppEngine()); |
140 | 138 | takePhotoHandler.detach(); |
141 | 139 | } |
142 | 140 |
|
143 | | -extern "C" JNIEXPORT void JNICALL |
144 | | -Java_com_sample_camera_basic_CameraActivity_OnExposureChanged( |
145 | | - JNIEnv*, jobject, jlong exposurePercent) { |
| 141 | +void OnExposureChanged(JNIEnv*, jobject, jlong exposurePercent) { |
146 | 142 | GetAppEngine()->OnCameraParameterChanged(ACAMERA_SENSOR_EXPOSURE_TIME, |
147 | 143 | exposurePercent); |
148 | 144 | } |
149 | 145 |
|
150 | | -extern "C" JNIEXPORT void JNICALL |
151 | | -Java_com_sample_camera_basic_CameraActivity_OnSensitivityChanged( |
152 | | - JNIEnv*, jobject, jlong sensitivity) { |
| 146 | +void OnSensitivityChanged(JNIEnv*, jobject, jlong sensitivity) { |
153 | 147 | GetAppEngine()->OnCameraParameterChanged(ACAMERA_SENSOR_SENSITIVITY, |
154 | 148 | sensitivity); |
155 | 149 | } |
| 150 | + |
| 151 | +extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM* _Nonnull vm, void* _Nullable) { |
| 152 | + JNIEnv* env; |
| 153 | + if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { |
| 154 | + return JNI_ERR; |
| 155 | + } |
| 156 | + |
| 157 | + jclass c = env->FindClass("com/sample/camera/basic/CameraActivity"); |
| 158 | + if (c == nullptr) return JNI_ERR; |
| 159 | + |
| 160 | + static const JNINativeMethod methods[] = { |
| 161 | + {"notifyCameraPermission", "(Z)V", |
| 162 | + reinterpret_cast<void*>(notifyCameraPermission)}, |
| 163 | + {"TakePhoto", "()V", reinterpret_cast<void*>(TakePhoto)}, |
| 164 | + {"OnExposureChanged", "(J)V", reinterpret_cast<void*>(OnExposureChanged)}, |
| 165 | + {"OnSensitivityChanged", "(J)V", |
| 166 | + reinterpret_cast<void*>(OnSensitivityChanged)}, |
| 167 | + }; |
| 168 | + int rc = env->RegisterNatives(c, methods, arraysize(methods)); |
| 169 | + if (rc != JNI_OK) return rc; |
| 170 | + |
| 171 | + return JNI_VERSION_1_6; |
| 172 | +} |
0 commit comments