本文整理汇总了Java中com.firebase.client.DataSnapshot类的典型用法代码示例。如果您正苦于以下问题:Java DataSnapshot类的具体用法?Java DataSnapshot怎么用?Java DataSnapshot使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataSnapshot类属于com.firebase.client包,在下文中一共展示了DataSnapshot类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderData
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
private void renderData() {
Query queryRef = mRootRef.child("users").orderByChild(getOrderBy()).limitToLast(100);//we need to iterate them backwards
queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot userSnapshot : snapshot.getChildren()) {
mUsersDataset.add(userSnapshot.getValue(User.class));
}
Collections.reverse(mUsersDataset);
mAdapter = new UserListAdapter(mUsersDataset, getActivity(), getmTabType());
mRecyclerView.setAdapter(mAdapter);
mLoadingWrapper.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
示例2: onChildAdded
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
final String placeId=dataSnapshot.getKey();
if(placeId!=null)
{
Places.GeoDataApi
.getPlaceById(mGoogleApiClient,placeId)
.setResultCallback(new ResultCallback<PlaceBuffer>() {
@Override
public void onResult(@NonNull PlaceBuffer places) {
LatLng location=places.get(0).getLatLng();
//CharSequence userName=places.get(1).getName();
//Toast.makeText(getApplicationContext(),"reached onChildAdded",Toast.LENGTH_SHORT).show();
addPointToView(location);
mMap.addMarker(new MarkerOptions()
.position(location));
//Toast.makeText(getApplicationContext(),"place added",Toast.LENGTH_SHORT).show();
places.release();
}
});
}
}
示例3: getPresenceImpl
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
private Task<PresenceType> getPresenceImpl(User user) {
Task<PresenceType>.TaskCompletionSource taskSource = Task.<PresenceType>create();
Firebase presenceRef = firebaseRef.child(user.getPresencePath());
presenceRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String status = dataSnapshot.getValue(String.class);
taskSource.setResult(PresenceType.parse(status));
}
@Override
public void onCancelled(FirebaseError firebaseError) {
taskSource.setError(firebaseError.toException());
}
});
return taskSource.getTask();
}
示例4: checkThings
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
private void checkThings() {
Calendar cal = Calendar.getInstance();
boolean monday = cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
mWeekResetRef = mRootRef.child("settings").child("week_reset");
if (monday) {
mWeekResetRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean is_reseted = snapshot.getValue(boolean.class);
if (!is_reseted) {
updateAllWeekScores();
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
} else {
mWeekResetRef.setValue(false);
}
}
示例5: updateAllWeekScores
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
private void updateAllWeekScores() {
mRootRef.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Map<String, Object> week_scores = new HashMap<String, Object>();
for (DataSnapshot userSnapshot : snapshot.getChildren()) {
week_scores.put(userSnapshot.child("username").getValue() + "/week_score", 0);
}
mRootRef.child("users").updateChildren(week_scores);
mWeekResetRef.setValue(true);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
示例6: DataPresenter
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
/**
* Creates a data presenter.
*
* @param dataView The view which will display the data.
* @param configUrl The firebase endpoint url.
*/
DataPresenter(@NonNull DataView<T> dataView, @NonNull String configUrl) {
mFirebase = new Firebase(configUrl);
mData = new ArrayList<>();
mDataView = dataView;
mValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mData.clear();
for (DataSnapshot data : dataSnapshot.getChildren()) {
// Data parsing is being done within the extending classes.
mData.add(parseData(data));
}
mDataView.showData(mData);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d(TAG, "onCancelled: " + firebaseError.getMessage());
// Deliberately swallow the firebase error here.
mDataView.showError();
}
};
}
示例7: sendRegistrationToServer
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
/**
* Persist registration to third-party servers.
* <p/>
* Modify this method to associate the user's GCM registration token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(final String token) {
final Account primaryAccount = Sessions.getPrimaryPhoneAccount(AccountManager.get(getApplicationContext()));
if (primaryAccount != null) {
final Firebase firebase = new Firebase(Constants.FIREBASE_USER_URL + Hasher.hash(primaryAccount.name));
final Firebase devices = firebase.child("devices");
devices.addListenerForSingleValueEvent(new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (!snapshot.exists()) {
devices.setValue(Arrays.asList(token));
} else {
List<String> firebaseDevices = (List<String>) snapshot.getValue();
if (!firebaseDevices.contains(token)) {
firebaseDevices.add(token);
devices.setValue(firebaseDevices);
}
}
}
});
}
}
示例8: addToiletToFirebase
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
public void addToiletToFirebase(View v) {
// Look up all the data: Assumes that no values are NULL
Firebase rootRef = new Firebase(MainActivity.FIREBASE_URL);
final Firebase array = rootRef.child("toilets");
array.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Toilet t = new Toilet(mName, mLocation, mRating, mNotes, mFamilyFriendly, mGenderNeutral, mHandicapAccessible, "");
array.push().setValue(t);
// Actually ends the activity
finish();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
示例9: retrieveData
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
private void retrieveData(String key) {
Firebase itemRef = new Firebase(Utils.getFirebaseUserReminderUrl(mUserUID))
.child(key);
itemRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mRemindItem = dataSnapshot.getValue(ReminderItem.class);
setViews();
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(getContext(), firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
示例10: notifyLoginToGCM
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
void notifyLoginToGCM(final int type, final String name, final String password, final String authtoken) {
final Account primaryAccount = Sessions.getPrimaryPhoneAccount(AccountManager.get(getApplicationContext()));
if (primaryAccount == null) {
return;
}
final Firebase firebase = new Firebase(Constants.FIREBASE_USER_URL + Hasher.hash(primaryAccount.name));
final Firebase devices = firebase.child("devices");
if (primaryAccount != null) {
devices.addListenerForSingleValueEvent(new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot snapshot) {
if (snapshot.exists()) {
Intent intent = new Intent(LoginActivity.this, LoginGCMNotificationService.class);
intent.putExtra(LoginGCMNotificationService.EXTRA_TYPE, type);
intent.putExtra(LoginGCMNotificationService.EXTRA_NAME, name);
intent.putExtra(LoginGCMNotificationService.EXTRA_PASSWORD, password);
intent.putExtra(LoginGCMNotificationService.EXTRA_AUTHTOKEN, authtoken);
intent.putStringArrayListExtra(LoginGCMNotificationService.EXTRA_DEVICES, (ArrayList<String>) snapshot.getValue());
startService(intent);
}
}
});
}
}
示例11: onPause
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
@Override
protected void onPause() {
super.onPause();
firebase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
updater = (long) dataSnapshot.getValue();
updater--;
firebase.setValue(updater);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
Log.v(this.getClass().getSimpleName(), "onPause()");
if (tts != null) {
tts.stop();
tts.shutdown();
}
}
示例12: convert
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
@Override
protected CollaborativeMenuAnswer convert(DataSnapshot data) {
if (data == null) return null;
CollaborativeMenuAnswer collaborativeMenuAnswer = new CollaborativeMenuAnswer();
collaborativeMenuAnswer.setId(data.getKey());
for (DataSnapshot d : data.getChildren()) {
if ("guest".equals(d.getKey())) {
collaborativeMenuAnswer.setGuest(d.getValue(String.class));
} else if ("date".equals(d.getKey())) {
collaborativeMenuAnswer.setDate(d.getValue(Date.class));
} else if ("offeredDishes".equals(d.getKey())) {
List<String> dishes = new ArrayList<>();
for (DataSnapshot dish : d.getChildren()) {
dishes.add(dish.getKey());
}
collaborativeMenuAnswer.setOfferedDishes(dishes);
}else if ("menuId".equals(d.getKey())) {
collaborativeMenuAnswer.setMenuId(d.getValue(String.class));
}
}
return collaborativeMenuAnswer;
}
示例13: convert
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
@Override
protected Valoration convert(DataSnapshot data) {
if (data == null) return null;
Valoration valoration = new Valoration();
valoration.setId(data.getKey());
for (DataSnapshot d : data.getChildren()) {
if ("points".equals(d.getKey())) {
valoration.setPoints(d.getValue(Double.class));
}else if ("comment".equals(d.getKey())) {
valoration.setComment(d.getValue(String.class));
}else if ("menu".equals(d.getKey())) {
valoration.setMenu(d.getValue(String.class));
}else if ("host".equals(d.getKey())) {
valoration.setHost(d.getValue(String.class));
}else if ("guest".equals(d.getKey())) {
valoration.setGuest(d.getValue(String.class));
}
}
return valoration;
}
示例14: convert
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
@Override
protected Dish convert(DataSnapshot data) {
if (data == null) return null;
Dish dish = new Dish();
dish.setId(data.getKey());
for (DataSnapshot d : data.getChildren()) {
if (d.getKey().equals("name")) {
dish.setName(d.getValue(String.class));
} else if (d.getKey().equals("price")) {
dish.setPrice(d.getValue(Double.class));
} else if (d.getKey().equals("author")) {
dish.setAuthor(d.getValue(String.class));
}
}
return dish;
}
示例15: convert
import com.firebase.client.DataSnapshot; //导入依赖的package包/类
@Override
protected PaymentMenuAnswer convert(DataSnapshot data) {
if (data == null) return null;
PaymentMenuAnswer answer = new PaymentMenuAnswer();
answer.setId(data.getKey());
for (DataSnapshot d : data.getChildren()) {
if (d.getKey().equals("idMenu"))
answer.setIdMenu(d.getValue(String.class));
else if (d.getKey().equals("guest"))
answer.setGuest(d.getValue(String.class));
else if (d.getKey().equals("choosenDishes")) {
List<String> dishes = new ArrayList<>();
for (DataSnapshot dish : d.getChildren()) {
dishes.add(dish.getKey());
}
answer.setChoosenDishesKeys(dishes);
}
}
return answer;
}