Skip to content

Commit 9e6a1bb

Browse files
committed
call native test method
1 parent 2ce3132 commit 9e6a1bb

File tree

7 files changed

+130
-10
lines changed

7 files changed

+130
-10
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
# Sets the minimum version of CMake required to build the native
3+
# library. You should either keep the default value or only pass a
4+
# value of 3.4.0 or lower.
5+
6+
cmake_minimum_required(VERSION 3.4.1)
7+
8+
set (CMAKE_CXX_STANDARD 11)
9+
10+
11+
add_library( # Sets the name of the library.
12+
native-lib
13+
14+
# Sets the library as a shared library.
15+
SHARED
16+
17+
# Provides a relative path to your source file(s).
18+
# Associated headers in the same location as their source
19+
# file are automatically included.
20+
src/main/cpp/native-lib.cpp )
21+
22+
23+
# Searches for a specified prebuilt library and stores the path as a
24+
# variable. Because system libraries are included in the search path by
25+
# default, you only need to specify the name of the public NDK library
26+
# you want to add. CMake verifies that the library exists before
27+
# completing its build.
28+
29+
find_library( # Sets the name of the path variable.
30+
log-lib
31+
32+
# Specifies the name of the NDK library that
33+
# you want CMake to locate.
34+
log )
35+
36+
# Specifies libraries CMake should link to your target library. You
37+
# can link multiple libraries, such as libraries you define in the
38+
# build script, prebuilt third-party libraries, or system libraries.
39+
40+
target_link_libraries( # Specifies the target library.
41+
native-lib
42+
43+
# Links the target library to the log library
44+
# included in the NDK.
45+
${log-lib} )

visionSamples/FaceTracker/app/build.gradle

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,43 @@ apply plugin: 'com.android.application'
22

33
android {
44
compileSdkVersion 24
5-
buildToolsVersion "24.0.2"
5+
buildToolsVersion '27.0.3'
66

77
defaultConfig {
88
applicationId "com.google.android.gms.samples.vision.face.facetracker"
99
minSdkVersion 9
1010
targetSdkVersion 24
1111
versionCode 1
1212
versionName "1.0"
13+
externalNativeBuild {
14+
cmake {
15+
cppFlags "-frtti -fexceptions"
16+
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a'
17+
//arguments "-DANDROID_STL=c++_shared"
18+
// Passes optional arguments to CMake.
19+
//arguments "-DANDROID_ARM_NEON=TRUE", "-DANDROID_TOOLCHAIN=clang"
20+
21+
// Sets a flag to enable format macro constants for the C compiler.
22+
//cFlags "-D__STDC_FORMAT_MACROS"
23+
}
24+
}
1325
}
1426
buildTypes {
1527
release {
1628
minifyEnabled false
1729
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1830
}
1931
}
32+
externalNativeBuild {
33+
cmake {
34+
path "CMakeLists.txt"
35+
}
36+
}
2037
}
2138

