org.android.activityminer.app.util
Class ObservableWorkerThreadWithProgressNotification

Package class diagram package ObservableWorkerThreadWithProgressNotification
java.lang.Object
  extended by java.lang.Thread
      extended by de.unikassel.android.sdcframework.util.AbstractWorkerThread
          extended by org.android.activityminer.app.util.ObservableWorkerThreadWithProgressNotification
All Implemented Interfaces:
ObservableEventSource<TaskFinishedEvent>, ObserverRegistration<TaskFinishedEvent>, WorkerThread, Runnable
Direct Known Subclasses:
AbstractLinearAccelerationUpdateThread, EvaluationThread, FeatureExtractionThread, FeatureSelectionThread, FeatureVectorExportThread, FileCopyThread, ModelCreationThread, NNInterpolationUpdateThread, TrainingDataDeletionThread

public abstract class ObservableWorkerThreadWithProgressNotification
extends AbstractWorkerThread
implements ObservableEventSource<TaskFinishedEvent>


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
private  Context applicationContext
          The application context.
private  android.support.v4.app.NotificationCompat.Builder builder
          The notification builder
private  String extraMaxProgress
          The intent max progress extra.
private  String extraMessage
          The intent message extra.
private  String extraProgress
          The intent progress extra.
private  String extraTitle
          The intent title extra.
private  long lastProgressNotificationTs
          The time stamp of the last notification
private  AtomicInteger maxProgress
          The maximum progress.
private  NotificationManager notificationManager
          The notification manager
private  ObservableEventSource<TaskFinishedEvent> observableEventSource
          The observable event source for delegation.
private  AtomicInteger progress
          The progress counter.
private static long PROGRESS_NOTIFICATION_INTERVALL
          Interval in milliseconds between two progress notifications
private  String progressMessage
          Field to store the last progress message change
private  String taskTitle
          The thread task title (description) for notification and result information
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ObservableWorkerThreadWithProgressNotification(Context context, CharSequence progressTitle, Class<? extends Activity> intentReceiver)
          Constructor
 
Method Summary
 void broadcastProgress()
          Method to broadcast the progress
private  void broadcastResult(TaskFinishedEvent taskFinishedEvent)
          Method to broadcast the result
protected  void doCleanUp()
           
 Context getApplicationContext()
          Getter for the application context
abstract  String getErrorNotificationMsg()
          Getter for the error notification message
 String getFinalResult()
          Getter for the final result message
 int getMaxProgress()
          Getter for the maximum progress
 Notification getNotification()
          Getter for the notification
abstract  int getNotificationId()
          Getter for the notification identifier
private  String getProgressMessage()
          Getter for the progress message
abstract  String getResultNotificationMsg()
          Getter for the result notification message
 String getTaskTitle()
          Getter for the task title
 boolean hasObservers()
           
abstract  boolean hasSucceeded()
          Test method for success in case of termination
 void incrementAndNotifyProgress()
          Progress increment and notification
 void incrementAndNotifyProgress(String message)
          Progress increment and notification
 void notify(TaskFinishedEvent data)
           
protected  void notifyProgress(String message)
          Progress notification
 void notifyProgress(String message, int progress)
          Progress notification
 void registerEventObserver(EventObserver<? extends TaskFinishedEvent> observer)
           
 void removeAllObservers()
           
 void setMaxProgress(int maxProgress)
          Setter for the maximum progress
private  void setProgressMessage(String progressMessage)
          Setter for the progress message
 void unregisterEventObserver(EventObserver<? extends TaskFinishedEvent> observer)
           
 
Methods inherited from class de.unikassel.android.sdcframework.util.AbstractWorkerThread
doTerminate, doWork, hasTerminated, isLogging, isWorking, logMessage, run, setLogging, start, startWork, stopWork
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROGRESS_NOTIFICATION_INTERVALL

private static final long PROGRESS_NOTIFICATION_INTERVALL
Interval in milliseconds between two progress notifications

See Also:
Constant Field Values

notificationManager

private final NotificationManager notificationManager
The notification manager


maxProgress

private final AtomicInteger maxProgress
The maximum progress.


progress

private final AtomicInteger progress
The progress counter.


