Java 类com.google.firebase.database.GenericTypeIndicator 实例源码

项目:firebase-admin-java    文件:CustomClassMapper.java   
/**
 * Converts a standard library Java representation of JSON data to an object of the class provided
 * through the GenericTypeIndicator
 *
 * @param object The representation of the JSON data
 * @param typeIndicator The indicator providing class of the object to convert to
 * @return The POJO object.
 */
public static <T> T convertToCustomClass(Object object, GenericTypeIndicator<T> typeIndicator) {
  Class<?> clazz = typeIndicator.getClass();
  Type genericTypeIndicatorType = clazz.getGenericSuperclass();
  if (genericTypeIndicatorType instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) genericTypeIndicatorType;
    if (!parameterizedType.getRawType().equals(GenericTypeIndicator.class)) {
      throw new DatabaseException(
          "Not a direct subclass of GenericTypeIndicator: " + genericTypeIndicatorType);
    }
    // We are guaranteed to have exactly one type parameter
    Type type = parameterizedType.getActualTypeArguments()[0];
    return deserializeToType(object, type);
  } else {
    throw new DatabaseException(
        "Not a direct subclass of GenericTypeIndicator: " + genericTypeIndicatorType);
  }
}
项目:firebase-admin-java    文件:DataTestIT.java   
@Test
public void testMultipleWriteValuesReconnectRead()
    throws ExecutionException, TimeoutException, InterruptedException, TestFailure {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  final DatabaseReference writer = refs.get(0);
  final DatabaseReference reader = refs.get(1);

  writer.child("a").child("b").child("c").setValueAsync(1);
  writer.child("a").child("d").child("e").setValueAsync(2);
  writer.child("a").child("d").child("f").setValueAsync(3);
  WriteFuture writeFuture = new WriteFuture(writer.child("g"), 4);
  writeFuture.timedGet();

  Map<String, Object> expected = new MapBuilder()
      .put("a",
          new MapBuilder().put("b", new MapBuilder().put("c", 1L).build())
              .put("d", new MapBuilder().put("e", 2L).put("f", 3L).build()).build())
      .put("g", 4L).build();
  ReadFuture readFuture = new ReadFuture(reader);

  GenericTypeIndicator<Map<String, Object>> t = new GenericTypeIndicator<Map<String, Object>>() {
  };
  Map<String, Object> result = readFuture.timedGet().get(0).getSnapshot().getValue(t);
  TestHelpers.assertDeepEquals(expected, result);
}
项目:kcards    文件:FavoritesDeckListActivity.java   
private void retrieveDeckFromFirebaseDb(String key) {
    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference databaseReference = database.getReference(FirebaseDb.DECK_KEY + "/" + key);
    databaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<Deck> t = new GenericTypeIndicator<Deck>() {
            };

            Deck deck = dataSnapshot.getValue(t);
            if (deck != null) {
                deck.setFirebaseKey(dataSnapshot.getKey()); // firebase reference for tracking following status
                decks.add(deck);
            }
            onDeckLoadedOrFailed();
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Logger.w(TAG, "loadPost:onCancelled", databaseError.toException());
            onDeckLoadedOrFailed();
        }
    });
}
项目:RUSpotlight    文件:StatisticsFragment.java   
private void updateChartReference(final String mealKey, final PieChart chart) {
    DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference().child("meals").child(mealKey);

    mDatabase.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<Map<String, Integer>> t = new GenericTypeIndicator<Map<String, Integer>>() {};
            Map<String, Integer> ratings = dataSnapshot.child("ratings").getValue(t);
            if( ratings == null ) {
                clearChartData(chart);
            }
            else {
                setChartData(chart, calculateRatings(ratings));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}
项目:gaso    文件:MilestoneDAO.java   
public void findLastMilestone(final OneMilestoneReceivedListener listener){
    final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    if(user!=null) {
        mDatabase.child(Constants.FIREBASE_MILESTONES).child(user.getUid()).child(SessionSingleton.getInstance().currentCar.getid()).limitToLast(1).addListenerForSingleValueEvent(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                GenericTypeIndicator<Map<String,Milestone>> indicator = new GenericTypeIndicator<Map<String, Milestone>>() {};
                Map<String, Milestone> map = dataSnapshot.getValue(indicator);
                if (map != null) {
                    final Milestone m = map.get(map.keySet().iterator().next());
                    Log.e("DataSnapshot", m.toString());
                    listener.onMilestoneReceived(m);
                } else {
                    listener.onMilestoneReceived(null);
                }


            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                listener.onCancelled(databaseError);
            }
        });
    }
}
项目:white-label-event-app    文件:FirebaseDatabaseHelpers.java   
public static AgendaSection toAgendaSection(final DataSnapshot data) {
    final AgendaSection section = new AgendaSection();
    populateSection(data, section);
    Map<String, AgendaItem> items = data.child("items").getValue(new GenericTypeIndicator<Map<String, AgendaItem>>() {});
    if (items == null) {
        items = Collections.emptyMap();
    }

    // Force empty speaker list when null so the client doesn't have to
    // always check null.
    for (final Map.Entry<String, AgendaItem> entry : items.entrySet()) {
        if (entry.getValue().getSpeakerIds() == null) {
            entry.getValue().setSpeakerIds(Collections.<String>emptyList());
        }
    }

    section.setItems(items);
    return section;
}
项目:RxFirebase2    文件:RxFirebaseDatabaseTest.java   
@Test public void testDataChangesOfGenericTypeIndicator() {
  List<String> values = new ArrayList<>();
  values.add("Foo");
  values.add("Bar");

  GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() {
  };

  TestObserver<Optional<List<String>>> sub = TestObserver.create();

  RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, typeIndicator).subscribe(sub);

  verifyAddValueEventListener();
  callValueEventOnDataChange(typeIndicator, values);

  sub.assertNotComplete();

  sub.assertValue(new Predicate<Optional<List<String>>>() {
    @Override public boolean test(Optional<List<String>> listOptional) throws Exception {
      return listOptional.isPresent() && "Foo".equals(listOptional.get().get(0)) && "Bar".equals(
          listOptional.get().get(1));
    }
  });

  sub.dispose();

  callValueEventOnDataChange(typeIndicator, values);

  // Ensure no more values are emitted after unsubscribe
  sub.assertValueCount(1);
}
项目:RxFirebase2    文件:RxFirebaseDatabaseTest.java   
@Test public void testDataOfGenericTypeIndicator() {
  List<String> values = new ArrayList<>();
  values.add("Foo");
  values.add("Bar");

  GenericTypeIndicator<List<String>> typeIndicator = new GenericTypeIndicator<List<String>>() {
  };

  TestObserver<Optional<List<String>>> sub = TestObserver.create();

  RxFirebaseDatabase.dataOf(mockDatabaseReference, typeIndicator).subscribe(sub);

  verifyAddListenerForSingleValueEvent();
  callValueEventOnDataChange(typeIndicator, values);

  sub.assertComplete();
  sub.assertNoErrors();

  sub.assertValue(new Predicate<Optional<List<String>>>() {
    @Override public boolean test(Optional<List<String>> listOptional) throws Exception {
      return listOptional.isPresent() && "Foo".equals(listOptional.get().get(0)) && "Bar".equals(
          listOptional.get().get(1));
    }
  });

  sub.dispose();

  callValueEventOnDataChange(typeIndicator, values);

  // Ensure no more values are emitted after unsubscribe
  sub.assertValueCount(1);
}
项目:HealthHelp    文件:AgendaDAO.java   
/**
 * Este método cria um evento com a primeira agenda que corresponde ao nome no firebase,
 * mesmo que mais de um seja encontrada
 *
 * @param nomeAgenda nome da agenda que se deseja obter
 */
