Skip to content
Snippets Groups Projects
Commit d3556d7b authored by Peter Joseph De Jonckheere CESM2014's avatar Peter Joseph De Jonckheere CESM2014
Browse files

Docs. Regular commits due to hard drive failure.

parent 2f4c5197
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment