Search in sources :

Example 1 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project RSAndroidApp by RailwayStations.

the class AuthActivity method fetchConfig.

// Fetch the config to determine the allowed length of messages.
public void fetchConfig() {
    // 1 hour in seconds
    long cacheExpiration = 3600;
    // server. This should not be used in release builds.
    if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()) {
        cacheExpiration = 0;
    }
    mFirebaseRemoteConfig.fetch(cacheExpiration).addOnSuccessListener(new OnSuccessListener<Void>() {

        @Override
        public void onSuccess(Void aVoid) {
            // Make the fetched config available via FirebaseRemoteConfig get<type> calls.
            mFirebaseRemoteConfig.activateFetched();
            applyRetrievedLengthLimit();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            // There has been an error fetching the config
            Log.w(TAG, "Error fetching config: " + e.getMessage());
            applyRetrievedLengthLimit();
        }
    });
}
Also used : OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 2 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project FirebaseUI-Android by firebase.

the class ChatActivity method signInAnonymously.

private void signInAnonymously() {
    Toast.makeText(this, "Signing in...", Toast.LENGTH_SHORT).show();
    mAuth.signInAnonymously().addOnSuccessListener(this, new OnSuccessListener<AuthResult>() {

        @Override
        public void onSuccess(AuthResult result) {
            attachRecyclerViewAdapter();
        }
    }).addOnCompleteListener(new SignInResultNotifier(this));
}
Also used : SignInResultNotifier(com.firebase.uidemo.util.SignInResultNotifier) AuthResult(com.google.firebase.auth.AuthResult) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener)

Example 3 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project quickstart-android by firebase.

the class MyDownloadService method downloadFromPath.

private void downloadFromPath(final String downloadPath) {
    Log.d(TAG, "downloadFromPath:" + downloadPath);
    // Mark task started
    taskStarted();
    showProgressNotification(getString(R.string.progress_downloading), 0, 0);
    // Download and get total bytes
    mStorageRef.child(downloadPath).getStream(new StreamDownloadTask.StreamProcessor() {

        @Override
        public void doInBackground(StreamDownloadTask.TaskSnapshot taskSnapshot, InputStream inputStream) throws IOException {
            long totalBytes = taskSnapshot.getTotalByteCount();
            long bytesDownloaded = 0;
            byte[] buffer = new byte[1024];
            int size;
            while ((size = inputStream.read(buffer)) != -1) {
                bytesDownloaded += size;
                showProgressNotification(getString(R.string.progress_downloading), bytesDownloaded, totalBytes);
            }
            // Close the stream at the end of the Task
            inputStream.close();
        }
    }).addOnSuccessListener(new OnSuccessListener<StreamDownloadTask.TaskSnapshot>() {

        @Override
        public void onSuccess(StreamDownloadTask.TaskSnapshot taskSnapshot) {
            Log.d(TAG, "download:SUCCESS");
            // Send success broadcast with number of bytes downloaded
            broadcastDownloadFinished(downloadPath, taskSnapshot.getTotalByteCount());
            showDownloadFinishedNotification(downloadPath, (int) taskSnapshot.getTotalByteCount());
            // Mark task completed
            taskCompleted();
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception exception) {
            Log.w(TAG, "download:FAILURE", exception);
            // Send failure broadcast
            broadcastDownloadFinished(downloadPath, -1);
            showDownloadFinishedNotification(downloadPath, -1);
            // Mark task completed
            taskCompleted();
        }
    });
}
Also used : InputStream(java.io.InputStream) StreamDownloadTask(com.google.firebase.storage.StreamDownloadTask) IOException(java.io.IOException) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) OnFailureListener(com.google.android.gms.tasks.OnFailureListener) IOException(java.io.IOException)

Example 4 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project Tapad by berict.

the class PresetStoreAdapter method onFirebasePresetUpdated.

private void onFirebasePresetUpdated(final String presetName, final Runnable onUpdated) {
    StorageReference metadataReference = FirebaseStorage.getInstance().getReferenceFromUrl("gs://tapad-4d342.appspot.com/presets/" + presetName).child("preset.zip");
    metadataReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

        @Override
        public void onSuccess(StorageMetadata storageMetadata) {
            Log.d(TAG, "Successful getting metadata");
            if (storageMetadata.getUpdatedTimeMillis() > new File(PROJECT_LOCATION_PRESETS + "/" + presetName + "/about/json.txt").lastModified()) {
                // firebase preset is updated since last download
                // get the new updated preset
                Log.d(TAG, "Preset updated");
                onUpdated.run();
            } else {
                Log.d(TAG, "Preset not updated");
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failed to get preset metadata");
        }
    });
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) StorageReference(com.google.firebase.storage.StorageReference) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) File(java.io.File) OnFailureListener(com.google.android.gms.tasks.OnFailureListener)

Example 5 with OnSuccessListener

use of com.google.android.gms.tasks.OnSuccessListener in project Tapad by berict.

the class FirebaseHelper method getStorageMetadata.

public StorageMetadata getStorageMetadata(StorageReference storageReference, Activity activity) {
    FirebaseApp.initializeApp(activity);
    final StorageMetadata[] mStorageMetadata = { null };
    storageReference.getMetadata().addOnSuccessListener(new OnSuccessListener<StorageMetadata>() {

        @Override
        public void onSuccess(StorageMetadata storageMetadata) {
            Log.d(TAG, "Successful getting metadata");
            mStorageMetadata[0] = storageMetadata;
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(@NonNull Exception e) {
            Log.d(TAG, "Failed to get metadata");
        }
    });
    return mStorageMetadata[0];
}
Also used : StorageMetadata(com.google.firebase.storage.StorageMetadata) OnSuccessListener(com.google.android.gms.tasks.OnSuccessListener) 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