public void buscarPeloNome(String nomeAgenda) {
    getDatabaseReference()
        .child(DATABASE_CHILD)
        .orderByChild("nome")
        .equalTo(nomeAgenda)
        .addListenerForSingleValueEvent(
            new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    Log.w(TAG, "SNAPSHOT: " + dataSnapshot);
                    // Agenda agenda = dataSnapshot.getValue(Agenda.class);
                    GenericTypeIndicator<HashMap<String, Agenda>> t =
                        new GenericTypeIndicator<HashMap<String, Agenda>>() {
                        };
                    HashMap<String, Agenda> agendasEncontradas = dataSnapshot.getValue(t);

                    Iterator it = agendasEncontradas.values().iterator();

                    Agenda agenda = null;
                    if (it.hasNext()) {
                        agenda = (Agenda) it.next();
                        //Salva no objeto agenda o id do banco gerado pelo firebase
                        agenda.setId(agendasEncontradas.keySet().iterator().next());
                        Log.w(TAG, "agenda buscada pelo nome: " + agenda.getId());
                    } else {
                        Log.w(TAG, "agenda não encontrada");
                    }

                    EventBus.getDefault().post(agenda);
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {
                    Log.e(TAG, "ValueListener: onCancelled:", databaseError.toException());
                    EventBus.getDefault().post(new DatabaseEvent<>(databaseError));
                }
            }
        );
}
项目:HealthHelp    文件:UsuarioDAO.java   
@Override
    public void buscarPelaId(String id) {
        getDatabaseReference()
            .child(DATABASE_CHILD)
            .orderByChild("id")
            .equalTo(id)
            .addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {
                        GenericTypeIndicator<HashMap<String, Usuario>> genericTypeIndicator =
                            new GenericTypeIndicator<HashMap<String, Usuario>>() {
                            };
                        HashMap<String, Usuario> usuarioHashMap = dataSnapshot.
                            getValue(genericTypeIndicator);
                        Usuario usuarioEncontrado = usuarioHashMap.values().iterator().next();
                        Log.w(TAG, "buscaPeloId.OnDataChange: o usuário encontrado foi: " +
                            usuarioEncontrado.getNome());

                        // chama de volta quem pediu o local que foi buscado
//                        getDatabaseCallback().onComplete(usuarioEncontrado);
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.e(TAG, "buscaPelaId: onCancelled:", databaseError.toException());
//                        getDatabaseCallback().onError(databaseError);
                    }
                }
            );
    }
