@Override public void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); if(requestCode == RC_SIGN_IN){ if (resultCode == RESULT_OK){ Toast.makeText(this, "Sign in successful", Toast.LENGTH_SHORT).show(); } else if (requestCode == RESULT_CANCELED){ Toast.makeText(this, "Sign in cancelled", Toast.LENGTH_SHORT).show(); finish(); } } else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){ Uri selectedImageUri = data.getData(); StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment()); photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Uri downloadUrl = taskSnapshot.getDownloadUrl(); FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString()); mMessagesDatabaseReference.push().setValue(friendlyMessage); } }); } }
private void taskChaining() { // [START task_chaining] Task<AuthResult> signInTask = FirebaseAuth.getInstance().signInAnonymously(); signInTask.continueWithTask(new Continuation<AuthResult, Task<String>>() { @Override public Task<String> then(@NonNull Task<AuthResult> task) throws Exception { // Take the result from the first task and start the second one AuthResult result = task.getResult(); return doSomething(result); } }).addOnSuccessListener(new OnSuccessListener<String>() { @Override public void onSuccess(String s) { // Chain of tasks completed successfully, got result from last task. // ... } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { // One of the tasks in the chain failed with an exception. // ... } }); // [END task_chaining] }
public void fetchConfig() { long cacheExpiration = 3600; // 1 hour in seconds // If developer mode is enabled reduce cacheExpiration to 0 so that each fetch goes to the // 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); applyRetrievedLengthLimit(); } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK) { Uri uri = data.getData(); StorageReference filepath = mStorage.child("Photos").child(uri.getLastPathSegment()); filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { downloadURL = taskSnapshot.getDownloadUrl().toString(); Picasso.with(getApplicationContext()).load(downloadURL).into(imageItem); Toast.makeText(AddItemActivity.this, "Upload Done", Toast.LENGTH_LONG).show(); } }); } }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){ showProgressDialog(); Uri uri = data.getData(); StorageReference filePath = mStorage.child("fotos").child(uri.getLastPathSegment()); filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { hideProgressDialog(); Uri downloadUri = taskSnapshot.getDownloadUrl(); imageUrl = downloadUri; Picasso.with(NewPostActivity.this).load(downloadUri).fit().centerCrop().into(mCriminalPicture); Toast.makeText(NewPostActivity.this, R.string.upload__success, Toast.LENGTH_SHORT).show(); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { hideProgressDialog(); Toast.makeText(NewPostActivity.this, R.string.upload_failure, Toast.LENGTH_SHORT).show(); } }); } }
public void achievement_show_list() { connect(); if (isConnected()) { mAchievementsClient.getAchievementsIntent() .addOnSuccessListener(new OnSuccessListener<Intent>() { @Override public void onSuccess(Intent intent) { activity.startActivityForResult(intent, REQUEST_ACHIEVEMENTS); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d(TAG, "Showing::Loaderboard::Failed:: " + e.toString()); } }); } else { Log.i(TAG, "PlayGameServices: Google calling connect"); } }
public void leaderboard_show(final String l_id) { connect(); if (isConnected()) { mLeaderboardsClient.getLeaderboardIntent(l_id) .addOnSuccessListener(new OnSuccessListener<Intent>() { @Override public void onSuccess (Intent intent) { Log.d(TAG, "Showing::Loaderboard::" + l_id); activity.startActivityForResult(intent, REQUEST_LEADERBOARD); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d(TAG, "Showing::Loaderboard::Failed:: " + e.toString()); } }); } else { Log.i(TAG, "PlayGameServices: Google not connected calling connect"); } }
public void leaderboard_show_list() { connect(); if (isConnected()) { mLeaderboardsClient.getAllLeaderboardsIntent() .addOnSuccessListener(new OnSuccessListener<Intent>() { @Override public void onSuccess (Intent intent) { Log.d(TAG, "Showing::Loaderboard::List"); activity.startActivityForResult(intent, REQUEST_LEADERBOARD); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d(TAG, "Showing::Loaderboard::Failed:: " + e.toString()); } }); } else { Log.i(TAG, "PlayGameServices: Google not connected calling connect"); } }
@SuppressLint("MissingPermission") public static void requestLastKnownLocation() { final AndroidLocationProvider instance = getInstance(); if (!instance.hasLocationPermission()) { return; } Log.d(TAG, "Requesting last known location"); instance.fusedLocationClient.getLastLocation() .addOnSuccessListener(getInstance().activity, new OnSuccessListener<android.location.Location>() { @Override public void onSuccess(android.location.Location androidLocation) { if (androidLocation != null) { instance.onLocationUpdateReceived(androidLocation); } else { Log.w(TAG, "Unable to get last known location"); } } }); }
public void updateComment(String commentId, String commentText, String postId, final OnTaskCompleteListener onTaskCompleteListener) { DatabaseReference mCommentReference = database.getReference().child("post-comments").child(postId).child(commentId).child("text"); mCommentReference.setValue(commentText).addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { if (onTaskCompleteListener != null) { onTaskCompleteListener.onTaskComplete(true); } } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { if (onTaskCompleteListener != null) { onTaskCompleteListener.onTaskComplete(false); } LogUtil.logError(TAG, "updateComment", e); } }); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == RC_SIGN_IN) { if (resultCode == RESULT_OK) { Toast.makeText(this, "Signed in , Oh yeah", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Signed In canceled", Toast.LENGTH_SHORT).show(); finish(); } }else if (requestCode==RC_PHOTO_PICKER && resultCode == RESULT_OK){ Uri selectedImageUri = data.getData(); StorageReference photoRef = photoStorageReference.child(selectedImageUri.getLastPathSegment()); photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Uri downloadURI = taskSnapshot.getDownloadUrl(); Message friendlyMessage = new Message(null,mUsername,downloadURI.toString()); messageDatabaseReference.push().setValue(friendlyMessage); } }); } }
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d(TAG, "firebaseAuthWithGooogle:" + acct.getId()); AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); showProgressDialog(getString(R.string.profile_progress_message)); mAuth.signInWithCredential(credential) .addOnSuccessListener(this, new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult result) { handleFirebaseAuthResult(result); } }) .addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { FirebaseCrash.logcat(Log.ERROR, TAG, "auth:onFailure:" + e.getMessage()); handleFirebaseAuthResult(null); } }); }
@Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.explore_button: mAuth.signInAnonymously().addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult authResult) { Intent feedsIntent = new Intent(WelcomeActivity.this, FeedsActivity.class); startActivity(feedsIntent); } }).addOnFailureListener( new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Toast.makeText(WelcomeActivity.this, "Unable to sign in anonymously.", Toast.LENGTH_SHORT).show(); Log.e(TAG, e.getMessage()); } }); break; case R.id.sign_in_button: Intent signInIntent = new Intent(this, ProfileActivity.class); startActivity(signInIntent); break; } }
public void fetchConfig(){ long catchExpiration = 3600; if (mFirebaseRemoteConfig.getInfo().getConfigSettings().isDeveloperModeEnabled()){ catchExpiration = 0; } mFirebaseRemoteConfig.fetch(catchExpiration) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { mFirebaseRemoteConfig.activateFetched(); applyRetrievedLengthLimit(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error fetching config", e); applyRetrievedLengthLimit(); } }); }
/** * Add onFailure and onSuccess listeners to uploadTask. * * @param uploadTask Upload task which we want to deal with. * @param callback Callback which will be call from {@link UploadTask#addOnFailureListener(OnFailureListener)} and {@link UploadTask#addOnSuccessListener(OnSuccessListener)} */ private void processUpload(UploadTask uploadTask, final UploadCallback callback) { uploadTask.addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { callback.onFail(e); } }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { FileMetadata fileMetadata = buildMetadata(taskSnapshot); callback.onSuccess(fileMetadata); } }); }
private void addAdaLovelace() { // [START add_ada_lovelace] // Create a new user with a first and last name Map<String, Object> user = new HashMap<>(); user.put("first", "Ada"); user.put("last", "Lovelace"); user.put("born", 1815); // Add a new document with a generated ID db.collection("users") .add(user) .addOnSuccessListener(new OnSuccessListener<DocumentReference>() { @Override public void onSuccess(DocumentReference documentReference) { Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error adding document", e); } }); // [END add_ada_lovelace] }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); if(requestCode == RC_SIGN_IN){ if (resultCode == RESULT_OK){ Toast.makeText(getActivity(), "Sign in successful", Toast.LENGTH_SHORT).show(); } else if (requestCode == RESULT_CANCELED){ Toast.makeText(getActivity(), "Sign in cancelled", Toast.LENGTH_SHORT).show(); getActivity().finish(); } } else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){ Uri selectedImageUri = data.getData(); StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment()); photoRef.putFile(selectedImageUri).addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Uri downloadUrl = taskSnapshot.getDownloadUrl(); FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString()); mMessagesDatabaseReference.push().setValue(friendlyMessage); } }); } }
protected void acceptInviteToRoom(String invitationId) { Log.d("ROOM", "Accepting invitation: " + invitationId); creator = false; mRoomConfig = RoomConfig.builder(mRoomUpdateCallbackImpl) .setInvitationIdToAccept(invitationId) .setOnMessageReceivedListener(SpaceRace.messageManager) .setRoomStatusUpdateCallback(mRoomStatusUpdateCallback) .build(); SpaceRace.messageManager.setmRoomConfig(mRoomConfig); mRealTimeMultiplayerClient.join(mRoomConfig) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Log.d("ROOM", "Room Joined Successfully!"); } }); }
void showWaitingRoom(Room room) { // minimum number of players required for our game // For simplicity, we require everyone to join the game before we start it // (this is signaled by Integer.MAX_VALUE). final int MIN_PLAYERS = Integer.MAX_VALUE; mRealTimeMultiplayerClient.getWaitingRoomIntent(room, MIN_PLAYERS) .addOnSuccessListener(new OnSuccessListener<Intent>() { @Override public void onSuccess(Intent intent) { // show waiting room UI startActivityForResult(intent, RC_WAITING_ROOM); } }) .addOnFailureListener(createFailureListener("There was a problem getting the waiting room!")); }
@OnClick(R.id.new_match) public void onClickNewMatch(View view) { if (!invitationPopupIsShowing) { showPopUpNotification(false, ""); mRealTimeMultiplayerClient .getSelectOpponentsIntent(MIN_NUMBER_OF_PLAYERS, MAX_NUMBER_OF_PLAYERS) .addOnSuccessListener( new OnSuccessListener<Intent>() { @Override public void onSuccess(Intent intent) { startActivityForResult(intent, RC_SELECT_PLAYERS); } } ).addOnFailureListener(createFailureListener("There was a problem selecting opponents.")); } }
/** * {@inheritDoc} */ @Override public void download(String path, long bytesLimit, @NonNull final DownloadCallback<byte[]> callback) { StorageReference pathRef = firebaseStorage().getReference().child(path); pathRef.getBytes(bytesLimit).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { callback.onFail(e); } }).addOnSuccessListener(new OnSuccessListener<byte[]>() { @Override public void onSuccess(byte[] bytes) { callback.onSuccess(bytes); } }); }
@Override public void loadData(Priority priority, final DataCallback<? super InputStream> callback) { mStreamTask = mRef.getStream(); mStreamTask .addOnSuccessListener(new OnSuccessListener<StreamDownloadTask.TaskSnapshot>() { @Override public void onSuccess(StreamDownloadTask.TaskSnapshot snapshot) { mInputStream = snapshot.getStream(); callback.onDataReady(mInputStream); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { callback.onLoadFailed(e); } }); }
/** * Handles click of location button on map. Sets current location. * @return */ @Override public boolean onMyLocationButtonClick() { if (Build.VERSION.SDK_INT >= 23) { if (checkLocationPermission()){ mFusedLocationClient.getLastLocation() .addOnSuccessListener(this, new OnSuccessListener<Location>() { @Override public void onSuccess(Location location) { // Got last known location. In some rare situations this can be null. if (location != null) { currentLoc = location; } } }); }else{ requestPermission(); } } return false; }
void fetch() { FirebaseRemoteConfig config = FirebaseRemoteConfig.getInstance(); config.activateFetched(); config.fetch(urgentUpdateFlag ? 0 : cacheExpiration) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.d("KiseFetcher", "onFailure: " + e.getMessage()); } }) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Log.d("KiseFetcher", "onSuccess"); } }) .addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { Log.d("KiseFetcher", "onComplete"); } }); disableUrgentUpdateFlag(); }
@Override public void signUp(final String email, final String password) { FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password) .addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult authResult) { postEvent(LoginEvent.onSignUpSuccess); signIn(email, password); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { postEvent(LoginEvent.onSignUpError, e.getMessage()); } }); }
@Override public void signUp(final String email, final String password) { FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, password) .addOnSuccessListener(new OnSuccessListener<AuthResult>() { @Override public void onSuccess(AuthResult authResult) { post(LoginEvent.onSignUpSuccess); signIn(email, password); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { post(LoginEvent.onSignUpError, e.getMessage()); } }); }
private void updateDocument() { // [START update_document] DocumentReference washingtonRef = db.collection("cities").document("DC"); // Set the "isCapital" field of the city 'DC' washingtonRef .update("capital", true) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Log.d(TAG, "DocumentSnapshot successfully updated!"); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error updating document", e); } }); // [END update_document] }
public LocationRepository(Activity activity, GoogleApiClient mGoogleApiClient) { mFusedLocationClient = LocationServices.getFusedLocationProviderClient(activity); this.mGoogleApiClient = mGoogleApiClient; mFusedLocationClient.getLastLocation() .addOnSuccessListener(activity, new OnSuccessListener<Location>() { @Override public void onSuccess(Location location) { if (location != null) { userLocation = location; publishSubject.onNext(userLocation); //addOverlay(new LatLng(userLocation.getLatitude(), userLocation.getLongitude())); //mMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } else { userLocation = null; } } }); }
private void sendSignRequestToClient(SignRequestParams signRequestParams) { U2fApiClient u2fApiClient = Fido.getU2fApiClient(this.getApplicationContext()); Task<U2fPendingIntent> result = u2fApiClient.getSignIntent(signRequestParams); result.addOnSuccessListener(new OnSuccessListener<U2fPendingIntent>() { @Override public void onSuccess(U2fPendingIntent u2fPendingIntent) { if (u2fPendingIntent.hasPendingIntent()) { try { u2fPendingIntent .launchPendingIntent(U2FDemoActivity.this, REQUEST_CODE_SIGN); } catch (IntentSender.SendIntentException e) { e.printStackTrace(); } } } }); }
private void addAlanTuring() { // [START add_alan_turing] // Create a new user with a first, middle, and last name Map<String, Object> user = new HashMap<>(); user.put("first", "Alan"); user.put("middle", "Mathison"); user.put("last", "Turring"); user.put("born", 1912); // Add a new document with a generated ID db.collection("users") .add(user) .addOnSuccessListener(new OnSuccessListener<DocumentReference>() { @Override public void onSuccess(DocumentReference documentReference) { Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error adding document", e); } }); // [END add_alan_turing] }
/** * {@inheritDoc} */ @Override public void delete(String path, @NonNull final DeleteCallback callback) { StorageReference pathRef = firebaseStorage().getReference().child(path); pathRef.delete().addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { callback.onFail(e); } }).addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { callback.onSuccess(); } }); }
@Override public void onRating(Rating rating) { // In a transaction, add the new rating and update the aggregate totals addRating(mRestaurantRef, rating) .addOnSuccessListener(this, new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Log.d(TAG, "Rating added"); // Hide keyboard and scroll to top hideKeyboard(); mRatingsRecycler.smoothScrollToPosition(0); } }) .addOnFailureListener(this, new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Add rating failed", e); // Show failure message and hide keyboard hideKeyboard(); Snackbar.make(findViewById(android.R.id.content), "Failed to add rating", Snackbar.LENGTH_SHORT).show(); } }); }
/** * This method store the user profile image to firebase storage. * if it stored in storage, the image is load to database of firebase which * make change in userdata and sets it's image to imageview. * @param imageUri */ public void storeUserImageInDatabase(final Uri imageUri){ FirebaseHelper.getUserImageStorageReference(USER_LINK_FIREBASE) .putFile(imageUri) .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { Map<String,Object> userImage = new HashMap<String, Object>(); userImage.put("userImage",taskSnapshot.getDownloadUrl().toString()); FirebaseHelper.USERS_DATABASE_REFERENCE.child(USER_LINK_FIREBASE).updateChildren(userImage); } }); }
@Override protected String doInBackground(final String... params) { Log.d("AsyncTest", params[0]); final long ONE_MEGABYTE = 1024 * 1024; storageReference.child("post").child(params[0]).child("photo.jpg") .getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() { @Override public void onSuccess(byte[] bytes) { // Data for "images/island.jpg" is returns, use this as needed bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); Bitmap resize = Bitmap.createScaledBitmap(bitmap, 300, 300, true); postImageView.get(params[0]).setImageBitmap(resize); } }); return ""; }
@Override protected String doInBackground(final String... params) { Log.d("AsyncTest", params[0]); final long ONE_MEGABYTE = 1024 * 1024; storageReference.child("post").child(params[0]).child("photo.jpg") .getBytes(ONE_MEGABYTE).addOnSuccessListener(new OnSuccessListener<byte[]>() { @Override public void onSuccess(byte[] bytes) { // Data for "images/island.jpg" is returns, use this as needed bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); Bitmap resize = Bitmap.createScaledBitmap(bitmap, 300, 300, true); ByteArrayOutputStream baos = new ByteArrayOutputStream(); postImageView.get(params[0]).setImageBitmap(resize); } }); return ""; }
public void changeGenderButton(int index) { Map<String, Object> userMap = new HashMap<>(); switch (index) { case R.id.womanButton: userMap.put("gender", 0); break; case R.id.manButton: userMap.put("gender", 1); break; } userColRef.document(user.getUid()) .update(userMap) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Toast.makeText(UserProfileActivity.this, "변경되었습니다", Toast.LENGTH_SHORT).show(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error updating document", e); } }); }
private void imageUpload() { Log.i(TAG, "imageupload"); StorageReference mountainsRef = storageRef.child("user").child(mAuth.getUid()).child("profile.jpg"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); byte[] data = baos.toByteArray(); UploadTask uploadTask = mountainsRef.putBytes(data); uploadTask.addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception exception) { // Handle unsuccessful uploads } }).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { @Override public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL. Uri downloadUrl = taskSnapshot.getDownloadUrl(); Log.d(TAG, String.valueOf(downloadUrl)); } }); }
private void uploadBirth() { Map<String, Object> birthMap = new HashMap<>(); birthMap.put("birth", mYear + "년 " + (mMonth + 1) + "월 " + mDay + "일"); userColRef.document(user.getUid()) .update(birthMap) .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Toast.makeText(UserProfileActivity.this, "변경되었습니다", Toast.LENGTH_SHORT).show(); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error updating document", e); } }); }
public void removeComment(String commentId, final String postId, final OnTaskCompleteListener onTaskCompleteListener) { final DatabaseHelper databaseHelper = ApplicationHelper.getDatabaseHelper(); databaseHelper.removeComment(commentId, postId).addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { decrementCommentsCount(postId, onTaskCompleteListener); } }).addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { onTaskCompleteListener.onTaskComplete(false); LogUtil.logError(TAG, "removeComment()", e); } }); }