Search in sources :

Example 71 with ValueEventListener

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());
        }
    }));
}
Also used : Party(se.zinokader.spotiq.model.Party) DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 72 with ValueEventListener

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);
}
Also used : User(com.teamplantpower.team_plant_power.User) DatabaseError(com.google.firebase.database.DatabaseError) Message(com.teamplantpower.team_plant_power.Message) TextView(android.widget.TextView) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView)

Example 73 with ValueEventListener

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());
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 74 with ValueEventListener

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());
        }
    });
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 75 with ValueEventListener

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 {
    }
}
Also used : DatabaseError(com.google.firebase.database.DatabaseError) NotificationManager(android.app.NotificationManager) NotificationCompat(android.support.v7.app.NotificationCompat) ValueEventListener(com.google.firebase.database.ValueEventListener) DataSnapshot(com.google.firebase.database.DataSnapshot)

Aggregations

DataSnapshot (com.google.firebase.database.DataSnapshot)211 ValueEventListener (com.google.firebase.database.ValueEventListener)211 DatabaseError (com.google.firebase.database.DatabaseError)210 DatabaseReference (com.google.firebase.database.DatabaseReference)62 View (android.view.View)47 Intent (android.content.Intent)43 TextView (android.widget.TextView)30 FirebaseDatabase (com.google.firebase.database.FirebaseDatabase)24 RecyclerView (android.support.v7.widget.RecyclerView)20 FirebaseUser (com.google.firebase.auth.FirebaseUser)20 HashMap (java.util.HashMap)20 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)19 Bundle (android.os.Bundle)16 ImageView (android.widget.ImageView)15 ArrayList (java.util.ArrayList)15 User (com.jexapps.bloodhub.m_Model.User)11 Map (java.util.Map)11 Date (java.util.Date)10 Query (com.google.firebase.database.Query)9 User (com.polito.mad17.madmax.entities.User)9