Newer
Older
package com.notificationFramework.sedentary.frontEnd;

Peter Joseph De Jonckheere CESM2014
committed

Peter Joseph De Jonckheere CESM2014
committed
import android.app.ActivityManager;

Peter Joseph De Jonckheere CESM2014
committed
import android.content.Context;

Peter Joseph De Jonckheere CESM2014
committed
import android.content.Intent;

Peter Joseph De Jonckheere CESM2014
committed
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorManager;

Peter Joseph De Jonckheere CESM2014
committed
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

Peter Joseph De Jonckheere CESM2014
committed
import android.view.View;
import android.widget.Button;

Peter Joseph De Jonckheere CESM2014
committed
import android.widget.ProgressBar;

Peter Joseph De Jonckheere CESM2014
committed
import com.notificationFramework.stimulus.Stimulus;
import com.notificationFramework.stimulus.SedentaryStimulus;
import com.notificationFramework.stimulusStrategy.Accelerometer;
import com.notificationFramework.stimulusStrategy.SigMotionDetect;

Peter Joseph De Jonckheere CESM2014
committed
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Peter Joseph De Jonckheere CESM2014
committed
setUpButtons();
}
@Override
protected void onStart(){
super.onStart();

Peter Joseph De Jonckheere CESM2014
committed
}

Peter Joseph De Jonckheere CESM2014
committed
@Override
protected void onStop(){
super.onStop();
}

Peter Joseph De Jonckheere CESM2014
committed
private void setUpButtons(){
Button settings = (Button)findViewById(R.id.settings);
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), Settings.class);
startActivity(intent);
}
});

Peter Joseph De Jonckheere CESM2014
committed
SharedPreferences shared = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar);
progress.setMax((shared.getInt(getString(R.string.daily_goal_set), R.integer.daily_goal_minutes)));

Peter Joseph De Jonckheere CESM2014
committed
progress.setProgress(shared.getInt(getString(R.string.daily_progress), 0));

Peter Joseph De Jonckheere CESM2014
committed
}
private void setUpStimulus(){
if(!(isServiceRunning(com.notificationFramework.stimulusStrategy.Accelerometer.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());
}
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;
}
}
return false;
}