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


Java Firebase.addListenerForSingleValueEvent方法代码示例

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


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

示例1: getPresenceImpl

import com.firebase.client.Firebase; //导入方法依赖的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();
}
 
开发者ID:aluxian,项目名称:Codementor,代码行数:20,代码来源:FirebaseTasks.java

示例2: addToiletToFirebase

import com.firebase.client.Firebase; //导入方法依赖的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) {
        }
    });
}
 
开发者ID:thorsteinson,项目名称:porcelain,代码行数:19,代码来源:AddToiletActivity.java

示例3: retrieveData

import com.firebase.client.Firebase; //导入方法依赖的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();
        }
    });
}
 
开发者ID:trigor74,项目名称:travelers-diary,代码行数:17,代码来源:ReminderItemFragment.java

示例4: orderSync

import com.firebase.client.Firebase; //导入方法依赖的package包/类
void orderSync() {
    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(LoggedActivity.this, NotifySyncService.class);
                    intent.putStringArrayListExtra(LoginGCMNotificationService.EXTRA_DEVICES, (ArrayList<String>) snapshot.getValue());
                    startService(intent);
                }
            }
        });
    }
}
 
开发者ID:Sefford,项目名称:BeAuthentic,代码行数:21,代码来源:LoggedActivity.java

示例5: notifyLoginToGCM

import com.firebase.client.Firebase; //导入方法依赖的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);
                }
            }
        });
    }
}
 
开发者ID:Sefford,项目名称:BeAuthentic,代码行数:25,代码来源:LoginActivity.java

示例6: sendRegistrationToServer

import com.firebase.client.Firebase; //导入方法依赖的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);
                    }
                }
            }
        });
    }
}
 
开发者ID:Sefford,项目名称:BeAuthentic,代码行数:30,代码来源:RegistrationIntentService.java

示例7: settingFirebase

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * ***************************************************************************
 */
private Firebase settingFirebase(String urlFirebase, String child) {
    Firebase firebase = new Firebase(urlFirebase).child(child);

    firebase.authWithPassword(mUsernameMail, mUsernamePwd, new AuthResultHandler("password"));
    mAuthStateListener = new Firebase.AuthStateListener() {
        @Override
        public void onAuthStateChanged(AuthData authData) {
            setAuthenticatedUser(authData);
        }
    };
    firebase.addAuthStateListener(mAuthStateListener);

    firebase.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            mAdapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
    return firebase;

}
 
开发者ID:benslamajihed,项目名称:GalleryPictureFirebaseAndroid,代码行数:30,代码来源:GalleryActivity.java

示例8: onCreate

import com.firebase.client.Firebase; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_review);

    getSupportActionBar().setTitle("New Review");

    View parent = findViewById(android.R.id.content);
    setupUI(parent);
    registerListeners();
    //grab this GUID from previous activity to use for searching the database
    key = getIntent().getStringExtra("GUID");

    //grab views to change
    reviewTitle = (TextView) findViewById(R.id.reviewTitle);
    rating = (RatingBar) findViewById(R.id.reviewRating);
    reviewText = (EditText) findViewById(R.id.reviewText);

    //grab the pieces of information from the Firebase
    Firebase rootRef = new Firebase(MainActivity.FIREBASE_URL);
    final Firebase bathroom = rootRef.child("toilets").child(key);
    reviewRef = bathroom.child("review");
    ratingRef = bathroom.child("rating");
    bathroom.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            HashMap<String, Object> fireToilet = (HashMap<String, Object>) dataSnapshot.getValue();

            //changes the title, so the user understands what restroom they're reviewing
            String title = (String) fireToilet.get("name");
            reviewTitle.setText("Create a new review for " + title);
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
        }
    });
}
 
开发者ID:thorsteinson,项目名称:porcelain,代码行数:39,代码来源:ReviewActivity.java

示例9: getFirebaseData_CurrentDay

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public List<FireBaseSensorData> getFirebaseData_CurrentDay(String currentDateandTime){
    //dummy values
    mRef = new Firebase("https://livingcityapp.firebaseio.com/"+currentDateandTime);

    final List<FireBaseSensorData> fbDataInHour = new ArrayList<>();

    mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot usersSnapshot) {

            for (DataSnapshot userSnapshot : usersSnapshot.getChildren()) {
                String hora = userSnapshot.child("Hora").getValue(String.class);
                String temp = userSnapshot.child("Temperature").getValue(String.class);
                String humi = userSnapshot.child("Humidade").getValue(String.class);
                String lati = userSnapshot.child("Latitude").getValue(String.class);
                String longi = userSnapshot.child("Longitude").getValue(String.class);
                String distr = userSnapshot.child("Distrito").getValue(String.class);

                fbDataInHour.add(new FireBaseSensorData(hora, humi, lati, longi, temp, distr));

            }

        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
        }
    });

    return fbDataInHour;
}
 
