Android Open Source - android-simple-storage Simple Storage






From Project

Back to project page android-simple-storage.

License

The source code is released under:

Apache License

If you think the Android project android-simple-storage 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.sromku.simple.storage;
//  ww  w. j  av  a 2 s . c  om
import android.content.Context;

/**
 * Singleton class that supply all possible storage options.<br>
 * <br>
 * <b>Permissions:</b>
 * <ul>
 * <li>android.permission.WRITE_EXTERNAL_STORAGE</li>
 * <li>android.permission.READ_EXTERNAL_STORAGE</li>
 * </ul>
 * 
 * @author Roman Kushnarenko - sromku (sromku@gmail.com)
 */
public class SimpleStorage {

  private static InternalStorage mInternalStorage = null;
  private static ExternalStorage mExternalStorage = null;

  private static SimpleStorage mInstance = null;
  private static SimpleStorageConfiguration mSimpleStorageConfiguration;

  private SimpleStorage() {
    // set default configuration
    mSimpleStorageConfiguration = new SimpleStorageConfiguration.Builder().build();

    mInternalStorage = new InternalStorage();
    mExternalStorage = new ExternalStorage();
  }

  private static SimpleStorage init() {
    if (mInstance == null) {
      mInstance = new SimpleStorage();
    }
    return mInstance;
  }

  /**
   * The type of the storage. <br>
   * Possible options:
   * <ul>
   * <li>{@link StorageType#INTERNAL}</li>
   * <li>{@link StorageType#EXTERNAL}</li>
   * </ul>
   * 
   * @author sromku
   * 
   */
  public enum StorageType {
    INTERNAL,
    EXTERNAL
  }

  /**
   * Get internal storage. The files and folders will be persisted on device
   * memory. The internal storage is good for saving <b>private and secure</b>
   * data.<br>
   * <br>
   * <b>Important:
   * <ul>
   * <li>When the device is low on internal storage space, Android may delete
   * these cache files to recover space.</li>
   * <li>You should always maintain the cache files yourself and stay within a
   * reasonable limit of space consumed, such as 1MB.</li>
   * <li>When the user uninstalls your application, these files are removed.</li>
   * </b>
   * </ul>
   * <i>http://developer.android.com/guide/topics/data/data-storage.html#
   * filesInternal</i>
   * 
   * @return {@link InternalStorage}
   * 
   */
  public static InternalStorage getInternalStorage(Context context) {
    init();
    mInternalStorage.initActivity(context);
    return mInternalStorage;
  }

  /**
   * Get external storage. <br>
   * 
   * @return {@link ExternalStorage}
   */
  public static ExternalStorage getExternalStorage() {
    init();
    return mExternalStorage;
  }

  /**
   * Check whereas the external storage is writable. <br>
   * 
   * @return <code>True</code> if external storage writable, otherwise return
   *         <code>False</code>
   */
  public static boolean isExternalStorageWritable() {
    init();
    return mExternalStorage.isWritable();
  }

  public static SimpleStorageConfiguration getConfiguration() {
    return mSimpleStorageConfiguration;
  }

  /**
   * Set and update the storage configuration
   * 
   * @param configuration
   */
  public static void updateConfiguration(SimpleStorageConfiguration configuration) {
    if (mInstance == null) {
      throw new RuntimeException("First instantiate the Storage and then you can update the configuration");
    }
    mSimpleStorageConfiguration = configuration;
  }

  /**
   * Set the configuration to default
   */
  public static void resetConfiguration() {
    SimpleStorageConfiguration configuration = new SimpleStorageConfiguration.Builder().build();
    mSimpleStorageConfiguration = configuration;
  }

}




Java Source Code List

com.sromku.simple.storage.AbstractDiskStorage.java
com.sromku.simple.storage.ExternalStorage.java
com.sromku.simple.storage.InternalStorage.java
com.sromku.simple.storage.SimpleStorageConfiguration.java
com.sromku.simple.storage.SimpleStorage.java
com.sromku.simple.storage.Storable.java
com.sromku.simple.storage.StorageException.java
com.sromku.simple.storage.Storage.java
com.sromku.simple.storage.helpers.ImmutablePair.java
com.sromku.simple.storage.helpers.OrderType.java
com.sromku.simple.storage.helpers.SizeUnit.java
com.sromku.simple.storage.security.CipherAlgorithmType.java
com.sromku.simple.storage.security.CipherModeType.java
com.sromku.simple.storage.security.CipherPaddingType.java
com.sromku.simple.storage.security.CipherTransformationType.java
com.sromku.simple.storage.security.SecurityUtil.java