de.unikassel.android.sdcframework.preferences
Class ApplicationPreferenceManagerImpl

Package class diagram package ApplicationPreferenceManagerImpl
java.lang.Object
  extended by de.unikassel.android.sdcframework.preferences.ApplicationPreferenceManagerImpl
All Implemented Interfaces:
ApplicationPreferenceManager, ConfigurationChangeEventSource, ObserverRegistration<ConfigurationChangeEvent<? extends Configuration>>

public final class ApplicationPreferenceManagerImpl
extends Object
implements ApplicationPreferenceManager

The application preference manager for the SDC framework is providing a uniform access to preferences or current configuration values.

Provided features are:


Nested Class Summary
 class ApplicationPreferenceManagerImpl.DeviceConfigurationChangeEventSource
          Observable event source implementation for sensor device configuration change events
 class ApplicationPreferenceManagerImpl.LogLevelConfigurationChangeEventSource
          Observable event source implementation for log level change events
 class ApplicationPreferenceManagerImpl.ServiceConfigurationChangeEventSource
          Observable event source implementation for service configuration change events
 class ApplicationPreferenceManagerImpl.TimeProviderConfigurationChangeEventSource
          Observable event source implementation for time provider change events
 
Field Summary
private  DevicePreferencesCollection devicePreferences
          The device preferences
private  SharedPreferences.OnSharedPreferenceChangeListener listener
          the shared preferences listener
private  SinglePreference<LogLevelConfiguration> logLevelPreference
          The log level preferences
private  Map<Class<? extends ObservableEventSource<? extends ConfigurationChangeEvent<? extends Configuration>>>,ObservableEventSource<? extends ConfigurationChangeEvent<? extends Configuration>>> mapChangeEventSource
          Map to hold the supported change event sources mapped to events class name
private  Map<String,SensorDevicePreferences> mapKeyToDevicePreferences
          preference key to device preferences mapping
private  ServicePreferences servicePreferences
          The service preferences
private  TimeProviderPreference timeProviderPreference
          The time provider preferences
private  UUIDPreference uuidPreference
          The UUID preferences
 
Constructor Summary
ApplicationPreferenceManagerImpl()
          Constructor
 
Method Summary
 SensorDeviceConfiguration getDeviceConfiguration(SensorDeviceIdentifier deviceIdentifier, Context applicationContext)
          Access to device configurations created from current device preferences
private  DevicePreferencesCollection getDevicePreferences()
          Getter for the device preferences
private  ApplicationPreferenceManagerImpl.DeviceConfigurationChangeEventSource getDeviceUpdateSource()
          Getter for the device update source
 LogLevelConfiguration getLogLevelConfiguration(Context applicationContext)
          Access to log level configuration created from current log level preferences
 SinglePreference<LogLevelConfiguration> getLogLevelPreference()
          Getter for log level preferences
private  ObservableEventSource<LogLevelConfigurationChangeEvent> getLogUpdateSource()
          Getter for the log update source
private  Map<String,SensorDevicePreferences> getMapKeyToDevicePreferences()
          Getter for the key to device preferences map
 Collection<ObservableEventSource<? extends ConfigurationChangeEvent<? extends Configuration>>> getObservableEventSources()
          Method to get a collection of the internal observable event sources for test purpose
 SensorDevicePreferences getPreferencesForDevice(SensorDeviceIdentifier deviceIdentifier)
          Getter for specific device preferences
 ServiceConfiguration getServiceConfiguration(Context applicationContext)
          Access to service configuration created from current service preferences
 ServicePreferences getServicePreferences()
          Getter for the service preferences
private  ObservableEventSource<ServiceConfigurationChangeEvent> getServiceUpdateSource()
          Getter for the service update source
 SharedPreferences getSharedPreferences(Context applicationContext)
          Does return the shared preferences for the application context
 TimeProviderConfiguration getTimeProviderConfiguration(Context applicationContext)
          Access to the time provider configuration created from current time provider preferences
 TimeProviderPreference getTimeProviderPreference()
          Getter for time provider preferences
private  ObservableEventSource<TimeProviderConfigurationChangeEvent> getTimeProviderUpdateSource()
          Getter for the time provider update source
 String getUUIDConfiguration(Context applicationContext)
          Access to the UUID configuration created from the current UUID preferences
 UUIDPreference getUUIDPreference()
          Getter for UUID preferences
private  void handlePreferenceUpdate(SharedPreferences sharedPreferences, String key)
          Handler for preference changes
 void onDestroy()
          Internal destroy method to clean up references
