Android Open Source - PicSync Preferences






From Project

Back to project page PicSync.

License

The source code is released under:

Apache License

If you think the Android project PicSync 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.darrenmowat.gdcu.data;
//from   ww  w .j  a va2 s .c o m
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

import com.darrenmowat.gdcu.R;
import com.darrenmowat.gdcu.utils.Preconditions;

public class Preferences {

  public final static String EMAIL = "email";
  public final static String UPLOADS_FOLDER = "uploads_folder";
  public final static String UPLOADS_FOLDER_NAME = "uploads_folder_name";

  private static SharedPreferences getSharedPreferences(Context context) {
    Preconditions.checkNotNull(context, "Context passed into Preferences is null");
    return PreferenceManager.getDefaultSharedPreferences(context);
  }

  public static String getEmail(Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    return sp.getString(EMAIL, null);
  }

  public static void storeEmail(Context context, String email) {
    SharedPreferences sp = getSharedPreferences(context);
    Editor editor = sp.edit();
    if (email == null) {
      editor.remove(EMAIL);
    } else {
      editor.putString(EMAIL, email);
    }
    editor.commit();
  }

  public static String getUploadsFolderName(Context context) {
    SharedPreferences sp = getSharedPreferences(context);
    String def = context.getString(R.string.uploads_folder_name);
    String uploadsFolderName = sp.getString(UPLOADS_FOLDER_NAME, def);
    // If stored vaule is empty, return default
    if(uploadsFolderName == null || uploadsFolderName.trim().equals("")) {
      storeUploadsFolderName(context, null);
      return def;
    }
    // If stored value isnt valid, return default
    if(uploadsFolderName.contains("/")) {
      storeUploadsFolderName(context, null);
      return def;
    }
    return uploadsFolderName;
  }

  public static void storeUploadsFolderName(Context context, String uploadsFolderName) {
    SharedPreferences sp = getSharedPreferences(context);
    Editor editor = sp.edit();
    if (uploadsFolderName == null) {
      editor.remove(UPLOADS_FOLDER_NAME);
    } else {
      editor.putString(UPLOADS_FOLDER_NAME, uploadsFolderName);
    }
    editor.commit();
  }

  public static void clearPreferences(Context context) {
    Preferences.storeEmail(context, null);
    Preferences.storeUploadsFolderName(context, null);
  }

}




Java Source Code List

com.darrenmowat.gdcu.GDCU.java
com.darrenmowat.gdcu.Keys.java
com.darrenmowat.gdcu.activity.AuthActivity.java
com.darrenmowat.gdcu.activity.RenameFolderActivity.java
com.darrenmowat.gdcu.activity.SettingsActivity.java
com.darrenmowat.gdcu.activity.WebviewActivity.java
com.darrenmowat.gdcu.data.Database.java
com.darrenmowat.gdcu.data.Preferences.java
com.darrenmowat.gdcu.drive.DriveApi.java
com.darrenmowat.gdcu.otto.DataBus.java
com.darrenmowat.gdcu.otto.UploadStatusEventProducer.java
com.darrenmowat.gdcu.otto.UploadStatusEvent.java
com.darrenmowat.gdcu.security.PackageSecurityException.java
com.darrenmowat.gdcu.security.PackageSecurity.java
com.darrenmowat.gdcu.service.GalleryAlarmListener.java
com.darrenmowat.gdcu.service.GalleryObserver.java
com.darrenmowat.gdcu.service.MediaService.java
com.darrenmowat.gdcu.service.MediaThread.java
com.darrenmowat.gdcu.service.Notifier.java
com.darrenmowat.gdcu.service.ServiceUtils.java
com.darrenmowat.gdcu.service.UploadService.java
com.darrenmowat.gdcu.service.UploadThread.java
com.darrenmowat.gdcu.service.helpers.CloudSyncer.java
com.darrenmowat.gdcu.service.helpers.Media.java
com.darrenmowat.gdcu.service.helpers.ServiceIntents.java
com.darrenmowat.gdcu.service.helpers.ThreadCallbacks.java
com.darrenmowat.gdcu.tasks.GetTokenTask.java
com.darrenmowat.gdcu.tasks.RenameFolderTask.java
com.darrenmowat.gdcu.ui.ProgressDialogFragment.java
com.darrenmowat.gdcu.utils.HexConversions.java
com.darrenmowat.gdcu.utils.MD5Utils.java
com.darrenmowat.gdcu.utils.Preconditions.java