Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SedentaryBehaviourApplication
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Joseph De Jonckheere CESM2014
SedentaryBehaviourApplication
Commits
d3556d7b
Commit
d3556d7b
authored
6 years ago
by
Peter Joseph De Jonckheere CESM2014
Browse files
Options
Downloads
Patches
Plain Diff
Docs. Regular commits due to hard drive failure.
parent
2f4c5197
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/notificationFramework/sedentary/frontEnd/MainActivity.java
+68
-32
68 additions, 32 deletions
...otificationFramework/sedentary/frontEnd/MainActivity.java
with
68 additions
and
32 deletions
src/main/java/com/notificationFramework/sedentary/frontEnd/MainActivity.java
+
68
−
32
View file @
d3556d7b
...
...
@@ -7,28 +7,39 @@ import android.content.Intent;
import
android.content.SharedPreferences
;
import
android.hardware.Sensor
;
import
android.hardware.SensorManager
;
import
android.support.v7.app.AppCompatActivity
;
import
android.os.Bundle
;
import
android.
util.Log
;
import
android.
support.v7.app.AppCompatActivity
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ProgressBar
;
import
com.notificationFramework.stimulus.Stimulus
;
import
com.notificationFramework.stimulus.SedentaryStimulus
;
import
com.notificationFramework.stimulus.Stimulus
;
import
com.notificationFramework.stimulusStrategy.Accelerometer
;
import
com.notificationFramework.stimulusStrategy.SigMotionDetect
;
/**
* Created by Peter De Jonckheere 21/11/2017
*
*
<p>
* Main activity is the front page of the application and also creates the stimulus with the chosen
* strategy. It allows navigation to settings and displays the user's daily progress in minutes and
* also has text boxes available to display a daily goal.
* strategy. It allows navigation to settings and displays the user's daily progress in minutes in
* the progress bar. There is currently (26/3/18) also a placeholder for a logo in the centre of
* the page.
* </p>
*/
public
class
MainActivity
extends
AppCompatActivity
{
/**
* Called when the MainActivity activity is started from somewhere else in the application, or
* the manifest file on startup. Sets up the layout using that which is defined in
* activity_main.xml and the delegates to further methods to set up the buttons for the page.
*
* @param savedInstanceState contains information pertaining to previous states of the activity
* if it has been used before
* @see android.support.v7.app.AppCompatActivity
*/
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -36,20 +47,21 @@ public class MainActivity extends AppCompatActivity {
setUpButtons
();
}
/**
* Used to ensure a stimulus object is created when the activity is restarted rather than
* created for the first time.
*/
@Override
protected
void
onStart
(){
protected
void
onStart
()
{
super
.
onStart
();
setUpStimulus
();
}
@Override
protected
void
onStop
(){
super
.
onStop
();
}
private
void
setUpButtons
(){
Button
settings
=
(
Button
)
findViewById
(
R
.
id
.
settings
);
/**
* Sets up the buttons for this page and also adds the current minute value to the progress bar.
*/
private
void
setUpButtons
()
{
Button
settings
=
findViewById
(
R
.
id
.
settings
);
settings
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
...
...
@@ -57,33 +69,57 @@ public class MainActivity extends AppCompatActivity {
startActivity
(
intent
);
}
});
SharedPreferences
shared
=
this
.
getSharedPreferences
(
getString
(
R
.
string
.
preference_file_key
),
Context
.
MODE_PRIVATE
);
ProgressBar
progress
=
(
ProgressBar
)
findViewById
(
R
.
id
.
progressBar
);
SharedPreferences
shared
=
this
.
getSharedPreferences
(
getString
(
R
.
string
.
preference_file_key
),
Context
.
MODE_PRIVATE
);
ProgressBar
progress
=
findViewById
(
R
.
id
.
progressBar
);
progress
.
setMax
((
shared
.
getInt
(
getString
(
R
.
string
.
daily_goal_set
),
R
.
integer
.
daily_goal_minutes
)));
progress
.
setProgress
(
shared
.
getInt
(
getString
(
R
.
string
.
daily_progress
),
0
));
}
private
void
setUpStimulus
(){
if
(!(
isServiceRunning
(
com
.
notificationFramework
.
stimulusStrategy
.
Accelerometer
.
class
))
&&
!(
isServiceRunning
(
com
.
notificationFramework
.
stimulusStrategy
.
SigMotionDetect
.
class
)))
{
SensorManager
sm
=
(
SensorManager
)
getSystemService
(
Context
.
SENSOR_SERVICE
);
/* if (sm.getDefaultSensor(Sensor.TYPE_STEP_COUNTER) != null){
Stimulus stimulus = new SedentaryStimulus(this, new SigMotionDetect());
} else {
Stimulus stimulus = new SedentaryStimulus(this, new Accelerometer());
}*/
Stimulus
stimulus
=
new
SedentaryStimulus
(
this
,
new
Accelerometer
());
/**
* Creates the stimulus object which initiates the background processes of the application. Uses
* the strategy here to begin monitoring sedentary behaviour. This strategy is currently
* selected based on the hardware available on the device.
*/
private
void
setUpStimulus
()
{
if
(!(
isServiceRunning
(
com
.
notificationFramework
.
stimulusStrategy
.
Accelerometer
.
class
))
&&
!(
isServiceRunning
(
com
.
notificationFramework
.
stimulusStrategy
.
SigMotionDetect
.
class
)))
{
SensorManager
sm
=
(
SensorManager
)
getSystemService
(
Context
.
SENSOR_SERVICE
);
try
{
if
(
sm
.
getDefaultSensor
(
Sensor
.
TYPE_STEP_COUNTER
)
!=
null
&&
sm
.
getDefaultSensor
(
Sensor
.
TYPE_SIGNIFICANT_MOTION
)
!=
null
)
{
Stimulus
stimulus
=
new
SedentaryStimulus
(
this
,
new
SigMotionDetect
());
}
else
{
Stimulus
stimulus
=
new
SedentaryStimulus
(
this
,
new
Accelerometer
());
}
}
catch
(
NullPointerException
e
)
{
Stimulus
stimulus
=
new
SedentaryStimulus
(
this
,
new
Accelerometer
());
}
}
}
/**
* Checks the currently running services to establish if the chosen straegy is already running
* on the deivce as a service.
*
* @param serviceClass the name of the class to be checked as a running service
* @return true if 'servoiceClass' is running, otheriwse false
*/
private
boolean
isServiceRunning
(
Class
<?>
serviceClass
)
{
ActivityManager
manager
=
(
ActivityManager
)
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
for
(
ActivityManager
.
RunningServiceInfo
service
:
manager
.
getRunningServices
(
Integer
.
MAX_VALUE
))
{
if
(
serviceClass
.
getName
().
equals
(
service
.
service
.
getClassName
()))
{
return
true
;
try
{
for
(
ActivityManager
.
RunningServiceInfo
service
:
manager
.
getRunningServices
(
Integer
.
MAX_VALUE
))
{
if
(
serviceClass
.
getName
().
equals
(
service
.
service
.
getClassName
()))
{
return
true
;
}
}
return
false
;
}
catch
(
NullPointerException
e
)
{
return
false
;
}
return
false
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment