sk.baka.ambient
Class PowerHandler

java.lang.Object
  extended by android.content.BroadcastReceiver
      extended by sk.baka.ambient.PowerHandler
All Implemented Interfaces:
IPlaylistPlayerListener

final class PowerHandler
extends BroadcastReceiver
implements IPlaylistPlayerListener

Ensures that the WiFi is not turned off while playing an online content. Thread-unsafe, should be invoked from the main Handler instance only.

Author:
Martin Vysny

Constructor Summary
PowerHandler(AmbientApplication app)
          Creates new power handler.
 
Method Summary
(package private)  void destroy()
          Destroys this handler and drops any power locks being held.
 void onReceive(Context context, Intent intent)
           
 void playbackStateChanged(PlayerStateEnum state)
          The playback state was changed.
 void playlistChanged(Interval target)
          Fired when the playlist changes - by removing a track, reshuffling etc.
 void randomChanged(Random random)
          The play mode was changed.
 void repeatChanged(Repeat repeat)
          The play mode was changed.
 void trackChanged(PlaylistItem track, boolean play, int positionMillis)
          A new track was selected in the playlist.
 void trackPositionChanged(int position, boolean playing)
           A position in the track was changed.
 
Methods inherited from class android.content.BroadcastReceiver
abortBroadcast, clearAbortBroadcast, getAbortBroadcast, getDebugUnregister, getResultCode, getResultData, getResultExtras, setDebugUnregister, setOrderedHint, setResult, setResultCode, setResultData, setResultExtras
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PowerHandler

public PowerHandler(AmbientApplication app)
Creates new power handler.

Parameters:
app - owner application.
Method Detail

playbackStateChanged

public void playbackStateChanged(PlayerStateEnum state)
Description copied from interface: IPlaylistPlayerListener
The playback state was changed.

Specified by:
playbackStateChanged in interface IPlaylistPlayerListener
Parameters:
state - new playback state.

playlistChanged

public void playlistChanged(Interval target)
Description copied from interface: IPlaylistPlayerListener
Fired when the playlist changes - by removing a track, reshuffling etc.

Specified by:
playlistChanged in interface IPlaylistPlayerListener
Parameters:
target - the "target" (or the product) of the operation - for example for copy/move operations this interval contains added items, for delete operation the interval is empty. May be null if the target is not known. Semantically, the target should contain tracks that were 'produced' by the operation and they should be the target of the next operation. This implies that the playlist view should make these tracks appear selected.

randomChanged

public void randomChanged(Random random)
Description copied from interface: IPlaylistPlayerListener
The play mode was changed.

Specified by:
randomChanged in interface IPlaylistPlayerListener
Parameters:
random - new random value, never null.

repeatChanged

public void repeatChanged(Repeat repeat)
Description copied from interface: IPlaylistPlayerListener
The play mode was changed.

Specified by:
repeatChanged in interface IPlaylistPlayerListener
Parameters:
repeat - new repeat value, never null.

trackChanged

public void trackChanged(PlaylistItem track,
                         boolean play,
                         int positionMillis)
Description copied from interface: IPlaylistPlayerListener
A new track was selected in the playlist.

Specified by:
trackChanged in interface IPlaylistPlayerListener
Parameters:
track - the new track, may be null - in this case the playback is stopped.
play - if true then the track is already being played (or is about to be played).
positionMillis - the starting playback position in milliseconds.

trackPositionChanged

public void trackPositionChanged(int position,
                                 boolean playing)
Description copied from interface: IPlaylistPlayerListener

A position in the track was changed. This is only due to PlaylistPlayer.seek(int) - it is never invoked periodically as the playback progresses. This event is not invoked when a playback is started with non-zero start seek time.

Note that the playback may be paused.

Specified by:
trackPositionChanged in interface IPlaylistPlayerListener
Parameters:
position - the new position in milliseconds.
playing - if true then playback is activated, if false then the playback is paused. This event is not invoked when the playback is stopped.

destroy

void destroy()
Destroys this handler and drops any power locks being held.


onReceive

public void onReceive(Context context,
                      Intent intent)
Specified by:
onReceive in class BroadcastReceiver


Copyright © 2007-2008. All Rights Reserved.