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

Added shared preferences for storage of values from settings

parent e60ce1e2
No related branches found
No related tags found
No related merge requests found
package com.example.pharmacy.frontEnd;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
......@@ -28,12 +30,20 @@ public class Settings extends AppCompatActivity{
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Get values and store them in a static? location
//Saved in shared preferences, add interger resource for default values to be used when obtaining from shared preferences.
boolean audio = findViewById(R.id.Audio).isActivated();
boolean vibration = findViewById(R.id.Vibration).isActivated();
boolean led = findViewById(R.id.LEDFlash).isActivated();
int notifyGap = findViewById(R.id.spinner).getTop();//???
String message = (findViewById(R.id.notificationMessage)).toString();
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);
editor.putBoolean(getString(R.string.vibration), vibration);
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.commit();
Intent intent = new Intent(view.getContext(), MainActivity.class);
displaySavedToast(view);
startActivity(intent);
......
......@@ -139,7 +139,7 @@
app:layout_constraintTop_toBottomOf="@+id/Vibration" />
<EditText
android:id="@+id/editText"
android:id="@+id/notificationMessage"
android:layout_width="346dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
......
......@@ -15,4 +15,5 @@
<string name="notf_text">Your personalised notification message here</string>
<string name="spinner_opt">Every 15 Minutes</string>
<string name="settings_saved">Settings saved!</string>
<string name="preference_file_key">com.example.sedbehav.not</string>
</resources>
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