Skip to content

Commit 43e6d4b

Browse files
Merge pull request #4 from hoopoe/activity
refactor to use 2 activities
2 parents c7e7768 + cb6d7af commit 43e6d4b

File tree

5 files changed

+81
-28
lines changed

5 files changed

+81
-28
lines changed

FaceTracker/app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@
3939
<intent-filter>
4040
<action android:name="android.intent.action.MAIN" />
4141

42+
<category android:name="android.intent.category.LAUNCHER" />
43+
</intent-filter>
44+
</activity>
45+
<activity
46+
android:name="org.opencv.android.facetracker.OpenCvActivity"
47+
android:icon="@drawable/icon"
48+
android:label="Face Recognition"
49+
android:theme="@style/Theme.AppCompat.NoActionBar"
50+
android:screenOrientation="fullSensor">
51+
<intent-filter>
52+
<action android:name="android.intent.action.MAIN" />
53+
4254
<category android:name="android.intent.category.LAUNCHER" />
4355
</intent-filter>
4456
</activity>

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,17 @@
2121
import android.app.Dialog;
2222
import android.content.Context;
2323
import android.content.DialogInterface;
24+
import android.content.Intent;
2425
import android.content.pm.PackageManager;
2526
import android.content.res.Configuration;
26-
import android.graphics.Bitmap;
27-
import android.graphics.BitmapFactory;
2827
import android.hardware.Camera;
2928
import android.os.Bundle;
3029
import android.support.design.widget.Snackbar;
3130
import android.support.v4.app.ActivityCompat;
3231
import android.support.v7.app.AppCompatActivity;
33-
import android.text.TextUtils;
3432
import android.util.Log;
3533
import android.view.View;
3634
import android.widget.Button;
37-
import android.widget.Toast;
3835

3936
import com.google.android.gms.common.ConnectionResult;
4037
import com.google.android.gms.common.GoogleApiAvailability;
@@ -46,11 +43,12 @@
4643
import com.google.android.gms.vision.face.Face;
4744
import com.google.android.gms.vision.face.FaceDetector;
4845

46+
import org.opencv.android.facetracker.OpenCvActivity;
47+
4948
import java.io.IOException;
5049
import java.util.List;
5150

5251
import dlib.android.FaceRecognizer;
53-
import xdroid.toaster.Toaster;
5452

5553
/**
5654
* Activity for the face tracker app. This app detects faces with the rear facing camera, and draws
@@ -63,7 +61,7 @@ public final class FaceTrackerActivity extends AppCompatActivity {
6361

6462
private CameraSourcePreview mPreview;
6563
private GraphicOverlay mGraphicOverlay;
66-
//private Button mBtnDetect;
64+
private Button mBtnDetect;
6765
private CustomDetector customDetector;
6866
//private FaceDetector mPictureDetector;
6967

@@ -92,7 +90,7 @@ public void onCreate(Bundle icicle) {
9290

9391
mPreview = (CameraSourcePreview) findViewById(R.id.preview);
9492
mGraphicOverlay = (GraphicOverlay) findViewById(R.id.faceOverlay);
95-
// mBtnDetect = (Button) findViewById(R.id.btnDetect);
93+
mBtnDetect = (Button) findViewById(R.id.btnDetect);
9694
mFaceRecognizer = new FaceRecognizer();
9795

9896
// Check for the camera permission before accessing the camera. If the
@@ -101,7 +99,6 @@ public void onCreate(Bundle icicle) {
10199
int rs = ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
102100

103101
if (rc == PackageManager.PERMISSION_GRANTED && rs == PackageManager.PERMISSION_GRANTED) {
104-
105102
createCameraSource();
106103
} else {
107104
requestCameraAndSdCardPermission();
@@ -235,6 +232,14 @@ private void createCameraSource() {
235232
.setRequestedFps(10)
236233
.build();
237234

235+
mBtnDetect.setOnClickListener(new View.OnClickListener() {
236+
@Override
237+
public void onClick(View v) {
238+
Intent myIntent = new Intent(FaceTrackerActivity.this, OpenCvActivity.class);
239+
FaceTrackerActivity.this.startActivity(myIntent);
240+
}
241+
});
242+
238243

239244
// mBtnDetect.setOnClickListener(new View.OnClickListener() {
240245
// @Override
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.opencv.android.facetracker;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.view.View;
7+
import android.widget.Button;
8+
9+
import com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity;
10+
import com.google.android.gms.samples.vision.face.facetracker.R;
11+
12+
public class OpenCvActivity extends AppCompatActivity {
13+
private static final String TAG = "OpenCvActivity";
14+
private Button mBtnDetect;
15+
16+
@Override
17+
public void onCreate(Bundle icicle) {
18+
super.onCreate(icicle);
19+
setContentView(R.layout.main);
20+
21+
mBtnDetect = (Button) findViewById(R.id.btnDetect);
22+
23+
mBtnDetect.setOnClickListener(new View.OnClickListener() {
24+
@Override
25+
public void onClick(View v) {
26+
Intent myIntent = new Intent(OpenCvActivity.this, FaceTrackerActivity.class);
27+
OpenCvActivity.this.startActivity(myIntent);
28+
}
29+
});
30+
}
31+
32+
}
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<LinearLayout
3+
<RelativeLayout
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
android:id="@+id/topLayout"
66
android:orientation="horizontal"
77
android:layout_width="match_parent"
88
android:layout_height="match_parent"
99
android:keepScreenOn="true">
10-
<!--<Button-->
11-
<!--android:id="@+id/btnDetect"-->
12-
<!--android:layout_width="35dp"-->
13-
<!--android:layout_height="wrap_content"-->
14-
<!--android:text="Identify" />-->
10+
11+
<Button
12+
android:id="@+id/btnDetect"
13+
android:layout_width="35dp"
14+
android:layout_height="wrap_content"
15+
android:layout_alignParentBottom="true"
16+
android:text="Switch Activity" />
17+
1518
<com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview
1619
android:id="@+id/preview"
1720
android:layout_width="match_parent"
@@ -26,4 +29,4 @@
2629

2730

2831

29-
</LinearLayout>
32+
</RelativeLayout>
Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22

3-
<LinearLayout
3+
<RelativeLayout
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
android:id="@+id/topLayout"
66
android:orientation="vertical"
@@ -9,24 +9,25 @@
99
android:keepScreenOn="true">
1010

1111

12-
<!--<Button-->
13-
<!--android:id="@+id/btnDetect"-->
14-
<!--android:layout_width="350dp"-->
15-
<!--android:layout_height="wrap_content"-->
16-
<!--android:text="Identify" />-->
12+
<Button
13+
android:id="@+id/btnDetect"
14+
android:layout_width="350dp"
15+
android:layout_height="wrap_content"
16+
android:layout_alignParentBottom="true"
17+
android:text="Switch Activity" />
1718

1819
<com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview
1920
android:id="@+id/preview"
2021
android:layout_width="match_parent"
2122
android:layout_height="match_parent">
2223

23-
<com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay
24-
android:id="@+id/faceOverlay"
25-
android:layout_width="match_parent"
26-
android:layout_height="match_parent">
24+
<com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay
25+
android:id="@+id/faceOverlay"
26+
android:layout_width="match_parent"
27+
android:layout_height="match_parent">
2728

28-
</com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay>
29+
</com.google.android.gms.samples.vision.face.facetracker.ui.camera.GraphicOverlay>
2930

30-
</com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview>
31+
</com.google.android.gms.samples.vision.face.facetracker.ui.camera.CameraSourcePreview>
3132

32-
</LinearLayout>
33+
</RelativeLayout>

0 commit comments

Comments
 (0)