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


Java Firebase.addValueEventListener方法代码示例

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


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

示例1: Repository

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public Repository(String firebaseUrl, final Class<T> modelClass) {
	firebase = new Firebase(firebaseUrl);

	firebase.addValueEventListener(new ValueEventListener() {
		@Override
		public void onDataChange(DataSnapshot snapshot) {
			List<T> items = new ArrayList<>();
			for (DataSnapshot postSnapshot : snapshot.getChildren()) {
				T restaurant = postSnapshot.getValue(modelClass);
				items.add(restaurant);
			}
			Repository.this.items = items;
			notifyDataChanged();
		}
		@Override
		public void onCancelled(FirebaseError firebaseError) {
			/* Do nothing */
		}
	});
}
 
开发者ID:alexmiragall,项目名称:Gourmet,代码行数:21,代码来源:Repository.java

示例2: getSchoolId

import com.firebase.client.Firebase; //导入方法依赖的package包/类
public void getSchoolId() {

        schoolRef = new Firebase(Constants.FIREBASE_URL+"schools");
        schoolRef.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                dataSnapshot.getKey();
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });

    }
 
开发者ID:blessingoraz,项目名称:Akwukwo,代码行数:17,代码来源:ListOfMySchhols.java

示例3: getFullPatientsList

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Method for getting full name list of patients
 * @param arrayList - list of all patients
 */
public ArrayList<String> getFullPatientsList(ArrayList<String> arrayList) {
    final ArrayList<String> tmp_list = new ArrayList<>();
    for (String mPatient : arrayList) {
        Firebase firebase = new Firebase("https://care-connect.firebaseio.com/patients/" + mPatient);
        firebase.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Map<String, Object> pData = (Map<String, Object>) dataSnapshot.getValue();
                tmp_list.add(getPatientFullName(pData));
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

            }
        });
    }
    return tmp_list;
}
 
开发者ID:ursopanda,项目名称:kneeRehabMonitoring,代码行数:24,代码来源:DrawerActivity.java

示例4: isPatient

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Method for checking handling whether patients exists or not
 * @param tmp_email - patients email address
 */