开发者ID:ruipoliveira,项目名称:livingCity-Android,代码行数:32,代码来源:FireBaseModule.java

示例10: getFirebaseStations

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public List<FireBaseStationsData> getFirebaseStations(){
    //dummy values
    mRef = new Firebase("https://livingcityapp.firebaseio.com/Polluent_Stations");

    final List<FireBaseStationsData>  fbDataInStations = new ArrayList<>();

    mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange (DataSnapshot usersSnapshot){
            String code = usersSnapshot.getKey();

            for (DataSnapshot userSnapshot : usersSnapshot.getChildren()) {
                String ambiente = userSnapshot.child("Ambiente").getValue(String.class);
                String concelho =userSnapshot.child("Concelho").getValue(String.class);
                String influ = userSnapshot.child("Influencia").getValue(String.class);
                Double lati = userSnapshot.child("LAT").getValue(Double.class);
                Double longi = userSnapshot.child("LON").getValue(Double.class);
                String nome = userSnapshot.child("Nome actual").getValue(String.class);

                fbDataInStations.add(new FireBaseStationsData(code, ambiente, concelho,influ,lati,longi,nome));

            }

        }

        @Override
        public void onCancelled(FirebaseError firebaseError) { }
    });


    return fbDataInStations;
}
 
开发者ID:ruipoliveira,项目名称:livingCity-Android,代码行数:33,代码来源:FireBaseModule.java

示例11: getFirebasePolluent

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public List<FireBasePolluentData> getFirebasePolluent(){
    //dummy values
    mRef = new Firebase("https://livingcityapp.firebaseio.com/Pollutent_2016-04-04");

    final List<FireBasePolluentData>  fbDataPolluent = new ArrayList<>();


    mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange (DataSnapshot usersSnapshot){

            for (DataSnapshot userSnapshot : usersSnapshot.getChildren()) {
                Integer dia = userSnapshot.child("day").getValue(Integer.class);
                Integer mes =userSnapshot.child("month").getValue(Integer.class);
                Integer ano = userSnapshot.child("year").getValue(Integer.class);
                Double value = userSnapshot.child("value").getValue(Double.class);
                Integer hora = userSnapshot.child("hour").getValue(Integer.class);
                String p_code = userSnapshot.child("pollutant/notation").getValue(String.class);
                String s_code = userSnapshot.child("station/code").getValue(String.class);


                fbDataPolluent.add(new FireBasePolluentData(mes, hora,ano,s_code,dia, value, p_code));

            }
        }
        @Override
        public void onCancelled(FirebaseError firebaseError) { }
    });


    return fbDataPolluent;
}
 
开发者ID:ruipoliveira,项目名称:livingCity-Android,代码行数:33,代码来源:FireBaseModule.java

示例12: createUserInFirebaseHelper

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Creates a new user in Firebase from the Java POJO
 */
private void createUserInFirebaseHelper(final String authUid) {
    final Firebase userLocation = new Firebase(Constants.FIREBASE_URL_USERS).child(authUid);

    // See if there is already a user (for example, if they already logged in with an associated Google account.
    userLocation.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            // If there is no user, make one
            LogUtils.LOGE("***> userLocation", "single value event - " + dataSnapshot.getValue());
            if (dataSnapshot.getValue() == null) {
                // Set raw version of date to the ServerValue.TIMESTAMP value and save into dateCreatedMap
                HashMap<String, Object> timestampJoined = new HashMap<>();
                timestampJoined.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);

                User newUser = new User(authUid, timestampJoined);
                userLocation.setValue(newUser);

                LogUtils.LOGE("***> add new user", authUid);
                PreferencesUtils.setInt(mActivity, R.string.key_device_number, 1);
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            LogUtils.LOGE(MainActivity.class.getSimpleName(), getString(R.string.log_error_occurred) + firebaseError.getMessage());
        }
    });
}
 
开发者ID:kyleparker,项目名称:io16experiment-master,代码行数:32,代码来源:MainActivity.java

示例13: onCreate