项目:HealthHelp    文件:AbstractDAO.java   
protected T construirObjetoFirebase(DataSnapshot snapshot) {
    T objetoEncontrado = null;
    GenericTypeIndicator tipoParaConverter = getTipoEntidadeConstrucao();
    if (tipoParaConverter != null) {
        objetoEncontrado = (T) snapshot.getValue(tipoParaConverter);
    } else {
        objetoEncontrado = snapshot.getValue(getTipoEntidade());
    }
    objetoEncontrado.setId(snapshot.getKey());
    return objetoEncontrado;
}
项目:FindMeAHome    文件:AnimalSelectionDialogFrament.java   
private void initRecyclerView() {

        databaseReference.child("animals").orderByChild("userUid").equalTo(getArguments()
                .getString("userUid")).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                if (dataSnapshot.getValue() != null) {
                    GenericTypeIndicator<HashMap<String, Animal>> objectGTI =
                            new GenericTypeIndicator<HashMap<String, Animal>>() {
                            };
                    Map<String, Animal> objectHashMap = dataSnapshot.getValue(objectGTI);
                    friends = new ArrayList<>(objectHashMap.values());
                }
                LinearLayoutManager llm = new LinearLayoutManager(getActivity());
                llm.setOrientation(LinearLayoutManager.VERTICAL);
                animalList.setLayoutManager(llm);
                RecyclerView.Adapter adapter = new RecyclerAnimalAdapter(friends);
                animalList.setAdapter(adapter);
                if (friends == null || friends.isEmpty()) {
                    animalListSeparator.setVisibility(View.GONE);
                    animalListWrapper.setVisibility(View.GONE);
                } else {
                    if(getActivity() != null) {
                        firstOption.setText(getActivity().getString(R.string.option) + " 1: " + firstOption.getText());
                        secondOption.setText(getActivity().getString(R.string.option) + " 2: " + secondOption.getText());
                    } else {
                        firstOption.setText("Option 1: " + firstOption.getText());
                        secondOption.setText("Option 2: " + secondOption.getText());
                    }
                }
                databaseReference.removeEventListener(this);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
                Log.e("databaseError", String.valueOf(databaseError));
            }
        });
    }
