diff --git a/README.md b/README.md index 17e261d4..ec6e5859 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,13 @@ Android Vision API Samples -============ +========================== -These samples demonstrate the vision API for detecting faces and barcodes. +The Mobile Vision API is now a part of [ML Kit][3]. We strongly encourage you to try it out, as it comes with new capabilities like on-device image labeling! Also, note that we ultimately plan to wind down the Mobile Vision API, with all new on-device ML capabilities released via ML Kit. Check out [this codelab][4] to use the vision APIs in ML Kit. -Introduction ------------- +This sample has been deprecated/archived meaning it's read-only and it's no longer actively maintained (more details on archiving can be found [here][1]). -Pre-requisites --------------- - Android Play Services SDK level 26 or greater. +For other related samples, check out the new [github.com/android/user-interface-samples][2] repo. Thank you! -Getting Started ---------------- -The samples build using Gradle in Android Studio. There is no special -configuration required. - -Support (Post Release) -------- - -For General questions and discussion on StackOverflow: -- Stack Overflow: http://stackoverflow.com/questions/tagged/android-vision - -If you've found an error in this sample, please file an issue: -https://github.com/googlesamples/android-vision/issues - -Patches are encouraged, and may be submitted by forking this project and -submitting a pull request through GitHub. - -License -------- - -Copyright 2015 Google, Inc. All Rights Reserved. - -Licensed to the Apache Software Foundation (ASF) under one or more contributor -license agreements. See the NOTICE file distributed with this work for -additional information regarding copyright ownership. The ASF licenses this -file to you under the Apache License, Version 2.0 (the "License"); you may not -use this file except in compliance with the License. You may obtain a copy of -the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -License for the specific language governing permissions and limitations under -the License. +[1]: https://help.github.com/en/articles/about-archiving-repositories +[2]: https://github.com/android/user-interface-samples +[3]: https://developers.google.com/ml-kit/vision +[4]: https://github.com/firebase/quickstart-android/tree/master/mlkit diff --git a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeCaptureActivity.java b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeCaptureActivity.java index d8c4306d..663d7ff4 100644 --- a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeCaptureActivity.java +++ b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeCaptureActivity.java @@ -57,7 +57,7 @@ * rear facing camera. During detection overlay graphics are drawn to indicate the position, * size, and ID of each barcode. */ -public final class BarcodeCaptureActivity extends AppCompatActivity { +public final class BarcodeCaptureActivity extends AppCompatActivity implements BarcodeGraphicTracker.BarcodeUpdateListener { private static final String TAG = "Barcode-reader"; // intent request code to handle updating play services if needed. @@ -170,7 +170,7 @@ private void createCameraSource(boolean autoFocus, boolean useFlash) { // graphics for each barcode on screen. The factory is used by the multi-processor to // create a separate tracker instance for each barcode. BarcodeDetector barcodeDetector = new BarcodeDetector.Builder(context).build(); - BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay); + BarcodeTrackerFactory barcodeFactory = new BarcodeTrackerFactory(mGraphicOverlay, this); barcodeDetector.setProcessor( new MultiProcessor.Builder<>(barcodeFactory).build()); @@ -428,4 +428,9 @@ public void onScaleEnd(ScaleGestureDetector detector) { mCameraSource.doZoom(detector.getScaleFactor()); } } + + @Override + public void onBarcodeDetected(Barcode barcode) { + //do something with barcode data returned + } } diff --git a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeGraphicTracker.java b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeGraphicTracker.java index aef330f2..5c23399d 100644 --- a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeGraphicTracker.java +++ b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeGraphicTracker.java @@ -15,6 +15,9 @@ */ package com.google.android.gms.samples.vision.barcodereader; +import android.content.Context; +import android.support.annotation.UiThread; + import com.google.android.gms.samples.vision.barcodereader.ui.camera.GraphicOverlay; import com.google.android.gms.vision.Detector; import com.google.android.gms.vision.Tracker; @@ -26,13 +29,30 @@ * to an overlay, update the graphics as the item changes, and remove the graphics when the item * goes away. */ -class BarcodeGraphicTracker extends Tracker { +public class BarcodeGraphicTracker extends Tracker { private GraphicOverlay mOverlay; private BarcodeGraphic mGraphic; - BarcodeGraphicTracker(GraphicOverlay overlay, BarcodeGraphic graphic) { - mOverlay = overlay; - mGraphic = graphic; + private BarcodeUpdateListener mBarcodeUpdateListener; + + /** + * Consume the item instance detected from an Activity or Fragment level by implementing the + * BarcodeUpdateListener interface method onBarcodeDetected. + */ + public interface BarcodeUpdateListener { + @UiThread + void onBarcodeDetected(Barcode barcode); + } + + BarcodeGraphicTracker(GraphicOverlay mOverlay, BarcodeGraphic mGraphic, + Context context) { + this.mOverlay = mOverlay; + this.mGraphic = mGraphic; + if (context instanceof BarcodeUpdateListener) { + this.mBarcodeUpdateListener = (BarcodeUpdateListener) context; + } else { + throw new RuntimeException("Hosting activity must implement BarcodeUpdateListener"); + } } /** @@ -41,6 +61,7 @@ class BarcodeGraphicTracker extends Tracker { @Override public void onNewItem(int id, Barcode item) { mGraphic.setId(id); + mBarcodeUpdateListener.onBarcodeDetected(item); } /** diff --git a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeTrackerFactory.java b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeTrackerFactory.java index 050322d4..8158893c 100644 --- a/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeTrackerFactory.java +++ b/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/BarcodeTrackerFactory.java @@ -15,6 +15,8 @@ */ package com.google.android.gms.samples.vision.barcodereader; +import android.content.Context; + import com.google.android.gms.samples.vision.barcodereader.ui.camera.GraphicOverlay; import com.google.android.gms.vision.MultiProcessor; import com.google.android.gms.vision.Tracker; @@ -26,15 +28,18 @@ */ class BarcodeTrackerFactory implements MultiProcessor.Factory { private GraphicOverlay mGraphicOverlay; + private Context mContext; - BarcodeTrackerFactory(GraphicOverlay barcodeGraphicOverlay) { - mGraphicOverlay = barcodeGraphicOverlay; + public BarcodeTrackerFactory(GraphicOverlay mGraphicOverlay, + Context mContext) { + this.mGraphicOverlay = mGraphicOverlay; + this.mContext = mContext; } @Override public Tracker create(Barcode barcode) { BarcodeGraphic graphic = new BarcodeGraphic(mGraphicOverlay); - return new BarcodeGraphicTracker(mGraphicOverlay, graphic); + return new BarcodeGraphicTracker(mGraphicOverlay, graphic, mContext); } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/build.gradle b/visionSamples/ocr-codelab/ocr-reader-complete/app/build.gradle index 7f1ab007..243d71b7 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/build.gradle +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { - applicationId "com.google.android.gms.samples.vision.barcodereader" + applicationId "com.google.android.gms.samples.vision.ocrreader" minSdkVersion 21 - targetSdkVersion 23 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -20,8 +20,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:24.2.0' - compile 'com.google.android.gms:play-services-vision:9.4.0+' - compile 'com.android.support:design:24.2.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.google.android.gms:play-services-vision:15.0.0' + implementation 'com.android.support:support-v4:27.1.1' + implementation 'com.android.support:design:27.1.1' } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java index c7aac93e..2e1fc9db 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java @@ -26,7 +26,6 @@ import android.content.IntentFilter; import android.content.pm.PackageManager; import android.hardware.Camera; -import android.os.Build; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.support.annotation.NonNull; @@ -42,7 +41,6 @@ import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.common.api.CommonStatusCodes; import com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSource; import com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview; import com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay; @@ -71,9 +69,9 @@ public final class OcrCaptureActivity extends AppCompatActivity { public static final String UseFlash = "UseFlash"; public static final String TextBlockObject = "String"; - private CameraSource mCameraSource; - private CameraSourcePreview mPreview; - private GraphicOverlay mGraphicOverlay; + private CameraSource cameraSource; + private CameraSourcePreview preview; + private GraphicOverlay graphicOverlay; // Helper objects for detecting taps and pinches. private ScaleGestureDetector scaleGestureDetector; @@ -90,8 +88,8 @@ public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture); - mPreview = (CameraSourcePreview) findViewById(R.id.preview); - mGraphicOverlay = (GraphicOverlay) findViewById(R.id.graphicOverlay); + preview = (CameraSourcePreview) findViewById(R.id.preview); + graphicOverlay = (GraphicOverlay) findViewById(R.id.graphicOverlay); // Set good defaults for capturing text. boolean autoFocus = true; @@ -109,7 +107,7 @@ public void onCreate(Bundle bundle) { gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); - Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", + Snackbar.make(graphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG) .show(); @@ -155,7 +153,7 @@ public void onClick(View view) { } }; - Snackbar.make(mGraphicOverlay, R.string.permission_camera_rationale, + Snackbar.make(graphicOverlay, R.string.permission_camera_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.ok, listener) .show(); @@ -187,7 +185,7 @@ private void createCameraSource(boolean autoFocus, boolean useFlash) { // graphics for each text block on screen. The factory is used by the multi-processor to // create a separate tracker instance for each text block. TextRecognizer textRecognizer = new TextRecognizer.Builder(context).build(); - textRecognizer.setProcessor(new OcrDetectorProcessor(mGraphicOverlay)); + textRecognizer.setProcessor(new OcrDetectorProcessor(graphicOverlay)); if (!textRecognizer.isOperational()) { // Note: The first time that an app using a Vision API is installed on a @@ -214,13 +212,13 @@ private void createCameraSource(boolean autoFocus, boolean useFlash) { // Creates and starts the camera. Note that this uses a higher resolution in comparison // to other detection examples to enable the text recognizer to detect small pieces of text. - mCameraSource = + cameraSource = new CameraSource.Builder(getApplicationContext(), textRecognizer) .setFacing(CameraSource.CAMERA_FACING_BACK) .setRequestedPreviewSize(1280, 1024) .setRequestedFps(2.0f) .setFlashMode(useFlash ? Camera.Parameters.FLASH_MODE_TORCH : null) - .setFocusMode(autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE : null) + .setFocusMode(autoFocus ? Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO : null) .build(); } @@ -239,8 +237,8 @@ protected void onResume() { @Override protected void onPause() { super.onPause(); - if (mPreview != null) { - mPreview.stop(); + if (preview != null) { + preview.stop(); } } @@ -251,8 +249,8 @@ protected void onPause() { @Override protected void onDestroy() { super.onDestroy(); - if (mPreview != null) { - mPreview.release(); + if (preview != null) { + preview.release(); } } @@ -285,7 +283,7 @@ public void onRequestPermissionsResult(int requestCode, if (grantResults.length != 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "Camera permission granted - initialize the camera source"); // we have permission, so create the camerasource - boolean autoFocus = getIntent().getBooleanExtra(AutoFocus,false); + boolean autoFocus = getIntent().getBooleanExtra(AutoFocus,true); boolean useFlash = getIntent().getBooleanExtra(UseFlash, false); createCameraSource(autoFocus, useFlash); return; @@ -322,13 +320,13 @@ private void startCameraSource() throws SecurityException { dlg.show(); } - if (mCameraSource != null) { + if (cameraSource != null) { try { - mPreview.start(mCameraSource, mGraphicOverlay); + preview.start(cameraSource, graphicOverlay); } catch (IOException e) { Log.e(TAG, "Unable to start camera source.", e); - mCameraSource.release(); - mCameraSource = null; + cameraSource.release(); + cameraSource = null; } } } @@ -341,7 +339,7 @@ private void startCameraSource() throws SecurityException { * @return true if the tap was on a TextBlock */ private boolean onTap(float rawX, float rawY) { - OcrGraphic graphic = mGraphicOverlay.getGraphicAtLocation(rawX, rawY); + OcrGraphic graphic = graphicOverlay.getGraphicAtLocation(rawX, rawY); TextBlock text = null; if (graphic != null) { text = graphic.getTextBlock(); @@ -418,8 +416,8 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { */ @Override public void onScaleEnd(ScaleGestureDetector detector) { - if (mCameraSource != null) { - mCameraSource.doZoom(detector.getScaleFactor()); + if (cameraSource != null) { + cameraSource.doZoom(detector.getScaleFactor()); } } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java index 229bec74..b488b42c 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java @@ -28,10 +28,10 @@ */ public class OcrDetectorProcessor implements Detector.Processor { - private GraphicOverlay mGraphicOverlay; + private GraphicOverlay graphicOverlay; OcrDetectorProcessor(GraphicOverlay ocrGraphicOverlay) { - mGraphicOverlay = ocrGraphicOverlay; + graphicOverlay = ocrGraphicOverlay; } /** @@ -43,15 +43,15 @@ public class OcrDetectorProcessor implements Detector.Processor { */ @Override public void receiveDetections(Detector.Detections detections) { - mGraphicOverlay.clear(); + graphicOverlay.clear(); SparseArray items = detections.getDetectedItems(); for (int i = 0; i < items.size(); ++i) { TextBlock item = items.valueAt(i); if (item != null && item.getValue() != null) { Log.d("OcrDetectorProcessor", "Text detected! " + item.getValue()); + OcrGraphic graphic = new OcrGraphic(graphicOverlay, item); + graphicOverlay.add(graphic); } - OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item); - mGraphicOverlay.add(graphic); } } @@ -60,6 +60,6 @@ public void receiveDetections(Detector.Detections detections) { */ @Override public void release() { - mGraphicOverlay.clear(); + graphicOverlay.clear(); } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java index 9e0aef29..137c8954 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java @@ -32,45 +32,45 @@ */ public class OcrGraphic extends GraphicOverlay.Graphic { - private int mId; + private int id; private static final int TEXT_COLOR = Color.WHITE; - private static Paint sRectPaint; - private static Paint sTextPaint; - private final TextBlock mText; + private static Paint rectPaint; + private static Paint textPaint; + private final TextBlock textBlock; OcrGraphic(GraphicOverlay overlay, TextBlock text) { super(overlay); - mText = text; + textBlock = text; - if (sRectPaint == null) { - sRectPaint = new Paint(); - sRectPaint.setColor(TEXT_COLOR); - sRectPaint.setStyle(Paint.Style.STROKE); - sRectPaint.setStrokeWidth(4.0f); + if (rectPaint == null) { + rectPaint = new Paint(); + rectPaint.setColor(TEXT_COLOR); + rectPaint.setStyle(Paint.Style.STROKE); + rectPaint.setStrokeWidth(4.0f); } - if (sTextPaint == null) { - sTextPaint = new Paint(); - sTextPaint.setColor(TEXT_COLOR); - sTextPaint.setTextSize(54.0f); + if (textPaint == null) { + textPaint = new Paint(); + textPaint.setColor(TEXT_COLOR); + textPaint.setTextSize(54.0f); } // Redraw the overlay, as this graphic has been added. postInvalidate(); } public int getId() { - return mId; + return id; } public void setId(int id) { - this.mId = id; + this.id = id; } public TextBlock getTextBlock() { - return mText; + return textBlock; } /** @@ -81,15 +81,12 @@ public TextBlock getTextBlock() { * @return True if the provided point is contained within this graphic's bounding box. */ public boolean contains(float x, float y) { - if (mText == null) { + if (textBlock == null) { return false; } - RectF rect = new RectF(mText.getBoundingBox()); - rect.left = translateX(rect.left); - rect.top = translateY(rect.top); - rect.right = translateX(rect.right); - rect.bottom = translateY(rect.bottom); - return (rect.left < x && rect.right > x && rect.top < y && rect.bottom > y); + RectF rect = new RectF(textBlock.getBoundingBox()); + rect = translateRect(rect); + return rect.contains(x, y); } /** @@ -97,24 +94,21 @@ public boolean contains(float x, float y) { */ @Override public void draw(Canvas canvas) { - if (mText == null) { + if (textBlock == null) { return; } // Draws the bounding box around the TextBlock. - RectF rect = new RectF(mText.getBoundingBox()); - rect.left = translateX(rect.left); - rect.top = translateY(rect.top); - rect.right = translateX(rect.right); - rect.bottom = translateY(rect.bottom); - canvas.drawRect(rect, sRectPaint); + RectF rect = new RectF(textBlock.getBoundingBox()); + rect = translateRect(rect); + canvas.drawRect(rect, rectPaint); // Break the text into multiple lines and draw each one according to its own bounding box. - List textComponents = mText.getComponents(); + List textComponents = textBlock.getComponents(); for(Text currentText : textComponents) { float left = translateX(currentText.getBoundingBox().left); float bottom = translateY(currentText.getBoundingBox().bottom); - canvas.drawText(currentText.getValue(), left, bottom, sTextPaint); + canvas.drawText(currentText.getValue(), left, bottom, textPaint); } } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java index 1a387522..e98c9576 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java @@ -113,12 +113,12 @@ public class CameraSource { @Retention(RetentionPolicy.SOURCE) private @interface FlashMode {} - private Context mContext; + private Context context; - private final Object mCameraLock = new Object(); + private final Object cameraLock = new Object(); - // Guarded by mCameraLock - private Camera mCamera; + // Guarded by cameraLock + private Camera camera; private int mFacing = CAMERA_FACING_BACK; @@ -126,39 +126,39 @@ public class CameraSource { * Rotation of the device, and thus the associated preview images captured from the device. * See {@link Frame.Metadata#getRotation()}. */ - private int mRotation; + private int rotation; - private Size mPreviewSize; + private Size previewSize; // These values may be requested by the caller. Due to hardware limitations, we may need to // select close, but not exactly the same values for these. - private float mRequestedFps = 30.0f; - private int mRequestedPreviewWidth = 1024; - private int mRequestedPreviewHeight = 768; + private float requestedFps = 30.0f; + private int requestedPreviewWidth = 1024; + private int requestedPreviewHeight = 768; - private String mFocusMode = null; - private String mFlashMode = null; + private String focusMode = null; + private String flashMode = null; // These instances need to be held onto to avoid GC of their underlying resources. Even though // these aren't used outside of the method that creates them, they still must have hard // references maintained to them. - private SurfaceView mDummySurfaceView; - private SurfaceTexture mDummySurfaceTexture; + private SurfaceView dummySurfaceView; + private SurfaceTexture dummySurfaceTexture; /** * Dedicated thread and associated runnable for calling into the detector with frames, as the * frames become available from the camera. */ - private Thread mProcessingThread; - private FrameProcessingRunnable mFrameProcessor; + private Thread processingThread; + private FrameProcessingRunnable frameProcessor; /** * Map to convert between a byte array, received from the camera, and its associated byte * buffer. We use byte buffers internally because this is a more efficient way to call into * native code later (avoids a potential copy). */ - private Map mBytesToByteBuffer = new HashMap<>(); + private Map bytesToByteBuffer = new HashMap<>(); //============================================================================================== // Builder @@ -168,8 +168,8 @@ public class CameraSource { * Builder for configuring and creating an associated camera source. */ public static class Builder { - private final Detector mDetector; - private CameraSource mCameraSource = new CameraSource(); + private final Detector detector; + private CameraSource cameraSource = new CameraSource(); /** * Creates a camera source builder with the supplied context and detector. Camera preview @@ -183,8 +183,8 @@ public Builder(Context context, Detector detector) { throw new IllegalArgumentException("No detector supplied."); } - mDetector = detector; - mCameraSource.mContext = context; + this.detector = detector; + cameraSource.context = context; } /** @@ -195,17 +195,17 @@ public Builder setRequestedFps(float fps) { if (fps <= 0) { throw new IllegalArgumentException("Invalid fps: " + fps); } - mCameraSource.mRequestedFps = fps; + cameraSource.requestedFps = fps; return this; } public Builder setFocusMode(@FocusMode String mode) { - mCameraSource.mFocusMode = mode; + cameraSource.focusMode = mode; return this; } public Builder setFlashMode(@FlashMode String mode) { - mCameraSource.mFlashMode = mode; + cameraSource.flashMode = mode; return this; } @@ -223,8 +223,8 @@ public Builder setRequestedPreviewSize(int width, int height) { if ((width <= 0) || (width > MAX) || (height <= 0) || (height > MAX)) { throw new IllegalArgumentException("Invalid preview size: " + width + "x" + height); } - mCameraSource.mRequestedPreviewWidth = width; - mCameraSource.mRequestedPreviewHeight = height; + cameraSource.requestedPreviewWidth = width; + cameraSource.requestedPreviewHeight = height; return this; } @@ -236,7 +236,7 @@ public Builder setFacing(int facing) { if ((facing != CAMERA_FACING_BACK) && (facing != CAMERA_FACING_FRONT)) { throw new IllegalArgumentException("Invalid camera: " + facing); } - mCameraSource.mFacing = facing; + cameraSource.mFacing = facing; return this; } @@ -244,8 +244,8 @@ public Builder setFacing(int facing) { * Creates an instance of the camera source. */ public CameraSource build() { - mCameraSource.mFrameProcessor = mCameraSource.new FrameProcessingRunnable(mDetector); - return mCameraSource; + cameraSource.frameProcessor = cameraSource.new FrameProcessingRunnable(detector); + return cameraSource; } } @@ -320,9 +320,9 @@ public interface AutoFocusMoveCallback { * Stops the camera and releases the resources of the camera and underlying detector. */ public void release() { - synchronized (mCameraLock) { + synchronized (cameraLock) { stop(); - mFrameProcessor.release(); + frameProcessor.release(); } } @@ -334,27 +334,27 @@ public void release() { */ @RequiresPermission(Manifest.permission.CAMERA) public CameraSource start() throws IOException { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { return this; } - mCamera = createCamera(); + camera = createCamera(); // SurfaceTexture was introduced in Honeycomb (11), so if we are running and // old version of Android. fall back to use SurfaceView. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME); - mCamera.setPreviewTexture(mDummySurfaceTexture); + dummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME); + camera.setPreviewTexture(dummySurfaceTexture); } else { - mDummySurfaceView = new SurfaceView(mContext); - mCamera.setPreviewDisplay(mDummySurfaceView.getHolder()); + dummySurfaceView = new SurfaceView(context); + camera.setPreviewDisplay(dummySurfaceView.getHolder()); } - mCamera.startPreview(); + camera.startPreview(); - mProcessingThread = new Thread(mFrameProcessor); - mFrameProcessor.setActive(true); - mProcessingThread.start(); + processingThread = new Thread(frameProcessor); + frameProcessor.setActive(true); + processingThread.start(); } return this; } @@ -368,18 +368,18 @@ public CameraSource start() throws IOException { */ @RequiresPermission(Manifest.permission.CAMERA) public CameraSource start(SurfaceHolder surfaceHolder) throws IOException { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { return this; } - mCamera = createCamera(); - mCamera.setPreviewDisplay(surfaceHolder); - mCamera.startPreview(); + camera = createCamera(); + camera.setPreviewDisplay(surfaceHolder); + camera.startPreview(); - mProcessingThread = new Thread(mFrameProcessor); - mFrameProcessor.setActive(true); - mProcessingThread.start(); + processingThread = new Thread(frameProcessor); + frameProcessor.setActive(true); + processingThread.start(); } return this; } @@ -394,26 +394,26 @@ public CameraSource start(SurfaceHolder surfaceHolder) throws IOException { * resources of the underlying detector. */ public void stop() { - synchronized (mCameraLock) { - mFrameProcessor.setActive(false); - if (mProcessingThread != null) { + synchronized (cameraLock) { + frameProcessor.setActive(false); + if (processingThread != null) { try { // Wait for the thread to complete to ensure that we can't have multiple threads // executing at the same time (i.e., which would happen if we called start too // quickly after stop). - mProcessingThread.join(); + processingThread.join(); } catch (InterruptedException e) { Log.d(TAG, "Frame processing thread interrupted on release."); } - mProcessingThread = null; + processingThread = null; } // clear the buffer to prevent oom exceptions - mBytesToByteBuffer.clear(); + bytesToByteBuffer.clear(); - if (mCamera != null) { - mCamera.stopPreview(); - mCamera.setPreviewCallbackWithBuffer(null); + if (camera != null) { + camera.stopPreview(); + camera.setPreviewCallbackWithBuffer(null); try { // We want to be compatible back to Gingerbread, but SurfaceTexture // wasn't introduced until Honeycomb. Since the interface cannot use a @@ -422,16 +422,16 @@ public void stop() { // SurfaceTexture if we are running at least Honeycomb. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mCamera.setPreviewTexture(null); + camera.setPreviewTexture(null); } else { - mCamera.setPreviewDisplay(null); + camera.setPreviewDisplay(null); } } catch (Exception e) { Log.e(TAG, "Failed to clear camera preview: " + e); } - mCamera.release(); - mCamera = null; + camera.release(); + camera = null; } } } @@ -440,7 +440,7 @@ public void stop() { * Returns the preview size that is currently in use by the underlying camera. */ public Size getPreviewSize() { - return mPreviewSize; + return previewSize; } /** @@ -452,13 +452,13 @@ public int getCameraFacing() { } public int doZoom(float scale) { - synchronized (mCameraLock) { - if (mCamera == null) { + synchronized (cameraLock) { + if (camera == null) { return 0; } int currentZoom = 0; int maxZoom; - Camera.Parameters parameters = mCamera.getParameters(); + Camera.Parameters parameters = camera.getParameters(); if (!parameters.isZoomSupported()) { Log.w(TAG, "Zoom is not supported on this device"); return currentZoom; @@ -479,7 +479,7 @@ public int doZoom(float scale) { currentZoom = maxZoom; } parameters.setZoom(currentZoom); - mCamera.setParameters(parameters); + camera.setParameters(parameters); return currentZoom; } } @@ -494,13 +494,13 @@ public int doZoom(float scale) { * @param jpeg the callback for JPEG image data, or null */ public void takePicture(ShutterCallback shutter, PictureCallback jpeg) { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { PictureStartCallback startCallback = new PictureStartCallback(); startCallback.mDelegate = shutter; PictureDoneCallback doneCallback = new PictureDoneCallback(); doneCallback.mDelegate = jpeg; - mCamera.takePicture(startCallback, null, null, doneCallback); + camera.takePicture(startCallback, null, null, doneCallback); } } } @@ -522,7 +522,7 @@ public void takePicture(ShutterCallback shutter, PictureCallback jpeg) { @Nullable @FocusMode public String getFocusMode() { - return mFocusMode; + return focusMode; } /** @@ -533,13 +533,13 @@ public String getFocusMode() { * @see #getFocusMode() */ public boolean setFocusMode(@FocusMode String mode) { - synchronized (mCameraLock) { - if (mCamera != null && mode != null) { - Camera.Parameters parameters = mCamera.getParameters(); + synchronized (cameraLock) { + if (camera != null && mode != null) { + Camera.Parameters parameters = camera.getParameters(); if (parameters.getSupportedFocusModes().contains(mode)) { parameters.setFocusMode(mode); - mCamera.setParameters(parameters); - mFocusMode = mode; + camera.setParameters(parameters); + focusMode = mode; return true; } } @@ -562,7 +562,7 @@ public boolean setFocusMode(@FocusMode String mode) { @Nullable @FlashMode public String getFlashMode() { - return mFlashMode; + return flashMode; } /** @@ -573,13 +573,13 @@ public String getFlashMode() { * @see #getFlashMode() */ public boolean setFlashMode(@FlashMode String mode) { - synchronized (mCameraLock) { - if (mCamera != null && mode != null) { - Camera.Parameters parameters = mCamera.getParameters(); + synchronized (cameraLock) { + if (camera != null && mode != null) { + Camera.Parameters parameters = camera.getParameters(); if (parameters.getSupportedFlashModes().contains(mode)) { parameters.setFlashMode(mode); - mCamera.setParameters(parameters); - mFlashMode = mode; + camera.setParameters(parameters); + flashMode = mode; return true; } } @@ -608,14 +608,14 @@ public boolean setFlashMode(@FlashMode String mode) { * @see #cancelAutoFocus() */ public void autoFocus(@Nullable AutoFocusCallback cb) { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { CameraAutoFocusCallback autoFocusCallback = null; if (cb != null) { autoFocusCallback = new CameraAutoFocusCallback(); autoFocusCallback.mDelegate = cb; } - mCamera.autoFocus(autoFocusCallback); + camera.autoFocus(autoFocusCallback); } } } @@ -629,9 +629,9 @@ public void autoFocus(@Nullable AutoFocusCallback cb) { * @see #autoFocus(AutoFocusCallback) */ public void cancelAutoFocus() { - synchronized (mCameraLock) { - if (mCamera != null) { - mCamera.cancelAutoFocus(); + synchronized (cameraLock) { + if (camera != null) { + camera.cancelAutoFocus(); } } } @@ -649,14 +649,14 @@ public boolean setAutoFocusMoveCallback(@Nullable AutoFocusMoveCallback cb) { return false; } - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { CameraAutoFocusMoveCallback autoFocusMoveCallback = null; if (cb != null) { autoFocusMoveCallback = new CameraAutoFocusMoveCallback(); autoFocusMoveCallback.mDelegate = cb; } - mCamera.setAutoFocusMoveCallback(autoFocusMoveCallback); + camera.setAutoFocusMoveCallback(autoFocusMoveCallback); } } @@ -699,9 +699,9 @@ public void onPictureTaken(byte[] data, Camera camera) { if (mDelegate != null) { mDelegate.onPictureTaken(data); } - synchronized (mCameraLock) { - if (mCamera != null) { - mCamera.startPreview(); + synchronized (cameraLock) { + if (CameraSource.this.camera != null) { + CameraSource.this.camera.startPreview(); } } } @@ -749,14 +749,14 @@ private Camera createCamera() { } Camera camera = Camera.open(requestedCameraId); - SizePair sizePair = selectSizePair(camera, mRequestedPreviewWidth, mRequestedPreviewHeight); + SizePair sizePair = selectSizePair(camera, requestedPreviewWidth, requestedPreviewHeight); if (sizePair == null) { throw new RuntimeException("Could not find suitable preview size."); } Size pictureSize = sizePair.pictureSize(); - mPreviewSize = sizePair.previewSize(); + previewSize = sizePair.previewSize(); - int[] previewFpsRange = selectPreviewFpsRange(camera, mRequestedFps); + int[] previewFpsRange = selectPreviewFpsRange(camera, requestedFps); if (previewFpsRange == null) { throw new RuntimeException("Could not find suitable preview frames per second range."); } @@ -767,7 +767,7 @@ private Camera createCamera() { parameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); } - parameters.setPreviewSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); + parameters.setPreviewSize(previewSize.getWidth(), previewSize.getHeight()); parameters.setPreviewFpsRange( previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); @@ -775,31 +775,31 @@ private Camera createCamera() { setRotation(camera, parameters, requestedCameraId); - if (mFocusMode != null) { + if (focusMode != null) { if (parameters.getSupportedFocusModes().contains( - mFocusMode)) { - parameters.setFocusMode(mFocusMode); + focusMode)) { + parameters.setFocusMode(focusMode); } else { - Log.i(TAG, "Camera focus mode: " + mFocusMode + + Log.i(TAG, "Camera focus mode: " + focusMode + " is not supported on this device."); } } - // setting mFocusMode to the one set in the params - mFocusMode = parameters.getFocusMode(); + // setting focusMode to the one set in the params + focusMode = parameters.getFocusMode(); - if (mFlashMode != null) { + if (flashMode != null) { if (parameters.getSupportedFlashModes().contains( - mFlashMode)) { - parameters.setFlashMode(mFlashMode); + flashMode)) { + parameters.setFlashMode(flashMode); } else { - Log.i(TAG, "Camera flash mode: " + mFlashMode + + Log.i(TAG, "Camera flash mode: " + flashMode + " is not supported on this device."); } } - // setting mFlashMode to the one set in the params - mFlashMode = parameters.getFlashMode(); + // setting flashMode to the one set in the params + flashMode = parameters.getFlashMode(); camera.setParameters(parameters); @@ -809,10 +809,10 @@ private Camera createCamera() { // one for the next pending frame to process immediately upon completing detection // two for the frames that the camera uses to populate future preview images camera.setPreviewCallbackWithBuffer(new CameraPreviewCallback()); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); return camera; } @@ -984,7 +984,7 @@ private int[] selectPreviewFpsRange(Camera camera, float desiredPreviewFps) { */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = - (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); + (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); switch (rotation) { @@ -1018,7 +1018,7 @@ private void setRotation(Camera camera, Camera.Parameters parameters, int camera } // This corresponds to the rotation constants in {@link Frame}. - mRotation = angle / 90; + this.rotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); @@ -1049,7 +1049,7 @@ private byte[] createPreviewBuffer(Size previewSize) { throw new IllegalStateException("Failed to create valid buffer for camera source."); } - mBytesToByteBuffer.put(byteArray, buffer); + bytesToByteBuffer.put(byteArray, buffer); return byteArray; } @@ -1063,7 +1063,7 @@ private byte[] createPreviewBuffer(Size previewSize) { private class CameraPreviewCallback implements Camera.PreviewCallback { @Override public void onPreviewFrame(byte[] data, Camera camera) { - mFrameProcessor.setNextFrame(data, camera); + frameProcessor.setNextFrame(data, camera); } } @@ -1100,7 +1100,7 @@ private class FrameProcessingRunnable implements Runnable { */ @SuppressLint("Assert") void release() { - assert (mProcessingThread.getState() == State.TERMINATED); + assert (processingThread.getState() == State.TERMINATED); mDetector.release(); mDetector = null; } @@ -1127,7 +1127,7 @@ void setNextFrame(byte[] data, Camera camera) { mPendingFrameData = null; } - if (!mBytesToByteBuffer.containsKey(data)) { + if (!bytesToByteBuffer.containsKey(data)) { Log.d(TAG, "Skipping frame. Could not find ByteBuffer associated with the image " + "data from the camera."); @@ -1138,7 +1138,7 @@ void setNextFrame(byte[] data, Camera camera) { // idea of the timing of frames received and when frames were dropped along the way. mPendingTimeMillis = SystemClock.elapsedRealtime() - mStartTimeMillis; mPendingFrameId++; - mPendingFrameData = mBytesToByteBuffer.get(data); + mPendingFrameData = bytesToByteBuffer.get(data); // Notify the processor thread if it is waiting on the next frame (see below). mLock.notifyAll(); @@ -1186,11 +1186,11 @@ public void run() { } outputFrame = new Frame.Builder() - .setImageData(mPendingFrameData, mPreviewSize.getWidth(), - mPreviewSize.getHeight(), ImageFormat.NV21) + .setImageData(mPendingFrameData, previewSize.getWidth(), + previewSize.getHeight(), ImageFormat.NV21) .setId(mPendingFrameId) .setTimestampMillis(mPendingTimeMillis) - .setRotation(mRotation) + .setRotation(rotation) .build(); // Hold onto the frame data locally, so that we can use this for detection @@ -1209,7 +1209,7 @@ public void run() { } catch (Throwable t) { Log.e(TAG, "Exception thrown from receiver.", t); } finally { - mCamera.addCallbackBuffer(data.array()); + camera.addCallbackBuffer(data.array()); } } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java index 2f7aca3c..e5782a94 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java @@ -32,23 +32,23 @@ public class CameraSourcePreview extends ViewGroup { private static final String TAG = "CameraSourcePreview"; - private Context mContext; - private SurfaceView mSurfaceView; - private boolean mStartRequested; - private boolean mSurfaceAvailable; - private CameraSource mCameraSource; + private Context context; + private SurfaceView surfaceView; + private boolean startRequested; + private boolean surfaceAvailable; + private CameraSource cameraSource; - private GraphicOverlay mOverlay; + private GraphicOverlay overlay; public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); - mContext = context; - mStartRequested = false; - mSurfaceAvailable = false; + this.context = context; + startRequested = false; + surfaceAvailable = false; - mSurfaceView = new SurfaceView(context); - mSurfaceView.getHolder().addCallback(new SurfaceCallback()); - addView(mSurfaceView); + surfaceView = new SurfaceView(context); + surfaceView.getHolder().addCallback(new SurfaceCallback()); + addView(surfaceView); } @RequiresPermission(Manifest.permission.CAMERA) @@ -57,58 +57,58 @@ public void start(CameraSource cameraSource) throws IOException, SecurityExcepti stop(); } - mCameraSource = cameraSource; + this.cameraSource = cameraSource; - if (mCameraSource != null) { - mStartRequested = true; + if (this.cameraSource != null) { + startRequested = true; startIfReady(); } } @RequiresPermission(Manifest.permission.CAMERA) public void start(CameraSource cameraSource, GraphicOverlay overlay) throws IOException, SecurityException { - mOverlay = overlay; + this.overlay = overlay; start(cameraSource); } public void stop() { - if (mCameraSource != null) { - mCameraSource.stop(); + if (cameraSource != null) { + cameraSource.stop(); } } public void release() { - if (mCameraSource != null) { - mCameraSource.release(); - mCameraSource = null; + if (cameraSource != null) { + cameraSource.release(); + cameraSource = null; } } @RequiresPermission(Manifest.permission.CAMERA) private void startIfReady() throws IOException, SecurityException { - if (mStartRequested && mSurfaceAvailable) { - mCameraSource.start(mSurfaceView.getHolder()); - if (mOverlay != null) { - Size size = mCameraSource.getPreviewSize(); + if (startRequested && surfaceAvailable) { + cameraSource.start(surfaceView.getHolder()); + if (overlay != null) { + Size size = cameraSource.getPreviewSize(); int min = Math.min(size.getWidth(), size.getHeight()); int max = Math.max(size.getWidth(), size.getHeight()); if (isPortraitMode()) { // Swap width and height sizes when in portrait, since it will be rotated by // 90 degrees - mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing()); + overlay.setCameraInfo(min, max, cameraSource.getCameraFacing()); } else { - mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing()); + overlay.setCameraInfo(max, min, cameraSource.getCameraFacing()); } - mOverlay.clear(); + overlay.clear(); } - mStartRequested = false; + startRequested = false; } } private class SurfaceCallback implements SurfaceHolder.Callback { @Override public void surfaceCreated(SurfaceHolder surface) { - mSurfaceAvailable = true; + surfaceAvailable = true; try { startIfReady(); } catch (SecurityException se) { @@ -120,7 +120,7 @@ public void surfaceCreated(SurfaceHolder surface) { @Override public void surfaceDestroyed(SurfaceHolder surface) { - mSurfaceAvailable = false; + surfaceAvailable = false; } @Override @@ -132,8 +132,8 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int previewWidth = 320; int previewHeight = 240; - if (mCameraSource != null) { - Size size = mCameraSource.getPreviewSize(); + if (cameraSource != null) { + Size size = cameraSource.getPreviewSize(); if (size != null) { previewWidth = size.getWidth(); previewHeight = size.getHeight(); @@ -189,7 +189,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto } private boolean isPortraitMode() { - int orientation = mContext.getResources().getConfiguration().orientation; + int orientation = context.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return false; } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java index 22c58221..5890b10a 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java +++ b/visionSamples/ocr-codelab/ocr-reader-complete/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java @@ -17,6 +17,8 @@ import android.content.Context; import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; @@ -44,13 +46,13 @@ * */ public class GraphicOverlay extends View { - private final Object mLock = new Object(); - private int mPreviewWidth; - private float mWidthScaleFactor = 1.0f; - private int mPreviewHeight; - private float mHeightScaleFactor = 1.0f; - private int mFacing = CameraSource.CAMERA_FACING_BACK; - private Set mGraphics = new HashSet<>(); + private final Object lock = new Object(); + private int previewWidth; + private float widthScaleFactor = 1.0f; + private int previewHeight; + private float heightScaleFactor = 1.0f; + private int facing = CameraSource.CAMERA_FACING_BACK; + private Set graphics = new HashSet<>(); /** * Base class for a custom graphics object to be rendered within the graphic overlay. Subclass @@ -88,14 +90,14 @@ public Graphic(GraphicOverlay overlay) { * scale. */ public float scaleX(float horizontal) { - return horizontal * mOverlay.mWidthScaleFactor; + return horizontal * mOverlay.widthScaleFactor; } /** * Adjusts a vertical value of the supplied value from the preview scale to the view scale. */ public float scaleY(float vertical) { - return vertical * mOverlay.mHeightScaleFactor; + return vertical * mOverlay.heightScaleFactor; } /** @@ -103,7 +105,7 @@ public float scaleY(float vertical) { * system. */ public float translateX(float x) { - if (mOverlay.mFacing == CameraSource.CAMERA_FACING_FRONT) { + if (mOverlay.facing == CameraSource.CAMERA_FACING_FRONT) { return mOverlay.getWidth() - scaleX(x); } else { return scaleX(x); @@ -118,6 +120,21 @@ public float translateY(float y) { return scaleY(y); } + /** + * Returns a RectF in which the left and right parameters of the provided Rect are adjusted + * by translateX, and the top and bottom are adjusted by translateY. + */ + public RectF translateRect(RectF inputRect) { + RectF returnRect = new RectF(); + + returnRect.left = translateX(inputRect.left); + returnRect.top = translateY(inputRect.top); + returnRect.right = translateX(inputRect.right); + returnRect.bottom = translateY(inputRect.bottom); + + return returnRect; + } + public void postInvalidate() { mOverlay.postInvalidate(); } @@ -131,8 +148,8 @@ public GraphicOverlay(Context context, AttributeSet attrs) { * Removes all graphics from the overlay. */ public void clear() { - synchronized (mLock) { - mGraphics.clear(); + synchronized (lock) { + graphics.clear(); } postInvalidate(); } @@ -141,8 +158,8 @@ public void clear() { * Adds a graphic to the overlay. */ public void add(T graphic) { - synchronized (mLock) { - mGraphics.add(graphic); + synchronized (lock) { + graphics.add(graphic); } postInvalidate(); } @@ -151,8 +168,8 @@ public void add(T graphic) { * Removes a graphic from the overlay. */ public void remove(T graphic) { - synchronized (mLock) { - mGraphics.remove(graphic); + synchronized (lock) { + graphics.remove(graphic); } postInvalidate(); } @@ -163,11 +180,11 @@ public void remove(T graphic) { * @return First graphic containing the point, or null if no text is detected. */ public T getGraphicAtLocation(float rawX, float rawY) { - synchronized (mLock) { + synchronized (lock) { // Get the position of this View so the raw location can be offset relative to the view. int[] location = new int[2]; this.getLocationOnScreen(location); - for (T graphic : mGraphics) { + for (T graphic : graphics) { if (graphic.contains(rawX - location[0], rawY - location[1])) { return graphic; } @@ -181,10 +198,10 @@ public T getGraphicAtLocation(float rawX, float rawY) { * image coordinates later. */ public void setCameraInfo(int previewWidth, int previewHeight, int facing) { - synchronized (mLock) { - mPreviewWidth = previewWidth; - mPreviewHeight = previewHeight; - mFacing = facing; + synchronized (lock) { + this.previewWidth = previewWidth; + this.previewHeight = previewHeight; + this.facing = facing; } postInvalidate(); } @@ -196,13 +213,13 @@ public void setCameraInfo(int previewWidth, int previewHeight, int facing) { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - synchronized (mLock) { - if ((mPreviewWidth != 0) && (mPreviewHeight != 0)) { - mWidthScaleFactor = (float) canvas.getWidth() / (float) mPreviewWidth; - mHeightScaleFactor = (float) canvas.getHeight() / (float) mPreviewHeight; + synchronized (lock) { + if ((previewWidth != 0) && (previewHeight != 0)) { + widthScaleFactor = (float) canvas.getWidth() / (float) previewWidth; + heightScaleFactor = (float) canvas.getHeight() / (float) previewHeight; } - for (Graphic graphic : mGraphics) { + for (Graphic graphic : graphics) { graphic.draw(canvas); } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/build.gradle b/visionSamples/ocr-codelab/ocr-reader-complete/build.gradle index d14039de..c06df431 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/build.gradle +++ b/visionSamples/ocr-codelab/ocr-reader-complete/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:3.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,5 +16,6 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/visionSamples/ocr-codelab/ocr-reader-complete/gradle/wrapper/gradle-wrapper.properties b/visionSamples/ocr-codelab/ocr-reader-complete/gradle/wrapper/gradle-wrapper.properties index d3b130d2..d4d566f5 100644 --- a/visionSamples/ocr-codelab/ocr-reader-complete/gradle/wrapper/gradle-wrapper.properties +++ b/visionSamples/ocr-codelab/ocr-reader-complete/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Apr 19 15:14:31 PDT 2016 +#Tue May 01 21:18:12 PDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip \ No newline at end of file +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/build.gradle b/visionSamples/ocr-codelab/ocr-reader-start/app/build.gradle index a5948ebc..9d101846 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/build.gradle +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 24 - buildToolsVersion "24.0.2" + compileSdkVersion 27 + buildToolsVersion '27.0.3' defaultConfig { - applicationId "com.google.android.gms.samples.vision.barcodereader" + applicationId "com.google.android.gms.samples.vision.ocrreader" minSdkVersion 21 - targetSdkVersion 24 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -20,7 +20,7 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:support-v4:24.2.0' - compile 'com.android.support:design:24.2.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:support-v4:27.1.1' + implementation 'com.android.support:design:27.1.1' } diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java index 7d757e94..c3875035 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrCaptureActivity.java @@ -22,11 +22,7 @@ import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; import android.content.pm.PackageManager; -import android.hardware.Camera; -import android.os.Build; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.support.annotation.NonNull; @@ -38,19 +34,14 @@ import android.view.MotionEvent; import android.view.ScaleGestureDetector; import android.view.View; -import android.widget.Toast; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GoogleApiAvailability; -import com.google.android.gms.common.api.CommonStatusCodes; import com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSource; import com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview; import com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay; -import com.google.android.gms.vision.text.TextBlock; -import com.google.android.gms.vision.text.TextRecognizer; import java.io.IOException; -import java.util.Locale; /** * Activity for the Ocr Detecting app. This app detects text and displays the value with the @@ -71,9 +62,9 @@ public final class OcrCaptureActivity extends AppCompatActivity { public static final String UseFlash = "UseFlash"; public static final String TextBlockObject = "String"; - private CameraSource mCameraSource; - private CameraSourcePreview mPreview; - private GraphicOverlay mGraphicOverlay; + private CameraSource cameraSource; + private CameraSourcePreview preview; + private GraphicOverlay graphicOverlay; // Helper objects for detecting taps and pinches. private ScaleGestureDetector scaleGestureDetector; @@ -90,8 +81,8 @@ public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture); - mPreview = (CameraSourcePreview) findViewById(R.id.preview); - mGraphicOverlay = (GraphicOverlay) findViewById(R.id.graphicOverlay); + preview = (CameraSourcePreview) findViewById(R.id.preview); + graphicOverlay = (GraphicOverlay) findViewById(R.id.graphicOverlay); // Set good defaults for capturing text. boolean autoFocus = true; @@ -109,7 +100,7 @@ public void onCreate(Bundle bundle) { gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); - Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", + Snackbar.make(graphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG) .show(); @@ -142,7 +133,7 @@ public void onClick(View view) { } }; - Snackbar.make(mGraphicOverlay, R.string.permission_camera_rationale, + Snackbar.make(graphicOverlay, R.string.permission_camera_rationale, Snackbar.LENGTH_INDEFINITE) .setAction(R.string.ok, listener) .show(); @@ -174,7 +165,7 @@ private void createCameraSource(boolean autoFocus, boolean useFlash) { // TODO: Check if the TextRecognizer is operational. - // TODO: Create the mCameraSource using the TextRecognizer. + // TODO: Create the cameraSource using the TextRecognizer. } /** @@ -192,8 +183,8 @@ protected void onResume() { @Override protected void onPause() { super.onPause(); - if (mPreview != null) { - mPreview.stop(); + if (preview != null) { + preview.stop(); } } @@ -204,8 +195,8 @@ protected void onPause() { @Override protected void onDestroy() { super.onDestroy(); - if (mPreview != null) { - mPreview.release(); + if (preview != null) { + preview.release(); } } @@ -275,13 +266,13 @@ private void startCameraSource() throws SecurityException { dlg.show(); } - if (mCameraSource != null) { + if (cameraSource != null) { try { - mPreview.start(mCameraSource, mGraphicOverlay); + preview.start(cameraSource, graphicOverlay); } catch (IOException e) { Log.e(TAG, "Unable to start camera source.", e); - mCameraSource.release(); - mCameraSource = null; + cameraSource.release(); + cameraSource = null; } } } @@ -356,8 +347,8 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { */ @Override public void onScaleEnd(ScaleGestureDetector detector) { - if (mCameraSource != null) { - mCameraSource.doZoom(detector.getScaleFactor()); + if (cameraSource != null) { + cameraSource.doZoom(detector.getScaleFactor()); } } } diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java index 8a9a84a2..8b614d04 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrDetectorProcessor.java @@ -15,12 +15,7 @@ */ package com.google.android.gms.samples.vision.ocrreader; -import android.util.Log; -import android.util.SparseArray; - import com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay; -import com.google.android.gms.vision.Detector; -import com.google.android.gms.vision.text.TextBlock; /** * A very simple Processor which gets detected TextBlocks and adds them to the overlay @@ -29,10 +24,10 @@ */ public class OcrDetectorProcessor { - private GraphicOverlay mGraphicOverlay; + private GraphicOverlay graphicOverlay; OcrDetectorProcessor(GraphicOverlay ocrGraphicOverlay) { - mGraphicOverlay = ocrGraphicOverlay; + graphicOverlay = ocrGraphicOverlay; } // TODO: Once this implements Detector.Processor, implement the abstract methods. diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java index e217396a..162ac27b 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/OcrGraphic.java @@ -18,59 +18,55 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.graphics.RectF; import com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay; -import com.google.android.gms.vision.text.Text; import com.google.android.gms.vision.text.TextBlock; -import java.util.List; - /** * Graphic instance for rendering TextBlock position, size, and ID within an associated graphic * overlay view. */ public class OcrGraphic extends GraphicOverlay.Graphic { - private int mId; + private int id; private static final int TEXT_COLOR = Color.WHITE; - private static Paint sRectPaint; - private static Paint sTextPaint; - private final TextBlock mText; + private static Paint rectPaint; + private static Paint textPaint; + private final TextBlock text; OcrGraphic(GraphicOverlay overlay, TextBlock text) { super(overlay); - mText = text; + this.text = text; - if (sRectPaint == null) { - sRectPaint = new Paint(); - sRectPaint.setColor(TEXT_COLOR); - sRectPaint.setStyle(Paint.Style.STROKE); - sRectPaint.setStrokeWidth(4.0f); + if (rectPaint == null) { + rectPaint = new Paint(); + rectPaint.setColor(TEXT_COLOR); + rectPaint.setStyle(Paint.Style.STROKE); + rectPaint.setStrokeWidth(4.0f); } - if (sTextPaint == null) { - sTextPaint = new Paint(); - sTextPaint.setColor(TEXT_COLOR); - sTextPaint.setTextSize(54.0f); + if (textPaint == null) { + textPaint = new Paint(); + textPaint.setColor(TEXT_COLOR); + textPaint.setTextSize(54.0f); } // Redraw the overlay, as this graphic has been added. postInvalidate(); } public int getId() { - return mId; + return id; } public void setId(int id) { - this.mId = id; + this.id = id; } public TextBlock getTextBlock() { - return mText; + return text; } /** diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java index 1a387522..e98c9576 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSource.java @@ -113,12 +113,12 @@ public class CameraSource { @Retention(RetentionPolicy.SOURCE) private @interface FlashMode {} - private Context mContext; + private Context context; - private final Object mCameraLock = new Object(); + private final Object cameraLock = new Object(); - // Guarded by mCameraLock - private Camera mCamera; + // Guarded by cameraLock + private Camera camera; private int mFacing = CAMERA_FACING_BACK; @@ -126,39 +126,39 @@ public class CameraSource { * Rotation of the device, and thus the associated preview images captured from the device. * See {@link Frame.Metadata#getRotation()}. */ - private int mRotation; + private int rotation; - private Size mPreviewSize; + private Size previewSize; // These values may be requested by the caller. Due to hardware limitations, we may need to // select close, but not exactly the same values for these. - private float mRequestedFps = 30.0f; - private int mRequestedPreviewWidth = 1024; - private int mRequestedPreviewHeight = 768; + private float requestedFps = 30.0f; + private int requestedPreviewWidth = 1024; + private int requestedPreviewHeight = 768; - private String mFocusMode = null; - private String mFlashMode = null; + private String focusMode = null; + private String flashMode = null; // These instances need to be held onto to avoid GC of their underlying resources. Even though // these aren't used outside of the method that creates them, they still must have hard // references maintained to them. - private SurfaceView mDummySurfaceView; - private SurfaceTexture mDummySurfaceTexture; + private SurfaceView dummySurfaceView; + private SurfaceTexture dummySurfaceTexture; /** * Dedicated thread and associated runnable for calling into the detector with frames, as the * frames become available from the camera. */ - private Thread mProcessingThread; - private FrameProcessingRunnable mFrameProcessor; + private Thread processingThread; + private FrameProcessingRunnable frameProcessor; /** * Map to convert between a byte array, received from the camera, and its associated byte * buffer. We use byte buffers internally because this is a more efficient way to call into * native code later (avoids a potential copy). */ - private Map mBytesToByteBuffer = new HashMap<>(); + private Map bytesToByteBuffer = new HashMap<>(); //============================================================================================== // Builder @@ -168,8 +168,8 @@ public class CameraSource { * Builder for configuring and creating an associated camera source. */ public static class Builder { - private final Detector mDetector; - private CameraSource mCameraSource = new CameraSource(); + private final Detector detector; + private CameraSource cameraSource = new CameraSource(); /** * Creates a camera source builder with the supplied context and detector. Camera preview @@ -183,8 +183,8 @@ public Builder(Context context, Detector detector) { throw new IllegalArgumentException("No detector supplied."); } - mDetector = detector; - mCameraSource.mContext = context; + this.detector = detector; + cameraSource.context = context; } /** @@ -195,17 +195,17 @@ public Builder setRequestedFps(float fps) { if (fps <= 0) { throw new IllegalArgumentException("Invalid fps: " + fps); } - mCameraSource.mRequestedFps = fps; + cameraSource.requestedFps = fps; return this; } public Builder setFocusMode(@FocusMode String mode) { - mCameraSource.mFocusMode = mode; + cameraSource.focusMode = mode; return this; } public Builder setFlashMode(@FlashMode String mode) { - mCameraSource.mFlashMode = mode; + cameraSource.flashMode = mode; return this; } @@ -223,8 +223,8 @@ public Builder setRequestedPreviewSize(int width, int height) { if ((width <= 0) || (width > MAX) || (height <= 0) || (height > MAX)) { throw new IllegalArgumentException("Invalid preview size: " + width + "x" + height); } - mCameraSource.mRequestedPreviewWidth = width; - mCameraSource.mRequestedPreviewHeight = height; + cameraSource.requestedPreviewWidth = width; + cameraSource.requestedPreviewHeight = height; return this; } @@ -236,7 +236,7 @@ public Builder setFacing(int facing) { if ((facing != CAMERA_FACING_BACK) && (facing != CAMERA_FACING_FRONT)) { throw new IllegalArgumentException("Invalid camera: " + facing); } - mCameraSource.mFacing = facing; + cameraSource.mFacing = facing; return this; } @@ -244,8 +244,8 @@ public Builder setFacing(int facing) { * Creates an instance of the camera source. */ public CameraSource build() { - mCameraSource.mFrameProcessor = mCameraSource.new FrameProcessingRunnable(mDetector); - return mCameraSource; + cameraSource.frameProcessor = cameraSource.new FrameProcessingRunnable(detector); + return cameraSource; } } @@ -320,9 +320,9 @@ public interface AutoFocusMoveCallback { * Stops the camera and releases the resources of the camera and underlying detector. */ public void release() { - synchronized (mCameraLock) { + synchronized (cameraLock) { stop(); - mFrameProcessor.release(); + frameProcessor.release(); } } @@ -334,27 +334,27 @@ public void release() { */ @RequiresPermission(Manifest.permission.CAMERA) public CameraSource start() throws IOException { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { return this; } - mCamera = createCamera(); + camera = createCamera(); // SurfaceTexture was introduced in Honeycomb (11), so if we are running and // old version of Android. fall back to use SurfaceView. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mDummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME); - mCamera.setPreviewTexture(mDummySurfaceTexture); + dummySurfaceTexture = new SurfaceTexture(DUMMY_TEXTURE_NAME); + camera.setPreviewTexture(dummySurfaceTexture); } else { - mDummySurfaceView = new SurfaceView(mContext); - mCamera.setPreviewDisplay(mDummySurfaceView.getHolder()); + dummySurfaceView = new SurfaceView(context); + camera.setPreviewDisplay(dummySurfaceView.getHolder()); } - mCamera.startPreview(); + camera.startPreview(); - mProcessingThread = new Thread(mFrameProcessor); - mFrameProcessor.setActive(true); - mProcessingThread.start(); + processingThread = new Thread(frameProcessor); + frameProcessor.setActive(true); + processingThread.start(); } return this; } @@ -368,18 +368,18 @@ public CameraSource start() throws IOException { */ @RequiresPermission(Manifest.permission.CAMERA) public CameraSource start(SurfaceHolder surfaceHolder) throws IOException { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { return this; } - mCamera = createCamera(); - mCamera.setPreviewDisplay(surfaceHolder); - mCamera.startPreview(); + camera = createCamera(); + camera.setPreviewDisplay(surfaceHolder); + camera.startPreview(); - mProcessingThread = new Thread(mFrameProcessor); - mFrameProcessor.setActive(true); - mProcessingThread.start(); + processingThread = new Thread(frameProcessor); + frameProcessor.setActive(true); + processingThread.start(); } return this; } @@ -394,26 +394,26 @@ public CameraSource start(SurfaceHolder surfaceHolder) throws IOException { * resources of the underlying detector. */ public void stop() { - synchronized (mCameraLock) { - mFrameProcessor.setActive(false); - if (mProcessingThread != null) { + synchronized (cameraLock) { + frameProcessor.setActive(false); + if (processingThread != null) { try { // Wait for the thread to complete to ensure that we can't have multiple threads // executing at the same time (i.e., which would happen if we called start too // quickly after stop). - mProcessingThread.join(); + processingThread.join(); } catch (InterruptedException e) { Log.d(TAG, "Frame processing thread interrupted on release."); } - mProcessingThread = null; + processingThread = null; } // clear the buffer to prevent oom exceptions - mBytesToByteBuffer.clear(); + bytesToByteBuffer.clear(); - if (mCamera != null) { - mCamera.stopPreview(); - mCamera.setPreviewCallbackWithBuffer(null); + if (camera != null) { + camera.stopPreview(); + camera.setPreviewCallbackWithBuffer(null); try { // We want to be compatible back to Gingerbread, but SurfaceTexture // wasn't introduced until Honeycomb. Since the interface cannot use a @@ -422,16 +422,16 @@ public void stop() { // SurfaceTexture if we are running at least Honeycomb. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - mCamera.setPreviewTexture(null); + camera.setPreviewTexture(null); } else { - mCamera.setPreviewDisplay(null); + camera.setPreviewDisplay(null); } } catch (Exception e) { Log.e(TAG, "Failed to clear camera preview: " + e); } - mCamera.release(); - mCamera = null; + camera.release(); + camera = null; } } } @@ -440,7 +440,7 @@ public void stop() { * Returns the preview size that is currently in use by the underlying camera. */ public Size getPreviewSize() { - return mPreviewSize; + return previewSize; } /** @@ -452,13 +452,13 @@ public int getCameraFacing() { } public int doZoom(float scale) { - synchronized (mCameraLock) { - if (mCamera == null) { + synchronized (cameraLock) { + if (camera == null) { return 0; } int currentZoom = 0; int maxZoom; - Camera.Parameters parameters = mCamera.getParameters(); + Camera.Parameters parameters = camera.getParameters(); if (!parameters.isZoomSupported()) { Log.w(TAG, "Zoom is not supported on this device"); return currentZoom; @@ -479,7 +479,7 @@ public int doZoom(float scale) { currentZoom = maxZoom; } parameters.setZoom(currentZoom); - mCamera.setParameters(parameters); + camera.setParameters(parameters); return currentZoom; } } @@ -494,13 +494,13 @@ public int doZoom(float scale) { * @param jpeg the callback for JPEG image data, or null */ public void takePicture(ShutterCallback shutter, PictureCallback jpeg) { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { PictureStartCallback startCallback = new PictureStartCallback(); startCallback.mDelegate = shutter; PictureDoneCallback doneCallback = new PictureDoneCallback(); doneCallback.mDelegate = jpeg; - mCamera.takePicture(startCallback, null, null, doneCallback); + camera.takePicture(startCallback, null, null, doneCallback); } } } @@ -522,7 +522,7 @@ public void takePicture(ShutterCallback shutter, PictureCallback jpeg) { @Nullable @FocusMode public String getFocusMode() { - return mFocusMode; + return focusMode; } /** @@ -533,13 +533,13 @@ public String getFocusMode() { * @see #getFocusMode() */ public boolean setFocusMode(@FocusMode String mode) { - synchronized (mCameraLock) { - if (mCamera != null && mode != null) { - Camera.Parameters parameters = mCamera.getParameters(); + synchronized (cameraLock) { + if (camera != null && mode != null) { + Camera.Parameters parameters = camera.getParameters(); if (parameters.getSupportedFocusModes().contains(mode)) { parameters.setFocusMode(mode); - mCamera.setParameters(parameters); - mFocusMode = mode; + camera.setParameters(parameters); + focusMode = mode; return true; } } @@ -562,7 +562,7 @@ public boolean setFocusMode(@FocusMode String mode) { @Nullable @FlashMode public String getFlashMode() { - return mFlashMode; + return flashMode; } /** @@ -573,13 +573,13 @@ public String getFlashMode() { * @see #getFlashMode() */ public boolean setFlashMode(@FlashMode String mode) { - synchronized (mCameraLock) { - if (mCamera != null && mode != null) { - Camera.Parameters parameters = mCamera.getParameters(); + synchronized (cameraLock) { + if (camera != null && mode != null) { + Camera.Parameters parameters = camera.getParameters(); if (parameters.getSupportedFlashModes().contains(mode)) { parameters.setFlashMode(mode); - mCamera.setParameters(parameters); - mFlashMode = mode; + camera.setParameters(parameters); + flashMode = mode; return true; } } @@ -608,14 +608,14 @@ public boolean setFlashMode(@FlashMode String mode) { * @see #cancelAutoFocus() */ public void autoFocus(@Nullable AutoFocusCallback cb) { - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { CameraAutoFocusCallback autoFocusCallback = null; if (cb != null) { autoFocusCallback = new CameraAutoFocusCallback(); autoFocusCallback.mDelegate = cb; } - mCamera.autoFocus(autoFocusCallback); + camera.autoFocus(autoFocusCallback); } } } @@ -629,9 +629,9 @@ public void autoFocus(@Nullable AutoFocusCallback cb) { * @see #autoFocus(AutoFocusCallback) */ public void cancelAutoFocus() { - synchronized (mCameraLock) { - if (mCamera != null) { - mCamera.cancelAutoFocus(); + synchronized (cameraLock) { + if (camera != null) { + camera.cancelAutoFocus(); } } } @@ -649,14 +649,14 @@ public boolean setAutoFocusMoveCallback(@Nullable AutoFocusMoveCallback cb) { return false; } - synchronized (mCameraLock) { - if (mCamera != null) { + synchronized (cameraLock) { + if (camera != null) { CameraAutoFocusMoveCallback autoFocusMoveCallback = null; if (cb != null) { autoFocusMoveCallback = new CameraAutoFocusMoveCallback(); autoFocusMoveCallback.mDelegate = cb; } - mCamera.setAutoFocusMoveCallback(autoFocusMoveCallback); + camera.setAutoFocusMoveCallback(autoFocusMoveCallback); } } @@ -699,9 +699,9 @@ public void onPictureTaken(byte[] data, Camera camera) { if (mDelegate != null) { mDelegate.onPictureTaken(data); } - synchronized (mCameraLock) { - if (mCamera != null) { - mCamera.startPreview(); + synchronized (cameraLock) { + if (CameraSource.this.camera != null) { + CameraSource.this.camera.startPreview(); } } } @@ -749,14 +749,14 @@ private Camera createCamera() { } Camera camera = Camera.open(requestedCameraId); - SizePair sizePair = selectSizePair(camera, mRequestedPreviewWidth, mRequestedPreviewHeight); + SizePair sizePair = selectSizePair(camera, requestedPreviewWidth, requestedPreviewHeight); if (sizePair == null) { throw new RuntimeException("Could not find suitable preview size."); } Size pictureSize = sizePair.pictureSize(); - mPreviewSize = sizePair.previewSize(); + previewSize = sizePair.previewSize(); - int[] previewFpsRange = selectPreviewFpsRange(camera, mRequestedFps); + int[] previewFpsRange = selectPreviewFpsRange(camera, requestedFps); if (previewFpsRange == null) { throw new RuntimeException("Could not find suitable preview frames per second range."); } @@ -767,7 +767,7 @@ private Camera createCamera() { parameters.setPictureSize(pictureSize.getWidth(), pictureSize.getHeight()); } - parameters.setPreviewSize(mPreviewSize.getWidth(), mPreviewSize.getHeight()); + parameters.setPreviewSize(previewSize.getWidth(), previewSize.getHeight()); parameters.setPreviewFpsRange( previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX], previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]); @@ -775,31 +775,31 @@ private Camera createCamera() { setRotation(camera, parameters, requestedCameraId); - if (mFocusMode != null) { + if (focusMode != null) { if (parameters.getSupportedFocusModes().contains( - mFocusMode)) { - parameters.setFocusMode(mFocusMode); + focusMode)) { + parameters.setFocusMode(focusMode); } else { - Log.i(TAG, "Camera focus mode: " + mFocusMode + + Log.i(TAG, "Camera focus mode: " + focusMode + " is not supported on this device."); } } - // setting mFocusMode to the one set in the params - mFocusMode = parameters.getFocusMode(); + // setting focusMode to the one set in the params + focusMode = parameters.getFocusMode(); - if (mFlashMode != null) { + if (flashMode != null) { if (parameters.getSupportedFlashModes().contains( - mFlashMode)) { - parameters.setFlashMode(mFlashMode); + flashMode)) { + parameters.setFlashMode(flashMode); } else { - Log.i(TAG, "Camera flash mode: " + mFlashMode + + Log.i(TAG, "Camera flash mode: " + flashMode + " is not supported on this device."); } } - // setting mFlashMode to the one set in the params - mFlashMode = parameters.getFlashMode(); + // setting flashMode to the one set in the params + flashMode = parameters.getFlashMode(); camera.setParameters(parameters); @@ -809,10 +809,10 @@ private Camera createCamera() { // one for the next pending frame to process immediately upon completing detection // two for the frames that the camera uses to populate future preview images camera.setPreviewCallbackWithBuffer(new CameraPreviewCallback()); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); - camera.addCallbackBuffer(createPreviewBuffer(mPreviewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); + camera.addCallbackBuffer(createPreviewBuffer(previewSize)); return camera; } @@ -984,7 +984,7 @@ private int[] selectPreviewFpsRange(Camera camera, float desiredPreviewFps) { */ private void setRotation(Camera camera, Camera.Parameters parameters, int cameraId) { WindowManager windowManager = - (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); + (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); int degrees = 0; int rotation = windowManager.getDefaultDisplay().getRotation(); switch (rotation) { @@ -1018,7 +1018,7 @@ private void setRotation(Camera camera, Camera.Parameters parameters, int camera } // This corresponds to the rotation constants in {@link Frame}. - mRotation = angle / 90; + this.rotation = angle / 90; camera.setDisplayOrientation(displayAngle); parameters.setRotation(angle); @@ -1049,7 +1049,7 @@ private byte[] createPreviewBuffer(Size previewSize) { throw new IllegalStateException("Failed to create valid buffer for camera source."); } - mBytesToByteBuffer.put(byteArray, buffer); + bytesToByteBuffer.put(byteArray, buffer); return byteArray; } @@ -1063,7 +1063,7 @@ private byte[] createPreviewBuffer(Size previewSize) { private class CameraPreviewCallback implements Camera.PreviewCallback { @Override public void onPreviewFrame(byte[] data, Camera camera) { - mFrameProcessor.setNextFrame(data, camera); + frameProcessor.setNextFrame(data, camera); } } @@ -1100,7 +1100,7 @@ private class FrameProcessingRunnable implements Runnable { */ @SuppressLint("Assert") void release() { - assert (mProcessingThread.getState() == State.TERMINATED); + assert (processingThread.getState() == State.TERMINATED); mDetector.release(); mDetector = null; } @@ -1127,7 +1127,7 @@ void setNextFrame(byte[] data, Camera camera) { mPendingFrameData = null; } - if (!mBytesToByteBuffer.containsKey(data)) { + if (!bytesToByteBuffer.containsKey(data)) { Log.d(TAG, "Skipping frame. Could not find ByteBuffer associated with the image " + "data from the camera."); @@ -1138,7 +1138,7 @@ void setNextFrame(byte[] data, Camera camera) { // idea of the timing of frames received and when frames were dropped along the way. mPendingTimeMillis = SystemClock.elapsedRealtime() - mStartTimeMillis; mPendingFrameId++; - mPendingFrameData = mBytesToByteBuffer.get(data); + mPendingFrameData = bytesToByteBuffer.get(data); // Notify the processor thread if it is waiting on the next frame (see below). mLock.notifyAll(); @@ -1186,11 +1186,11 @@ public void run() { } outputFrame = new Frame.Builder() - .setImageData(mPendingFrameData, mPreviewSize.getWidth(), - mPreviewSize.getHeight(), ImageFormat.NV21) + .setImageData(mPendingFrameData, previewSize.getWidth(), + previewSize.getHeight(), ImageFormat.NV21) .setId(mPendingFrameId) .setTimestampMillis(mPendingTimeMillis) - .setRotation(mRotation) + .setRotation(rotation) .build(); // Hold onto the frame data locally, so that we can use this for detection @@ -1209,7 +1209,7 @@ public void run() { } catch (Throwable t) { Log.e(TAG, "Exception thrown from receiver.", t); } finally { - mCamera.addCallbackBuffer(data.array()); + camera.addCallbackBuffer(data.array()); } } } diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java index 2f7aca3c..e5782a94 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/CameraSourcePreview.java @@ -32,23 +32,23 @@ public class CameraSourcePreview extends ViewGroup { private static final String TAG = "CameraSourcePreview"; - private Context mContext; - private SurfaceView mSurfaceView; - private boolean mStartRequested; - private boolean mSurfaceAvailable; - private CameraSource mCameraSource; + private Context context; + private SurfaceView surfaceView; + private boolean startRequested; + private boolean surfaceAvailable; + private CameraSource cameraSource; - private GraphicOverlay mOverlay; + private GraphicOverlay overlay; public CameraSourcePreview(Context context, AttributeSet attrs) { super(context, attrs); - mContext = context; - mStartRequested = false; - mSurfaceAvailable = false; + this.context = context; + startRequested = false; + surfaceAvailable = false; - mSurfaceView = new SurfaceView(context); - mSurfaceView.getHolder().addCallback(new SurfaceCallback()); - addView(mSurfaceView); + surfaceView = new SurfaceView(context); + surfaceView.getHolder().addCallback(new SurfaceCallback()); + addView(surfaceView); } @RequiresPermission(Manifest.permission.CAMERA) @@ -57,58 +57,58 @@ public void start(CameraSource cameraSource) throws IOException, SecurityExcepti stop(); } - mCameraSource = cameraSource; + this.cameraSource = cameraSource; - if (mCameraSource != null) { - mStartRequested = true; + if (this.cameraSource != null) { + startRequested = true; startIfReady(); } } @RequiresPermission(Manifest.permission.CAMERA) public void start(CameraSource cameraSource, GraphicOverlay overlay) throws IOException, SecurityException { - mOverlay = overlay; + this.overlay = overlay; start(cameraSource); } public void stop() { - if (mCameraSource != null) { - mCameraSource.stop(); + if (cameraSource != null) { + cameraSource.stop(); } } public void release() { - if (mCameraSource != null) { - mCameraSource.release(); - mCameraSource = null; + if (cameraSource != null) { + cameraSource.release(); + cameraSource = null; } } @RequiresPermission(Manifest.permission.CAMERA) private void startIfReady() throws IOException, SecurityException { - if (mStartRequested && mSurfaceAvailable) { - mCameraSource.start(mSurfaceView.getHolder()); - if (mOverlay != null) { - Size size = mCameraSource.getPreviewSize(); + if (startRequested && surfaceAvailable) { + cameraSource.start(surfaceView.getHolder()); + if (overlay != null) { + Size size = cameraSource.getPreviewSize(); int min = Math.min(size.getWidth(), size.getHeight()); int max = Math.max(size.getWidth(), size.getHeight()); if (isPortraitMode()) { // Swap width and height sizes when in portrait, since it will be rotated by // 90 degrees - mOverlay.setCameraInfo(min, max, mCameraSource.getCameraFacing()); + overlay.setCameraInfo(min, max, cameraSource.getCameraFacing()); } else { - mOverlay.setCameraInfo(max, min, mCameraSource.getCameraFacing()); + overlay.setCameraInfo(max, min, cameraSource.getCameraFacing()); } - mOverlay.clear(); + overlay.clear(); } - mStartRequested = false; + startRequested = false; } } private class SurfaceCallback implements SurfaceHolder.Callback { @Override public void surfaceCreated(SurfaceHolder surface) { - mSurfaceAvailable = true; + surfaceAvailable = true; try { startIfReady(); } catch (SecurityException se) { @@ -120,7 +120,7 @@ public void surfaceCreated(SurfaceHolder surface) { @Override public void surfaceDestroyed(SurfaceHolder surface) { - mSurfaceAvailable = false; + surfaceAvailable = false; } @Override @@ -132,8 +132,8 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width, int heig protected void onLayout(boolean changed, int left, int top, int right, int bottom) { int previewWidth = 320; int previewHeight = 240; - if (mCameraSource != null) { - Size size = mCameraSource.getPreviewSize(); + if (cameraSource != null) { + Size size = cameraSource.getPreviewSize(); if (size != null) { previewWidth = size.getWidth(); previewHeight = size.getHeight(); @@ -189,7 +189,7 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto } private boolean isPortraitMode() { - int orientation = mContext.getResources().getConfiguration().orientation; + int orientation = context.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { return false; } diff --git a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java index 22c58221..5890b10a 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java +++ b/visionSamples/ocr-codelab/ocr-reader-start/app/src/main/java/com/google/android/gms/samples/vision/ocrreader/ui/camera/GraphicOverlay.java @@ -17,6 +17,8 @@ import android.content.Context; import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.RectF; import android.util.AttributeSet; import android.view.View; @@ -44,13 +46,13 @@ * */ public class GraphicOverlay extends View { - private final Object mLock = new Object(); - private int mPreviewWidth; - private float mWidthScaleFactor = 1.0f; - private int mPreviewHeight; - private float mHeightScaleFactor = 1.0f; - private int mFacing = CameraSource.CAMERA_FACING_BACK; - private Set mGraphics = new HashSet<>(); + private final Object lock = new Object(); + private int previewWidth; + private float widthScaleFactor = 1.0f; + private int previewHeight; + private float heightScaleFactor = 1.0f; + private int facing = CameraSource.CAMERA_FACING_BACK; + private Set graphics = new HashSet<>(); /** * Base class for a custom graphics object to be rendered within the graphic overlay. Subclass @@ -88,14 +90,14 @@ public Graphic(GraphicOverlay overlay) { * scale. */ public float scaleX(float horizontal) { - return horizontal * mOverlay.mWidthScaleFactor; + return horizontal * mOverlay.widthScaleFactor; } /** * Adjusts a vertical value of the supplied value from the preview scale to the view scale. */ public float scaleY(float vertical) { - return vertical * mOverlay.mHeightScaleFactor; + return vertical * mOverlay.heightScaleFactor; } /** @@ -103,7 +105,7 @@ public float scaleY(float vertical) { * system. */ public float translateX(float x) { - if (mOverlay.mFacing == CameraSource.CAMERA_FACING_FRONT) { + if (mOverlay.facing == CameraSource.CAMERA_FACING_FRONT) { return mOverlay.getWidth() - scaleX(x); } else { return scaleX(x); @@ -118,6 +120,21 @@ public float translateY(float y) { return scaleY(y); } + /** + * Returns a RectF in which the left and right parameters of the provided Rect are adjusted + * by translateX, and the top and bottom are adjusted by translateY. + */ + public RectF translateRect(RectF inputRect) { + RectF returnRect = new RectF(); + + returnRect.left = translateX(inputRect.left); + returnRect.top = translateY(inputRect.top); + returnRect.right = translateX(inputRect.right); + returnRect.bottom = translateY(inputRect.bottom); + + return returnRect; + } + public void postInvalidate() { mOverlay.postInvalidate(); } @@ -131,8 +148,8 @@ public GraphicOverlay(Context context, AttributeSet attrs) { * Removes all graphics from the overlay. */ public void clear() { - synchronized (mLock) { - mGraphics.clear(); + synchronized (lock) { + graphics.clear(); } postInvalidate(); } @@ -141,8 +158,8 @@ public void clear() { * Adds a graphic to the overlay. */ public void add(T graphic) { - synchronized (mLock) { - mGraphics.add(graphic); + synchronized (lock) { + graphics.add(graphic); } postInvalidate(); } @@ -151,8 +168,8 @@ public void add(T graphic) { * Removes a graphic from the overlay. */ public void remove(T graphic) { - synchronized (mLock) { - mGraphics.remove(graphic); + synchronized (lock) { + graphics.remove(graphic); } postInvalidate(); } @@ -163,11 +180,11 @@ public void remove(T graphic) { * @return First graphic containing the point, or null if no text is detected. */ public T getGraphicAtLocation(float rawX, float rawY) { - synchronized (mLock) { + synchronized (lock) { // Get the position of this View so the raw location can be offset relative to the view. int[] location = new int[2]; this.getLocationOnScreen(location); - for (T graphic : mGraphics) { + for (T graphic : graphics) { if (graphic.contains(rawX - location[0], rawY - location[1])) { return graphic; } @@ -181,10 +198,10 @@ public T getGraphicAtLocation(float rawX, float rawY) { * image coordinates later. */ public void setCameraInfo(int previewWidth, int previewHeight, int facing) { - synchronized (mLock) { - mPreviewWidth = previewWidth; - mPreviewHeight = previewHeight; - mFacing = facing; + synchronized (lock) { + this.previewWidth = previewWidth; + this.previewHeight = previewHeight; + this.facing = facing; } postInvalidate(); } @@ -196,13 +213,13 @@ public void setCameraInfo(int previewWidth, int previewHeight, int facing) { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - synchronized (mLock) { - if ((mPreviewWidth != 0) && (mPreviewHeight != 0)) { - mWidthScaleFactor = (float) canvas.getWidth() / (float) mPreviewWidth; - mHeightScaleFactor = (float) canvas.getHeight() / (float) mPreviewHeight; + synchronized (lock) { + if ((previewWidth != 0) && (previewHeight != 0)) { + widthScaleFactor = (float) canvas.getWidth() / (float) previewWidth; + heightScaleFactor = (float) canvas.getHeight() / (float) previewHeight; } - for (Graphic graphic : mGraphics) { + for (Graphic graphic : graphics) { graphic.draw(canvas); } } diff --git a/visionSamples/ocr-codelab/ocr-reader-start/build.gradle b/visionSamples/ocr-codelab/ocr-reader-start/build.gradle index d14039de..c06df431 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/build.gradle +++ b/visionSamples/ocr-codelab/ocr-reader-start/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:3.1.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,5 +16,6 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/visionSamples/ocr-codelab/ocr-reader-start/gradle/wrapper/gradle-wrapper.properties b/visionSamples/ocr-codelab/ocr-reader-start/gradle/wrapper/gradle-wrapper.properties index af6e4e55..d95b9686 100644 --- a/visionSamples/ocr-codelab/ocr-reader-start/gradle/wrapper/gradle-wrapper.properties +++ b/visionSamples/ocr-codelab/ocr-reader-start/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Apr 19 15:14:31 PDT 2016 +#Tue May 01 22:54:41 PDT 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/visionSamples/ocr-reader/app/build.gradle b/visionSamples/ocr-reader/app/build.gradle index e53e2ae9..fc453729 100644 --- a/visionSamples/ocr-reader/app/build.gradle +++ b/visionSamples/ocr-reader/app/build.gradle @@ -2,10 +2,10 @@ apply plugin: 'com.android.application' android { compileSdkVersion 23 - buildToolsVersion "23.0.1" + buildToolsVersion '25.0.0' defaultConfig { - applicationId "com.google.android.gms.samples.vision.barcodereader" + applicationId "com.google.android.gms.samples.vision.ocrreader" minSdkVersion 9 targetSdkVersion 23 versionCode 1 diff --git a/visionSamples/ocr-reader/build.gradle b/visionSamples/ocr-reader/build.gradle index d14039de..ea98e44f 100644 --- a/visionSamples/ocr-reader/build.gradle +++ b/visionSamples/ocr-reader/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.1.3' + classpath 'com.android.tools.build:gradle:2.3.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/visionSamples/ocr-reader/gradle/wrapper/gradle-wrapper.properties b/visionSamples/ocr-reader/gradle/wrapper/gradle-wrapper.properties index af6e4e55..49458f84 100644 --- a/visionSamples/ocr-reader/gradle/wrapper/gradle-wrapper.properties +++ b/visionSamples/ocr-reader/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Apr 19 15:14:31 PDT 2016 +#Thu May 18 20:58:24 PDT 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip