本文整理汇总了Java中com.firebase.client.ValueEventListener类的典型用法代码示例。如果您正苦于以下问题:Java ValueEventListener类的具体用法?Java ValueEventListener怎么用?Java ValueEventListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ValueEventListener类属于com.firebase.client包,在下文中一共展示了ValueEventListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderData
import com.firebase.client.ValueEventListener; //导入依赖的package包/类
private void renderData() {
Query queryRef = mRootRef.child("users").orderByChild(getOrderBy()).limitToLast(100);//we need to iterate them backwards
queryRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
for (DataSnapshot userSnapshot : snapshot.getChildren()) {
mUsersDataset.add(userSnapshot.getValue(User.class));
}
Collections.reverse(mUsersDataset);
mAdapter = new UserListAdapter(mUsersDataset, getActivity(), getmTabType());
mRecyclerView.setAdapter(mAdapter);
mLoadingWrapper.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
示例2: getPresenceImpl
import com.firebase.client.ValueEventListener; //导入依赖的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();
}
示例3: checkThings
import com.firebase.client.ValueEventListener; //导入依赖的package包/类
private void checkThings() {
Calendar cal = Calendar.getInstance();
boolean monday = cal.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY;
mWeekResetRef = mRootRef.child("settings").child("week_reset");
if (monday) {
mWeekResetRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean is_reseted = snapshot.getValue(boolean.class);
if (!is_reseted) {
updateAllWeekScores();
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
} else {
mWeekResetRef.setValue(false);
}
}
示例4: updateAllWeekScores
import com.firebase.client.ValueEventListener; //导入依赖的package包/类
private void updateAllWeekScores() {
mRootRef.child("users").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
Map<String, Object> week_scores = new HashMap<String, Object>();
for (DataSnapshot userSnapshot : snapshot.getChildren()) {
week_scores.put(userSnapshot.child("username").getValue() + "/week_score", 0);
}
mRootRef.child("users").updateChildren(week_scores);
mWeekResetRef.setValue(true);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
}
示例5: DataPresenter
import com.firebase.client.ValueEventListener; //导入依赖的package包/类
/**
* Creates a data presenter.
*
* @param dataView The view which will display the data.
* @param configUrl The firebase endpoint url.
*/
DataPresenter(@NonNull DataView<T> dataView, @NonNull String configUrl) {
mFirebase = new Firebase(configUrl);
mData = new ArrayList<>();
mDataView = dataView;
mValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
mData.clear();
for (DataSnapshot data : dataSnapshot.getChildren()) {
// Data parsing is being done within the extending classes.
mData.add(parseData(data));
}
mDataView.showData(mData);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
Log.d(TAG, "onCancelled: " + firebaseError.getMessage());
// Deliberately swallow the firebase error here.
mDataView.showError();
}
};
}
示例6: addToiletToFirebase
import com.firebase.client.ValueEventListener; //导入依赖的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) {
}
});
}
示例7: retrieveData
import com.firebase.client.ValueEventListener; //导入依赖的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();
}
});
}
示例8: onPause
import com.firebase.client.ValueEventListener; //导入依赖的package包/类
@Override
protected void onPause() {
super.onPause();
firebase.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
updater = (long) dataSnapshot.getValue();
updater--;
firebase.setValue(updater);
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
Log.v(this.getClass().getSimpleName(), "onPause()");
if (tts != null) {
tts.stop();
tts.shutdown();
}
}
示例9: Repository
import com.firebase.client.ValueEventListener; //导入依赖的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 */
}
});
}
示例10: getSchoolId
import com.firebase.client.ValueEventListener; //导入依赖的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) {
}
});
}
示例11: compareEmail
import com.firebase.client.ValueEventListener; //导入依赖的package包/类
public void compareEmail (final UserDetails userDetails, final String emailFromUserDetail, final String userdetailUid) {
ref.addValueEventListener (new ValueEventListener () {
@Override
public void onDataChange (DataSnapshot dataSnapshot) {
for (DataSnapshot users : dataSnapshot.getChildren ()) {
String email = (String) users.child ("users").child ("email").getValue ();
if (emailFromUserDetail.trim ().equalsIgnoreCase (email)) {
Utils.showShortToast ("Email already exist!", SignUpPageActivity.this);
} else {
userRef.child (userdetailUid).setValue (userDetails);
}
}
}
@Override
public void onCancelled (FirebaseError firebaseError) {
}
});
}
示例12: getFullPatientsList
import com.firebase.client.ValueEventListener; //导入依赖的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;
}
示例13: isPatient
import com.firebase.client.ValueEventListener; //导入依赖的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) {
}
});
}
示例14: checkPatient
import com.firebase.client.ValueEventListener; //导入依赖的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) {
}
});
}
示例15: assignPrecept
import com.firebase.client.ValueEventListener; //导入依赖的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) {
}
});
}