Android Open Source - AndroIUT Preferences Manager






From Project

Back to project page AndroIUT.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroIUT listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.iutdijon.androiut2.util;
/* ww w  .  ja v  a2  s. c  o  m*/
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Classe permettant de stocker des informations pr?f?rentielles li?s ? l'utilisateur de mani?re persistante en m?moire
 * @author Morgan Funtowicz
 *
 */
public class PreferencesManager {
  private static PreferencesManager instance = null;
  private static SharedPreferences preferences = null;
  
  private static final String PREFS_NAME = "AndroIUT_prefs";
  
  public static final String REMEMBER_ME_OPTION = "remember_me";
  public static final String REMEMBER_ME_PASSWORD = "password";
  public static final String REMEMBER_ME_CHECKBOX_VAL = "rememberMeOpt";
  
  public PreferencesManager() {
    
  }
  /**
   * Initilialise et r?cup?re les ?ventuelles pr?f?rences sauvegard?es
   * @param c
   */
  public void init(Context c){
    preferences = c.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
  }
  
  /**
   * V?rifie que le gestionnaire de pr?f?rences est bien initiliser
   */
  public void checkPrefs(){
    if(preferences == null){
      throw new NullPointerException("Preferences Manager must be initialized by calling init() method");
    }
  }
  
  /**
   * R?cup?re la valeur d'une pr?f?rences si elle existe
   * @param entry L'identifiant de la pr?f?rance
   * @return Un boolean, si l'identifiant n'est pas trouv?, la fonction renvoie false
   */
  public boolean getBoolean(String entry){
    checkPrefs();
    return preferences.getBoolean(entry, false);
  }
  /**
   * Enregistre une pr?f?rence en m?moire
   * @param entry L'identifiant de la pr?f?rences
   * @param value La valeur a associ?e
   */
  public void setBoolean(String entry, boolean value){
    checkPrefs();
    preferences.edit().putBoolean(entry, value).commit();
  }
  
  /**
   * R?cup?re la valeur d'une pr?f?rences si elle existe
   * @param entry L'identifiant de la pr?f?r?nces 
   * @return Une chaine de caract?res, si l'identifiant n'est pas trouv?, la fonction renvoie "" 
   */
  public String getString(String entry){
    checkPrefs();
    return preferences.getString(entry, "");
  }
  /**
   * Enregistre une pr?f?rence en m?moire
   * @param entry L'identifiant de la pr?f?rences
   * @param value La valeur a associ?e
   */
  public void setString(String entry, String value){
    checkPrefs();
    preferences.edit().putString(entry, value).commit();
  }
  /**
   * R?cup?re la valeur d'une pr?f?rences si elle existe
   * @param entry L'identifiant de la pr?f?r?nces 
   * @return Une entier, si l'identifiant n'est pas trouv?, la fonction renvoie -1
   */
  public int getInt(String entry){
    checkPrefs();
    return preferences.getInt(entry, -1);
  }
  /**
   * Enregistre une pr?f?rence en m?moire
   * @param entry L'identifiant de la pr?f?rences
   * @param value La valeur a associ?e
   */
  public void setInt(String entry, int value){
    checkPrefs();
    preferences.edit().putInt(entry, value).commit();
  }
  
  /**
   * Singleton permettant d'acc?der ? l'instance
   * @return L'instance unique en m?moire
   */
  public static PreferencesManager getInstance(){
    if(instance == null){
      instance = new PreferencesManager();
    }
    return instance;
  }

}




Java Source Code List