private  void registerDevicePreferences(SensorDevicePreferences preferences)
          Does register device preferences for the key to device preference mapping
 void registerEventObserver(EventObserver<? extends ConfigurationChangeEvent<? extends Configuration>> observer)
          Does register an observer
 void removeAllObservers()
          Does remove all registered observers
 void resetToDefaults(Context applicationContext)
          Does reset the local stored changes for all preferences.
 void startListening(Context applicationContext)
          Does start the listening for application preferences changes
 void stopListening(Context applicationContext)
          Does stop the listening for application preferences changes
 void unregisterEventObserver(EventObserver<? extends ConfigurationChangeEvent<? extends Configuration>> observer)
          Does delete a registered observer
 void updateLogLevelConfiguration(Context applicationContext, LogLevel logLevel)
          Method to update the store log level preference
 void updatePreferenceState(Context applicationContext, SinglePreference<Boolean> preference, boolean state)
          Method to change the state for a given boolean preference
protected  void updateSchedule(Context applicationContext, WeeklySchedule schedule)
          Internal update method for the weekly schedule
 void updateUUIDConfiguration(Context applicationContext, String sUuid)
          Method to update the stored device UUID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapChangeEventSource

private final Map<Class<? extends ObservableEventSource<? extends ConfigurationChangeEvent<? extends Configuration>>>,ObservableEventSource<? extends ConfigurationChangeEvent<? extends Configuration>>> mapChangeEventSource
Map to hold the supported change event sources mapped to events class name


devicePreferences

private final DevicePreferencesCollection devicePreferences
The device preferences


logLevelPreference

private final SinglePreference<LogLevelConfiguration> logLevelPreference
The log level preferences


uuidPreference

private final UUIDPreference uuidPreference
The UUID preferences


timeProviderPreference

private final TimeProviderPreference timeProviderPreference
The time provider preferences


servicePreferences

private final ServicePreferences servicePreferences
The service preferences


listener

private final SharedPreferences.OnSharedPreferenceChangeListener listener
the shared preferences listener


mapKeyToDevicePreferences

private final Map<String,SensorDevicePreferences> mapKeyToDevicePreferences
preference key to device preferences mapping

Constructor Detail

ApplicationPreferenceManagerImpl

public ApplicationPreferenceManagerImpl()
Constructor

Method Detail

getDeviceUpdateSource

private final ApplicationPreferenceManagerImpl.DeviceConfigurationChangeEventSource getDeviceUpdateSource()
Getter for the device update source

Returns:
the device update source

getLogUpdateSource

private final ObservableEventSource<LogLevelConfigurationChangeEvent> getLogUpdateSource()
Getter for the log update source

Returns:
the log update source

getTimeProviderUpdateSource

private final ObservableEventSource<TimeProviderConfigurationChangeEvent> getTimeProviderUpdateSource()
Getter for the time provider update source

Returns:
the log update source

getServiceUpdateSource

private final ObservableEventSource<ServiceConfigurationChangeEvent> getServiceUpdateSource()
Getter for the service update source

Returns:
the service update source

getObservableEventSources

public final Collection<ObservableEventSource<? extends ConfigurationChangeEvent<? extends Configuration>>> getObservableEventSources()
Method to get a collection of the internal observable event sources for test purpose

Returns:
the observable event sources as collection

getDevicePreferences

private final DevicePreferencesCollection getDevicePreferences()
Getter for the device preferences

Returns:
the device preferences

getMapKeyToDevicePreferences

private final Map<String,SensorDevicePreferences> getMapKeyToDevicePreferences()
Getter for the key to device preferences map

Returns:
the key to device preferences map

handlePreferenceUpdate

private final void handlePreferenceUpdate(SharedPreferences sharedPreferences,
                                          String key)
Handler for preference changes

Parameters:
sharedPreferences - the shared preferences
key - the preference key identifier

registerDevicePreferences

private final void registerDevicePreferences(SensorDevicePreferences preferences)
Does register device preferences for the key to device preference mapping

Parameters:
preferences - the device preferences to register

getPreferencesForDevice

public final SensorDevicePreferences getPreferencesForDevice(SensorDeviceIdentifier deviceIdentifier)
Description copied from interface: ApplicationPreferenceManager
Getter for specific device preferences

Specified by:
getPreferencesForDevice in interface ApplicationPreferenceManager
Parameters:
deviceIdentifier - the device identifier
Returns:
the preferences for the device with the given identifier

getLogLevelPreference

public final SinglePreference<LogLevelConfiguration> getLogLevelPreference()
Description copied from interface: ApplicationPreferenceManager
Getter for log level preferences

Specified by:
getLogLevelPreference in interface ApplicationPreferenceManager
Returns:
the log level preference

getTimeProviderPreference

public final TimeProviderPreference getTimeProviderPreference()
Description copied from interface: ApplicationPreferenceManager
Getter for time provider preferences

Specified by:
getTimeProviderPreference in interface ApplicationPreferenceManager
Returns:
the time provider preference

