summaryrefslogtreecommitdiffstats
path: root/src_wrapper/org/codeaurora/snapcam/wrapper/ExtendedFaceWrapper.java
blob: 3a61505585f0b9ef6138edb2dc9272fca18ad478 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above
 *    copyright notice, this list of conditions and the following
 *    disclaimer in the documentation and/or other materials provided
 *    with the distribution.
 *  * Neither the name of The Linux Foundation nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package org.codeaurora.snapcam.wrapper;

import java.lang.reflect.Method;

import android.hardware.Camera.Face;
import android.os.Bundle;
import android.util.Log;

public class ExtendedFaceWrapper extends Wrapper{
    private final static String CLASS_NAME = "org.codeaurora.camera.ExtendedFace";
    private static Class<?> mExtendFaceClass;

    public static boolean isExtendedFaceInstance(Object object) {
        if ( mExtendFaceClass == null ){
            try {
                mExtendFaceClass = Class.forName(CLASS_NAME);
            }catch (Exception exception){
                exception.printStackTrace();
                return false;
            }
        }
        return mExtendFaceClass.isInstance(object);
    }

    private static Method method_getSmileDegree = null;
    public static int getSmileDegree(Face face) {
        int degree = 0;
        try {
            if (method_getSmileDegree == null) {
                method_getSmileDegree = getMethod("getSmileDegree");
            }
            degree = (int) method_getSmileDegree.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return degree;
    }

    private static Method method_getSmileScore = null;
    public static int getSmileScore(Face face) {
        int score = 0;
        try{
            if ( method_getSmileScore == null ){
                method_getSmileScore = getMethod("getSmileScore");
            }
            score = (int)method_getSmileScore.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return score;
    }

    private static Method method_getBlinkDetected = null;
    public static int getBlinkDetected(Face face) {
        int blink = 0;
        try{
            if ( method_getBlinkDetected == null ){
                method_getBlinkDetected = getMethod("getBlinkDetected");
            }
            blink = (int)method_getBlinkDetected.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return blink;
    }

    private static Method method_getFaceRecognized = null;
    public static int getFaceRecognized(Face face) {
        int faces = 0;
        try{
            if ( method_getFaceRecognized == null ){
                method_getFaceRecognized = getMethod("getFaceRecognized");
            }
            faces = (int)method_getFaceRecognized.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return faces;
    }

    private static Method method_getGazeAngle = null;
    public static int getGazeAngle(Face face) {
        int angle = 0;
        try{
            if ( method_getGazeAngle == null ){
                method_getGazeAngle = getMethod("getGazeAngle");
            }
            angle = (int)method_getGazeAngle.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return angle;
    }

    private static Method method_getUpDownDirection = null;
    public static int getUpDownDirection(Face face) {
        int direction = 0;
        try{
            if ( method_getUpDownDirection == null ){
                method_getUpDownDirection = getMethod("getUpDownDirection");
            }
            direction = (int)method_getUpDownDirection.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return direction;
    }

    private static Method method_getLeftRightDirection = null;
    public static int getLeftRightDirection(Face face) {
        int direction = 0;
        try{
            if ( method_getLeftRightDirection == null ){
                method_getLeftRightDirection = getMethod("getLeftRightDirection");
            }
            direction = (int)method_getLeftRightDirection.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return direction;
    }

    private static Method method_getRollDirection = null;
    public static int getRollDirection(Face face) {
        int direction = 0;
        try{
            if ( method_getRollDirection == null ){
                method_getRollDirection = getMethod("getRollDirection");
            }
            direction = (int)method_getRollDirection.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return direction;
    }

    private static Method method_getLeftEyeBlinkDegree = null;
    public static int getLeftEyeBlinkDegree(Face face) {
        int degree = 0;
        try{
            if ( method_getLeftEyeBlinkDegree == null ){
                method_getLeftEyeBlinkDegree = getMethod("getLeftEyeBlinkDegree");
            }
            degree = (int)method_getLeftEyeBlinkDegree.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return degree;
    }

    private static Method method_getRightEyeBlinkDegree = null;
    public static int getRightEyeBlinkDegree(Face face) {
        int degree = 0;
        try{
            if ( method_getRightEyeBlinkDegree == null ){
                method_getRightEyeBlinkDegree = getMethod("getRightEyeBlinkDegree");
            }
            degree = (int)method_getRightEyeBlinkDegree.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return degree;
    }

    private static Method method_getLeftRightGazeDegree = null;
    public static int getLeftRightGazeDegree(Face face) {
        int degree = 0;
        try{
            if ( method_getLeftRightGazeDegree == null ){
                method_getLeftRightGazeDegree = getMethod("getLeftRightGazeDegree");
            }
            degree = (int)method_getLeftRightGazeDegree.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return degree;
    }

    private static Method method_getTopBottomGazeDegree = null;
    public static int getTopBottomGazeDegree(Face face) {
        int degree = 0;
        try{
            if ( method_getTopBottomGazeDegree == null ){
                method_getTopBottomGazeDegree = getMethod("getTopBottomGazeDegree");
            }
            degree = (int)method_getTopBottomGazeDegree.invoke(face);
        }catch(Exception exception){
            exception.printStackTrace();
        }
        return degree;
    }


    private static Method getMethod(String name) throws Exception{
        if ( DEBUG ){
            Log.e(TAG, "Debug:" + CLASS_NAME + " no " + name);
            return null;
        }
        if (mExtendFaceClass == null) {
            mExtendFaceClass = Class.forName(CLASS_NAME);
        }
        return  mExtendFaceClass.getDeclaredMethod(name);
    }
}