当前位置: 首页>>代码示例>>Java>>正文


Java Query.addValueEventListener方法代码示例

本文整理汇总了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();
            }
        }
    });
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:27,代码来源:ChatRoomServices.java

示例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;
}
 
开发者ID:rapidpro,项目名称:ureport-android,代码行数:14,代码来源:UserServices.java

示例3: set

import com.firebase.client.Query; //导入方法依赖的package包/类
@Override
protected void set(Query query) {
    query.addValueEventListener(this);
}
 
开发者ID:aluxian,项目名称:Codementor,代码行数:5,代码来源:ChatroomItemViewHolder.java

示例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) {
        }
    });
}
 
开发者ID:kyleparker,项目名称:io16experiment-master,代码行数:48,代码来源:MessageFragment.java


注:本文中的com.firebase.client.Query.addValueEventListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。