sk.baka.ambient.activity.main
Class AbstractListController

java.lang.Object
  extended by sk.baka.ambient.activity.main.AbstractController
      extended by sk.baka.ambient.activity.main.AbstractListController
All Implemented Interfaces:
IGestureListViewListener
Direct Known Subclasses:
AbstractCollectionController, AbstractPlaylistController, FileBrowserController, PlaylistManagerController, ShoutcastController, StringListController

public abstract class AbstractListController
extends AbstractController
implements IGestureListViewListener

The items in this controller are rendered as a list and can be selected.

Author:
Martin Vysny

Nested Class Summary
 
Nested classes/interfaces inherited from class sk.baka.ambient.activity.main.AbstractController
AbstractController.Listener
 
Field Summary
protected  int highlightColor
          The color of highlighted items in the list.
 GesturesListView listView
          The list instance.
 
Fields inherited from class sk.baka.ambient.activity.main.AbstractController
app, cycle, listener, mainActivity, mainView
 
Constructor Summary
protected AbstractListController(int mainViewId, int listViewId, Activity mainActivity)
          Creates new controller.
 
Method Summary
 boolean canComputeItems()
          Checks if the model currently supports computing tracks.
 boolean canHighlight()
          Checks if we can start highlight mode now.
 List<TrackMetadataBean> computeTracks(Interval highlight)
           Retrieve a list of tracks from the selection.
 void destroy()
          The controller is about to be destroyed.
 void dropItems(List<TrackMetadataBean> tracks, int x, int y, int index)
          The drag'n'drop operation is finished.
 Object getClipboard()
          Retrieves current clipboard value.
 String getHint(Interval highlight)
           Returns a very short and simple string representation of the selected contents.
 void highlightChanged(Interval highlight)
          Selection was changed.
 boolean isComputeTracksLong(Interval interval)
           Checks if the IGestureListViewListener.computeTracks(Interval) method will be a long operation.
 boolean isComputeTracksOnlineOp(Interval interval)
           Checks if the IGestureListViewListener.computeTracks(Interval) method will involve polling of some data from the Internet.
 boolean isReadOnly()
          Checks if the list view is currently read-only.
 Interval moveItems(Interval highlight, int delta)
           Move selected items up or down.
 Interval moveItemsByOne(Interval highlight, boolean down)
           Move selected items up or down.
protected  void performZoom(boolean zoom)
          Zooms, or un-zooms the controller.
protected abstract  void recomputeListItems()
          Recomputes the model.
 void removeItems(Interval remove)
           Remove these items from the list.
 void setClipboard(TrackListClipboardObject clipboard)
          Sets the new clipboard.
 void update(Interval target)
          Overrides default functionality - the recomputeListItems() is invoked and the list view contents are updated.
 
Methods inherited from class sk.baka.ambient.activity.main.AbstractController
equals, flipVisibility, hashCode, hide, initButtonBar, initButtonBar, initButtonBar, isDestroyed, isVisible, isZoomed, onAction, setVisibility, show, visibilityChanged, zoom
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface sk.baka.ambient.views.gesturelist.IGestureListViewListener
itemActivated, update
 

Field Detail

listView

public GesturesListView listView
The list instance.


highlightColor

protected final int highlightColor
The color of highlighted items in the list.

Constructor Detail

AbstractListController

protected AbstractListController(int mainViewId,
                                 int listViewId,
                                 Activity mainActivity)
Creates new controller.

Parameters:
mainViewId - the view whose visibility is controlled.
listViewId - the id of the GesturesListView
mainActivity - the main activity instance.
Method Detail

recomputeListItems

protected abstract void recomputeListItems()
Recomputes the model. You don't have to call the ModelHolder.notifyModified() - it is called automatically after the method finishes.


highlightChanged

public void highlightChanged(Interval highlight)
Description copied from interface: IGestureListViewListener
Selection was changed. The new highlight is already being drawn.

Specified by:
highlightChanged in interface IGestureListViewListener
Parameters:
highlight - highlighted items

update

public void update(Interval target)
Overrides default functionality - the recomputeListItems() is invoked and the list view contents are updated.

Overrides:
update in class AbstractController
Parameters:
target - reset selection to this interval.

canComputeItems

public boolean canComputeItems()
Description copied from interface: IGestureListViewListener
Checks if the model currently supports computing tracks. This also affects the drag'n'drop capability - we cannot drag'n'drop if a track list cannot be computed.

Specified by:
canComputeItems in interface IGestureListViewListener
Returns:
true if the model can compute tracks, false otherwise.

isReadOnly

public boolean isReadOnly()
Description copied from interface: IGestureListViewListener
Checks if the list view is currently read-only.

Specified by:
isReadOnly in interface IGestureListViewListener
Returns:
true if the view cannot be modified, false otherwise.

computeTracks

public List<TrackMetadataBean> computeTracks(Interval highlight)
Description copied from interface: IGestureListViewListener

Retrieve a list of tracks from the selection. This operation may not be invoked from the handler's thread (depending on the result of the IGestureListViewListener.isComputeTracksLong(Interval) method). The method implementation should thus periodically check for the interrupted flag. When interrupted, it should return an empty list or null ASAP. It may do so by throwing an exception