import com.firebase.client.Firebase; //导入方法依赖的package包/类
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getSupportActionBar().setTitle("Restroom Details");

    setContentView(R.layout.activity_toilet_detail);

    //load all views that need to be adjusted to fit data
    final TextView mTitle = (TextView) findViewById(R.id.detailTitle);
    final TextView mFamily = (TextView) findViewById(R.id.familyDetail);
    final TextView mGender = (TextView) findViewById(R.id.genderDetail);
    final TextView mHandicap = (TextView) findViewById(R.id.handicapDetail);
    final RatingBar mRating = (RatingBar) findViewById(R.id.toiletDescriptionRating);
    final TextView mDescription = (TextView) findViewById(R.id.toiletDetailDescription);
    final TextView mReview = (TextView) findViewById(R.id.toiletDetailReview);

    //grabs guid from selected restroom on main page, so we can access values
    key = getIntent().getStringExtra("GUID");

    //Reads through restroom's data and sets all necessary fields to match that
    //data. Does not show amenities that the restroom does not have, and shows
    //its rating and most recent review
    Firebase rootRef = new Firebase(MainActivity.FIREBASE_URL);
    final Firebase bathroom = rootRef.child("toilets").child(key);
    bathroom.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            HashMap<String, Object> fireToilet = (HashMap<String, Object>) dataSnapshot.getValue();
            String title = (String) fireToilet.get("name");
            boolean familyValue  = (boolean) fireToilet.get("isFamilyFriendly");
            boolean genderValue  = (boolean) fireToilet.get("isGenderNeutral");
            boolean handicapValue  = (boolean) fireToilet.get("isHandicapAccessible");
            long rating = (long) fireToilet.get("rating");
            String description = (String) fireToilet.get("descr");
            String review = (String) fireToilet.get("review");

            mTitle.setText(title);
            if(!familyValue) {
                mFamily.setVisibility(TextView.GONE);
            }
            if(!genderValue) {
                mGender.setVisibility(TextView.GONE);
            }
            if(!handicapValue) {
                mHandicap.setVisibility(TextView.GONE);
            }
            mRating.setRating(rating);
            mDescription.setText(description);
            mReview.setText(review);

        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
        }
    });


}
 
开发者ID:thorsteinson,项目名称:porcelain,代码行数:60,代码来源:ToiletDetail.java

示例14: getFirebaseDistricts

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public List<FireBaseDistrictsData> getFirebaseDistricts(){
    //dummy values
    mRef = new Firebase("https://livingcityapp.firebaseio.com/Portugal_Districts/features");

    final List<FireBaseDistrictsData>  fbDataInDistricts = new ArrayList<>();

    mRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange (DataSnapshot usersSnapshot){
            Double lat=0.0;
            Double lon=0.0;

            for (DataSnapshot userSnapshot : usersSnapshot.getChildren()) {
                String nome2 = userSnapshot.child("id").getValue(String.class);

                for(DataSnapshot geometrySnap : userSnapshot.getChildren()){
                    for(DataSnapshot cordinatesSnap : geometrySnap.getChildren()){
                        for(DataSnapshot cordinatesfirst : cordinatesSnap.getChildren()){
                            for(DataSnapshot cordinatessecond : cordinatesfirst.getChildren()){
                                    if (cordinatessecond.getChildrenCount() == 2) {
                                        lat = cordinatessecond.child("0").getValue(Double.class);
                                        lon = cordinatessecond.child("1").getValue(Double.class);

                                        fbDataInDistricts.add(new FireBaseDistrictsData(lat, lon, nome2));
                                    } else{
                                        for (DataSnapshot cordinatesthird : cordinatessecond.getChildren()) {
                                            lat = cordinatesthird.child("0").getValue(Double.class);
                                            lon = cordinatesthird.child("1").getValue(Double.class);

                                            fbDataInDistricts.add(new FireBaseDistrictsData(lat, lon, nome2));
                                        }
                                    }
                            }
                        }
                    }
                }


                fbDataInDistricts.add(new FireBaseDistrictsData(lat,lon,nome2));
            }

        }

        @Override
        public void onCancelled(FirebaseError firebaseError) { }
    });


    return fbDataInDistricts;
}
 
开发者ID:ruipoliveira,项目名称:livingCity-Android,代码行数:51,代码来源:FireBaseModule.java

示例15: getUsrList

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public void getUsrList(final String self_uid, final usrListCallback callback) {
    final ProgressDialog pd = createProgressDialog(mContext);
    pd.show();

    Firebase usrListRef = new Firebase(Constant_ApplicationConstant.FirebaseURL+"/users");
    usrListRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Log.e("UsrCount", dataSnapshot.getChildrenCount() + "");
            ArrayList<Object_User> usrs = new ArrayList<Object_User>();
            String self_name = null, self_avatar=null;
            for (DataSnapshot data : dataSnapshot.getChildren()) {
                Log.e("usr", data.getValue().toString());
                Object_User usr = data.getValue(Object_User.class);
                if (data.getKey().equals(self_uid)){
                    self_name = usr.getUserName();
                    self_avatar = usr.getUserAvatar();
                }
                else {
                    usrs.add(usr);
                }

            }

            callback.onSuccess(usrs,self_name, self_avatar);

            pd.dismiss();
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            callback.onFail(firebaseError);
            /*
            Toast.makeText(getBaseContext(), "Can't get the user list", Toast.LENGTH_SHORT).show();
            Log.e("UsrListErr", firebaseError.toString());
            */
            pd.dismiss();
        }
    });

}
 
开发者ID:WenhaoWu,项目名称:Morsi,代码行数:42,代码来源:Model_UserAndGroup.java


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