Search in sources :

Example 11 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project Instafood by Gear61.

the class LocationManager method checkLocationServicesAndFetchLocationIfOn.

private void checkLocationServicesAndFetchLocationIfOn() {
    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
    SettingsClient client = LocationServices.getSettingsClient(activity);
    client.checkLocationSettings(builder.build()).addOnSuccessListener(new OnSuccessListener<LocationSettingsResponse>() {

        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            fetchAutomaticLocation();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            if (exception instanceof ResolvableApiException) {
                locationServicesManager.askForLocationServices(LOCATION_SERVICES_CODE);
            } else {
                onLocationFetchFail();
            }
        }
    });
}
Also used : SettingsClient(com.google.android.gms.location.SettingsClient) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException)

Example 12 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project HikingApp by wickhama.

the class ImageTemp method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_image_temp);
    imageContainer = findViewById(R.id.imageButtonTest);
    uploadImage = (Button) findViewById(R.id.uploadImageTest);
    mAuth = FirebaseAuth.getInstance();
    currentUser = mAuth.getCurrentUser();
    /**
     * Anonymous Auth Again -- this will not be needed later as we should move this to a launch
     * activity.
     */
    mAuth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

        @Override
        public void onComplete(@NonNull Task<AuthResult> task) {
            if (task.isSuccessful()) {
                // Sign in success, update UI with the signed-in user's information
                System.out.println("***Anonymous User Authentication successful.");
                FirebaseUser user = mAuth.getCurrentUser();
            } else {
                // If sign in fails, display a message to the user.
                System.out.println("***Anonymous User Authentication failed.");
            }
        // ...
        }
    });
    /**
     * Getting images from the gallery.
     */
    uploadImage = (Button) findViewById(R.id.uploadImageTest);
    addImage = (ImageButton) findViewById(R.id.imageButtonTest);
    addImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
            galleryIntent.setType("image/*");
            startActivityForResult(galleryIntent, GALLERY_CODE);
        }
    });
    /**
     * UPLOADING images to Firebase Storage.
     */
    uploadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (imageUri != null) {
                // added for UUID
                String path = "images/" + UUID.randomUUID() + ".jpg";
                storageRef = storage.getReference();
                imageRef = storageRef.child(path);
                uploadTask = storageRef.putFile(imageUri);
                imageRef.getName().equals(imageRef.getName());
                imageRef.getPath().equals(imageRef.getPath());
                Uri file = imageUri;
                // Sets path with UUID
                imageRef = storageRef.child(path);
                saveInternal(imageUri);
                uploadTask = imageRef.putFile(file);
                uploadTask.addOnFailureListener(new OnFailureListener() {

                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(getApplicationContext(), "File Upload Failure.", Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                    }
                }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

                    @Override
                    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                        Toast.makeText(getApplicationContext(), "File Upload Success.", Toast.LENGTH_LONG).show();
                    // This will be needed when saving to the Trail object
                    /*
                            Uri downloadUrl = taskSnapshot.getDownloadUrl();
                            String url = downloadUrl.toString();
                            */
                    }
                });
            }
        }
    });
    /**
     * DOWNLOADING from Firebase Storage
     */
    // Hardcoded to get things working.
    String url = "https://firebasestorage.googleapis.com/v0/b/arctrails-b1a84.appspot.com/o/" + "images%2F20e1ee59-1fe1-4a05-82e8-9f40845ba6d5.jpg?alt=media&token=3b43df3d-1546-" + "4143-a8ae-2be667857cb5";
    StorageReference displayRef = storage.getReferenceFromUrl(url);
    ImageView displayImage = (ImageView) findViewById(R.id.photoHolder);
    Glide.with(ImageTemp.this).using(new FirebaseImageLoader()).load(displayRef).into(displayImage);
}
Also used : StorageReference(com.google.firebase.storage.StorageReference) AuthResult(com.google.firebase.auth.AuthResult) Intent(android.content.Intent) FirebaseUser(com.google.firebase.auth.FirebaseUser) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Uri(android.net.Uri) FirebaseImageLoader(com.firebase.ui.storage.images.FirebaseImageLoader) IOException(java.io.IOException) UploadTask(com.google.firebase.storage.UploadTask) ImageView(android.widget.ImageView) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 13 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project HikingApp by wickhama.

the class Database method downloadImage.

public void downloadImage(Trail trail, Context context) {
    File localFile = new File(context.getExternalFilesDir(null), trail.getMetadata().getId() + ".jpg");
    StorageReference islandRef = storageRef.child("images/" + trail.getMetadata().getId() + ".jpg");
    islandRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
        // Local temp file has been created
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
        // Handle any errors
        }
    });
}
Also used : FileDownloadTask(com.google.firebase.storage.FileDownloadTask) StorageReference(com.google.firebase.storage.StorageReference) File(java.io.File) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 14 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project NightSkyGuide by MTBehnke.