getServicePreferences

public final ServicePreferences getServicePreferences()
Description copied from interface: ApplicationPreferenceManager
Getter for the service preferences

Specified by:
getServicePreferences in interface ApplicationPreferenceManager
Returns:
the service preferences

getUUIDPreference

public UUIDPreference getUUIDPreference()
Description copied from interface: ApplicationPreferenceManager
Getter for UUID preferences

Specified by:
getUUIDPreference in interface ApplicationPreferenceManager
Returns:
the UUID preference

getDeviceConfiguration

public final SensorDeviceConfiguration getDeviceConfiguration(SensorDeviceIdentifier deviceIdentifier,
                                                              Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Access to device configurations created from current device preferences

Specified by:
getDeviceConfiguration in interface ApplicationPreferenceManager
Parameters:
deviceIdentifier - the device identifier
applicationContext - the application context
Returns:
the current device configuration

getLogLevelConfiguration

public final LogLevelConfiguration getLogLevelConfiguration(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Access to log level configuration created from current log level preferences

Specified by:
getLogLevelConfiguration in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
Returns:
the current log level configuration

updateLogLevelConfiguration

public void updateLogLevelConfiguration(Context applicationContext,
                                        LogLevel logLevel)
Description copied from interface: ApplicationPreferenceManager
Method to update the store log level preference

Specified by:
updateLogLevelConfiguration in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
logLevel - the logLevel to update to

getTimeProviderConfiguration

public final TimeProviderConfiguration getTimeProviderConfiguration(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Access to the time provider configuration created from current time provider preferences

Specified by:
getTimeProviderConfiguration in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
Returns:
the current time provider configuration

getServiceConfiguration

public final ServiceConfiguration getServiceConfiguration(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Access to service configuration created from current service preferences

Specified by:
getServiceConfiguration in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
Returns:
the current service configuration

getUUIDConfiguration

public String getUUIDConfiguration(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Access to the UUID configuration created from the current UUID preferences

Specified by:
getUUIDConfiguration in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
Returns:
the current UUID configuration

updateUUIDConfiguration

public void updateUUIDConfiguration(Context applicationContext,
                                    String sUuid)
Description copied from interface: ApplicationPreferenceManager
Method to update the stored device UUID.

Specified by:
updateUUIDConfiguration in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
sUuid - the new UUID to store in preferences

startListening

public final void startListening(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Does start the listening for application preferences changes

Specified by:
startListening in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context

stopListening

public final void stopListening(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Does stop the listening for application preferences changes

Specified by:
stopListening in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context

getSharedPreferences

public final SharedPreferences getSharedPreferences(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Does return the shared preferences for the application context

Specified by:
getSharedPreferences in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
Returns:
the applications shared preferences

unregisterEventObserver

public final void unregisterEventObserver(EventObserver<? extends ConfigurationChangeEvent<? extends Configuration>> observer)
Description copied from interface: ObserverRegistration
Does delete a registered observer

Specified by:
unregisterEventObserver in interface ObserverRegistration<ConfigurationChangeEvent<? extends Configuration>>
Parameters:
observer - the observer to delete

registerEventObserver

public final void registerEventObserver(EventObserver<? extends ConfigurationChangeEvent<? extends Configuration>> observer)
Description copied from interface: ObserverRegistration
Does register an observer

Specified by:
registerEventObserver in interface ObserverRegistration<ConfigurationChangeEvent<? extends Configuration>>
Parameters:
observer - the observer to add

onDestroy

public final void onDestroy()
Description copied from interface: ApplicationPreferenceManager
Internal destroy method to clean up references

Specified by:
onDestroy in interface ApplicationPreferenceManager

removeAllObservers

public void removeAllObservers()
Description copied from interface: ObserverRegistration
Does remove all registered observers

Specified by:
removeAllObservers in interface ObserverRegistration<ConfigurationChangeEvent<? extends Configuration>>

resetToDefaults

public void resetToDefaults(Context applicationContext)
Description copied from interface: ApplicationPreferenceManager
Does reset the local stored changes for all preferences.

Specified by:
resetToDefaults in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context

updateSchedule

protected final void updateSchedule(Context applicationContext,
                                    WeeklySchedule schedule)
Internal update method for the weekly schedule

Parameters:
applicationContext - the application context
schedule - the schedule

updatePreferenceState

public final void updatePreferenceState(Context applicationContext,
                                        SinglePreference<Boolean> preference,
                                        boolean state)
Description copied from interface: ApplicationPreferenceManager
Method to change the state for a given boolean preference

Specified by:
updatePreferenceState in interface ApplicationPreferenceManager
Parameters:
applicationContext - the application context
preference - the preference to change
state - the state to set