i renamed the project and package in prep for converting this project into a library.
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
/**
|
||||
* @author Twenty Codes
|
||||
* @author ricky barrette
|
||||
*/
|
||||
package com.TwentyCodes.android.SweetDreamsLib;
|
||||
|
||||
|
||||
import com.TwentyCodes.android.SweetSoundsLite.R;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
|
||||
/**
|
||||
* this is a settings activity for WhiteNoise. it handles user changeable settings and saves them
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class Settings extends PreferenceActivity implements OnPreferenceChangeListener {
|
||||
|
||||
//shared_prefs file name
|
||||
protected static final String SETTINGS = "settings";
|
||||
|
||||
//the following strings are for sound track selection
|
||||
protected static final String SOUNDS = "sounds";
|
||||
protected static final String SOUND_RIVER = "Rainy River";
|
||||
protected static final String SOUND_BEACH = "Beach";
|
||||
protected static final String SOUND_CRICKETS = "Crickets";
|
||||
protected static final String SOUND_FALLS = "Water Falls";
|
||||
protected static final String SOUND_AC = "Air Conditioner";
|
||||
|
||||
//the following strings are for saving volume level from the audiomanager.STREAM_MUSIC so we can restore them back when the app quits
|
||||
protected static final String MUSIC_VOLUME = "music_volume";
|
||||
|
||||
//the following strings are for timer preference
|
||||
protected static final String TIMER_ENABLED = "timer_enabled";
|
||||
protected static final String TIMER_LENGTH = "timer_length";
|
||||
protected static final String TIMER_EXIT_ON_FINISH = "timer_exit_on_finish";
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//set shared_prefs name
|
||||
getPreferenceManager().setSharedPreferencesName(SETTINGS);
|
||||
|
||||
//load preferences xml
|
||||
this.addPreferencesFromResource(R.xml.settings);
|
||||
|
||||
//get shared_prefs
|
||||
SharedPreferences settings = getPreferenceManager().getSharedPreferences();
|
||||
|
||||
/*
|
||||
* Initialize preference sound
|
||||
* set OnPreferenceChangeListener
|
||||
* and set summary to current settings
|
||||
*/
|
||||
Preference pSounds = findPreference(SOUNDS);
|
||||
pSounds.setOnPreferenceChangeListener(this);
|
||||
pSounds.setSummary(settings.getString(SOUNDS, SOUND_RIVER));
|
||||
|
||||
/*
|
||||
* Initialize preference timerLength
|
||||
* set OnPreferenceChangeListener
|
||||
* and set summary to current settings
|
||||
*/
|
||||
Preference timerLength = findPreference(TIMER_LENGTH);
|
||||
timerLength.setOnPreferenceChangeListener(this);
|
||||
try {
|
||||
timerLength.setSummary(settings.getInt(TIMER_LENGTH, 5));
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* called when a preference is changed
|
||||
* @param preference
|
||||
* @param newValue
|
||||
* @return
|
||||
* @author ricky barrette
|
||||
*/
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
preference.setSummary(newValue.toString());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user