use of com.google.firebase.database.ValueEventListener in project SpotiQ by ZinoKader.
the class PartiesRepository method isHostOfParty.
public Observable<Boolean> isHostOfParty(String partyTitle, String spotifyUserId) {
return Observable.create(subscriber -> databaseReference.child(partyTitle).child(FirebaseConstants.CHILD_PARTYINFO).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Party dbParty = dataSnapshot.getValue(Party.class);
boolean isHost = dbParty != null && dbParty.getHostSpotifyId().equals(spotifyUserId);
subscriber.onNext(isHost);
subscriber.onComplete();
}
@Override
public void onCancelled(DatabaseError databaseError) {
subscriber.onError(databaseError.toException());
}
}));
}
use of com.google.firebase.database.ValueEventListener in project Team-Plant-Power by Alexander1994.
the class MessageBoardActivity method onCreate.
/**
* Called on the creation of the Message Board activity, iniates login listener and display listener
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message_board);
enterInput = (EditText) findViewById(R.id.EnterName);
nameText = (TextView) findViewById(R.id.Name);
submit = (Button) findViewById(R.id.Submit);
// Load User if signed up
userDbRef.orderByKey().equalTo(User.getId(getApplicationContext())).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot != null && dataSnapshot.getValue() != null) {
String name = dataSnapshot.child(User.getId(getApplicationContext())).getValue(String.class);
u = new User(name);
nameText.setText(u.getName());
enterInput.setText("Enter Message");
loggedIn = true;
} else {
u = null;
nameText.setText(" ");
enterInput.setText("Enter Name");
loggedIn = false;
}
}
public void onCancelled(DatabaseError err) {
}
});
// Populate message list
messageListView = (ListView) findViewById(R.id.List);
// Set up the List View
firebaseAdapter = new FirebaseListAdapter<Message>(this, Message.class, android.R.layout.simple_list_item_1, messageDbRef) {
@Override
protected void populateView(View v, Message model, int position) {
TextView contactName = (TextView) v.findViewById(android.R.id.text1);
String dateStr = firebaseAdapter.getRef(position).getKey();
contactName.setText(model.getFullDisplayMessage(dateStr));
}
};
messageListView.setAdapter(firebaseAdapter);
}
use of com.google.firebase.database.ValueEventListener in project Team-Plant-Power by Alexander1994.
the class TemperatureDisplay method onCreate.
/**
* Run on activity open.
* @param savedInstanceState The app instance
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_temperature_display);
celciusValue = (TextView) findViewById(R.id.celciusValue);
farenheitValue = (TextView) findViewById(R.id.fahrenheitValue);
minimumValue = (EditText) findViewById(R.id.setMinTemp);
maximumValue = (EditText) findViewById(R.id.setMaxTemp);
// get range
firebaseReference = database.getReference("range/temperature");
firebaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
temperatureRange = dataSnapshot.getValue(Range.class);
minimumValue.setText("" + temperatureRange.getMinRange());
maximumValue.setText("" + temperatureRange.getMaxRange());
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
// get temperature
firebaseReference = database.getReference("currentTemperature");
firebaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
// remove any characters like letters or symbols
double temp = Double.parseDouble(value.replaceAll("[^\\d.]", ""));
temperatureUI.setCelciusValue(temp);
celciusValue.setText("" + temperatureUI.getCelciusValue());
farenheitValue.setText("" + temperatureUI.getFarenheitValue());
// must go here otherwise will check before data is in
checkInRange();
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
}
use of com.google.firebase.database.ValueEventListener in project Team-Plant-Power by Alexander1994.
the class HumidityDisplay method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_humidity_display);
humidityExposureValue = (TextView) findViewById(R.id.humidityExposureValue);
minimumValue = (EditText) findViewById(R.id.setMinHumidity);
maximumValue = (EditText) findViewById(R.id.setMaxHumidity);
// get range
firebaseReference = database.getReference("range/humidity");
firebaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
humidityRange = dataSnapshot.getValue(Range.class);
minimumValue.setText("" + humidityRange.getMinRange());
maximumValue.setText("" + humidityRange.getMaxRange());
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
// get humidity
firebaseReference = database.getReference("currentHumidity");
firebaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
// remove any characters like letters or symbols
double humidityx = Double.parseDouble(value.replaceAll("[^\\d.]", ""));
humidityUI.setPercentHumidity(humidityx);
humidityExposureValue.setText("" + humidityUI.getPercentHumidity());
// must go here otherwise will check before data is in
checkInRange();
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
}
use of com.google.firebase.database.ValueEventListener in project Team-Plant-Power by Alexander1994.
the class MyServiceNotification method TempNotification.
// notification TEMPERATURE
public void TempNotification() {
// get range
firebaseReference = database.getReference("range/temperature");
firebaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
temperatureRange = dataSnapshot.getValue(Range.class);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
// get temperature
firebaseReference = database.getReference("currentTemperature");
firebaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
String value = dataSnapshot.getValue(String.class);
// remove any characters like letters or symbols
double temp = Double.parseDouble(value.replaceAll("[^\\d.]", ""));
temperatureUI.setCelciusValue(temp);
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
// Log.w(TAG, "Failed to read value.", error.toException());
}
});
if (temperatureRange.isRangeSet() && !temperatureRange.isInRange(temperatureUI.getCelciusValue())) {
;
android.support.v4.app.NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(thermometer).setContentTitle("warning").setContentText("Temperature out of Range " + temperatureUI.getCelciusValue());
// Sets an ID for the notification
int mNotificationId = 001;
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
mNotifyMgr.notify(mNotificationId, mBuilder.build());
} else {
}
}
Aggregations