visageSDK
DetectorActivity.java
1 package com.visagetechnologies.facedetectdemo;
2 
3 
4 import android.app.ActionBar.LayoutParams;
5 import android.app.Activity;
6 import android.app.AlertDialog;
7 import android.net.Uri;
8 import android.os.Bundle;
9 import android.util.Log;
10 import android.util.TypedValue;
11 import android.view.Gravity;
12 import android.view.WindowManager;
13 import android.widget.RelativeLayout;
14 import android.widget.TextView;
15 
16 import java.io.File;
17 import java.io.IOException;
18 
21 public class DetectorActivity extends Activity
22 {
23  int count = 0;
24  int chooseFeature;
25 
26  public void onCreate(Bundle savedInstanceState)
27  {
28  getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
29 
30  super.onCreate(savedInstanceState);
31 
32  Bundle bundle = getIntent().getExtras();
33 
34  String uri = bundle.getString("imageURI");
35  Uri imageURI = Uri.parse(uri);
36 
37  chooseFeature = bundle.getInt("type");
38 
39  //Send the image, initialise the detector and draw results
40  try {
41  StartDetector(imageURI);
42  } catch (IOException e) {
43  e.printStackTrace();
44  }
45 
46  }
47 
48  @Override
49  public void onPause() {
50  super.onPause();
51  this.finish();
52  }
53 
54  @Override
55  public void onDestroy()
56  {
57  super.onDestroy();
58  CleanUp();
59  }
60 
65  public void StartDetector(Uri uri) throws IOException {
66  ImageDetectorView tpreview = new ImageDetectorView(this, uri, true);
67  RelativeLayout layout = new RelativeLayout(this);
68 
69  layout.addView(tpreview);
70 
71  DetectorGLSurfaceView tGLView = new DetectorGLSurfaceView(this, true);
72  tpreview.setGLView(tGLView);
73  layout.addView(tGLView);
74 
75  RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
76 
77  layout.setLayoutParams(params);
78  setContentView(layout);
79 
80  DetectorInit(getFilesDir().getAbsolutePath(), ".");
81  }
82 
83  public void AlertDialogFunction(String message)
84  {
85  TextView title = new TextView(this);
86  title.setText("License warning");
87  title.setGravity(Gravity.CENTER);
88  title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30);
89 
90  TextView msg = new TextView(this);
91  msg.setText(message);
92  msg.setGravity(Gravity.CENTER);
93  msg.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
94 
95  new AlertDialog.Builder(this)
96  .setCustomTitle(title)
97  .setView(msg)
98  .setPositiveButton(android.R.string.yes, null)
99  .setIcon(android.R.drawable.ic_dialog_alert)
100  .show();
101  }
102 
108  public native void DetectorInit(String appPath, String modelName);
109 
113  public native void CleanUp();
114 
115  static
116  {
117  System.loadLibrary("VisageVision");
118  System.loadLibrary("FaceDetectorWrapper");
119  }
120 }
native void DetectorInit(String appPath, String modelName)
Interface to native method used to initialize VisageFeaturesDetector object.
native void CleanUp()
Interface to native method used to clean up resources.
Implementation of GLSurfaceView class provided by Android.
Activity called to initiate and control detection.
void StartDetector(Uri uri)
Called to initialize and start detection.
void setGLView(DetectorGLSurfaceView tview)
Called to set GLSurfaceView used for rendering with OpenGL.