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


Java Query.addValueEventListener方法代码示例

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


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

示例1: loaditems

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void loaditems() {
    Query query = mDatabase.orderByChild("createdBy").equalTo(mAuth.getCurrentUser().getUid());
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            items.clear();
            itemKey.clear();
            for(DataSnapshot snap : dataSnapshot.getChildren()) {
                if(snap.child("isItemSold").getValue(String.class)==null){
                    items.add(snap.child("itemName").getValue(String.class));
                    itemKey.add(snap.getKey());
                }
            }
            loadListView();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:ppdesai434,项目名称:MavsSnapUp,代码行数:23,代码来源:MyItemsActivity.java

示例2: onResume

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
protected void onResume() {
    super.onResume();

    Query listenNewNotif = FirebaseDatabase
            .getInstance()
            .getReference(getString(R.string.firebase_key_last_notif))
            .child(getString(R.string.firebase_key_notif_id));
    listenNewNotif.keepSynced(true);
    final DatabaseHelper dbHelper = new DatabaseHelper(this);
    listenNewNotif.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            if(dbHelper.getUnreadCount()>0 && notifMenu!=null){
                notifMenu.setIcon(getResources().getDrawable(R.drawable.ic_notification_new));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d(TAG,databaseError.getMessage());
        }
    });
}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:26,代码来源:MainActivity.java

示例3: populateProfile

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void populateProfile() {
    nameEt.setText(currentUser.getDisplayName());
    emailEt.setText(currentUser.getEmail());

    Query userQuery = databaseReference.child("users").child(currentUser.getUid());
    userQuery.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            try {
                User user = dataSnapshot.getValue(User.class);
                nameEt.setText(user.getName());
                emailEt.setText(user.getEmail());
                collegeEt.setText(user.getCollege());
                departmentEt.setText(user.getDepartment());
                yearEt.setText(String.valueOf(user.getYear()));
                mobileEt.setText(user.getMobile());
            } catch (Exception e) {
                Log.e("populateProfile", e.toString());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
 
开发者ID:adithya321,项目名称:Instincts-2k17,代码行数:27,代码来源:RegisterActivity.java

示例4: open

import com.google.firebase.database.Query; //导入方法依赖的package包/类
/**
 * Creates one query per week up to 4 weeks in the past
 */
@Override
public void open() {
    completionResultArray.clear();
    completionRates = new double[4];
    completionLatch = new CountDownLatch(4);

    if(habit.getSchedule().size() > 0) {
        for(Week week : DateUtil.GetNPastWeeks(DateTime.now(), 4)) {
            String startKey = HabitEventDataModel.habitStampKey(habit.getKey(), week.getStartOfWeek());
            String endKey = HabitEventDataModel.habitStampKey(habit.getKey(), week.getEndOfWeek());

            Query eventCountQuery = FirebaseDatabase.getInstance().getReference("events/" + habit.getUserId())
                    .orderByChild("habitStamp").startAt(startKey).endAt(endKey);

            eventCountQuery.addValueEventListener(this);
            queryRegister.add(eventCountQuery);
        }
    }
}
 
开发者ID:CMPUT301F17T13,项目名称:cat-is-a-dog,代码行数:23,代码来源:CompletionMetricDataSource.java

示例5: addValueEventListener

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void addValueEventListener(final String name, final ReadableArray modifiers) {
  final FirestackDBReference self = this;

  mValueListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
      self.handleDatabaseEvent("value", mPath, dataSnapshot);
    }

    @Override
    public void onCancelled(DatabaseError error) {
      self.handleDatabaseError("value", mPath, error);
    }
  };

  Query ref = this.getDatabaseQueryAtPathAndModifiers(modifiers);
  ref.addValueEventListener(mValueListener);
  this.setListeningTo(mPath, "value");
}
 
开发者ID:fullstackreact,项目名称:react-native-firestack,代码行数:20,代码来源:FirestackDatabase.java