the class SettingsActivity method startLocationUpdates.

public void startLocationUpdates() {
    // if settings are satisfied initialize location requests
    mSettingsClient.checkLocationSettings(mLocationSettingsRequest).addOnSuccessListener(this, new OnSuccessListener<LocationSettingsResponse>() {

        @Override
        public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
            locUpdates = true;
            // All location settings are satisfied.
            // noinspection MissingPermission - this comment needs to stay here to stop inspection on next line
            mFusedLocationClient.requestLocationUpdates(mLocationRequest, mLocationCallback, Looper.myLooper());
        }
    }).addOnFailureListener(this, new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            int statusCode = ((ApiException) e).getStatusCode();
            switch(statusCode) {
                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                    // location settings are not satisfied, but this can be fixed by showing the user a dialog.
                    try {
                        // show the dialog by calling startResolutionForResult(), and check the result in onActivityResult().
                        ResolvableApiException resolvable = (ResolvableApiException) e;
                        resolvable.startResolutionForResult(SettingsActivity.this, REQUEST_CHECK_SETTINGS);
                    } catch (IntentSender.SendIntentException sendEx) {
                    // Ignore the error
                    }
                    break;
                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                    // location settings are not satisfied, however no way to fix the settings so don't show dialog.
                    Toast.makeText(context, "Location Services Unavailable", Toast.LENGTH_LONG).show();
                    useGPS = false;
                    SharedPreferences.Editor edit = preferences.edit();
                    edit.putBoolean("use_device_location", false);
                    edit.apply();
                    settingsFragment.useDeviceLocation.setChecked(false);
                    settingsFragment.setLocSummary();
                    break;
            }
        }
    });
}
Also used : ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) LocationSettingsResponse(com.google.android.gms.location.LocationSettingsResponse) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) ResolvableApiException(com.google.android.gms.common.api.ResolvableApiException) ApiException(com.google.android.gms.common.api.ApiException)

Example 15 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project react-native-camera by lwansbrough.

the class FaceDetectorAsyncTask method doInBackground.

@Override
protected Void doInBackground(Void... ignored) {
    if (isCancelled() || mDelegate == null || mFaceDetector == null) {
        return null;
    }
    InputImage image = InputImage.fromByteArray(mImageData, mWidth, mHeight, getFirebaseRotation(), InputImage.IMAGE_FORMAT_YV12);
    FaceDetector detector = mFaceDetector.getDetector();
    detector.process(image).addOnSuccessListener(new OnSuccessListener<List<Face>>() {

        @Override
        public void onSuccess(List<Face> faces) {
            WritableArray facesList = serializeEventData(faces);
            mDelegate.onFacesDetected(facesList);
            mDelegate.onFaceDetectingTaskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "Text recognition task failed" + e);
            mDelegate.onFaceDetectingTaskCompleted();
        }
    });
    return null;
}
Also used : RNFaceDetector(org.reactnative.facedetector.RNFaceDetector) FaceDetector(com.google.mlkit.vision.face.FaceDetector) WritableArray(com.facebook.react.bridge.WritableArray) List(java.util.List) Face(com.google.mlkit.vision.face.Face) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) InputImage(com.google.mlkit.vision.common.InputImage) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Aggregations

OnSuccessListener (com.google.android.gms.tasks.OnSuccessListener)44 OnFailureListener (com.google.android.gms.tasks.OnFailureListener)43 StorageReference (com.google.firebase.storage.StorageReference)13 UploadTask (com.google.firebase.storage.UploadTask)10 File (java.io.File)9 AuthResult (com.google.firebase.auth.AuthResult)8 Uri (android.net.Uri)7 ApiException (com.google.android.gms.common.api.ApiException)6 FileDownloadTask (com.google.firebase.storage.FileDownloadTask)6 IOException (java.io.IOException)6 ResolvableApiException (com.google.android.gms.common.api.ResolvableApiException)5 LocationSettingsResponse (com.google.android.gms.location.LocationSettingsResponse)4 InputImage (com.google.mlkit.vision.common.InputImage)4 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 WritableArray (com.facebook.react.bridge.WritableArray)3 TaskFailureLogger (com.firebase.ui.auth.ui.TaskFailureLogger)3 FirebaseUser (com.google.firebase.auth.FirebaseUser)3 OnProgressListener (com.google.firebase.storage.OnProgressListener)3 StorageMetadata (com.google.firebase.storage.StorageMetadata)3