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();
}
}
});
}
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);
}
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
}
});
}
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;
}
}
});
}
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;
}
Aggregations