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

More docs. Post hard drive failure.

parent de4539bf
No related branches found
No related tags found
No related merge requests found
......@@ -63,11 +63,13 @@ public class SedentaryNotification extends Notification {
builder.setSmallIcon(android.R.drawable.btn_star);
builder.setContentTitle(this.getClass().getSimpleName());
String notificationText =
preferences.getString(getString(R.string.daily_goal_text), getString(R.string.default_notification_message));
preferences.getString(getString(R.string.daily_goal_text),
getString(R.string.default_notification_message));
if (!(preferences.getBoolean(getString(R.string.goal_met), false))) {
notificationText = notificationText
+ " " + String.valueOf((preferences.getInt(getString(R.string.daily_goal_set), getResources().getInteger(R.integer.daily_goal_minutes)))
- (preferences.getInt(getString(R.string.daily_progress), 0)))
+ " " + String.valueOf((preferences.getInt(getString(R.string.daily_goal_set),
getResources().getInteger(R.integer.daily_goal_minutes)))
- (preferences.getInt(getString(R.string.daily_progress), 0)))
+ " minutes to reach your goal!";
}
builder.setContentText(notificationText);
......@@ -83,9 +85,12 @@ public class SedentaryNotification extends Notification {
}
if (preferences.getBoolean(getString(R.string.led), false)) {
builder.mNotification.flags |= android.app.Notification.FLAG_SHOW_LIGHTS;
builder.mNotification.ledARGB = Color.parseColor(preferences.getString(getString(R.string.led_colour), "RED"));
builder.mNotification.ledOnMS = (preferences.getInt(getString(R.string.led_period), 1)) * 1000;
builder.mNotification.ledOffMS = (preferences.getInt(getString(R.string.led_period), 1)) * 1000;
builder.mNotification.ledARGB = Color.parseColor
(preferences.getString(getString(R.string.led_colour), "RED"));
builder.mNotification.ledOnMS =
(preferences.getInt(getString(R.string.led_period), 1)) * 1000;
builder.mNotification.ledOffMS =
(preferences.getInt(getString(R.string.led_period), 1)) * 1000;
}
return builder;
......
......@@ -10,7 +10,6 @@ import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TimePicker;
......@@ -20,10 +19,24 @@ import java.io.File;
/**
* Created by Peter De Jonckheere on 16/02/2018.
* <p>
* The activity which is used to set the advanced, in depth, settings for the application. This
* activity contains more involved settings than the standard settings page and can be used by
* users to obtain further personalisation in certain features.
* </p>
*/
public class AdvancedSettings extends AppCompatActivity {
/**
* Called when the AdvancedSettings activity is started from somewhere else in the application.
* Sets up the layout using that which is defined in advanced_settings.xml and the delegates to
* further methods to set up the buttons and settings 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);
......@@ -32,22 +45,38 @@ public class AdvancedSettings extends AppCompatActivity {
retrieveSettings();
}
/**
* Called when the activity is stopped by the user or the OS to save the settings of this page.
*
* @see android.support.v7.app.AppCompatActivity
*/
@Override
protected void onStop(){
protected void onStop() {
super.onStop();
saveSharedPreferenceData();
}
private void retrieveSettings(){
SharedPreferences shared = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
((Spinner)findViewById(R.id.PeriodSpinner)).setSelection(shared.getInt(getString(R.string.led_period_pos), 0));
((Spinner)findViewById(R.id.ColourSpinner)).setSelection(shared.getInt(getString(R.string.led_colour_pos), 0));
((Spinner)findViewById(R.id.AccelSpinner)).setSelection(shared.getInt(getString(R.string.accel_sensitivity_pos), 0));
/**
* Gets the data stored in Shared Preferences which is required to initialise the page to a
* previous state.
*/
private void retrieveSettings() {
SharedPreferences shared =
this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
((Spinner) findViewById(R.id.PeriodSpinner))
.setSelection(shared.getInt(getString(R.string.led_period_pos), 0));
((Spinner) findViewById(R.id.ColourSpinner))
.setSelection(shared.getInt(getString(R.string.led_colour_pos), 0));
((Spinner) findViewById(R.id.AccelSpinner))
.setSelection(shared.getInt(getString(R.string.accel_sensitivity_pos), 0));
}
private void setUpButtons(){
ImageButton back = (ImageButton)findViewById(R.id.back);
/**
* Used to set up the background processes for ech of the buttons and spinners on this page.
*/
private void setUpButtons() {
//Adds the onClickListener for the button which navigates back to the standard settings page
ImageButton back = findViewById(R.id.back);
back.bringToFront();
back.setOnClickListener(new View.OnClickListener() {
@Override
......@@ -58,38 +87,54 @@ public class AdvancedSettings extends AppCompatActivity {
startActivity(intent);
}
});
//Defines the code which allows the data collcted to be uploaded via an intent which calls
//on another application to share the file. the file is a zip file created here containing
//the three data files stored throughout the application's use
Button upload = findViewById(R.id.upload);
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
File file = SaveFile.zipFiles(view.getContext());
Intent sendIntent = new Intent(Intent.ACTION_SEND);
if(file.exists() && (file != null)){
if (file.exists()) {
//The extras added to the intent to obtain the best possible options for sharing
//the zip file.
sendIntent.setType("notificationapp/zip");
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+file.getAbsolutePath()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT,"Sharing File...");
sendIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file://" + file.getAbsolutePath()));
sendIntent.putExtra(Intent.EXTRA_SUBJECT, "Sharing File...");
sendIntent.putExtra(Intent.EXTRA_TEXT, "Sharing File...");
startActivity(Intent.createChooser(sendIntent, "Share File"));
}
}
});
//Sets up the button which allows the user to take the post-user trial survey. As above this
//is done through an intent designed to open a web browser with the provided URL
Button survey = findViewById(R.id.survey);
survey.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent webIntent = new Intent(Intent.ACTION_VIEW);
webIntent.setData(Uri.parse(getString(R.string.survey_link)));
webIntent.setData(
Uri.parse(getString(R.string.survey_link)));
startActivity(webIntent);
}
});
//Sets the code for the button for the start of the do not disturb period which creates a
//time picker pop-up then stores the time chosen by the user in Shared Preferences
Button startTime = findViewById(R.id.startTime);
startTime.setOnClickListener(new View.OnClickListener(){
startTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final SharedPreferences shared = view.getContext().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
final SharedPreferences shared = view.getContext().
getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
int hour = shared.getInt(getString(R.string.dnd_shour), 23);
int minute = shared.getInt(getString(R.string.dnd_smin), 0);
TimePickerDialog dialog = new TimePickerDialog(view.getContext(), new TimePickerDialog.OnTimeSetListener() {
TimePickerDialog dialog =
new TimePickerDialog(view.getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selHour, int selMin) {
SharedPreferences.Editor editor = shared.edit();
......@@ -102,50 +147,84 @@ public class AdvancedSettings extends AppCompatActivity {
dialog.show();
}
});
//As above but for the end time
Button endTime = findViewById(R.id.endTime);
endTime.setOnClickListener(new View.OnClickListener(){
endTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final SharedPreferences shared = view.getContext().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
final SharedPreferences shared = view.getContext().
getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
int hour = shared.getInt(getString(R.string.dnd_ehour), 9);
int minute = shared.getInt(getString(R.string.dnd_emin), 0);
TimePickerDialog dialog = new TimePickerDialog(view.getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selHour, int selMin) {
SharedPreferences.Editor editor = shared.edit();
editor.putInt(getString(R.string.dnd_ehour), selHour);
editor.putInt(getString(R.string.dnd_emin), selMin);
editor.commit();
}
}, hour, minute, true);
TimePickerDialog dialog =
new TimePickerDialog(view.getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int selHour, int selMin) {
SharedPreferences.Editor editor = shared.edit();
editor.putInt(getString(R.string.dnd_ehour), selHour);
editor.putInt(getString(R.string.dnd_emin), selMin);
editor.commit();
}
}, hour, minute, true);
dialog.setTitle(getString(R.string.dnd_etitle));
dialog.show();
}
});
populateSpinner((Spinner)findViewById(R.id.PeriodSpinner), R.array.LED_periods);
populateSpinner((Spinner)findViewById(R.id.ColourSpinner), R.array.LED_colours);
populateSpinner((Spinner)findViewById(R.id.AccelSpinner), R.array.accel_sensitivities);
}
//Calls the populate spinner method for each spinner which adds the relevant data to each
//spinner
populateSpinner((Spinner) findViewById(R.id.PeriodSpinner), R.array.LED_periods);
populateSpinner((Spinner) findViewById(R.id.ColourSpinner), R.array.LED_colours);
populateSpinner((Spinner) findViewById(R.id.AccelSpinner), R.array.accel_sensitivities);
}
private void populateSpinner(Spinner spinner, int arrayID){
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, arrayID, android.R.layout.simple_spinner_dropdown_item);
/**
* Using the params provided fills the spinner with the desired data specififed by the arrayID.
*
* @param spinner the spinner which is to be populated with data
* @param arrayID the resource ID of the array which contains the data to be added to the
* spinner
*/
private void populateSpinner(Spinner spinner, int arrayID) {
ArrayAdapter<CharSequence> adapter =
ArrayAdapter.createFromResource(this, arrayID,
android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
private void displaySavedToast(View view){
Toast saved = Toast.makeText(view.getContext(), R.string.settings_saved,Toast.LENGTH_SHORT);
/**
* Displays a Toast object which informs the user that the information entered on this page has
* been stored.
*
* @param view the view object with which the Toast object is displayed within
*/
private void displaySavedToast(View view) {
Toast saved = Toast.makeText(view.getContext(), R.string.settings_saved, Toast.LENGTH_SHORT);
saved.show();
}
private void saveSharedPreferenceData(){
SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
int spinnerPPos = ((Spinner)findViewById(R.id.PeriodSpinner)).getSelectedItemPosition();
int notifyGap = Integer.parseInt(((Spinner)findViewById(R.id.PeriodSpinner)).getSelectedItem().toString());
int spinnerCPos = ((Spinner)findViewById(R.id.ColourSpinner)).getSelectedItemPosition();
String colour = ((Spinner)findViewById(R.id.ColourSpinner)).getSelectedItem().toString();
int spinnerAPos = ((Spinner)findViewById(R.id.AccelSpinner)).getSelectedItemPosition();
String sensitivity = ((Spinner)findViewById(R.id.AccelSpinner)).getSelectedItem().toString();
/**
* Stores the data of this page in the Shared Preferences whihc allows it to be used elsewhere
* in the program and also allows this page to be reconstructed in the correct form when it is
* returned to.
*/
private void saveSharedPreferenceData() {
SharedPreferences sharedPref =
this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
int spinnerPPos =
((Spinner) findViewById(R.id.PeriodSpinner)).getSelectedItemPosition();
int notifyGap = Integer.parseInt(
((Spinner) findViewById(R.id.PeriodSpinner)).getSelectedItem().toString());
int spinnerCPos =
((Spinner) findViewById(R.id.ColourSpinner)).getSelectedItemPosition();
String colour =
((Spinner) findViewById(R.id.ColourSpinner)).getSelectedItem().toString();
int spinnerAPos =
((Spinner) findViewById(R.id.AccelSpinner)).getSelectedItemPosition();
String sensitivity =
((Spinner) findViewById(R.id.AccelSpinner)).getSelectedItem().toString();
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.led_period_pos), spinnerPPos);
editor.putInt(getString(R.string.led_period), notifyGap);
......
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