@Override
public void isPatient(String tmp_email) {
    addPatientEmail = tmp_email.replace(".", "");
    Firebase firebase = new Firebase("https://care-connect.firebaseio.com/patients/"
            + addPatientEmail);
    firebase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (exists(dataSnapshot)) {
                checkPatient();
            } else {
                patientDoesNotExistError();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}
 
开发者ID:ursopanda,项目名称:kneeRehabMonitoring,代码行数:26,代码来源:DrawerActivity.java

示例5: checkPatient

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Method for checking whether there is a patient already added for doctor
 */
public void checkPatient() {
    String doc_key = email.replace(".", "");
    addPatFirebase = new Firebase("https://care-connect.firebaseio.com/doctors/"
            + doc_key + "/patients/"
            + addPatientEmail);
    mListener = addPatFirebase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (exists(dataSnapshot)) {
                patientAlreadyAddedError();
                return;
            } else {
                addPatient(addPatientEmail);
                patientAdded();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}
 
开发者ID:ursopanda,项目名称:kneeRehabMonitoring,代码行数:27,代码来源:DrawerActivity.java

示例6: assignPrecept

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Method for assigning precept for patient
 * @param patient_email - patients email address
 * @param o_angle - optimal flexion angle
 * @param m_angle - maximal flexion angle
 * @param duration - rehab duration
 * @param frequency - rehab frequency
 *                  Parameters from input form
 */
@Override
public void assignPrecept(String patient_email, int o_angle, int m_angle, int duration, int frequency) {
    preceptFirebase = new Firebase("https://care-connect.firebaseio.com/patients/"
            + patient_email + "/precept");
    final Precept precept = new Precept(o_angle, m_angle, duration, frequency);

    precpetListener = preceptFirebase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (exists(dataSnapshot)) {
                preceptExistsError();
            } else {
                //assigning precept and tis values for patient
                preceptFirebase.setValue(precept);
                preceptAdded();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}
 
开发者ID:ursopanda,项目名称:kneeRehabMonitoring,代码行数:34,代码来源:DrawerActivity.java

示例7: onResume

import com.firebase.client.Firebase; //导入方法依赖的package包/类
@Override
protected void onResume() {
    super.onResume();
    mFirebaseRef.addAuthStateListener(mAuthListener);
    String userUID = mSharedPreferences.getString(Constants.KEY_USER_UID, null);
    if (userUID != null) {
        mActiveTravelQuery = new Firebase(Utils.getFirebaseUserActiveTravelUrl(userUID));
        mActiveTravelQuery.addValueEventListener(mActiveTravelListener);
    }
}
 
开发者ID:trigor74,项目名称:travelers-diary,代码行数:11,代码来源:BaseActivity.java

示例8: onCreate

import com.firebase.client.Firebase; //导入方法依赖的package包/类
@Override
public void onCreate() {
    super.onCreate();
    final Context context=this;
    Firebase.setAndroidContext(this);
    firebase=new Firebase("https://marvelement.firebaseio.com/");
    firebase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if(((String)dataSnapshot.child("Notify").getValue()).equals("Yes")){
                System.out.println("Push Notification Received!");
                Intent intent = new Intent(context, MainActivity.class);
                PendingIntent pIntent = PendingIntent.getActivity(context, 0, intent, 0);
                Notification n  = new Notification.Builder(context)
                        .setContentTitle((String) dataSnapshot.child("NotifyTitle").getValue())
                        .setContentText((String) dataSnapshot.child("NotifyContent").getValue())
                        .setSmallIcon(R.drawable.polymer)
                        .setContentIntent(pIntent)
                        .setAutoCancel(true)
                        .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                        .build();
                NotificationManager notificationManager =
                        (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                notificationManager.notify(0, n);
                Handler j=new Handler();
                j.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        firebase.child("Notify").setValue("No");
                    }
                },8500);
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}
 
开发者ID:siddhantvinchurkar,项目名称:Marv,代码行数:41,代码来源:NotificationService.java

示例9: FirebaseCartCount

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**FUNCTION TO UPDATE CART COUNTS IN ACTION BAR USING FIREBASE**/

    public void FirebaseCartCount(Firebase ref){
        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                UpdateCartCount((int) dataSnapshot.getChildrenCount());
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
            }
        });
    }
 
开发者ID:satwikkansal,项目名称:witty,代码行数:15,代码来源:UserActivity.java

示例10: FirebaseBargainCartCount

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**FUNCTION TO UPDATE BARGAIN REQUESTS COUNTS IN ACTION BAR USING FIREBASE**/

    public void FirebaseBargainCartCount(Firebase ref){
        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                UpdateBargainCartCount((int) dataSnapshot.getChildrenCount());
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {
            }
        });
    }
 
开发者ID:satwikkansal,项目名称:witty,代码行数:15,代码来源:UserActivity.java

示例11: getData

import com.firebase.client.Firebase; //导入方法依赖的package包/类
private void getData(Firebase firebase,final String child){
    Log.d("getData()", child);
    firebase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Log.d("getData() " + child, ((ArrayList<Long>) dataSnapshot.getValue()).toString());
            if(child.equals(StoryType.TOPSTORIES)){
                Data.topStories = (ArrayList<Long>)dataSnapshot.getValue();
                getItemsForType(StoryType.TOPSTORIES);
            }
            if(child.equals(StoryType.NEWSTORIES)) {
                Data.newStories = (ArrayList<Long>)dataSnapshot.getValue();
                getItemsForType(StoryType.NEWSTORIES);
            }
            if(child.equals(StoryType.ASKSTORIES)) {
                Data.askStories = (ArrayList<Long>)dataSnapshot.getValue();
                getItemsForType(StoryType.ASKSTORIES);
            }
            if(child.equals(StoryType.SHOWSTORIES)) {
                Data.showStories = (ArrayList<Long>)dataSnapshot.getValue();
                getItemsForType(StoryType.SHOWSTORIES);
            }
            if(child.equals(StoryType.BESTSTORIES)) {
                Data.bestStories = (ArrayList<Long>)dataSnapshot.getValue();
                getItemsForType(StoryType.BESTSTORIES);
            }
            if(child.equals(StoryType.JOBSTORIES)) {
                Data.jobStories = (ArrayList<Long>)dataSnapshot.getValue();
                getItemsForType(StoryType.JOBSTORIES);
            }

        }
        @Override
        public void onCancelled(FirebaseError firebaseError) {
            System.out.println("Read Failed with error: " + firebaseError.getMessage());
        }
    });
}
 