observableEventSource

private final ObservableEventSource<TaskFinishedEvent> observableEventSource
The observable event source for delegation.


applicationContext

private final Context applicationContext
The application context.


taskTitle

private final String taskTitle
The thread task title (description) for notification and result information


progressMessage

private String progressMessage
Field to store the last progress message change


lastProgressNotificationTs

private long lastProgressNotificationTs
The time stamp of the last notification


builder

private final android.support.v4.app.NotificationCompat.Builder builder
The notification builder


extraTitle

private final String extraTitle
The intent title extra.


extraMessage

private final String extraMessage
The intent message extra.


extraProgress

private final String extraProgress
The intent progress extra.


extraMaxProgress

private final String extraMaxProgress
The intent max progress extra.

Constructor Detail

ObservableWorkerThreadWithProgressNotification

public ObservableWorkerThreadWithProgressNotification(Context context,
                                                      CharSequence progressTitle,
                                                      Class<? extends Activity> intentReceiver)
Constructor

Parameters:
context - the application context
progressTitle - the progress notification title
intentReceiver - the intent receiver class
Method Detail

getProgressMessage

private final String getProgressMessage()
Getter for the progress message

Returns:
the progress message

setProgressMessage

private final void setProgressMessage(String progressMessage)
Setter for the progress message

Parameters:
progressMessage - the progress message to set

getApplicationContext

public final Context getApplicationContext()
Getter for the application context

Returns:
the application context

getNotification

public final Notification getNotification()
Getter for the notification

Returns:
the notification

getMaxProgress

public final int getMaxProgress()
Getter for the maximum progress

Returns:
the maximum progress

setMaxProgress

public final void setMaxProgress(int maxProgress)
Setter for the maximum progress

Parameters:
maxProgress - the maximum progress to set

broadcastProgress

public final void broadcastProgress()
Method to broadcast the progress


broadcastResult

private final void broadcastResult(TaskFinishedEvent taskFinishedEvent)
Method to broadcast the result

Parameters:
taskFinishedEvent - the result to progress

notifyProgress

protected final void notifyProgress(String message)
Progress notification

Parameters:
message - the progress text

incrementAndNotifyProgress

public final void incrementAndNotifyProgress(String message)
Progress increment and notification

Parameters:
message - the progress text

incrementAndNotifyProgress

public final void incrementAndNotifyProgress()
Progress increment and notification


notifyProgress

public final void notifyProgress(String message,
                                 int progress)
Progress notification

Parameters:
message - the progress text
progress - the updated progress

getErrorNotificationMsg

public abstract String getErrorNotificationMsg()
Getter for the error notification message

Returns:
the error notification message

getResultNotificationMsg

public abstract String getResultNotificationMsg()
Getter for the result notification message

Returns:
the result notification message

getNotificationId

public abstract int getNotificationId()
Getter for the notification identifier

Returns:
the notification identifier

hasSucceeded

public abstract boolean hasSucceeded()
Test method for success in case of termination

Returns:
true if thread has successfully finished it's task, false in case of errors

doCleanUp

protected void doCleanUp()
Specified by:
doCleanUp in class AbstractWorkerThread

registerEventObserver

public final void registerEventObserver(EventObserver<? extends TaskFinishedEvent> observer)
Specified by:
registerEventObserver in interface ObserverRegistration<TaskFinishedEvent>

unregisterEventObserver

public final void unregisterEventObserver(EventObserver<? extends TaskFinishedEvent> observer)
Specified by:
unregisterEventObserver in interface ObserverRegistration<TaskFinishedEvent>

removeAllObservers

public final void removeAllObservers()
Specified by:
removeAllObservers in interface ObserverRegistration<TaskFinishedEvent>

notify

public final void notify(TaskFinishedEvent data)
Specified by:
notify in interface ObservableEventSource<TaskFinishedEvent>

hasObservers

public final boolean hasObservers()
Specified by:
hasObservers in interface ObservableEventSource<TaskFinishedEvent>

getFinalResult

public final String getFinalResult()
Getter for the final result message

Returns:
the result message

getTaskTitle

public final String getTaskTitle()
Getter for the task title

Returns:
the task title