If the method is invoked in a non-handler thread the callee wraps the result in a thread-safe list.

The method may throw RuntimeException - it will be caught and displayed unless the thread is interrupted.

This method is only invoked when IGestureListViewListener.canComputeItems() returns true.

Specified by:
computeTracks in interface IGestureListViewListener
Parameters:
highlight - the selection
Returns:
a list of tracks, must not be null.

dropItems

public void dropItems(List<TrackMetadataBean> tracks,
                      int x,
                      int y,
                      int index)
Description copied from interface: IGestureListViewListener
The drag'n'drop operation is finished. This view has received a list of tracks.

Specified by:
dropItems in interface IGestureListViewListener
Parameters:
tracks - the tracks
x - the drop point x axis relative to the item upper-left corner.
y - the drop point y axis relative to the item upper-left corner.
index - the index of the item where the files were dropped.

moveItems

public Interval moveItems(Interval highlight,
                          int delta)
Description copied from interface: IGestureListViewListener

Move selected items up or down. The listener must update the items and return the new highlight. This operation is always considered as a short-running and thus always executed directly in handler's event thread.

The list view will be redrawn automatically when the method returns.

This operation is invoked only when IGestureListViewListener.isReadOnly() returns false.

Specified by:
moveItems in interface IGestureListViewListener
Parameters:
highlight - move these items
delta - drop the items before item with this index.
Returns:
new interval which contains all moved tracks.

moveItemsByOne

public Interval moveItemsByOne(Interval highlight,
                               boolean down)
Description copied from interface: IGestureListViewListener

Move selected items up or down. The listener must update the items and return the new highlight. This operation is always considered as a short-running and thus always executed directly in handler's event thread.

The list view will be redrawn automatically when the method returns.

This operation is invoked only when IGestureListViewListener.isReadOnly() returns false.

Specified by:
moveItemsByOne in interface IGestureListViewListener
Parameters:
highlight - move these items
down - down if true then move the highlighted interval down, otherwise move it up.
Returns:
new interval which contains all moved tracks.

getHint

public String getHint(Interval highlight)
Description copied from interface: IGestureListViewListener

Returns a very short and simple string representation of the selected contents.

This method is only invoked when IGestureListViewListener.canComputeItems() returns true.

Specified by:
getHint in interface IGestureListViewListener
Parameters:
highlight - the highlighted items.
Returns:
short description of selected contents. May be null if no hint should be shown.

isComputeTracksLong

public boolean isComputeTracksLong(Interval interval)
Description copied from interface: IGestureListViewListener

Checks if the IGestureListViewListener.computeTracks(Interval) method will be a long operation. If yes, then the operation will be run in new thread. If not, the operation will be run in handler event thread.

This method is only invoked when IGestureListViewListener.canComputeItems() returns true.

Specified by:
isComputeTracksLong in interface IGestureListViewListener
Parameters:
interval - the selection
Returns:
true if long operation, false otherwise.

isComputeTracksOnlineOp

public boolean isComputeTracksOnlineOp(Interval interval)
Description copied from interface: IGestureListViewListener

Checks if the IGestureListViewListener.computeTracks(Interval) method will involve polling of some data from the Internet.

This method is only invoked when IGestureListViewListener.canComputeItems() returns true.

Specified by:
isComputeTracksOnlineOp in interface IGestureListViewListener
Parameters:
interval - the selection
Returns:
true if some Internet resources will be polled, false otherwise.

removeItems

public void removeItems(Interval remove)
Description copied from interface: IGestureListViewListener

Remove these items from the list. The list view sets the highlight automatically to zero interval.

This operation is invoked even when IGestureListViewListener.isReadOnly() returns false as some use cases activates a "Go Back" activity instead of deleting items.

Specified by:
removeItems in interface IGestureListViewListener
Parameters:
remove - remove these items. The interval is not null however it may be empty.

canHighlight

public boolean canHighlight()
Description copied from interface: IGestureListViewListener
Checks if we can start highlight mode now.

Specified by:
canHighlight in interface IGestureListViewListener
Returns:
true if highlight mode can be started, false otherwise.

setClipboard

public void setClipboard(TrackListClipboardObject clipboard)
Description copied from interface: IGestureListViewListener
Sets the new clipboard.

Specified by:
setClipboard in interface IGestureListViewListener
Parameters:
clipboard - the clipboard to set.

getClipboard

public Object getClipboard()
Description copied from interface: IGestureListViewListener
Retrieves current clipboard value.

Specified by:
getClipboard in interface IGestureListViewListener
Returns:
current clipboard contents. Do NOT cache this value.

destroy

public void destroy()
Description copied from class: AbstractController
The controller is about to be destroyed. No invocations are performed after this call. The controller should release its resources, stop its activities etc. Make sure that you call super() if you override this method!

Overrides:
destroy in class AbstractController

performZoom

protected void performZoom(boolean zoom)
Description copied from class: AbstractController
Zooms, or un-zooms the controller.

Specified by:
performZoom in class AbstractController
Parameters:
zoom - true zoom the controller in, false zoom the controller out.


Copyright © 2007-2008. All Rights Reserved.