Skip to content
Snippets Groups Projects
Settings.java 8.53 KiB
package com.notificationFramework.sedentary.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;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Peter De Jonckheere on 21/11/2017.
 * <p>
 * Contains the buttons and menus which set a variety of user defined data which is used throughout
 * the application. Settings are saved either when the activity is stopped or when navigation is
 * made back to the main activity page.
 * </p>
 */

public class Settings extends AppCompatActivity {

    /**
     * Called when the Settings activity is navigated to from the main activity.Sets up the layout
     * using that which is defined in settings.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);
        setContentView(R.layout.settings);
        setUpButtons();
        retrieveSettings();
    }

    /**
     * Saves the settings of this page to the Shared Preferences if the activity is stopped.
     *
     * @see android.support.v7.app.AppCompatActivity
     */
    @Override
    protected void onStop() {
        super.onStop();
        saveSharedPreferenceData();
    }

    /**
     * Obtains settings which have been previously stored in Shared Preferences and initialise the
     * page with these values.
     */
    private void retrieveSettings() {
        SharedPreferences shared =
                this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
        ((CheckBox) findViewById(R.id.Audio)).setChecked(shared.getBoolean(getString(R.string.audio), false));
        ((CheckBox) findViewById(R.id.Vibration)).
                setChecked(shared.getBoolean(getString(R.string.vibration), false));
        ((CheckBox) findViewById(R.id.LEDFlash)).