项目:gaso    文件:StationEvaluationDAO.java   
public void findStationEvaluationById(String stationId, final OneStationEvaluationReceivedListener listener) {
    mDatabase.child(Constants.FIREBASE_STATIONS_EVALUATIONS).child(stationId).addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<HashMap<String,GeneralStationEvaluation>> indicator = new GenericTypeIndicator<HashMap<String, GeneralStationEvaluation>>() {};
            HashMap<String,GeneralStationEvaluation> evaluation = dataSnapshot.getValue(indicator);
            listener.onStationEvaluationReceived(evaluation);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            listener.onCancelled(databaseError);
        }
    });
}
项目:rxfirebase    文件:RxFirebaseDatabase.java   
/**
 * @param ref
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Observable<DataValue<T>> dataChangesOf(
        @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return dataChanges(ref)
            .compose(new TransformerOfGenericTypeIndicator<T>(typeIndicator));
}
项目:rxfirebase    文件:RxFirebaseDatabase.java   
/**
 * @param query
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Observable<DataValue<T>> dataChangesOf(
        @NonNull Query query, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return dataChanges(query)
            .compose(new TransformerOfGenericTypeIndicator<T>(typeIndicator));
}
项目:rxfirebase    文件:RxFirebaseDatabase.java   
/**
 * @param ref
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Single<T> dataOf(
        @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return data(ref).compose(new SingleTransformerOfGenericTypeIndicator<T>(typeIndicator));
}
项目:rxfirebase    文件:RxFirebaseDatabase.java   
/**
 * @param query
 * @param typeIndicator
 * @param <T>
 * @return
 */