示例6: testQueriesOnLeafNodes

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Test
public void testQueriesOnLeafNodes()
    throws InterruptedException, ExecutionException, TestFailure, TimeoutException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
  final Semaphore semaphore = new Semaphore(0);
  new WriteFuture(ref, "leaf-node").timedGet();

  final List<DataSnapshot> snapshots = new ArrayList<>();
  Query query = ref.orderByChild("foo").limitToLast(1);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());
  Assert.assertNull(snapshots.get(0).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(ref);
  ref.removeEventListener(listener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:34,代码来源:OrderByTestIT.java

示例7: testServerRespectsKeyIndex

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Test
public void testServerRespectsKeyIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  Map<String, Object> initial = MapBuilder.of("a", 1, "b", 2, "c", 3);
  // If the server doesn't respect the index, it will send down limited data, but with no
  // offset, so the expected and actual data don't match.
  Query query = reader.orderByKey().startAt("b").limitToFirst(2);

  new WriteFuture(writer, initial).timedGet();

  final List<String> actualChildren = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  ValueEventListener valueListener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              for (DataSnapshot child : snapshot.getChildren()) {
                actualChildren.add(child.getKey());
              }
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);
  Assert.assertEquals(ImmutableList.of("b", "c"), actualChildren);

  // cleanup
  reader.removeEventListener(valueListener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:40,代码来源:OrderByTestIT.java

示例8: ReadFuture

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private ReadFuture(
    final Query ref, final CompletionCondition condition, final boolean ignoreFirstNull) {
  semaphore = new Semaphore(0);
  this.valueEventListener =
      new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
          if (ignoreFirstNull && events.size() == 0 && snapshot.getValue() == null) {
            return;
          }
          events.add(new EventRecord(snapshot, Event.EventType.VALUE, null));
          try {
            if (condition.isComplete(events)) {
              ref.removeEventListener(valueEventListener);
              finish();
            }
          } catch (Exception e) {
            exception = e;
            finish();
          }
        }

        @Override
        public void onCancelled(DatabaseError error) {
          wasCancelled = true;
          finish();
        }
      };
  ref.addValueEventListener(this.valueEventListener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:31,代码来源:ReadFuture.java

示例9: doMySearch

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public boolean doMySearch(String search_string) {

      DatabaseReference mFirebaseDatabaseReference = mFireBaseDatabase.getReference();
      Query query =  mFirebaseDatabaseReference.child("Entertainments").orderByChild("name")
                .startAt(search_string)
                .endAt(search_string+"\uf8ff");

        ValueEventListener valueEventListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
               arr = new ArrayList<>();
                for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                    arr.add(postSnapshot);
                }
                if(arr.size() == 0){

                    Snackbar sb = Snackbar.make(findViewById(R.id.search_acivity), "No results found", Snackbar.LENGTH_LONG);
                    View v = sb.getView();
                    v.setBackgroundColor(ContextCompat.getColor(getApplication(), R.color.colorPrimary));
                    sb.show();
                }else {
                    dataset = new DataSnapshot[arr.size()];
                    for (int i = 0; i < arr.size(); i++) {
                        dataset[i] = arr.get(i);
                    }
                    mAdapter = new MyAdapter(dataset);
                    mRecyclerView.setAdapter(mAdapter);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        };

        query.addValueEventListener(valueEventListener);
        return true;
    }
 
开发者ID:Socialate,项目名称:furry-sniffle,代码行数:40,代码来源:SearchableActivity.java

示例10: onResume

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
protected void onResume() {
    super.onResume();
    final DatabaseHelper dbHelper = new DatabaseHelper(this);
    Query listenNewNotif = FirebaseDatabase
            .getInstance()
            .getReference(getString(R.string.firebase_key_last_notif))
            .child(getString(R.string.firebase_key_notif_id));
    listenNewNotif.keepSynced(true);

    listenNewNotif.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            notifications.clear();
            notifications.addAll(dbHelper.selectAllNotifications());
            notifAdapter.notifyDataSetChanged();
            // Scroll to top
            ((LinearLayoutManager)recyclerView.getLayoutManager()).scrollToPositionWithOffset(0,0);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.d(TAG,databaseError.getMessage());
        }
    });

}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:29,代码来源:NotificationActivity.java

示例11: onActivityCreated

import com.google.firebase.database.Query; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Log.d(TAG,"In onActivityCreated");
    list = new ArrayList<>();
    adapter = new CouncilMemberAdapter(getContext(), list);
    listingsView = view.findViewById(R.id.council_members_listingsview);
    listingsView.setLayoutManager(new LinearLayoutManager(getContext()));
    listingsView.setAdapter(adapter);

    final Query cmDb = FirebaseDatabase.getInstance()
            .getReference(getString(R.string.firebase_key_council_member))
            .orderByChild(getString(R.string.firebase_key_member_id));
    cmDb.keepSynced(true);
    cmDb.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for(DataSnapshot data : dataSnapshot.getChildren()){
                CouncilMember member = data.getValue(CouncilMember.class);
                list.add(member);
            }
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:CSI-KJSCE,项目名称:CSI-KJSCEOfficial,代码行数:32,代码来源:CouncilDetailsFragment.java