.ADEResourcesDataTree.java
com.iutdijon.androiut2.ade.activities.ADEActivity.java
com.iutdijon.androiut2.ade.activities.ADEListResourcesChooser.java
com.iutdijon.androiut2.ade.activities.OnImageDownloadedCallback.java
com.iutdijon.androiut2.ade.service.ADEICalendarDownloader.java
com.iutdijon.androiut2.ftp.activities.FTPActivity.java
com.iutdijon.androiut2.ftp.adapters.FTPFileListAdapter.java
com.iutdijon.androiut2.ftp.data.FTPCommandResult.java
com.iutdijon.androiut2.ftp.data.FTPCommandWrapper.java
com.iutdijon.androiut2.ftp.data.FTPCommand.java
com.iutdijon.androiut2.ftp.services.FTPDownloadMonitor.java
com.iutdijon.androiut2.ftp.services.FTPServiceCall.java
com.iutdijon.androiut2.ftp.services.ProgressDownload.java
com.iutdijon.androiut2.global.AndroIUTApplication.java
com.iutdijon.androiut2.iut.activities.HomeActivity.java
com.iutdijon.androiut2.iut.activities.LoginActivity.java
com.iutdijon.androiut2.iut.data.Credential.java
com.iutdijon.androiut2.iut.data.UserFactory.java
com.iutdijon.androiut2.iut.data.account.StudentAccount.java
com.iutdijon.androiut2.iut.data.account.TeacherAccount.java
com.iutdijon.androiut2.iut.data.account.UserAccount.java
com.iutdijon.androiut2.iut.services.IUTLoginServiceCall.java
com.iutdijon.androiut2.mail.activities.MailActivity.java
com.iutdijon.androiut2.mail.activities.MailReaderActivity.java
com.iutdijon.androiut2.mail.adapters.MailDisplayAdapter.java
com.iutdijon.androiut2.mail.adapters.MailsListAdapter.java
com.iutdijon.androiut2.mail.services.EmailUtils.java
com.iutdijon.androiut2.mail.services.MailReader.java
com.iutdijon.androiut2.mail.services.MailService.java
com.iutdijon.androiut2.schooling.activities.SchoolingActivity.java
com.iutdijon.androiut2.schooling.activities.SchoolingTabActivity.java
com.iutdijon.androiut2.schooling.adapters.SectionedAdapter.java
com.iutdijon.androiut2.schooling.data.Absence.java
com.iutdijon.androiut2.schooling.data.Mark.java
com.iutdijon.androiut2.schooling.data.SchoolingData.java
com.iutdijon.androiut2.schooling.service.SchoolingDataServiceCall.java
com.iutdijon.androiut2.util.AndroIUTLogger.java
com.iutdijon.androiut2.util.IOUtils.java
com.iutdijon.androiut2.util.PreferencesManager.java
com.iutdijon.androiut2.util.UIUtil.java
com.iutdijon.androiut2.util.adapters.AbsencesAdapter.java
com.iutdijon.androiut2.util.adapters.BitmapAdapter.java
com.iutdijon.androiut2.util.adapters.CalendarAdapter.java
com.iutdijon.androiut2.util.adapters.IAdapter.java
com.iutdijon.androiut2.util.adapters.MarksAdapter.java
com.iutdijon.androiut2.util.adapters.UserAdapter.java
com.iutdijon.androiut2.util.adapters.XmlAdapter.java
com.iutdijon.androiut2.util.bridge.BridgeFinder.java
com.iutdijon.androiut2.util.loaders.AndroIUTHTTPConnection.java
com.iutdijon.androiut2.util.loaders.AsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.BitmapDownloaderTask.java
com.iutdijon.androiut2.util.loaders.GetAsyncServiceCall.java
com.iutdijon.androiut2.util.loaders.ImageDownloader.java
com.iutdijon.androiut2.util.loaders.PostAsyncServiceCall.java
com.iutdijon.androiut2.util.observers.Observable.java
com.iutdijon.androiut2.util.observers.Observer.java
com.iutdijon.androiut2.util.security.SecureCenter.java
com.iutdijon.androiut2.util.view.ImageZoomView.java
com.iutdijon.androiut2.util.zoom.AspectQuotient.java
com.iutdijon.androiut2.util.zoom.DynamicZoomControl.java
com.iutdijon.androiut2.util.zoom.LongPressZoomListener.java
com.iutdijon.androiut2.util.zoom.PinchZoomListener.java
com.iutdijon.androiut2.util.zoom.SimpleZoomListener.java
com.iutdijon.androiut2.util.zoom.ZoomState.java
com.iutdijon.androiut2.util.zoom.util.Dynamics.java
com.iutdijon.androiut2.util.zoom.util.SpringDynamics.java