本文整理汇总了Java中com.firebase.client.Query.addValueEventListener方法的典型用法代码示例。如果您正苦于以下问题:Java Query.addValueEventListener方法的具体用法?Java Query.addValueEventListener怎么用?Java Query.addValueEventListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.firebase.client.Query
的用法示例。
在下文中一共展示了Query.addValueEventListener方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadLastChatMessage
import com.firebase.client.Query; //导入方法依赖的package包/类
public ValueEventListener loadLastChatMessage(final ChatRoomHolder holder
, final ChatRoomInterface.OnChatLastMessageLoadedListener onChatLastMessageLoadedListener) {
Query query = getDefaultRoot().child(messagesPath).child(holder.chatRoom.getKey()).orderByKey().limitToLast(1);
return query.addValueEventListener(new ValueEventListenerAdapter() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
super.onDataChange(dataSnapshot);
Log.d(TAG, "onDataChange() called with: " + "dataSnapshot = [" + dataSnapshot + "]");
if (dataSnapshot.exists() && dataSnapshot.getChildrenCount() > 0) {
ChatMessage lastChatMessage = dataSnapshot.getChildren().iterator().next().getValue(ChatMessage.class);
if (lastChatMessage != null) {
lastChatMessage.setKey(dataSnapshot.getKey());
int indexOfUser = holder.members.getUsers().indexOf(lastChatMessage.getUser());
if (indexOfUser >= 0) {
lastChatMessage.setUser(holder.members.getUsers().get(indexOfUser));
}
holder.lastMessage = lastChatMessage;
}
onChatLastMessageLoadedListener.onChatLastMessageLoaded(lastChatMessage);
} else {
onChatLastMessageLoadedListener.onChatLastMessageLoadFailed();
}
}
});
}
示例2: loadUsers
import com.firebase.client.Query; //导入方法依赖的package包/类
private ValueEventListener loadUsers(final OnLoadAllUsersListener onLoadAllUsersListener, Query query) {
ValueEventListener listener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
handleDataResponse(dataSnapshot, onLoadAllUsersListener);
}
@Override
public void onCancelled(FirebaseError firebaseError) {}
};
query.addValueEventListener(listener);
return listener;
}
示例3: set
import com.firebase.client.Query; //导入方法依赖的package包/类
@Override
protected void set(Query query) {
query.addValueEventListener(this);
}
示例4: getNextDeviceFirebase
import com.firebase.client.Query; //导入方法依赖的package包/类
/**
* Retrieve the next device from Firebase and generate the appropriate message
*/
private void getNextDeviceFirebase() {
// Retrieve next deviceId from Firebase
Firebase nextDeviceRef = new Firebase(Constants.FIREBASE_URL_DEVICES).child(mFirebaseUid);
Query queryRef = nextDeviceRef.orderByChild(Constants.FIREBASE_PROPERTY_DEVICE_NUMBER).equalTo(mDeviceNum + 1);
queryRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot item : dataSnapshot.getChildren()) {
Device d = item.getValue(Device.class);
if (d != null) {
LogUtils.LOGE("***> child updated", "device connected: " + d.isConnected());
// If the device has connected to the parent uid, handle the message display based on whether
// the message has been received by the child device
if (d.isConnected()) {
if (!PreferencesUtils.getBoolean(mActivity, R.string.key_message_received, false)){
PreferencesUtils.setBoolean(mActivity, R.string.key_message_received, true);
// Once the message has been received by the child device, unpublish the message so the
// next device can begin broadcasting
unpublish();
mDiscover.setVisibility(View.GONE);
mIntroConnectDevice.setText(mActivity.getString(R.string.text_message_received));
}
} else {
// The device has not been connected yet, so generate the message to be sent and prepare
// to publish
LogUtils.LOGE("***> child updated", "device: " + d.getDeviceId());
// Update message
String message = mActivity.getString(R.string.message_body, mFirebaseUid, mDeviceNum + 1,
mTotalDevices, d.getDeviceId());
LogUtils.LOGE("***> child message", message);
mDeviceInfoMessage = DeviceMessage.newNearbyMessage(
InstanceID.getInstance(mActivity.getApplicationContext()).getId(), message);
}
}
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}