示例12: populateProfile

import com.google.firebase.database.Query; //导入方法依赖的package包/类
public void populateProfile() {
    nameEt.setText(sharedPreferences.getString("name", ""));
    collegeEt.setText(sharedPreferences.getString("college", ""));
    departmentEt.setText(sharedPreferences.getString("department", ""));
    yearEt.setText(sharedPreferences.getString("year", ""));
    mobileEt.setText(sharedPreferences.getString("mobile", ""));

    Query userQuery = databaseReference.child("users").child(currentUser.getUid());
    userQuery.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            try {
                User user = dataSnapshot.getValue(User.class);
                nameEt.setText(user.getName());
                collegeEt.setText(user.getCollege());
                departmentEt.setText(user.getDepartment());
                yearEt.setText(String.valueOf(user.getYear()));
                mobileEt.setText(user.getMobile());
                paid = user.isPaid();
            } catch (Exception e) {
                Log.e("populateProfile", e.toString());
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
 
开发者ID:adithya321,项目名称:Instincts-2k17,代码行数:30,代码来源:ProfileActivity.java

示例13: getmydata

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void getmydata(final List<Event> events) {
        databaseReference = FirebaseDatabase.getInstance().getReference().child(Constants.events);
        final Query query = databaseReference.orderByChild("private").equalTo(false);
        query.addValueEventListener( new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                for(final DataSnapshot eventSnapshot : dataSnapshot.getChildren()) {
                    Log.d("mytestings", String.valueOf( eventSnapshot) );
                    Event event = eventSnapshot.getValue(Event.class);
                    Log.d("mytestings2", String.valueOf(event.getName()) );
                    Log.d("vikkkkky", String.valueOf(events) );
                    if(!events.contains(event) && !adapter.events.contains(event)) {
                        adapter.events.add(event);
                        Log.d("vikky2", String.valueOf(event) );
                    }
                    adapter.notifyDataSetChanged();

                }


                }


            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        } );


}
 
开发者ID:picopalette,项目名称:event-me,代码行数:32,代码来源:EventSearchActivity.java

示例14: fetchFirebaseData

import com.google.firebase.database.Query; //导入方法依赖的package包/类
private void fetchFirebaseData() {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    final DatabaseReference ordersRef = database.getReference("orders");
    Query query = ordersRef.limitToLast(1);


    final AdminPageActivity thisActivity = this;

    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            ArrayList<GroupOrder> groupOrders = new ArrayList<>();

            for (DataSnapshot groupOrderSnapshot : dataSnapshot.getChildren()) {
                String uid = groupOrderSnapshot.getKey();
                GroupOrder groupOrder = groupOrderSnapshot.getValue(GroupOrder.class);
                groupOrder.setUid(uid);

                groupOrders.add(groupOrder);
            }

            Optional<GroupOrder> maybeNewestOrder = Stream.of(groupOrders)
                    .findFirst();

            thisActivity.maybeNewestOrder = maybeNewestOrder;
            thisActivity.updateView();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
 
开发者ID:Consamables,项目名称:AndroidPizza,代码行数:35,代码来源:AdminPageActivity.java

示例15: setup

import com.google.firebase.database.Query; //导入方法依赖的package包/类
/**
 * Firebaseのデータベースからデータを取得する
 */
private void setup() {

    DatabaseReference reference = database.getReference("attendance");
    Query query = reference.orderByKey();
    query.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            mTxtHistory.setText(null);

            StringBuilder sb = new StringBuilder();
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {

                String key = snapshot.getKey();
                Attendance attendance = snapshot.getValue(Attendance.class);

                sb.append(key).append(" ").append(attendance.arrive).append(" ").append(attendance.leave);
                sb.append("\n");
            }

            mTxtHistory.setText(sb.toString());
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
}
 
开发者ID:yokmama,项目名称:honki_android2,代码行数:32,代码来源:MainActivity.java


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