sk.baka.ambient
Class AmbientApplication

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.app.Application
              extended by sk.baka.ambient.AmbientApplication
All Implemented Interfaces:
ComponentCallbacks

public final class AmbientApplication
extends Application

Serves mainly for a primary access point to a singleton data structures and services, such as Library, PlaylistPlayer etc.

Author:
Martin Vysny

Field Summary
 
Fields inherited from class android.content.Context
ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MODE_APPEND, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NOTIFICATION_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, TELEPHONY_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Constructor Summary
AmbientApplication()
           
 
Method Summary
 void error(Class<?> sender, boolean error, String message, Throwable cause)
          An error occurred.
 BackgroundOpExecutor getBackgroundTasks()
          Returns the background tasks executor.
 SimpleBus getBus()
          Returns the message bus.
 Object getClipboard()
          Retrieves a clipboard object.
 CoverCache getCovers()
          Returns the cover cache manager instance.
 ErrorHandler getErrorHandler()
          Returns the error handler instance.
static Handler getHandler()
          Returns the main message loop handler.
static AmbientApplication getInstance()
          Returns application instance.
 LRCStorage getKaraoke()
          Returns the karaoke lyrics manager instance.
 Library getLibrary()
          Returns singleton instance of the library.
 PlaybackNotificator getNotificator()
          Returns the playback notificator instance.
 PlaylistPlayer getPlaylist()
          Returns singleton instance of the playlist.
 ObjectStorage getPlaylistStorage()
          Returns the cover cache manager instance.
 ICollection getProvider(TrackOriginEnum origin)
          Returns the provider for given origin.
 AppStateHandler getStateHandler()
          Returns the application state and configuration handler instance.
 String getVersion()
          Returns the Ambient version.
 boolean isMainActivityVisible()
          Checks if MainActivity is visible.
 boolean isShutdown()
          Checks if the application is shutting down.
 void onCreate()
           
 void onTerminate()
           
 void registerProvider(TrackOriginEnum origin, ICollection provider)
          Registers new provider for given origin.
 void setClipboard(Object obj)
          Sets clipboard contents.
 void setOffline(boolean offline)
          Sets the online/offline state.
 void shutdown()
          Shuts down the application.
 
Methods inherited from class android.app.Application
onConfigurationChanged, onLowMemory
 
Methods inherited from class android.content.ContextWrapper
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getFilesDir, getFileStreamPath, getMainLooper, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, setTheme, setWallpaper, setWallpaper, startActivity, startInstrumentation, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AmbientApplication

public AmbientApplication()
Method Detail

getHandler

public static Handler getHandler()
Returns the main message loop handler.

Returns:
the handler.

getNotificator

public PlaybackNotificator getNotificator()
Returns the playback notificator instance.

Returns:
the instance, never null.

onCreate

public void onCreate()
Overrides:
onCreate in class Application

setOffline

public void setOffline(boolean offline)
Sets the online/offline state.

Parameters:
offline - if true then the application switches into offline mode.

getErrorHandler

public ErrorHandler getErrorHandler()
Returns the error handler instance.

Returns:
the error handler instance, never null.

getStateHandler

public AppStateHandler getStateHandler()
Returns the application state and configuration handler instance.

Returns:
the application state and configuration handler instance, never null.

isMainActivityVisible

public boolean isMainActivityVisible()
Checks if MainActivity is visible.

Returns:
true if the activity is visible, false otherwise.

getCovers

public CoverCache getCovers()
Returns the cover cache manager instance.

Returns:
the cover cache manager.

getKaraoke

public LRCStorage getKaraoke()
Returns the karaoke lyrics manager instance.

Returns:
the karaoke lyrics manager.

getPlaylistStorage

public ObjectStorage getPlaylistStorage()
Returns the cover cache manager instance.

Returns:
the cover cache manager.

getInstance

public static AmbientApplication getInstance()
Returns application instance.

Returns:
the application instance.

getLibrary

public Library getLibrary()
Returns singleton instance of the library.

Returns:
never null

getBackgroundTasks

public BackgroundOpExecutor getBackgroundTasks()
Returns the background tasks executor.

Returns:
non-null instance of executor.

getPlaylist

public PlaylistPlayer getPlaylist()
Returns singleton instance of the playlist.

Returns:
never null.

getBus

public SimpleBus getBus()
Returns the message bus.

Returns:
the message bus.

onTerminate

public void onTerminate()
Overrides:
onTerminate in class Application

error

public void error(Class<?> sender,
                  boolean error,
                  String message,
                  Throwable cause)
An error occurred. A notification will be shown to the user.

Parameters:
sender - the sender.
error - error if true, warning if false.
message - the message to show. The message will be followed by a new line, the Cause: string and the Throwable.getMessage() if the cause is not null.
cause - optional cause.

setClipboard

public void setClipboard(Object obj)
Sets clipboard contents.

Parameters:
obj - the clipboard object to set.

getClipboard

public Object getClipboard()
Retrieves a clipboard object.

Returns:
the clipboard object, may be null if the clipboard was cleared, either by client or by the garbage collector.

isShutdown

public boolean isShutdown()
Checks if the application is shutting down.

Returns:
true if we are shutting down, false otherwise.

shutdown

public void shutdown()
Shuts down the application.


registerProvider

public void registerProvider(TrackOriginEnum origin,
                             ICollection provider)
Registers new provider for given origin. The provider will be used only for location fixing and must support ICollection.fixLocations(java.util.Collection).

Parameters:
origin - the origin
provider - the provider instance.

getProvider

public ICollection getProvider(TrackOriginEnum origin)
Returns the provider for given origin. May return null if no such provider was registered.

Parameters:
origin - the origin
Returns:
the provider instance.

getVersion

public String getVersion()
Returns the Ambient version.

Returns:
the version string or "unknown" if the version is not available.


Copyright © 2007-2008. All Rights Reserved.