本文整理匯總了Java中com.firebase.client.DataSnapshot.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java DataSnapshot.getValue方法的具體用法?Java DataSnapshot.getValue怎麽用?Java DataSnapshot.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.firebase.client.DataSnapshot
的用法示例。
在下文中一共展示了DataSnapshot.getValue方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
/**
* Custom de-serializer that uses a similar approach to {@link DataSnapshot#getValue(Class)}, but uses {@link Gson}
* instead.
*
* @param <T>
* Type of object to return
* @param snapshot
* The {@link DataSnapshot} provided by a Firebase event callback
* @param clazz
* Class of object to deserialize
*
* @return
*/
@Nullable
@SuppressWarnings("Unchecked")
public <T> T deserialize(DataSnapshot snapshot, Class<T> clazz) {
T deserialized = null;
Map<String, String> value = (Map<String, String>) snapshot.getValue();
if (value != null) {
try {
// JSON stringify the snapshot value using Firebase's mapper
String jsonStr = JsonHelpers.getMapper().writeValueAsString(value);
deserialized = gson.fromJson(jsonStr, clazz);
} catch (JsonProcessingException e) {
// Swallow error
}
}
return deserialized;
}
示例2: onChildAdded
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
String key = dataSnapshot.getKey();
if (!mKeys.contains(key)) {
T item = dataSnapshot.getValue(FirebaseRecyclerAdapter.this.mItemClass);
int insertedPosition;
if (previousChildName == null) {
mItems.add(0, item);
mKeys.add(0, key);
insertedPosition = 0;
} else {
int previousIndex = mKeys.indexOf(previousChildName);
int nextIndex = previousIndex + 1;
if (nextIndex == mItems.size()) {
mItems.add(item);
mKeys.add(key);
} else {
mItems.add(nextIndex, item);
mKeys.add(nextIndex, key);
}
insertedPosition = nextIndex;
}
notifyItemInserted(insertedPosition);
itemAdded(item, key, insertedPosition);
}
}
示例3: onChildChanged
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
String key = dataSnapshot.getKey();
if (mKeys.contains(key)) {
int index = mKeys.indexOf(key);
T oldItem = mItems.get(index);
T newItem = dataSnapshot.getValue(FirebaseRecyclerAdapter.this.mItemClass);
mItems.set(index, newItem);
notifyItemChanged(index);
itemChanged(oldItem, newItem, key, index);
}
}
示例4: onChildMoved
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
String key = dataSnapshot.getKey();
int index = mKeys.indexOf(key);
T item = dataSnapshot.getValue(FirebaseRecyclerAdapter.this.mItemClass);
mItems.remove(index);
mKeys.remove(index);
int newPosition;
if (previousChildName == null) {
mItems.add(0, item);
mKeys.add(0, key);
newPosition = 0;
} else {
int previousIndex = mKeys.indexOf(previousChildName);
int nextIndex = previousIndex + 1;
if (nextIndex == mItems.size()) {
mItems.add(item);
mKeys.add(key);
} else {
mItems.add(nextIndex, item);
mKeys.add(nextIndex, key);
}
newPosition = nextIndex;
}
notifyItemMoved(index, newPosition);
itemMoved(item, key, index, newPosition);
}
示例5: nextVideo
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
public File nextVideo() {
if (nearestHourScheduler == null) {return null;}
// Attempt to use the closest hour.
DataSnapshot snapshot = nearestHourScheduler.closestToCurrentHour();
if (snapshot != null && videoStorage.hasVideo(snapshot.getKey())) {
currentVideo = snapshot.getValue(Video.class);
return videoStorage.getVideo(snapshot.getKey());
}
return null;
}
示例6: onChildAdded
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
@Override public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// Start Video download
Video video = dataSnapshot.getValue(Video.class);
String key = dataSnapshot.getKey();
if (!videoStorage.hasVideo(key)) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(video.getUrl()));
request.setVisibleInDownloadsUi(true);
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE);
request.setDestinationInExternalFilesDir(context, null, dataSnapshot.getKey());
keyToDownloadIdMap.put(downloadManager.enqueue(request), key);
}
}
示例7: NearestHourScheduler
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
public NearestHourScheduler(Iterable<DataSnapshot> items) {
this.videoDataSnapshotMap = new TreeMap<>(new Comparator<Video>() {
@Override public int compare(Video video, Video that) {
return Integer.compare(video.getHour(), that.getHour());
}
});
for (DataSnapshot snapshot : items) {
Video video = snapshot.getValue(Video.class);
videoDataSnapshotMap.put(video, snapshot);
}
}
示例8: parse
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
private TreeSet<Message> parse(DataSnapshot dataSnapshot) {
TreeSet<Message> messages = new TreeSet<>();
for (DataSnapshot child : dataSnapshot.getChildren()) {
Message message = child.getValue(Message.class);
message.setKey(child.getKey());
messages.add(message);
}
return messages;
}
示例9: getFirebaseUser
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
private void getFirebaseUser(final User current_user) {
mCurrentUserRef = mRootRef.child("users").child(current_user.getUsername());
mGetUserListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Log.d("FIREBASE", "Called firebase to get user " + current_user.getUsername());
if (snapshot.exists()) {
Log.d("FIREBASE", "User " + current_user.getUsername() + " was registered before");
Helper.currentUser = snapshot.getValue(User.class); // addValueEventListenerwill reset the week score in case its monday
if (Helper.currentUser.getMax_streak() > 0)
doesntHaveStreakYet = false;
} else {
Log.d("FIREBASE", "User " + current_user.getUsername() + " didn't exist");
Helper.currentUser = current_user;
Helper.currentUser.setScore(0);
Helper.currentUser.setMax_streak(0);
Helper.currentUser.setWeek_score(0);
mCurrentUserRef.setValue(Helper.currentUser);
}
mScoreText.setText("" + Helper.currentUser.getScore());
if (isFirstLoad) play();
isFirstLoad = false;
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d("FIREBASE", "The read failed: " + firebaseError.getMessage());
}
};
mCurrentUserRef.addValueEventListener(mGetUserListener);
}
示例10: onDataChange
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
value = dataSnapshot.getValue(type);
semaphore.release();
throw new UnsupportedOperationException("Not implemented");
}
示例11: create
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
public static SyncedNotification create(DataSnapshot snapshot) {
return snapshot.getValue(SyncedNotification.class);
}
示例12: addDataChangeListener
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
private void addDataChangeListener() {
mItemRef = new Firebase(Utils.getFirebaseUserDiaryUrl(mUserUID))
.child(mKey);
mValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mDiaryNote = dataSnapshot.getValue(DiaryNote.class);
if (mDiaryNote == null) {
return;
}
mEdtDiaryNoteTitle.setText(mDiaryNote.getTitle());
mBigTitle.setText(mDiaryNote.getTitle());
mTravelTitle.setText(mDiaryNote.getTravelTitle());
mRtEditText.setRichTextEditing(true, mDiaryNote.getText());
if (Utils.isEmpty(mRtEditText)) {
mRtEditText.setVisibility(View.GONE);
} else {
mRtEditText.setVisibility(View.VISIBLE);
}
if (mDiaryNote.getPhotos() != null && !mDiaryNote.getPhotos().isEmpty()) {
mImages = mDiaryNote.getPhotos();
boolean showWarning = mSharedPreferences.getBoolean(Constants.KEY_SHOW_WARNING, true);
if (showWarning) {
for (int i = 0; i < mImages.size(); i++) {
if (!Utils.checkFileExists(getContext(), mImages.get(i).getLocalUri()) &&
mImages.get(i).getPicasaUri() == null) {
mWarning.setVisibility(View.VISIBLE);
break;
}
}
}
mImagesRecyclerView.setVisibility(View.VISIBLE);
((DiaryImagesListAdapter) mImagesRecyclerView.getAdapter()).changeList(mImages);
mImagesRecyclerView.scrollToPosition(0);
} else {
mImagesRecyclerView.setVisibility(View.GONE);
}
mDiaryFooterLayout.setVisibility(View.VISIBLE);
setWeatherViews();
if (mDiaryNote.getLocation() != null) {
mLocationLayout.setVisibility(View.VISIBLE);
setupMap();
if (mDiaryNote.getAddressDetails() != null) {
setLocationText(mDiaryNote.getAddressDetails());
} else {
mTxtLocation.setText(getResources()
.getString(R.string.location_format_address_line_with_gps,
mDiaryNote.getLocation().getLatitude(),
mDiaryNote.getLocation().getLongitude()));
mTxtSubLocation.setVisibility(View.GONE);
}
putMarker(new LatLng(mDiaryNote.getLocation().getLatitude(),
mDiaryNote.getLocation().getLongitude()));
} else {
mLocationLayout.setVisibility(View.GONE);
if (mDiaryNote.getWeather() == null) {
mDiaryFooterLayout.setVisibility(View.GONE);
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Toast.makeText(getContext(), firebaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
};
mItemRef.addValueEventListener(mValueEventListener);
}
示例13: exists
import com.firebase.client.DataSnapshot; //導入方法依賴的package包/類
/**
* Method returning is there such a patient added or not
* @param dataSnapshot - database object
*/
public boolean exists(DataSnapshot dataSnapshot) {
return dataSnapshot.getValue() != null;
}