2239
dependencies {
23-
compile fileTree(dir: 'libs', include: ['*.jar'])
24-
compile 'com.android.support:support-v4:24.2.0'
25-
compile 'com.android.support:design:24.2.0'
26-
compile 'com.google.android.gms:play-services-vision:9.4.0+'
40+
implementation fileTree(dir: 'libs', include: ['*.jar'])
41+
implementation 'com.android.support:support-v4:24.2.0'
42+
implementation 'com.android.support:design:24.2.0'
43+
implementation 'com.google.android.gms:play-services-vision:9.4.0+'
2744
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include <jni.h>
2+
#include <string>
3+
#include <android/log.h>
4+
5+
using namespace std;
6+
#define AppTag "Native"
7+
8+
extern "C"
9+
JNIEXPORT void JNICALL
10+
Java_com_google_android_gms_samples_vision_face_facetracker_FaceGraphic_test(JNIEnv *env,
11+
jobject instance) {
12+
13+
__android_log_print(ANDROID_LOG_DEBUG, AppTag, "Load resources started test1" );
14+
15+
}

visionSamples/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceGraphic.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.graphics.Canvas;
1919
import android.graphics.Color;
2020
import android.graphics.Paint;
21+
import android.util.Log;
2122

2223
import com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay;
2324
import com.google.android.gms.vision.face.Face;
@@ -52,6 +53,9 @@ class FaceGraphic extends GraphicOverlay.Graphic {
5253
private int mFaceId;
5354
private float mFaceHappiness;
5455

56+
private static final String RTAG = "RTAG";
57+
private Thread mT;
58+
5559
FaceGraphic(GraphicOverlay overlay) {
5660
super(overlay);
5761

@@ -75,6 +79,34 @@ void setId(int id) {
7579
mFaceId = id;
7680
}
7781

82+
public void startRecognition(Face item)
83+
{
84+
test();
85+
mT = new Thread(new Runnable() {
86+
@Override
87+
public void run() {
88+
Log.i(RTAG, "startRecognition: ");
89+
try {
90+
Thread.sleep(5000);
91+
mFaceId = 777;
92+
} catch (InterruptedException e) {
93+
e.printStackTrace();
94+
}
95+
//mFace
96+
}
97+
});
98+
mT.start();
99+
}
100+
101+
public void stopRecognition()
102+
{
103+
Log.i(RTAG, "stopRecognition: ");
104+
if (mT.isAlive())
105+
{
106+
mT.stop();
107+
}
108+
}
109+
78110

79111
/**
80112
* Updates the face instance from the detection of the most recent frame. Invalidates the
@@ -113,4 +145,6 @@ public void draw(Canvas canvas) {
113145
float bottom = y + yOffset;
114146
canvas.drawRect(left, top, right, bottom, mBoxPaint);
115147
}
148+
149+
public native void test();
116150
}

visionSamples/FaceTracker/app/src/main/java/com/google/android/gms/samples/vision/face/facetracker/FaceTrackerActivity.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public void onClick(View view) {
114114
.show();
115115
}
116116

117+
private void loadNative() {
118+
System.loadLibrary("native-lib");
119+
}
120+
117121
/**
118122
* Creates and starts the camera. Note that this uses a higher resolution in comparison
119123
* to other detection examples to enable the barcode detector to detect small barcodes
@@ -155,7 +159,7 @@ private void createCameraSource() {
155159
@Override
156160
protected void onResume() {
157161
super.onResume();
158-
162+
loadNative();
159163
startCameraSource();
160164
}
161165

@@ -208,6 +212,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
208212
Log.d(TAG, "Camera permission granted - initialize the camera source");
209213
// we have permission, so create the camerasource
210214
createCameraSource();
215+
211216
return;
212217
}
213218

@@ -290,8 +295,10 @@ private class GraphicFaceTracker extends Tracker<Face> {
290295
* Start tracking the detected face instance within the face overlay.
291296
*/
292297
@Override
293-
public void onNewItem(int faceId, Face item) {
298+
public void onNewItem(int faceId, Face item)
299+
{
294300
mFaceGraphic.setId(faceId);
301+
mFaceGraphic.startRecognition(item);
295302
}
296303

297304
/**
@@ -310,6 +317,7 @@ public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face)
310317
*/
311318
@Override
312319
public void onMissing(FaceDetector.Detections<Face> detectionResults) {
320+
mFaceGraphic.stopRecognition();
313321
mOverlay.remove(mFaceGraphic);
314322
}
315323

visionSamples/FaceTracker/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
buildscript {
44
repositories {
55
jcenter()
6+
google()
67
}
78
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.1.3'
9+
classpath 'com.android.tools.build:gradle:3.1.1'
910

1011
// NOTE: Do not place your application dependencies here; they belong
1112
// in the individual module build.gradle files
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Wed Aug 31 13:39:19 CEST 2016
1+
#Sun Apr 15 17:57:31 MSK 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 commit comments

Comments
 (0)