package com.google.firebase.quickstart.mlkit;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.ml.vision.FirebaseVision;
import com.google.firebase.ml.vision.common.FirebaseVisionImage;
import com.google.firebase.ml.vision.label.FirebaseVisionLabel;
import com.google.firebase.ml.vision.label.FirebaseVisionLabelDetector;
import com.google.firebase.ml.vision.label.FirebaseVisionLabelDetectorOptions;

import java.util.List;

public class ImageLabelingActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image_labeling);
    }

    private void labelImages(FirebaseVisionImage image) {
        // [START set_detector_options]
        FirebaseVisionLabelDetectorOptions options =
                new FirebaseVisionLabelDetectorOptions.Builder()
                        .setConfidenceThreshold(0.8f)
                        .build();
        // [END set_detector_options]

        // [START get_detector_default]
        FirebaseVisionLabelDetector detector = FirebaseVision.getInstance()
                .getVisionLabelDetector();
        // [END get_detector_default]

        /*
        // [START get_detector_options]
        // Or, to set the minimum confidense required:
        FirebaseVisionLabelDetector detector = FirebaseVision.getInstance()
                .getVisionLabelDetector(options);
        // [END get_detector_options]
        */

        // [START run_detector]
        Task<List<FirebaseVisionLabel>> result =
                detector.detectInImage(image)
                        .addOnSuccessListener(
                                new OnSuccessListener<List<FirebaseVisionLabel>>() {
                                    @Override
                                    public void onSuccess(List<FirebaseVisionLabel> labels) {
                                        // Task completed successfully
                                        // [START_EXCLUDE]
                                        // [START get_labels]
                                        for (FirebaseVisionLabel label: labels) {
                                            String text = label.getLabel();
                                            String entityId = label.getEntityId();
                                            float confidence = label.getConfidence();
                                        }
                                        // [END run_detector]
                                        // [END_EXCLUDE]
                                    }
                                })
                        .addOnFailureListener(
                                new OnFailureListener() {
                                    @Override
                                    public void onFailure(@NonNull Exception e) {
                                        // Task failed with an exception
                                        // ...
                                    }
                                });
        // [END run_detector]
    }
}

@@ -364,16 +364,253 @@
 Vision;%0A
+import com.google.firebase.ml.vision.cloud.FirebaseVisionCloudDetectorOptions;%0Aimport com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabel;%0Aimport com.google.firebase.ml.vision.cloud.label.FirebaseVisionCloudLabelDetector;%0A
 import c
@@ -666,16 +666,16 @@
 nImage;%0A
-
 import c
@@ -1784,17 +1784,17 @@
 confiden
-s
+c
 e requir
@@ -2977,36 +2977,2475 @@
     // %5BEND 
-run_detector
+get_labels%5D%0A                                        // %5BEND_EXCLUDE%5D%0A                                    %7D%0A                                %7D)%0A                        .addOnFailureListener(%0A                                new OnFailureListener() %7B%0A                                    @Override%0A                                    public void onFailure(@NonNull Exception e) %7B%0A                                        // Task failed with an exception%0A                                        // ...%0A                                    %7D%0A                                %7D);%0A        // %5BEND run_detector%5D%0A    %7D%0A%0A    private void labelImagesCloud(FirebaseVisionImage image) %7B%0A        // %5BSTART set_detector_options_cloud%5D%0A        FirebaseVisionCloudDetectorOptions options = new FirebaseVisionCloudDetectorOptions.Builder()%0A                .setModelType(FirebaseVisionCloudDetectorOptions.LATEST_MODEL)%0A                .setMaxResults(30)%0A                .build();%0A        // %5BEND set_detector_options_cloud%5D%0A%0A        // %5BSTART get_detector_cloud%5D%0A        FirebaseVisionCloudLabelDetector detector = FirebaseVision.getInstance()%0A                .getVisionCloudLabelDetector();%0A        // Or, to change the default settings:%0A        // FirebaseVisionCloudLabelDetector detector = FirebaseVision.getInstance()%0A        //         .getVisionCloudLabelDetector(options);%0A        // %5BEND get_detector_cloud%5D%0A%0A        // %5BSTART run_detector_cloud%5D%0A        Task%3CList%3CFirebaseVisionCloudLabel%3E%3E result =%0A                detector.detectInImage(image)%0A                        .addOnSuccessListener(%0A                                new OnSuccessListener%3CList%3CFirebaseVisionCloudLabel%3E%3E() %7B%0A                                    @Override%0A                                    public void onSuccess(List%3CFirebaseVisionCloudLabel%3E labels) %7B%0A                                        // Task completed successfully%0A                                        // %5BSTART_EXCLUDE%5D%0A                                        // %5BSTART get_labels_cloud%5D%0A                                        for (FirebaseVisionCloudLabel label: labels) %7B%0A                                            String text = label.getLabel();%0A                                            String entityId = label.getEntityId();%0A                                            float confidence = label.getConfidence();%0A                                        %7D%0A                                        // %5BEND get_labels_cloud
 %5D%0A          
@@ -5983,32 +5983,32 @@
             %7D);%0A
-
         // %5BEND 
@@ -6011,26 +6011,32 @@
 END run_detector
+_cloud
 %5D%0A    %7D%0A%7D%0A

Add cloud label detection snippets