org.android.activityminer.app.util
Class ServiceBasedActivity

Package class diagram package ServiceBasedActivity
java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.view.ContextThemeWrapper
              extended by android.app.Activity
                  extended by org.android.activityminer.app.util.SharedPreferenceChangeAwareActivity
                      extended by org.android.activityminer.app.util.ServiceBasedActivity
All Implemented Interfaces:
ComponentCallbacks, ComponentCallbacks2, KeyEvent.Callback, LayoutInflater.Factory, LayoutInflater.Factory2, View.OnCreateContextMenuListener, Window.Callback, GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>, SharedPreferenceChangeNotificationReceiver, SharedPreferenceChangeObserver
Direct Known Subclasses:
ActivityMiner, EvaluationActivity, ManagerActivity

public abstract class ServiceBasedActivity
extends SharedPreferenceChangeAwareActivity
implements GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>

Base class for Android activities using a service connection


Field Summary
private  TaskFinishedEventBroadcastReceiver backgroundServiceTaskFinishedEventReceiver
          Broadcast receiver for task finished events in the background service
private  ProgressBroadcastReceiver backgroundServiceTaskProgressReceiver
          Broadcast receiver for progress in the background service
private  BackgroundServiceConnectionHolder connectionHolder
          The background service connection holder
private  ProgressDialog progressDialog
          The progress dialog for a running task in the background service
private  IBackgroundService service
          The background service reference
 
Fields inherited from class android.app.Activity
DEFAULT_KEYS_DIALER, DEFAULT_KEYS_DISABLE, DEFAULT_KEYS_SEARCH_GLOBAL, DEFAULT_KEYS_SEARCH_LOCAL, DEFAULT_KEYS_SHORTCUT, FOCUSED_STATE_SET, RESULT_CANCELED, RESULT_FIRST_USER, RESULT_OK
 
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, APP_OPS_SERVICE, AUDIO_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CAPTIONING_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONSUMER_IR_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, PRINT_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, UI_MODE_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Fields inherited from interface android.content.ComponentCallbacks2
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
 
Constructor Summary
ServiceBasedActivity()
          Constructor
 
Method Summary
private static String formatTaskFinishedEventResult(Context context, TaskFinishedEvent event)
          Method to create a formatted result text of a task finished event
protected  IBackgroundService getService()
          Getter for the service
protected  ServiceState getServiceState()
          Getter for the service state
protected  void handleTaskFinishedEvent(TaskFinishedEvent taskFinishedEvent)
          Handler for task finished events
protected  boolean isServiceAvailable()
          Test method for service availability
 void onAboutToDisconnect(IBackgroundService service)
           
protected  void onBackgroundTaskProgress(CharSequence title, CharSequence message, int maximum, int progress)
          Does update the progress for a running task in the background service
 void onBindingFailed()
           
 void onConnectionEstablished(IBackgroundService service)
           
 void onConnectionLost()
           
protected  void onCreate(Bundle savedInstanceState)
           
protected  void onDefaultTaskFinishedEvent(TaskFinishedEvent event)
          Default handler for task finished events
private  void onEvaluationFinishedEvent(TaskFinishedEvent event)
          Handler for a evaluation task finished event
private  void onEvaluationResult(TaskFinishedEvent event)
          Handler for a new evaluation result from background service
protected  void onNewIntent(Intent intent)
           
protected  void onPause()
           
protected  void onResume()
           
protected abstract  void onServiceFinishedCurrentTask(TaskFinishedEvent event)
          Handler for finished service tasks
 void onServiceUnavailable()
           
protected  void safeUnregisterReceiver(BroadcastReceiver receiver)
          Safe method to unregister receivers
private  void setService(IBackgroundService service)
          Setter for the service
protected  void showServiceTaskFinishedResult(TaskFinishedEvent event)
          Does display the result from a task finished event received from the service
protected  void startBackgroundServiceProgressObservation()
          Method to start the background service progress observation
protected  void stopBackgroundServiceProgressObservation()
          Method to stop the background service progress observation
 
