This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" JNIEXPORT jbyteArray JNICALL | |
JNI_METHOD(detectFacesAndLandmarks)(JNIEnv *env, | |
jobject thiz, | |
jobject bitmap) { | |
if (sFaceDetector.num_detectors() == 0) { | |
LOGI("L%d: sFaceDetector is not initialized!", __LINE__); | |
throwException(env, "sFaceDetector is not initialized!"); | |
return NULL; | |
} | |
if (sFaceLandmarksDetector.num_parts() == 0) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FaceLandmarksDetector68 { | |
public FaceLandmarksDetector68() { | |
// Load STL library. | |
try { | |
System.loadLibrary("c++_shared"); | |
Log.d("jni", "libc++_shared.so is loaded"); | |
} catch (UnsatisfiedLinkError error) { | |
throw new RuntimeException( | |
"\"c++_shared\" not found; check that the correct native " + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Activity or Fragment ::onResume | |
// 1. Wait for the surface ready. | |
mTextureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() { | |
@Override | |
public void onSurfaceTextureAvailable(SurfaceTexture texture, | |
int width, int height) { | |
// 2. Open the camera. | |
manager.openCamera( | |
cameraId, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Activity or Fragment ::onResume | |
mDisposables = new CompositeDisposable(); | |
mDisposables.add( | |
grantPermission() | |
// Step 1, use TextureViewObservable to wait for the surface ready. | |
.compose(waitForTextureSurfaceReady()) | |
// Step 2, use Camera2Observable to wait for the device opened. | |
.compose(openCameraToGetCameraDevice()) | |
// Step 3, use Camera2CaptureSessionObservable and Camera2ImageReaderObservable | |
// to wait for the session configured. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources xmlns:tools="http://schemas.android.com/tools"> | |
<!-- Transparent Window Activity --> | |
<style name="AppTheme.TransparentWindow" parent="AppTheme.CustomToolbar"> | |
<!-- | |
We want the translucent background painted by the root layout instead | |
of painted by the window. | |
--> | |
<item name="android:windowIsTranslucent">true</item> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Hold the disposable in order to cancel the operation later. | |
val sharingDisposable = mView | |
.onClickStart() | |
.switchMap { _ -> | |
// 1. Generate BMP | |
getGenBmpObservable() | |
// 2. Show dialog | |
.switchMap { _ -> | |
getDialogSingle().toObservable() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val mDisposablesOnCreate = CompositeDisposable() | |
private val INTENT_OF_DO_SOMETHING = 0 | |
private val INTENT_OF_CANCEL_EVERYTHING = 1 | |
// Activity onCreate(). | |
override fun onCreate() { | |
// Share and cancel input: | |
// | |
// start + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun toShareAction(): Observable<ShareProgressState> { | |
// 1. Generate BMP | |
return getGenBmpObservable() | |
// 2. Show dialog | |
.switchMap { _ -> | |
getDialogSingle() | |
.toObservable() | |
} | |
// 3. Share | |
.switchMap { dialogPayload -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the snippet of SwitchMapObserver code. | |
// 1. The inner observer #1 's onNext, this function is called when it | |
// receives the data from upstream. | |
@Override | |
public void onNext(T t) { | |
long c = unique + 1; | |
unique = c; | |
// 2. Cancel (dispose) the given Observable from your mapper funtion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int largestRectanglularAreaInHistogram(int[] hist) { | |
int maxArea = 0; | |
// Iterate through the histogram. | |
for (int i = 0; i < hist.length; ++i) { | |
int h = hist[i]; | |
maxArea = Math.max(maxArea, h); | |
for (int j = i - 1; j >= 0; --j) { |