Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022 – 144
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ganepola G.A.S.L IT19050386
2022 – 144
Commits
e0532784
Commit
e0532784
authored
Nov 18, 2022
by
Ravishani W.M.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
8eae2caf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
195 additions
and
0 deletions
+195
-0
LightTherapyF.java
LightTherapyF.java
+195
-0
No files found.
LightTherapyF.java
0 → 100644
View file @
e0532784
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment