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


Java DataSnapshot.hasChild方法代码示例

本文整理汇总了Java中com.google.firebase.database.DataSnapshot.hasChild方法的典型用法代码示例。如果您正苦于以下问题:Java DataSnapshot.hasChild方法的具体用法?Java DataSnapshot.hasChild怎么用?Java DataSnapshot.hasChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.firebase.database.DataSnapshot的用法示例。


在下文中一共展示了DataSnapshot.hasChild方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createDataListener

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
private ValueEventListener createDataListener() {
    return new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (dataSnapshot.exists()) {
                if (dataSnapshot.hasChild(Integer.toString(remoteOpponentSeqNum))) {
                    DataSnapshot newCheckPointData = dataSnapshot.child(Integer.toString(remoteOpponentSeqNum));
                    remoteOpponentSeqNum++;

                    CheckPoint newCheckPoint = new CheckPoint(
                            ((double)newCheckPointData.child(FirebaseNodes.LATITUDE).getValue()),
                            ((double)newCheckPointData.child(FirebaseNodes.LONGITUDE).getValue()));

                    callbackHandler.hasNewData(newCheckPoint);
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            throw databaseError.toException();
        }
    };
}
 
开发者ID:IrrilevantHappyLlamas,项目名称:Runnest,代码行数:25,代码来源:FirebaseProxy.java

示例2: 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();
        }
    }
}
 
开发者ID:brianjaustin,项目名称:permitlog-android,代码行数:22,代码来源:HomeFragment.java

示例3: onChildAdded

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
    //Add the data to logDurations and logsAtNight:
    long duration = (long)dataSnapshot.child("end").getValue() - (long)dataSnapshot.child("start").getValue();
    logDurations.add(duration);
    //Add whether or not it is night/weather/adverse to the appropriate conditions:
    boolean night = (boolean)dataSnapshot.child("night").getValue();
    logsAtNight.add(night);
    //For weather and adverse, outdated users may not have this property, so make sure to use .hasChild()
    boolean weather = dataSnapshot.hasChild("weather") && (boolean)dataSnapshot.child("weather").getValue();
    logsBadWeather.add(weather);
    boolean adverse = dataSnapshot.hasChild("adverse") && (boolean)dataSnapshot.child("adverse").getValue();
    logsAdverse.add(adverse);
    //Update the time totals:
    timeTracker.total += duration;
    if (night) timeTracker.night += duration;
    else timeTracker.day += duration;
    if (weather) timeTracker.weather += duration;
    if (adverse) timeTracker.adverse += duration;
    //Call the callback:
    if (callback != null) callback.accept(timeTracker);
}
 
开发者ID:brianjaustin,项目名称:permitlog-android,代码行数:23,代码来源:ElapsedTime.java

示例4: getDriverInfo

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
private List<String> getDriverInfo(DataSnapshot logSnapshot) {
    // The following variables hold info about the drivers. These are their default values:
    String driverId = logSnapshot.child("driver_id").getValue().toString();
    int driverIndex = -1;
    DataSnapshot driverSnapshot = null;
    String driverName = "DELETED DRIVER";
    String driverAge = "";
    String driverLicense = "DELETED DRIVER";
    // If possible, get driver index and info:
    if (driversInfo.driverIds.contains(driverId)) {
        driverIndex = driversInfo.driverIds.indexOf(driverId);
        driverSnapshot = driversInfo.driverSnapshots.get(driverIndex);
        // Get the driver's name
        if (DriverAdapter.hasCompleteName.accept(driverSnapshot)) {
            driverName = driversInfo.driverNames.get(driverIndex);
        }
        // Get the driver's age
        if (driverSnapshot.hasChild("age"))
            driverAge += ", " + driverSnapshot.child("age").getValue().toString();
        // Get the driver's license number
        if (driverSnapshot.hasChild("license_number"))
            driverLicense = driverSnapshot.child("license_number").getValue().toString();
    }
    //Return the info:
    return Arrays.asList(driverName, driverAge, driverLicense);
}
 
开发者ID:brianjaustin,项目名称:permitlog-android,代码行数:27,代码来源:LogFragment.java

示例5: onDataChange

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    //If the user does not have a day/night goal or both of them 0, hide the night checkbox:
    if ((!dataSnapshot.hasChild("day") || ((long)dataSnapshot.child("day").getValue() == 0)) &&
        (!dataSnapshot.hasChild("night") || ((long)dataSnapshot.child("night").getValue() == 0))) {
        findViewById(R.id.night_checkbox).setVisibility(View.GONE);
    }
    //Do the same thing for weather and adverse
    if(!dataSnapshot.hasChild("weather") || ((long)dataSnapshot.child("weather").getValue() == 0)){
        findViewById(R.id.weather_checkbox).setVisibility(View.GONE);
    }
    if(!dataSnapshot.hasChild("adverse") || ((long)dataSnapshot.child("adverse").getValue() == 0)){
        findViewById(R.id.adverse_checkbox).setVisibility(View.GONE);
    }
}
 
