Commit e0532784 authored by Ravishani W.M.S's avatar Ravishani W.M.S

Upload New File

parent 8eae2caf
package com.example.smartpillow;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.widget.Button;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.text.DecimalFormat;
public class LightTherapyF extends AppCompatActivity{
Button btnv1,btnv2,btnv3,btnv4,btnv5,btnv6;
int automaticvalue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_light_therapy_f);
btnv1 = findViewById(R.id.BtnV1);
btnv2 = findViewById(R.id.BtnV2);
btnv3 = findViewById(R.id.BtnV3);
btnv4 = findViewById(R.id.BtnV4);
btnv5 = findViewById(R.id.BtnV5);
btnv6 = findViewById(R.id.BtnV6);
getData();
}
public void getData()
{
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
automaticvalue = dataSnapshot.child("Automatic").getValue(int.class);
btnv2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnv2.setBackgroundColor(Color.RED);
btnv1.setBackgroundColor(Color.GRAY);
btnv3.setBackgroundColor(Color.BLUE);
btnv4.setBackgroundColor(Color.GREEN);
btnv5.setBackgroundColor(Color.YELLOW);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("Automatic").setValue(0);
myRef.child("ledStO1").setValue(1);
myRef.child("ledStO2").setValue(0);
myRef.child("ledStO3").setValue(0);
}
});
btnv1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnv2.setBackgroundColor(Color.GRAY);
btnv1.setBackgroundColor(Color.GREEN);
btnv3.setBackgroundColor(Color.GRAY);
btnv4.setBackgroundColor(Color.GRAY);
btnv5.setBackgroundColor(Color.GRAY);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("Automatic").setValue(1);
myRef.child("ledStO1").setValue(0);
myRef.child("ledStO2").setValue(0);
myRef.child("ledStO3").setValue(0);
}
});
if (automaticvalue == 1){
btnv3.setBackgroundColor(Color.GRAY);
btnv4.setBackgroundColor(Color.GRAY);
btnv5.setBackgroundColor(Color.GRAY);
btnv1.setBackgroundColor(Color.GREEN);
btnv2.setBackgroundColor(Color.GRAY);
btnv6.setBackgroundColor(Color.RED);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("ledStO1").setValue(0);
myRef.child("ledStO2").setValue(0);
myRef.child("ledStO3").setValue(0);
}
else if (automaticvalue == 0)
{
btnv3.setBackgroundColor(Color.BLUE);
btnv4.setBackgroundColor(Color.GREEN);
btnv5.setBackgroundColor(Color.YELLOW);
btnv2.setBackgroundColor(Color.RED);
btnv1.setBackgroundColor(Color.GRAY);
btnv6.setBackgroundColor(Color.RED);
btnv3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnv3.setBackgroundColor(Color.BLUE);
btnv4.setBackgroundColor(Color.GREEN);
btnv5.setBackgroundColor(Color.YELLOW);
btnv6.setBackgroundColor(Color.RED);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("ledStO1").setValue(1);
myRef.child("ledStO2").setValue(0);
myRef.child("ledStO3").setValue(0);
}
});
btnv4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnv3.setBackgroundColor(Color.BLUE);
btnv4.setBackgroundColor(Color.GREEN);
btnv5.setBackgroundColor(Color.YELLOW);
btnv6.setBackgroundColor(Color.RED);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("ledStO1").setValue(0);
myRef.child("ledStO2").setValue(1);
myRef.child("ledStO3").setValue(0);
}
});
btnv5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnv3.setBackgroundColor(Color.BLUE);
btnv4.setBackgroundColor(Color.GREEN);
btnv5.setBackgroundColor(Color.YELLOW);
btnv6.setBackgroundColor(Color.RED);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("ledStO1").setValue(0);
myRef.child("ledStO2").setValue(0);
myRef.child("ledStO3").setValue(1);
}
});
}
else
{
btnv1.setBackgroundColor(Color.GRAY);
btnv2.setBackgroundColor(Color.GRAY);
btnv3.setBackgroundColor(Color.GRAY);
btnv4.setBackgroundColor(Color.GRAY);
btnv5.setBackgroundColor(Color.GRAY);
btnv6.setBackgroundColor(Color.RED);
}
btnv6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btnv1.setBackgroundColor(Color.GRAY);
btnv2.setBackgroundColor(Color.GRAY);
btnv3.setBackgroundColor(Color.GRAY);
btnv4.setBackgroundColor(Color.GRAY);
btnv5.setBackgroundColor(Color.GRAY);
btnv6.setBackgroundColor(Color.RED);
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("LedStatus");
myRef.child("Automatic").setValue(3);
myRef.child("ledStO1").setValue(3);
myRef.child("ledStO2").setValue(3);
myRef.child("ledStO3").setValue(3);
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment