Posted By

on 03/29/10


Tagged


Versions (?)

Sudoku (Prefs.java)


 / Published in: Java
 

from "Hello Android 2nd Edition" (ISBN: 1-934356-49-2)

  1. package org.example.sudoku;
  2.  
  3. import android.os.Bundle;
  4. import android.preference.PreferenceActivity;
  5. import android.preference.PreferenceManager;
  6. import android.content.Context;
  7.  
  8. public class Prefs extends PreferenceActivity {
  9. // Option names and default values
  10. private static final String OPT_MUSIC = "music";
  11. private static final boolean OPT_MUSIC_DEF = true;
  12. private static final String OPT_HINTS = "hints";
  13. private static final boolean OPT_HINTS_DEF = true;
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. addPreferencesFromResource(R.xml.settings);
  19. }
  20.  
  21. /** Get the current value of the music option */
  22. public static boolean getMusic(Context context) {
  23. return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(OPT_MUSIC, OPT_MUSIC_DEF);
  24. }
  25.  
  26. /** Get the current value of the hints option */
  27. public static boolean getHints(Context context) {
  28. return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(OPT_HINTS, OPT_HINTS_DEF);
  29. }
  30. }

Report this snippet  

You need to login to post a comment.