@NonNull
@CheckReturnValue
public static <T> Single<T> dataOf(
        @NonNull Query query, @NonNull GenericTypeIndicator<T> typeIndicator) {
    return data(query).compose(new SingleTransformerOfGenericTypeIndicator<T>(typeIndicator));
}
项目:rxfirebase    文件:RxFirebaseDatabaseTest.java   
@Test
public void testDataChangesOfGenericTypeIndicator_DataReference() {
    List<String> values = new ArrayList<>();
    values.add("Foo");
    values.add("Bar");

    GenericTypeIndicator<List<String>> typeIndicator =
            new GenericTypeIndicator<List<String>>() {
            };

    TestObserver<DataValue<List<String>>> sub = TestObserver.create();

    RxFirebaseDatabase.dataChangesOf(mockDatabaseReference, typeIndicator)
            .subscribe(sub);

    verifyDataReferenceAddValueEventListener();
    callValueEventOnDataChange(typeIndicator, values);

    sub.assertNotComplete();

    sub.assertValue(new Predicate<DataValue<List<String>>>() {
        @Override
        public boolean test(DataValue<List<String>> value) throws Exception {
            return value.isPresent()
                    && "Foo".equals(value.get().get(0))
                    && "Bar".equals(value.get().get(1));
        }
    });

    sub.dispose();

    callValueEventOnDataChange(typeIndicator, values);

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(1);
}
项目:rxfirebase    文件:RxFirebaseDatabaseTest.java   
@Test
public void testDataOfGenericTypeIndicator_DataReference() {
    List<String> values = new ArrayList<>();
    values.add("Foo");
    values.add("Bar");

    GenericTypeIndicator<List<String>> typeIndicator =
            new GenericTypeIndicator<List<String>>() {
            };

    TestObserver<List<String>> sub = TestObserver.create();

    RxFirebaseDatabase.dataOf(mockDatabaseReference, typeIndicator)
            .subscribe(sub);

    verifyDataReferenceAddListenerForSingleValueEvent();
    callValueEventOnDataChange(typeIndicator, values);

    sub.assertComplete();
    sub.assertNoErrors();

    sub.assertValue(new Predicate<List<String>>() {
        @Override
        public boolean test(List<String> value) throws Exception {
            return "Foo".equals(value.get(0))
                    && "Bar".equals(value.get(1));
        }
    });

    sub.dispose();

    callValueEventOnDataChange(typeIndicator, values);

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(1);
}
项目:rxfirebase    文件:RxFirebaseDatabaseTest.java   
@Test
public void testDataChangesOfGenericTypeIndicator_Query() {
    List<String> values = new ArrayList<>();
    values.add("Foo");
    values.add("Bar");

    GenericTypeIndicator<List<String>> typeIndicator =
            new GenericTypeIndicator<List<String>>() {
            };

    TestObserver<DataValue<List<String>>> sub = TestObserver.create();

    RxFirebaseDatabase.dataChangesOf(mockQuery, typeIndicator)
            .subscribe(sub);

    verifyQueryAddValueEventListener();
    callValueEventOnDataChange(typeIndicator, values);

    sub.assertNotComplete();

    sub.assertValue(new Predicate<DataValue<List<String>>>() {
        @Override
        public boolean test(DataValue<List<String>> value) throws Exception {
            return value.isPresent()
                    && "Foo".equals(value.get().get(0))
                    && "Bar".equals(value.get().get(1));
        }
    });

    sub.dispose();

    callValueEventOnDataChange(typeIndicator, values);

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(1);
}
项目:rxfirebase    文件:RxFirebaseDatabaseTest.java   
@Test
public void testDataOfGenericTypeIndicator_Query() {
    List<String> values = new ArrayList<>();
    values.add("Foo");
    values.add("Bar");

    GenericTypeIndicator<List<String>> typeIndicator =
            new GenericTypeIndicator<List<String>>() {
            };

    TestObserver<List<String>> sub = TestObserver.create();

    RxFirebaseDatabase.dataOf(mockQuery, typeIndicator)
            .subscribe(sub);

    verifyQueryAddListenerForSingleValueEvent();
    callValueEventOnDataChange(typeIndicator, values);

    sub.assertComplete();
    sub.assertNoErrors();

    sub.assertValue(new Predicate<List<String>>() {
        @Override
        public boolean test(List<String> value) throws Exception {
            return "Foo".equals(value.get(0))
                    && "Bar".equals(value.get(1));
        }
    });

    sub.dispose();

    callValueEventOnDataChange(typeIndicator, values);

    // Ensure no more values are emitted after unsubscribe
    sub.assertValueCount(1);
}
项目:rxfirebase    文件:RxFirebaseDatabaseTest.java   
private <T> void callValueEventOnDataChange(GenericTypeIndicator<T> type, T value) {
    when(mockDataSnapshot.exists())
            .thenReturn(true);
    when(mockDataSnapshot.getValue(type))
            .thenReturn(value);

    valueEventListener.getValue().onDataChange(mockDataSnapshot);
}
项目:white-label-event-app    文件:SessionFeedbackFragment.java   
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
    LOGGER.fine("Answers");
    LOGGER.fine(dataSnapshot.toString());
    priorAnswers = dataSnapshot.getValue(new GenericTypeIndicator<List<Object>>() {});
    if (priorAnswers == null) {
        priorAnswers = new ArrayList<>();
    }
    updateUi();
}
项目:white-label-event-app    文件:FirebaseDatabaseHelpers.java   
public static SpeakersSection toSpeakersSection(final DataSnapshot data) {
    final SpeakersSection section = new SpeakersSection();
    populateSection(data, section);
    Map<String, SpeakerItem> items = data.child("items").getValue(new GenericTypeIndicator<Map<String, SpeakerItem>>() {});
    if (items == null) {
        items = Collections.emptyMap();
    }
    section.setItems(items);
    return section;
}
项目:white-label-event-app    文件:FirebaseDatabaseHelpers.java   
public static AttendeesSection toAttendeesSection(final DataSnapshot data) {
    final AttendeesSection section = new AttendeesSection();
    populateSection(data, section);
    Map<String, AttendeeItem> items = data.child("items").getValue(new GenericTypeIndicator<Map<String, AttendeeItem>>() {});
    if (items == null) {
        items = Collections.emptyMap();
    }
    section.setItems(items);
    return section;
}
项目:white-label-event-app    文件:FirebaseDatabaseHelpers.java   
public static CompaniesSection toCompaniesSection(final DataSnapshot data) {
    final CompaniesSection section = new CompaniesSection();
    populateSection(data, section);
    Map<String, CompanyItem> items = data.child("items").getValue(new GenericTypeIndicator<Map<String, CompanyItem>>() {});
    if (items == null) {
        items = Collections.emptyMap();
    }
    section.setItems(items);
    return section;
}
项目:white-label-event-app    文件:FirebaseDatabaseHelpers.java   
public static MapsSection toMapsSection(DataSnapshot data) {
    final MapsSection section = new MapsSection();
    populateSection(data, section);
    Map<String, MapItem> items = data.child("items").getValue(new GenericTypeIndicator<Map<String, MapItem>>() {});
    if (items == null) {
        items = Collections.emptyMap();
    }
    section.setItems(items);
    return section;
}
项目:white-label-event-app    文件:FirebaseDatabaseHelpers.java   
public static List<FeedbackQuestion> toFeedbackQuestions(final DataSnapshot data) {
    final List<FeedbackQuestion2> questions = data.getValue(new GenericTypeIndicator<List<FeedbackQuestion2>>() {});
    int size = questions != null ? questions.size() : 0;
    ArrayList<FeedbackQuestion> qs = new ArrayList<>(size);
    if (questions != null) {
        for (final FeedbackQuestion2 q : questions) {
            qs.add(new FeedbackQuestion(QuestionType.valueOf(q.getType()), q.getText()));
        }
    }
    return qs;

}
项目:showcase-android    文件:DataSnapshotMapper.java   
public static <U> DataSnapshotMapper<DataSnapshot, U> of(GenericTypeIndicator<U> genericTypeIndicator) {
   return new GenericTypedDataSnapshotMapper<U>(genericTypeIndicator);
}
项目:showcase-android    文件:DataSnapshotMapper.java   
public GenericTypedDataSnapshotMapper(GenericTypeIndicator<U> genericTypeIndicator) {
   this.genericTypeIndicator = genericTypeIndicator;
}
项目:gogo    文件:MapsActivity.java   
private void showDistanceInBetween(int checkBusSelection) {

        /*Bundle extras = getIntent().getExtras();
        String userId = extras.getString("email");*/
                //String userId = email;
                //assert userId != null;
                //String[] temp = userId.split("@");
                //userId = temp[0];
                String BUS = "b" + checkBusSelection;
                mDatabase = FirebaseDatabase.getInstance().getReference();
                DatabaseReference userDatabase = mDatabase.child(USER).child(BUS);

                userDatabase.addValueEventListener(new ValueEventListener() {
                        //@RequiresApi(api = Build.VERSION_CODES.N)
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {

                                GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {
                                };
                                Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator);

                                Log.d(TAG, "Data : " + dataSnapshot.getValue());
                                Log.d(TAG, "My Location : " + mCurrentLocation.getLatitude() + ", " + mCurrentLocation.getLongitude());

                                String latitudeStr = map.get("latitude");
                                String longitudeStr = map.get("longitude");

                                Log.d(TAG, " Destination Latitude = " + latitudeStr);
                                Log.d(TAG, "Destination Longitude = " + longitudeStr);

                                double latitude = Double.parseDouble(latitudeStr);
                                double longitude = Double.parseDouble(longitudeStr);

                                // https://maps.googleapis.com/maps/api/directions/json?origin=Toronto&destination=Montreal
                                // &key=YOUR_API_KEY
                                if (mCurrentLocation != null) {
                                        String url = "https://maps.googleapis.com/maps/api/directions/json?origin="
                                                + mCurrentLocation.getLatitude() + "," + mCurrentLocation.getLongitude()
                                                + "&destination=" + latitudeStr + "," + longitudeStr + "&key=AIzaSyChXllnUaESuRZPDpSHtb3oyXgL1edHITg";// + R.string.google_direction_api_key;
                                        /*String url = "https://maps.googleapis.com/maps/api/directions/json?origin="
                                                + "40.81649,-73.907807&destination=40.819585,-73.90177"+ "&key=AIzaSyChXllnUaESuRZPDpSHtb3oyXgL1edHITg";// + R.string.google_direction_api_key;*/
                                         Log.d(TAG, "URL : " + url);
                                        DownloadTask downloadTask = new DownloadTask();

                                        // Start downloading json data from Google Directions API
                                        downloadTask.execute(url);
                                }

                                /*LatLng bus1_location = new LatLng(latitude,  longitude);
                                LatLng myLocation = new LatLng(mCurrentLocation.getLatitude(),  mCurrentLocation.getLongitude());
                                String DIFFERENCE = CalculationByDistance(myLocation, bus1_location);
                                String dist = DIFFERENCE + " Km";*/
                                //distance.setText(dist);
                /*TextView time = (TextView) findViewById(R.id.time);
                String theTime = latitudeStr + ", " +  longitudeStr;
                time.setText(theTime);*/

                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {

                        }
                });
                //return myClass.getLongitude();
        }