Methods inherited from class org.android.activityminer.app.util.SharedPreferenceChangeAwareActivity
getConfiguration, isInterestedInLimitViolations, onBetaPreferenceChange, onBWCutOffPreferenceChanged, onBWFilterOrderPreferenceChanged, onClassSelectionChange, onCountDownTimeChange, onCrossValidationParameterKChange, onDefaultRecordingTimeChange, onDestroy, onEvaluationAccuracyThresholdChanged, onFeatureSelection, onGravitationCutOffPreferenceChanged, onKNNClassifierParameterKChange, onKNNClassifierParameterNormalizeChange, onLimitViolation, onLocationDataUsageFlagChange, onMaximumRecordingTimeChange, onMaximumSampleRateChange, onMinCutOffPreferenceChanged, onOverlapSizeChange, onOwnLinAccImplementationUsageFlagChange, onSampleRateChange, onSelectedAccFilterChanged, onSelectedClassifierChange, onWindowSizeChange
 
Methods inherited from class android.app.Activity
addContentView, closeContextMenu, closeOptionsMenu, createPendingResult, dismissDialog, dispatchGenericMotionEvent, dispatchKeyEvent, dispatchKeyShortcutEvent, dispatchPopulateAccessibilityEvent, dispatchTouchEvent, dispatchTrackballEvent, dump, findViewById, finish, finishActivity, finishActivityFromChild, finishAffinity, finishFromChild, getActionBar, getApplication, getCallingActivity, getCallingPackage, getChangingConfigurations, getComponentName, getCurrentFocus, getFragmentManager, getIntent, getLastNonConfigurationInstance, getLayoutInflater, getLoaderManager, getLocalClassName, getMenuInflater, getParent, getParentActivityIntent, getPreferences, getRequestedOrientation, getSystemService, getTaskId, getTitle, getTitleColor, getVolumeControlStream, getWindow, getWindowManager, hasWindowFocus, invalidateOptionsMenu, isChangingConfigurations, isChild, isDestroyed, isFinishing, isImmersive, isTaskRoot, managedQuery, moveTaskToBack, navigateUpTo, navigateUpToFromChild, onActionModeFinished, onActionModeStarted, onActivityResult, onApplyThemeResource, onAttachedToWindow, onAttachFragment, onBackPressed, onChildTitleChanged, onConfigurationChanged, onContentChanged, onContextItemSelected, onContextMenuClosed, onCreateContextMenu, onCreateDescription, onCreateDialog, onCreateDialog, onCreateNavigateUpTaskStack, onCreateOptionsMenu, onCreatePanelMenu, onCreatePanelView, onCreateThumbnail, onCreateView, onCreateView, onDetachedFromWindow, onGenericMotionEvent, onKeyDown, onKeyLongPress, onKeyMultiple, onKeyShortcut, onKeyUp, onLowMemory, onMenuItemSelected, onMenuOpened, onNavigateUp, onNavigateUpFromChild, onOptionsItemSelected, onOptionsMenuClosed, onPanelClosed, onPostCreate, onPostResume, onPrepareDialog, onPrepareDialog, onPrepareNavigateUpTaskStack, onPrepareOptionsMenu, onPreparePanel, onProvideAssistData, onRestart, onRestoreInstanceState, onRetainNonConfigurationInstance, onSaveInstanceState, onSearchRequested, onStart, onStop, onTitleChanged, onTouchEvent, onTrackballEvent, onTrimMemory, onUserInteraction, onUserLeaveHint, onWindowAttributesChanged, onWindowFocusChanged, onWindowStartingActionMode, openContextMenu, openOptionsMenu, overridePendingTransition, recreate, registerForContextMenu, removeDialog, reportFullyDrawn, requestWindowFeature, runOnUiThread, setContentView, setContentView, setContentView, setDefaultKeyMode, setFeatureDrawable, setFeatureDrawableAlpha, setFeatureDrawableResource, setFeatureDrawableUri, setFinishOnTouchOutside, setImmersive, setIntent, setProgress, setProgressBarIndeterminate, setProgressBarIndeterminateVisibility, setProgressBarVisibility, setRequestedOrientation, setResult, setResult, setSecondaryProgress, setTitle, setTitle, setTitleColor, setVisible, setVolumeControlStream, shouldUpRecreateTask, showDialog, showDialog, startActionMode, startActivities, startActivities, startActivity, startActivity, startActivityForResult, startActivityForResult, startActivityFromChild, startActivityFromChild, startActivityFromFragment, startActivityFromFragment, startActivityIfNeeded, startActivityIfNeeded, startIntentSender, startIntentSender, startIntentSenderForResult, startIntentSenderForResult, startIntentSenderFromChild, startIntentSenderFromChild, startManagingCursor, startNextMatchingActivity, startNextMatchingActivity, startSearch, stopManagingCursor, takeKeyEvents, triggerSearch, unregisterForContextMenu
 