开发者ID:sahilshekhawat,项目名称:Pocket-Hacker-News,代码行数:39,代码来源:PostListActivity.java

示例12: testFirebase

import com.firebase.client.Firebase; //导入方法依赖的package包/类
void testFirebase() {
    Firebase rootRef = new Firebase("https://fiery-torch-3951.firebaseio.com/");
    final Firebase array = rootRef.child("toilets");
    array.addValueEventListener(new ValueEventListener() {
        boolean addedData = false;

        @Override
        // This callback get's called when the data FIRST becomes available, and then
        // when it changes as well.
        public void onDataChange(DataSnapshot snapshot) {
            Log.v(TAG, "Data change called");
            // Prevents infinite loop, we only want to change the data once
            // Without this, as soon as a value changes, it would trigger another change
            Map<String, HashMap<String, Object>> val = (HashMap<String, HashMap<String, Object>>) snapshot.getValue();

            Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.toilet);
            Bitmap smaller = Bitmap.createScaledBitmap(icon, (icon.getWidth() / 4) * 3, (icon.getHeight() / 4) * 3, false);
            BitmapDescriptor toil = BitmapDescriptorFactory.fromBitmap(smaller);

            //LatLng point = new LatLng(-23,44.00);
            //Place p = new Place("A Bathroom", point, 3.0, "A clean and safe environment");
            //Log.v(TAG, "" + val);
            if (val != null) {
                for (String s : val.keySet()) {
                    HashMap h = val.get(s);

                    // Log.d(TAG, "Added Marker To Map " + h.get("name"));
                    HashMap<String, Double> coords = (HashMap) h.get("latLng");
                    LatLng point = new LatLng((Double) coords.get("latitude"), (Double) coords.get("longitude"));

                    Marker mapPoint = mMap.addMarker(new MarkerOptions()
                            .position(point)
                            .title(s)
                            .snippet("" + h.get("name"))
                            .icon(toil));


                    Place p = new Place((String) h.get("name"),
                            point,
                            (Long) h.get("rating"),
                            (String) h.get("descr"),
                            (Boolean) h.get("isFamilyFriendly"),
                            (Boolean) h.get("isGenderNeutral"),
                            (Boolean) h.get("isHandicapAccessible"),
                            (String) h.get("review"), s);

                    boolean familyFilter = sharedPref.getBoolean("pref_family", false);
                    boolean genderFilter = sharedPref.getBoolean("pref_gender", false);
                    boolean handicapFilter = sharedPref.getBoolean("pref_handicap", false);
                    String ratingFilter = sharedPref.getString("rating_filter", "3");

                    //sets all markers to 'visible' state, in case the filters have changed
                    mapPoint.setVisible(true);

                    //sets all irrelevant data based off of filter and amenity settings
                    if (!((!familyFilter || (familyFilter && (Boolean) h.get("isFamilyFriendly")))
                            && (!genderFilter || (genderFilter && (Boolean) h.get("isGenderNeutral")))
                            && (!handicapFilter || (handicapFilter && (Boolean) h.get("isHandicapAccessible")))
                            && (Long.parseLong(ratingFilter) <= (Long)h.get("rating")))) {
                        mapPoint.setVisible(false);
                    }

                    mMarkerMap.put(mapPoint, p);
                }
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {
            Log.v(TAG, "The read failed: " + firebaseError.getMessage());
        }
    });
}
 
开发者ID:thorsteinson,项目名称:porcelain,代码行数:74,代码来源:MainActivity.java

示例13: onCreate

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

    toolbar.setNavigationIcon(R.drawable.arrow);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivity(new Intent(ListOfMySchhols.this, ViewPageActivity.class));
        }
    });

    Firebase.setAndroidContext(this);

    listView = (ListView) findViewById(R.id.my_registered_schools);

    SharedPreferences preferences = getSharedPreferences("UserDetails", Context.MODE_PRIVATE);

    id = preferences.getString(Constants.USER_TOKEN, "");

    ref = new Firebase(Constants.FIREBASE_URL_USERS+"/"+id);

    mProgress = ProgressDialog.show(ListOfMySchhols.this, "", getString(R.string.loading), true, false);

    if(Utils.isOnLine(ListOfMySchhols.this)) {
        ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                if (mProgress != null)
                    mProgress.dismiss();

                for(DataSnapshot schools: dataSnapshot.child("schools").getChildren()) {

                    Utils.showLongMessage(schools.getKey(), ListOfMySchhols.this);

                     UserDetails details = schools.getValue(UserDetails.class);
                    details.setSchoolId( schools.getKey());

                    mListOfSchools.add(details);

                }

                for (UserDetails content : mListOfSchools ) {

                    if (mProgress != null)
                        mProgress.dismiss();

                    setupListview();
                }
            }

            @Override
            public void onCancelled(FirebaseError firebaseError) {

                if (mProgress != null)
                    mProgress.dismiss();

            }
        });
    } else {

        Utils.showLongMessage(Constants.CHECK_CONNECTION, ListOfMySchhols.this);
    }

}
 
