com.ryanm.preflect
Class Persist

java.lang.Object
  extended by com.ryanm.preflect.Persist

public class Persist
extends java.lang.Object

Allows storage of configurations. Configurations are JSON-encoded and placed in a SharedPreferences

Author:
ryanm

Method Summary
static void delete(Activity owner, java.lang.String savename)
          Deletes a saved configuration
static java.lang.String[] listSaves(Activity owner)
          Lists saved configurations
static void load(Activity owner, java.lang.String savename, java.lang.Object... roots)
          Loads and applies a saved configuration.
static boolean onActivityResult(int requestCode, int resultCode, Intent data, Activity owner, java.lang.String autoSaveName, java.lang.Object... configTargets)
          Call this from your activity in Activity .onActivityResult() as an alternative to Preflect.onActivityResult(int, int, Intent, Object...) to apply a configuration and to automatically save the configuration
static void save(Activity owner, java.lang.String savename, java.lang.Object... roots)
          Saves the configuration of an object tree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

onActivityResult

public static boolean onActivityResult(int requestCode,
                                       int resultCode,
                                       Intent data,
                                       Activity owner,
                                       java.lang.String autoSaveName,
                                       java.lang.Object... configTargets)
Call this from your activity in Activity .onActivityResult() as an alternative to Preflect.onActivityResult(int, int, Intent, Object...) to apply a configuration and to automatically save the configuration

Parameters:
requestCode - from Activity.onActivityResult()
resultCode - from Activity.onActivityResult()
data - from Activity.onActivityResult()
owner - The Activity that will own the saved configuration
autoSaveName - The name of the saved configuration
configTargets - roots of the object trees to apply configurations to
Returns:
true if the configuration was applied, false otherwise

save

public static void save(Activity owner,
                        java.lang.String savename,
                        java.lang.Object... roots)
Saves the configuration of an object tree

Parameters:
owner - The activity that owns the data
savename - The name of the saved data
roots - The objects whose configuration to save

load

public static void load(Activity owner,
                        java.lang.String savename,
                        java.lang.Object... roots)
Loads and applies a saved configuration. If there's a problem in loading or parsing the save it is deleted.

Parameters:
owner - The activity that owns the data
savename - The name of the saved data
roots - The objects to apply the configuration to

delete

public static void delete(Activity owner,
                          java.lang.String savename)
Deletes a saved configuration

Parameters:
owner - The activity that owns the data
savename - The name of the save to delete

listSaves

public static java.lang.String[] listSaves(Activity owner)
Lists saved configurations

Parameters:
owner - The activity that owns the saves
Returns:
A sorted list of save names