本文整理汇总了Java中com.google.firebase.database.DataSnapshot类的典型用法代码示例。如果您正苦于以下问题:Java DataSnapshot类的具体用法?Java DataSnapshot怎么用?Java DataSnapshot使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataSnapshot类属于com.google.firebase.database包,在下文中一共展示了DataSnapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onDataChange
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
EditText username = (EditText)findViewById(R.id.usernameText);
name = username.getText().toString();
EditText password = (EditText)findViewById(R.id.passwordText);
pass = password.getText().toString();
Spinner grabAccountType = findViewById(R.id.accountTypeSpinner);
String accountType = (String) grabAccountType.getSelectedItem();
if (!(dataSnapshot.child(email).hasChild(name))) {
if (accountType.equals("Child")) {
newUser = new User(name, pass, MenuActivity.getManager().nextSerialNumber(), resID);
manager.setCurrentUserId(newUser.getUserId());
manager.addRegUser(newUser);
fbRef.child(email).child("ChoreManager").setValue(manager);
} else {
newAdminUser = new AdminUser(name, pass, MenuActivity.getManager().nextSerialNumber(), resID);
manager.setCurrentUserId(newAdminUser.getUserId());
manager.addAdminUser(newAdminUser);
fbRef.child(email).child("ChoreManager").setValue(manager);
}
}
finish();
}
示例2: get
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
/**
* Get a FollowRequest from Firebase.
* @param key
* @param resultListener
*/
@Override
public void get(String key, final OnResultListener<FollowRequest> resultListener) {
mFollowRequestRef.child(key).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
FollowRequest request = dataSnapshot.getValue(FollowRequest.class);
resultListener.onResult(request);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例3: getNowListening
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
public void getNowListening(String uid, final OnCompleteGetNowListening listener)
{
rdm.getUsersReference().child(uid).child("now").addValueEventListener(
new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
String state = dataSnapshot.getValue(String.class);
if (state == null) return;
Log.e(TAG, "getNowListening:complete, " + state);
listener.onComplete(state);
}
@Override
public void onCancelled(DatabaseError databaseError)
{
Log.e(TAG, "getNowListening:onCancelled", databaseError.toException());
}
});
}
示例4: setUser
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
private void setUser(){
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
User user = snapshot.getValue(User.class);
users.add(user);
}
name.setText(users.get(0).getResults().get(0).getName().getFirst());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例5: buildValueListener
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
private void buildValueListener() {
try {
Log.i(TAG, "Building value listener");
mValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
processJSONResult(dataSnapshot, null, false);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.i(TAG, "ValueEventListener:onCancelled" + databaseError.getMessage());
mDatabaseComponent.removeListener(listenerID);
mValueEventListener = null;
callbackContext.error(databaseError.getMessage());
}
};
} catch (Exception e) {
Log.e(TAG, "Error building query");
callbackContext.error(e.getMessage());
}
}
示例6: removeDetectiveProcess
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
public void removeDetectiveProcess(ViewAppHolder.UserProfileViewHolder userProfileViewHolder,
Context context){
FirebaseHelper.getUserAccountSettings(USER_LINK_FIREBASE)
.child(Constants.DETECTION_MODE).setValue(Constants.USER_DETECTION_INACTIVE);
userProfileViewHolder.DETECTION_ICON.setImageTintList(
context.getResources().getColorStateList(R.color.safe_color));
FirebaseHelper.getUserFriendList(USER_LINK_FIREBASE)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
FirebaseHelper.getUserDetection(Utility.encodeUserEmail(dataSnapshot1.getValue(String.class)))
.child(USER_LINK_FIREBASE).removeValue();
}
FirebaseHelper.getUserLocation(USER_LINK_FIREBASE)
.removeEventListener(userDetectionLocationListener);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例7: testSetDataMultipleTimesEnsureValueIsCalledAppropriately
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
@Test
public void testSetDataMultipleTimesEnsureValueIsCalledAppropriately()
throws TestFailure, TimeoutException, InterruptedException {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
ReadFuture readFuture = ReadFuture.untilEquals(ref, 2L, /*ignoreFirstNull=*/ true);
ZombieVerifier.verifyRepoZombies(ref);
for (int i = 0; i < 3; ++i) {
ref.setValueAsync(i);
}
List<EventRecord> events = readFuture.timedGet();
for (long i = 0; i < 3; ++i) {
DataSnapshot snap = events.get((int) i).getSnapshot();
assertEquals(i, snap.getValue());
}
ZombieVerifier.verifyRepoZombies(ref);
}
示例8: setDistanceRemainingToUI
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
private void setDistanceRemainingToUI(final DatabaseReference databaseReference, FirebaseUser firebaseUser) {
databaseReference.child("global")
.child("distanceRemaining")
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Update the android UI
setDistanceRemainingToUI(dataSnapshot.getValue(Long.class).intValue());
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e(TAG, "Database Error Occurred", databaseError.toException());
FirebaseCrash.report(databaseError.toException());
}
});
}
示例9: correctlySetUserReady
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
@Test
public void correctlySetUserReady() {
firebaseHelper.setUserStatus("testChallenge", "testUser1", FirebaseNodes.ChallengeStatus.READY, true);
firebaseHelper.getDatabase().child(FirebaseNodes.CHALLENGES).child("testChallenge")
.child("testUser1").child(FirebaseNodes.ChallengeStatus.READY.toString())
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Assert.assertTrue(dataSnapshot.exists());
Assert.assertTrue((boolean)dataSnapshot.getValue());
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例10: deleteHelpRequest
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
private void deleteHelpRequest(){
FirebaseHelper.getUserFriendList(USER_LINK_FIREBASE)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()){
FirebaseHelper.getUserHelpRequest(Utility.encodeUserEmail(dataSnapshot1.getValue(String.class)))
.child(USER_LINK_FIREBASE).removeValue();
Log.e("help ",dataSnapshot1.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例11: getAddedCount
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
/**
* Get how long the user has been a botanist
* @return Returns the total number of added plants
*/
private long getAddedCount() {
getUserReference().child("plantsAdded").addListenerForSingleValueEvent(new ValueEventListener() {
/**
* Handle a change in the database contents
* @param snapshot - current database contents
*/
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
mPlantsAdded = (long) snapshot.getValue();
}
}
/**
* Do nothing when the process is cancelled
* @param databaseError - Ignored error
*/
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return mPlantsAdded;
}
示例12: onDataChange
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//If there is an incomplete drive:
if (dataSnapshot.hasChild("start")) {
Log.d(TAG, "There's an incomplete drive in Firebase!");
//Get the starting time from the incomplete value:
startingTime.setTimeInMillis((long)dataSnapshot.child("start").getValue());
//If the user has completed the ongoing drive and just needs to go to the dialog
if (dataSnapshot.hasChild("end")) {
//Get the ending time:
endingTime.setTimeInMillis((long)dataSnapshot.child("end").getValue());
//Show the dialog using the driver ID:
showDialog(dataSnapshot.child("driver_id").getValue().toString());
} else { //Otherwise, if the drive is still ongoing:
//Enable the start button and update the timer label:
startButton.setEnabled(false);
stopButton.setEnabled(true);
timerUpdateLabel();
}
}
}
示例13: setNewNotificationsListener
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
public void setNewNotificationsListener (final TextView notificationTextView){
FirebaseHelper.getUserNewNotificationsNumber(USER_LINK_FIREBASE)
.addValueEventListener(newNotificationsListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Integer newNotificationsNumber = dataSnapshot.getValue(Integer.class);
if(newNotificationsNumber != null && newNotificationsNumber > 0) {
notificationTextView.setVisibility(View.VISIBLE);
notificationTextView.setText(String.valueOf(newNotificationsNumber));
}else{
notificationTextView.setVisibility(View.GONE);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例14: flagsSettingsToActive
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
/**
* Check flags state
*/
private void flagsSettingsToActive(){
FirebaseHelper.getUserAccountSettings(USER_LINK_FIREBASE)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
final boolean PUBLIC_FLAG_MARKERS_ACTIVE_STATE =
dataSnapshot.getValue(AccountSettings.class).getShowPublicFlags();
final boolean FRIENDS_FLAG_MARKERS_ACTIVE_STATE =
dataSnapshot.getValue(AccountSettings.class).getShowFriendsFlags();
if(PUBLIC_FLAG_MARKERS_ACTIVE_STATE){
setupFlagsPublicMarkers();
}
if(FRIENDS_FLAG_MARKERS_ACTIVE_STATE){
setupFlagsFriendsMarkers();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
示例15: testAttachingListener
import com.google.firebase.database.DataSnapshot; //导入依赖的package包/类
@Test
public void testAttachingListener() {
DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
ValueEventListener listener = ref.limitToLast(1)
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
// No-op
}
@Override
public void onCancelled(DatabaseError error) {
}
});
assertNotNull(listener);
}