开发者ID:blessingoraz,项目名称:Akwukwo,代码行数:70,代码来源:ListOfMySchhols.java

示例14: handleIncomingMessage

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Handle the incoming message from the nearby device. Parse the message to retrieve the appropriate data.
 */
private void handleIncomingMessage(Message message) {
    LogUtils.LOGE("***> message", DeviceMessage.fromNearbyMessage(message).getMessageBody());

    String[] messageParts = DeviceMessage.fromNearbyMessage(message).getMessageBody().split(Pattern.quote("|"));

    if (messageParts.length == 0) {
        LogUtils.LOGE("***> error", "error parsing message");
        return;
    }

    mFirebaseUid = messageParts[0];
    mDeviceNum = Integer.valueOf(messageParts[1]);
    mTotalDevices = Integer.valueOf(messageParts[2]);
    String deviceId = messageParts[3];

    if (!PreferencesUtils.getBoolean(mActivity, R.string.key_is_connected, false)) {
        // Update Firebase and remove the old FirebaseUid
        String currentFirebaseUid = PreferencesUtils.getString(mActivity, R.string.key_firebase_uid, "");
        LogUtils.LOGE("***> handleIncomingMessage", "remove firebase uid:" + currentFirebaseUid);
        Firebase userChallengeRef = new Firebase(Constants.FIREBASE_URL_USERS).child(currentFirebaseUid);
        userChallengeRef.removeValue();
    }

    // Update the shared preferences
    PreferencesUtils.setString(mActivity, R.string.key_firebase_uid, mFirebaseUid);
    PreferencesUtils.setInt(mActivity, R.string.key_total_devices, mTotalDevices);
    PreferencesUtils.setInt(mActivity, R.string.key_device_number, mDeviceNum);
    PreferencesUtils.setBoolean(mActivity, R.string.key_is_connected, true);

    // Display the message
    displayMessage();

    // Update the background color
    setInitialValues();

    // Generate next message, based on Firebase
    getNextDeviceFirebase();

    // Update connected status on Firebase
    Map<String, Object> device = new HashMap<>();
    device.put(Constants.FIREBASE_PROPERTY_CONNECTED, true);

    Firebase deviceRef = new Firebase(Constants.FIREBASE_URL_DEVICES).child(mFirebaseUid).child(deviceId);
    deviceRef.updateChildren(device);
    deviceRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            Device d = dataSnapshot.getValue(Device.class);
            LogUtils.LOGE("***> deviceRef", "here");
            if (d == null) {
                LogUtils.LOGE("***> setupFirebase", "reset device");
                MainActivity.resetDevice();
            }
        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });

    if (mDeviceNum < mTotalDevices) {
        // Change the display text
        mIntroConnectDevice.setText(mActivity.getString(R.string.text_connect_device, mDeviceNum + 1));

        // Change text/button action
        mDiscover.setOnClickListener(mConnectedClickListener);
    } else {
        mIntroConnectDevice.setVisibility(View.GONE);
        mDiscover.setVisibility(View.GONE);
    }

    unsubscribe();
}
 
