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

Further shared preferences and beginning to modify notifications.

parent f5021edf
No related branches found
No related tags found
No related merge requests found
......@@ -8,10 +8,12 @@ import android.app.Service;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.support.v4.app.NotificationCompat;
import com.example.pharmacy.frontEnd.NotificationClicked;
import com.example.pharmacy.frontEnd.R;
/**
* Created by pharmacy on 09/01/2018.
......@@ -21,11 +23,13 @@ public abstract class Notification extends Service{
protected NotificationManager nm;
protected int snId = 0;
protected SharedPreferences preferences;
@Override
public void onCreate(){
nm = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
buildNotification();
preferences = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
}
protected void buildNotification(){
......
......@@ -9,6 +9,8 @@ import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import com.example.pharmacy.frontEnd.R;
/**
* Created by pharmacy on 09/01/2018.
......@@ -27,8 +29,8 @@ public class SedentaryNotification extends Notification {
protected NotificationCompat.Builder setParameters(NotificationCompat.Builder builder) {
//Get parameters from settings? or set strings?
builder.setSmallIcon(0);
builder.setContentTitle("");
builder.setContentText("");
builder.setContentTitle(this.getClass().getName());
builder.setContentText(preferences.getString(getString(R.string.daily_goal_text), getString(R.string.notf_text)));
return builder;
}
......
package com.example.pharmacy.frontEnd;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import com.example.stimulus.Stimulus;
import com.example.stimulus.SedentaryStimulus;
......@@ -32,6 +36,9 @@ 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);
progress.setMax((shared.getInt(getString(R.string.daily_goal_set), R.integer.daily_goal_minutes)));
}
private void setUpStimulus(){
......
......@@ -14,7 +14,10 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
......@@ -39,6 +42,8 @@ public class Settings extends AppCompatActivity{
((CheckBox)findViewById(R.id.LEDFlash)).setChecked(shared.getBoolean(getString(R.string.led), false));
((Spinner)findViewById(R.id.PeriodSpinner)).setSelection(shared.getInt(getString(R.string.daily_goal), R.integer.notify_period_minutes));
((EditText)findViewById(R.id.notificationMessage)).setText(shared.getString(getString(R.string.daily_goal_text), getString(R.string.notf_text)));
((SeekBar)findViewById(R.id.seekBar2)).setProgress(shared.getInt(getString(R.string.daily_goal_set), R.integer.daily_goal_minutes));
((Switch)findViewById(R.id.NotSwitch)).setChecked(shared.getBoolean(getString(R.string.notf_switch), true));
}
private void setUpButtons(){
......@@ -61,12 +66,6 @@ public class Settings extends AppCompatActivity{
private void populateSpinner(){
Spinner spinner = findViewById(R.id.PeriodSpinner);
// Resources r = this.getResources();
// String[] periods = r.getStringArray(R.array.notification_periods);
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, periods);
// ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
// android.R.layout.simple_spinner_item,
// android.R.id.text1, periods);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.notification_periods, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
......@@ -83,6 +82,8 @@ public class Settings extends AppCompatActivity{
boolean led = ((CheckBox)findViewById(R.id.LEDFlash)).isChecked();
int notifyGap = ((Spinner)findViewById(R.id.PeriodSpinner)).getSelectedItemPosition();//???
String message = ((EditText)findViewById(R.id.notificationMessage)).getText().toString();
int progress = ((SeekBar) findViewById(R.id.seekBar2)).getProgress();
boolean nswitch = ((Switch)findViewById(R.id.NotSwitch)).isChecked();
SharedPreferences sharedPref = view.getContext().getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putBoolean(getString(R.string.audio), audio);
......@@ -90,6 +91,8 @@ public class Settings extends AppCompatActivity{
editor.putBoolean(getString(R.string.led), led);
editor.putInt(getString(R.string.daily_goal), notifyGap);
editor.putString(getString(R.string.daily_goal_text), message);
editor.putInt(getString(R.string.daily_goal_set), progress);
editor.putBoolean(getString(R.string.notf_switch), nswitch);
editor.commit();
}
}
......@@ -3,7 +3,9 @@ package com.example.stimulus;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.example.pharmacy.frontEnd.R;
import com.example.stimulusStrategy.StimulusStrategy;
......@@ -45,6 +47,8 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
public void onReceive(Context context, Intent intent) {
//If a condition - such as time elapsed since last notification or not night time
//Intent data used here to configure notification?? Intent would need to be configured properly for this.
SharedPreferences shared = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
if(shared.getBoolean())
context.startService(intent);
//Restarts the chosen strategy process.
chooseStrategy(strategy);
......
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