项目:Wallpapers-Android-Clean-Architecture    文件:CommentPresenter.java   
@Override public void loadData(Object... params) {
    final CommentsModule model = new CommentsModule();
    model.setPhotoId(Integer.valueOf(String.valueOf(params[0])));
    setModel(model);

    interactor.execute(new Observer<DataSnapshot>() {
        @Override public void onError(Throwable e) {
            if (getView() != null) {
                getView().onError(e.getMessage());
            }
        }

        @Override public void onComplete() {

        }

        @Override public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {

        }

        @Override public void onNext(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<Map<String, CommentsModel>> t =
                    new GenericTypeIndicator<Map<String, CommentsModel>>() {
                    };

            Map<String, CommentsModel> stringList = dataSnapshot.getValue(t);

            if (stringList != null && stringList.size() > 0) {
                List<CommentsModel> comments = new ArrayList<>(stringList.values());

                Collections.sort(comments, (t1, t2) -> t1.getDate().compareTo(t2.getDate()));

                model.setComments(comments);
            }

            if (getView() != null) {
                getView().onComplete(model);
            }
        }
    }, params[0]);
}
项目:RxFirebase2    文件:ObsTransformerOfGenericTypeIndicator.java   
public ObsTransformerOfGenericTypeIndicator(GenericTypeIndicator<T> indicator) {
  this.typeIndicator = indicator;
}
项目:RxFirebase2    文件:SingleTransformerOfGenericTypeIndicator.java   
public SingleTransformerOfGenericTypeIndicator(GenericTypeIndicator<T> indicator) {
  this.typeIndicator = indicator;
}
项目:RxFirebase2    文件:RxFirebaseDatabase.java   
/**
 * @see DatabaseReference#addValueEventListener(ValueEventListener)
 */