开发者ID:kyleparker,项目名称:io16experiment-master,代码行数:78,代码来源:MessageFragment.java

示例15: setupFirebase

import com.firebase.client.Firebase; //导入方法依赖的package包/类
/**
 * Setup Firebase for the user and connected devices
 *
 * Update the existing user data with the number of devices selected on the previous screen
 * Add the devices based on the selection
 * Generate the message for the next device
 */
private void setupFirebase() {
    // Update Firebase to include the total number of devices
    if (!TextUtils.isEmpty(mFirebaseUid)) {
        Map<String, Object> profile = new HashMap<>();
        profile.put(Constants.FIREBASE_PROPERTY_NUMBER_DEVICES, mTotalDevices);

        Firebase userRef = new Firebase(Constants.FIREBASE_URL_USERS).child(mFirebaseUid);
        userRef.updateChildren(profile);
        LogUtils.LOGE("***> setupFirebase", "update firebase uid:" + mFirebaseUid);

        // Add device ids to Firebase
        for (int i = 0; i < PreferencesUtils.getInt(mActivity, R.string.key_total_devices, 1); i++) {
            // If the challengeCode is empty, then push a new value to the database
            Firebase deviceRef = new Firebase(Constants.FIREBASE_URL_DEVICES).child(mFirebaseUid);
            final Firebase newDeviceRef = deviceRef.push();

            mDeviceIds[i] = newDeviceRef.getKey();
            final int currentDeviceNumber = i + 1;

            LogUtils.LOGE("***> new device #" + currentDeviceNumber, mDeviceIds[i]);

            Device device = new Device(mDeviceIds[i], i + 1, mDeviceNum == currentDeviceNumber);
            newDeviceRef.setValue(device);
            newDeviceRef.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    Device d = dataSnapshot.getValue(Device.class);
                    if (d != null) {
                        LogUtils.LOGE("***> child updated", "id: " + d.getDeviceId());
                        LogUtils.LOGE("***> child updated", "number: " + d.getDeviceNumber());
                        LogUtils.LOGE("***> child updated", "connected: " + d.isConnected());
                        LogUtils.LOGE("***> child updated", "next: " + currentDeviceNumber);

                        // Hide the button and show the message for the first device
                        if (d.isConnected() && d.getDeviceNumber() > 1) {
                            PreferencesUtils.setBoolean(mActivity, R.string.key_message_received, true);

                            LogUtils.LOGE("***> child updated", "unpublished: " + currentDeviceNumber);
                            unpublish();
                            mDiscover.setVisibility(View.GONE);
                            mIntroConnectDevice.setText(mActivity.getString(R.string.text_message_received));
                        }
                    } else {
                        if (!PreferencesUtils.getBoolean(mActivity, R.string.key_device_reset_done, false)) {
                            LogUtils.LOGE("***> setupFirebase", "reset device");
                            MainActivity.resetDevice();
                        }
                    }
                }

                @Override
                public void onCancelled(FirebaseError firebaseError) {

                }
            });

            // Create the message for the next device
            if (i == mDeviceNum) {
                LogUtils.LOGE("***> device", "message created");
                String message = mActivity.getString(R.string.message_body, mFirebaseUid, mDeviceNum + 1,
                        mTotalDevices, newDeviceRef.getKey());
                mDeviceInfoMessage = DeviceMessage.newNearbyMessage(
                        InstanceID.getInstance(mActivity.getApplicationContext()).getId(), message);
            }
        }
    }
}
 
开发者ID:kyleparker,项目名称:io16experiment-master,代码行数:75,代码来源:MessageFragment.java


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