Methods inherited from class android.view.ContextThemeWrapper
applyOverrideConfiguration, attachBaseContext, getResources, getTheme, setTheme
 
Methods inherited from class android.content.ContextWrapper
bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getObbDirs, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getSharedPreferences, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setWallpaper, setWallpaper, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionHolder

private final BackgroundServiceConnectionHolder connectionHolder
The background service connection holder


service

private IBackgroundService service
The background service reference


progressDialog

private ProgressDialog progressDialog
The progress dialog for a running task in the background service


backgroundServiceTaskProgressReceiver

private ProgressBroadcastReceiver backgroundServiceTaskProgressReceiver
Broadcast receiver for progress in the background service


backgroundServiceTaskFinishedEventReceiver

private final TaskFinishedEventBroadcastReceiver backgroundServiceTaskFinishedEventReceiver
Broadcast receiver for task finished events in the background service

Constructor Detail

ServiceBasedActivity

public ServiceBasedActivity()
Constructor

Method Detail

onBackgroundTaskProgress

protected final void onBackgroundTaskProgress(CharSequence title,
                                              CharSequence message,
                                              int maximum,
                                              int progress)
Does update the progress for a running task in the background service

Parameters:
title - the task title
message - the message
maximum - the maximum
progress - the progress

startBackgroundServiceProgressObservation

protected final void startBackgroundServiceProgressObservation()
Method to start the background service progress observation


stopBackgroundServiceProgressObservation

protected final void stopBackgroundServiceProgressObservation()
Method to stop the background service progress observation


isServiceAvailable

protected final boolean isServiceAvailable()
Test method for service availability

Returns:
true if the service interface is available

getServiceState

protected final ServiceState getServiceState()
Getter for the service state

Returns:
the service state if available, null otherwise

setService

private final void setService(IBackgroundService service)
Setter for the service

Parameters:
service - the service to set

getService

protected final IBackgroundService getService()
Getter for the service

Returns:
the service

onCreate

protected void onCreate(Bundle savedInstanceState)
Overrides:
onCreate in class SharedPreferenceChangeAwareActivity

onResume

protected void onResume()
Overrides:
onResume in class Activity

handleTaskFinishedEvent

protected void handleTaskFinishedEvent(TaskFinishedEvent taskFinishedEvent)
Handler for task finished events

Parameters:
taskFinishedEvent - the task finished event

onNewIntent

protected final void onNewIntent(Intent intent)
Overrides:
onNewIntent in class Activity

onPause

protected void onPause()
Overrides:
onPause in class Activity

formatTaskFinishedEventResult

private static final String formatTaskFinishedEventResult(Context context,
                                                          TaskFinishedEvent event)
Method to create a formatted result text of a task finished event

Parameters:
context - the context
event - the task finished event
Returns:
the formatted result

showServiceTaskFinishedResult

protected final void showServiceTaskFinishedResult(TaskFinishedEvent event)
Does display the result from a task finished event received from the service

Parameters:
event - the task finished event

onServiceFinishedCurrentTask

protected abstract void onServiceFinishedCurrentTask(TaskFinishedEvent event)
Handler for finished service tasks

Parameters:
event - the task finished event

onEvaluationFinishedEvent

private final void onEvaluationFinishedEvent(TaskFinishedEvent event)
Handler for a evaluation task finished event

Parameters:
event - the event

onEvaluationResult

private final void onEvaluationResult(TaskFinishedEvent event)
Handler for a new evaluation result from background service

Parameters:
event - the task finished event

onDefaultTaskFinishedEvent

protected void onDefaultTaskFinishedEvent(TaskFinishedEvent event)
Default handler for task finished events

Parameters:
event - the event

onConnectionEstablished

public void onConnectionEstablished(IBackgroundService service)
Specified by:
onConnectionEstablished in interface GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>

onAboutToDisconnect

public void onAboutToDisconnect(IBackgroundService service)
Specified by:
onAboutToDisconnect in interface GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>

safeUnregisterReceiver

protected final void safeUnregisterReceiver(BroadcastReceiver receiver)
Safe method to unregister receivers

Parameters:
receiver - the receiver to unregister

onConnectionLost

public void onConnectionLost()
Specified by:
onConnectionLost in interface GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>

onBindingFailed

public final void onBindingFailed()
Specified by:
onBindingFailed in interface GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>

onServiceUnavailable

public final void onServiceUnavailable()
Specified by:
onServiceUnavailable in interface GenericServiceConnectionHolder.ServiceConnectionEventReceiver<IBackgroundService>