@NonNull @CheckResult public static <T> Observable<Optional<T>> dataChangesOf(
    @NonNull DatabaseReference ref, @NonNull GenericTypeIndicator<T> typeIndicator) {
  return dataChanges(ref).compose(new ObsTransformerOfGenericTypeIndicator<T>(typeIndicator));
}
项目:RxFirebase2    文件:RxFirebaseDatabase.java   
/**
 * @see DatabaseReference#addListenerForSingleValueEvent(ValueEventListener)
 */
@NonNull @CheckResult public static <T> Single<Optional<T>> dataOf(@NonNull DatabaseReference ref,
    @NonNull GenericTypeIndicator<T> typeIndicator) {
  return data(ref).compose(new SingleTransformerOfGenericTypeIndicator<T>(typeIndicator));
}
项目:RxFirebase2    文件:RxFirebaseDatabaseTest.java   
private <T> void callValueEventOnDataChange(GenericTypeIndicator<T> type, T value) {
  when(mockDataSnapshot.getValue(type)).thenReturn(value);

  valueEventListener.getValue().onDataChange(mockDataSnapshot);
}
项目:kcards    文件:PublicDeckListActivity.java   
private void retrieveDecksFromFirebaseDb(final String SORT_BY, final boolean reverseOrder) {
    deckListAdapter.clear();
    progressBar.setVisibility(View.VISIBLE);

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    DatabaseReference databaseReference = database.getReference(FirebaseDb.DECK_KEY);
    Query query = databaseReference.orderByChild(SORT_BY);
    if (reverseOrder) {
        query.limitToLast(MAX_DECKS);
    } else {
        query.limitToFirst(MAX_DECKS);
    }
    query.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            GenericTypeIndicator<Deck> t = new GenericTypeIndicator<Deck>() {
            };

            ArrayList<Deck> decks = new ArrayList<>();
            // iterate through the children to preserve order
            for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                Deck deck = snapshot.getValue(t);
                deck.setFirebaseKey(snapshot.getKey()); // firebase reference for tracking following status
                decks.add(deck);
            }

            // for ordering by timestamps, order by most recent
            if (reverseOrder) {
                Collections.reverse(decks);
            }

            deckListAdapter.setDeckList(decks);
            progressBar.setVisibility(View.GONE);
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Logger.w(TAG, "loadPost:onCancelled", databaseError.toException());
        }
    });
}
项目:HealthHelp    文件:AbstractDAO.java   
protected GenericTypeIndicator<T> getTipoEntidadeConstrucao() {
    return null;
}
项目:RxFirebase    文件:DataSnapshotMapper.java   
public static <U> DataSnapshotMapper<DataSnapshot, U> of(GenericTypeIndicator<U> genericTypeIndicator) {
    return new GenericTypedDataSnapshotMapper<U>(genericTypeIndicator);
}