Skip to content

Commit 30159d1

Browse files
committed
Adding low device storage check to all face detection samples.
Also fixes type in FaceGraphic pointed out in a github PR. Change-Id: Ib1edff665d2811bd6cea353deff8f85800f5fdb7
1 parent a16d60f commit 30159d1

File tree

7 files changed

+44
-1
lines changed

7 files changed

+44
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void draw(Canvas canvas) {
102102
canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint);
103103
canvas.drawText("happiness: " + String.format("%.2f", face.getIsSmilingProbability()), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint);
104104
canvas.drawText("right eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint);
105-
canvas.drawText("left eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x - ID_X_OFFSET*2, y - ID_Y_OFFSET*2, mIdPaint);
105+
canvas.drawText("left eye: " + String.format("%.2f", face.getIsLeftEyeOpenProbability()), x - ID_X_OFFSET*2, y - ID_Y_OFFSET*2, mIdPaint);
106106

107107
// Draws a bounding box around the face.
108108
float xOffset = scaleX(face.getWidth() / 2.0f);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
import android.app.Dialog;
2222
import android.content.Context;
2323
import android.content.DialogInterface;
24+
import android.content.Intent;
25+
import android.content.IntentFilter;
2426
import android.content.pm.PackageManager;
2527
import android.os.Bundle;
2628
import android.support.design.widget.Snackbar;
2729
import android.support.v4.app.ActivityCompat;
2830
import android.support.v7.app.AppCompatActivity;
2931
import android.util.Log;
3032
import android.view.View;
33+
import android.widget.Toast;
3134

3235
import com.google.android.gms.common.ConnectionResult;
3336
import com.google.android.gms.common.GoogleApiAvailability;
@@ -140,6 +143,17 @@ private void createCameraSource() {
140143
// available. The detector will automatically become operational once the library
141144
// download completes on device.
142145
Log.w(TAG, "Face detector dependencies are not yet available.");
146+
147+
// Check for low storage. If there is low storage, the native library will not be
148+
// downloaded, so detection will not become operational.
149+
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
150+
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
151+
152+
153+
if (hasLowStorage) {
154+
Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
155+
Log.w(TAG, getString(R.string.low_storage_error));
156+
}
143157
}
144158

145159
mCameraSource = new CameraSource.Builder(context, detector)

visionSamples/FaceTracker/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<string name="ok">OK</string>
44
<string name="permission_camera_rationale">Access to the camera is needed for detection</string>
55
<string name="no_camera_permission">This application cannot run because it does not have the camera permission. The application will now exit.</string>
6+
<string name="low_storage_error">Face detector dependencies cannot be downloaded due to low device storage</string>
67
</resources>

visionSamples/multi-tracker/app/src/main/java/com/google/android/gms/samples/vision/face/multitracker/MultiTrackerActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
import android.app.Dialog;
2323
import android.content.Context;
2424
import android.content.DialogInterface;
25+
import android.content.Intent;
26+
import android.content.IntentFilter;
2527
import android.content.pm.PackageManager;
2628
import android.os.Bundle;
2729
import android.support.design.widget.Snackbar;
2830
import android.support.v4.app.ActivityCompat;
2931
import android.support.v7.app.AppCompatActivity;
3032
import android.util.Log;
3133
import android.view.View;
34+
import android.widget.Toast;
3235

3336
import com.google.android.gms.common.ConnectionResult;
3437
import com.google.android.gms.common.GoogleApiAvailability;
@@ -163,6 +166,16 @@ private void createCameraSource() {
163166
// available. The detectors will automatically become operational once the library
164167
// downloads complete on device.
165168
Log.w(TAG, "Detector dependencies are not yet available.");
169+
170+
// Check for low storage. If there is low storage, the native library will not be
171+
// downloaded, so detection will not become operational.
172+
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
173+
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
174+
175+
if (hasLowStorage) {
176+
Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
177+
Log.w(TAG, getString(R.string.low_storage_error));
178+
}
166179
}
167180

168181
// Creates and starts the camera. Note that this uses a higher resolution in comparison

visionSamples/multi-tracker/app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
<string name="ok">OK</string>
44
<string name="permission_camera_rationale">Access to the camera is needed for detection</string>
55
<string name="no_camera_permission">This application cannot run because it does not have the camera permission. The application will now exit.</string>
6+
<string name="low_storage_error">Face detector dependencies cannot be downloaded due to low device storage</string>
67
</resources>

visionSamples/photo-demo/app/src/main/java/com/google/android/gms/samples/vision/face/photo/PhotoViewerActivity.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
package com.google.android.gms.samples.vision.face.photo;
1717

1818
import android.app.Activity;
19+
import android.content.Intent;
20+
import android.content.IntentFilter;
1921
import android.graphics.Bitmap;
2022
import android.graphics.BitmapFactory;
2123
import android.os.Bundle;
2224
import android.util.Log;
2325
import android.util.SparseArray;
26+
import android.widget.Toast;
2427

2528
import com.google.android.gms.samples.vision.face.patch.SafeFaceDetector;
2629
import com.google.android.gms.vision.Detector;
@@ -79,6 +82,16 @@ protected void onCreate(Bundle savedInstanceState) {
7982
// available. The detector will automatically become operational once the library
8083
// download completes on device.
8184
Log.w(TAG, "Face detector dependencies are not yet available.");
85+
86+
// Check for low storage. If there is low storage, the native library will not be
87+
// downloaded, so detection will not become operational.
88+
IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW);
89+
boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null;
90+
91+
if (hasLowStorage) {
92+
Toast.makeText(this, R.string.low_storage_error, Toast.LENGTH_LONG).show();
93+
Log.w(TAG, getString(R.string.low_storage_error));
94+
}
8295
}
8396

8497
FaceView overlay = (FaceView) findViewById(R.id.faceView);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<resources>
22
<string name="app_name">Photo Demo</string>
33
<string name="title_activity_photo_viewer">Photo Viewer</string>
4+
<string name="low_storage_error">Face detector dependencies cannot be downloaded due to low device storage</string>
45
</resources>

0 commit comments

Comments
 (0)