开发者ID:brianjaustin,项目名称:permitlog-android,代码行数:16,代码来源:CustomDriveDialog.java

示例6: 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();
    if (!(dataSnapshot.hasChild(name))) {
        newUser = new AdminUser(name,pass,MenuActivity.getManager().nextSerialNumber(), resID);
        manager.setCurrentUserId(newUser.getUserId());
        manager.addAdminUser(newUser);
        fbRef.child(email).child("ChoreManager").setValue(manager);
    }
}
 
开发者ID:TranAlan,项目名称:Chore-Manager-App,代码行数:14,代码来源:SpecialAdminUserCreationActivity.java

示例7: onStart

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
@Override
protected void onStart() {
    super.onStart();
    // Add value event listener to the post
    // [START post_value_event_listener]
    ValueEventListener buddyListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // Get User object and use the values to update the UI
            buddies = new ArrayList<User>();

            DataSnapshot children = dataSnapshot.child(interest);
            if(children.hasChild(username)){
                mDatabase.child(interest).child(username).setValue(user);
            }else if(!remove){
                writeNewUser(user);
            }
            for (DataSnapshot postSnapshot: children.getChildren()) {
                User buddy = postSnapshot.getValue(User.class);
                if (buddy.distance(lati,longi)<3 && !buddy.getEmail().equals(memail)){
                    buddies.add(buddy);
                }
            }
            // [START_EXCLUDE]
            // Update buddies View
            mBuddyView.setAdapter(new mAdapter(buddies));

            // [END_EXCLUDE]
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            // Getting Post failed, log a message
            Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
            // [START_EXCLUDE]
            Toast.makeText(BuddiesActivity.this, "Failed to load list.",
                    Toast.LENGTH_SHORT).show();
            // [END_EXCLUDE]
        }
    };
    mDatabase.addValueEventListener(buddyListener);
    // [END post_value_event_listener]

}
 
开发者ID:YoWenqin,项目名称:BuddiesGo,代码行数:45,代码来源:BuddiesActivity.java

示例8: accept

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
@Override public boolean accept(DataSnapshot dataSnapshot) {
    /* Returns true iff there is the start, end, night, and driver_id children. */
    return dataSnapshot.hasChild("start") && dataSnapshot.hasChild("end")
            && dataSnapshot.hasChild("night") && dataSnapshot.hasChild("driver_id");
}
 
开发者ID:brianjaustin,项目名称:permitlog-android,代码行数:6,代码来源:LogFragment.java

示例9: setupPost

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
private void setupPost(final PostViewHolder postViewHolder, final Post post, final int position, final String inPostKey) {
    postViewHolder.setPhoto(post.getThumb_url());
    postViewHolder.setText(post.getText());
    postViewHolder.setTimestamp(DateUtils.getRelativeTimeSpanString(
            (long) post.getTimestamp()).toString());
    final String postKey;
    if (mAdapter instanceof FirebaseRecyclerAdapter) {
        postKey = ((FirebaseRecyclerAdapter) mAdapter).getRef(position).getKey();
    } else {
        postKey = inPostKey;
    }

    Author author = post.getAuthor();
    postViewHolder.setAuthor(author.getFull_name(), author.getUid());
    postViewHolder.setIcon(author.getProfile_picture(), author.getUid());

    ValueEventListener likeListener = new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            postViewHolder.setNumLikes(dataSnapshot.getChildrenCount());
            if (dataSnapshot.hasChild(FirebaseUtil.getCurrentUserId())) {
                postViewHolder.setLikeStatus(PostViewHolder.LikeStatus.LIKED, getActivity());
            } else {
                postViewHolder.setLikeStatus(PostViewHolder.LikeStatus.NOT_LIKED, getActivity());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    };
    FirebaseUtil.getLikesRef().child(postKey).addValueEventListener(likeListener);
    postViewHolder.mLikeListener = likeListener;

    postViewHolder.setPostClickListener(new PostViewHolder.PostClickListener() {
        @Override
        public void showComments() {
            Log.d(TAG, "Comment position: " + position);
            mListener.onPostComment(postKey);
        }

        @Override
        public void toggleLike() {
            Log.d(TAG, "Like position: " + position);
            mListener.onPostLike(postKey);
        }
    });
}
 
开发者ID:firebase,项目名称:friendlypix-android,代码行数:50,代码来源:PostsFragment.java

示例10: onDataChange

import com.google.firebase.database.DataSnapshot; //导入方法依赖的package包/类
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    if (!(dataSnapshot.hasChild(emailEscaped))) {
        databaseFamilies.child(emailEscaped).setValue(email);
    }
}
 
开发者ID:TranAlan,项目名称:Chore-Manager-App,代码行数:7,代码来源:AppLoginActivity.java


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