de.unikassel.android.sdcframework.devices
Class ContentProviderDeviceScanner

Package class diagram package ContentProviderDeviceScanner
java.lang.Object
  extended by de.unikassel.android.sdcframework.util.ObservableEventSourceImpl<Sample>
      extended by de.unikassel.android.sdcframework.devices.AbstractSensorDeviceScanner
          extended by de.unikassel.android.sdcframework.devices.ContentProviderDeviceScanner
All Implemented Interfaces:
SensorDeviceScanner, ObservableEventSource<Sample>, ObserverRegistration<Sample>
Direct Known Subclasses:
AudioDeviceScanner, TagDeviceScanner, TwitterDeviceScanner

public abstract class ContentProviderDeviceScanner
extends AbstractSensorDeviceScanner

Abstract base class for content provider based device scanner types.

A content provider based scanner does register itself as observer for a content provider and creates samples from the notified data. It can be used together with the VirtualSensorDevice to create virtual observable sensor devices which are not related to a physical device.

Just to mention it, this scanner is triggered by content provider changes and is simply ignoring the configured device frequency.

See Also:
TwitterDeviceScanner

Field Summary
private  ContentObserver contentObserver
          The content observer
private  Uri contentURI
          The URI for the scanned provider content
private  ContentResolver resolver
          The content resolver context
 
Constructor Summary
ContentProviderDeviceScanner(ContentResolver resolver, Uri contentURI)
          Constructor
 
Method Summary
 void doDeleteGatheredData(ContentResolver contentResolver, Queue<Long> rowIds)
          Method to delete content from the provider
protected  void doGatherSamples()
          The gathering method to request available data from the content provider, create samples from it, notify observers and finally remove gathered data from the provider content.
 Queue<Long> doNotifyForSamples(ContentResolver contentResolver)
          Method to gather content from the provider and create sample notifications
protected  ContentObserver getContentObserver()
          Getter for the content observer
protected  ContentResolver getContentResolver()
          Getter for the content resolver
protected  Uri getContentURI()
          Getter for the content URI
protected abstract  SampleData getSampleDataFromCursor(Cursor cursor)
          Method to extract concrete sample data at database cursor position
protected  boolean isCompatibleDevice(SensorDevice device)
          Validation method for a compatible device type
 void onDestroy(Context context)
          Is called when the owner destroys this scanner
 boolean start(Context context)
          Does start sampling
 boolean stop(Context context)
          Does stop sampling
 
Methods inherited from class de.unikassel.android.sdcframework.devices.AbstractSensorDeviceScanner
enable, getDevice, isActive, isEnabled, setActive, setDevice
 
Methods inherited from class de.unikassel.android.sdcframework.util.ObservableEventSourceImpl
getObservers, hasObservers, notify, onObserverRegistration, onObserverUnregistration, registerEventObserver, removeAllObservers, unregisterEventObserver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.unikassel.android.sdcframework.util.facade.ObservableEventSource
hasObservers, notify
 
Methods inherited from interface de.unikassel.android.sdcframework.util.facade.ObserverRegistration
registerEventObserver, removeAllObservers, unregisterEventObserver
 

Field Detail

resolver

private final ContentResolver resolver
The content resolver context


contentURI

private final Uri contentURI
The URI for the scanned provider content


contentObserver

private final ContentObserver contentObserver
The content observer

Constructor Detail

ContentProviderDeviceScanner

public ContentProviderDeviceScanner(ContentResolver resolver,
                                    Uri contentURI)
Constructor

Parameters:
resolver - the content resolver
contentURI -
Method Detail

isCompatibleDevice

protected boolean isCompatibleDevice(SensorDevice device)
Description copied from class: AbstractSensorDeviceScanner
Validation method for a compatible device type

Specified by:
isCompatibleDevice in class AbstractSensorDeviceScanner
Parameters:
device - the device to test for compatibility

getContentResolver

protected final ContentResolver getContentResolver()
Getter for the content resolver


getContentObserver

protected ContentObserver getContentObserver()
Getter for the content observer

Returns:
the content observer

getContentURI

protected final Uri getContentURI()
Getter for the content URI

Returns:
the content URI

start

public final boolean start(Context context)
Description copied from interface: SensorDeviceScanner
Does start sampling

Parameters:
context - the application context
Returns:
true if successful started, false otherwise

stop

public final boolean stop(Context context)
Description copied from interface: SensorDeviceScanner
Does stop sampling

Parameters:
context - the application context
Returns:
true if successful started, false otherwise

onDestroy

public void onDestroy(Context context)
Description copied from interface: SensorDeviceScanner
Is called when the owner destroys this scanner

Specified by:
onDestroy in interface SensorDeviceScanner
Overrides:
onDestroy in class AbstractSensorDeviceScanner
Parameters:
context - the application context

doGatherSamples

protected final void doGatherSamples()
The gathering method to request available data from the content provider, create samples from it, notify observers and finally remove gathered data from the provider content.


doDeleteGatheredData

public void doDeleteGatheredData(ContentResolver contentResolver,
                                 Queue<Long> rowIds)
Method to delete content from the provider

Parameters:
contentResolver - the content resolver to use
rowIds - the row id's to delete

doNotifyForSamples

public final Queue<Long> doNotifyForSamples(ContentResolver contentResolver)
Method to gather content from the provider and create sample notifications

Parameters:
contentResolver - the content resolver to use
Returns:
the id's of the gathered rows

getSampleDataFromCursor

protected abstract SampleData getSampleDataFromCursor(Cursor cursor)
Method to extract concrete sample data at database cursor position

Parameters:
cursor - the database cursor
Returns:
the extracted sample data