com.android.sdklib.internal.repository.sources
Class SdkSources

java.lang.Object
  extended by com.android.sdklib.internal.repository.sources.SdkSources

public class SdkSources
extends java.lang.Object

A list of sdk-repository and sdk-addon sources, sorted by SdkSourceCategory.


Constructor Summary
SdkSources()
           
 
Method Summary
 void add(SdkSourceCategory category, SdkSource source)
          Adds a new source to the Sources list.
 void addChangeListener(java.lang.Runnable changeListener)
          Adds a listener that will be notified when the sources list has changed.
 void clearAllPackages()
          Each source keeps a local cache of whatever it loaded recently.
 SdkSource[] getAllSources()
          Returns an array of the sources across all categories.
 SdkSourceCategory[] getCategories()
          Returns a set of all categories that must be displayed.
 SdkSourceCategory getCategory(SdkSource source)
          Returns the category of a given source, or null if the source is unknown.
 SdkSource[] getSources(SdkSourceCategory category)
          Returns a new array of sources attached to the given category.
 boolean hasSourceUrl(SdkSource source)
          Returns true if there's already a similar source in the sources list under any category.
 boolean hasSourceUrl(SdkSourceCategory category, SdkSource source)
          Returns true if there's already a similar source in the sources list under the specified category.
 void loadUserAddons(com.android.utils.ILogger log)
          Loads all user sources.
 void notifyChangeListeners()
          Invoke all the registered change listeners, if any.
 void remove(SdkSource source)
          Removes a source from the Sources list.
 void removeAll(SdkSourceCategory category)
          Removes all the sources in the given category.
 void removeChangeListener(java.lang.Runnable changeListener)
          Removes a listener from the list of listeners to notify when the sources change.
 void saveUserAddons(com.android.utils.ILogger log)
          Saves all the user sources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SdkSources

public SdkSources()
Method Detail

add

public void add(SdkSourceCategory category,
                SdkSource source)
Adds a new source to the Sources list.

Implementation detail: SdkSources doesn't invoke notifyChangeListeners() directly. Callers who use add() are responsible for notifying the listeners once they are done modifying the sources list. The intent is to notify the listeners only once at the end, not for every single addition.


remove

public void remove(SdkSource source)
Removes a source from the Sources list.

Callers who remove entries are responsible for notifying the listeners using notifyChangeListeners() once they are done modifying the sources list.


removeAll

public void removeAll(SdkSourceCategory category)
Removes all the sources in the given category.

Callers who remove entries are responsible for notifying the listeners using notifyChangeListeners() once they are done modifying the sources list.


getCategories

public SdkSourceCategory[] getCategories()
Returns a set of all categories that must be displayed. This includes all categories that are to be always displayed as well as all categories which have at least one source. Might return a empty array, but never returns null.


getSources

public SdkSource[] getSources(SdkSourceCategory category)
Returns a new array of sources attached to the given category. Might return an empty array, but never returns null.


getAllSources

public SdkSource[] getAllSources()
Returns an array of the sources across all categories. This is never null.


clearAllPackages

public void clearAllPackages()
Each source keeps a local cache of whatever it loaded recently. This calls SdkSource.clearPackages() on all the available sources, and the next call to SdkSource.getPackages() will actually reload the remote package list.


getCategory

public SdkSourceCategory getCategory(SdkSource source)
Returns the category of a given source, or null if the source is unknown.

Note that this method uses object identity to find a given source, and does not identify sources by their URL like hasSourceUrl(SdkSource) does.

The search is O(N), which should be acceptable on the expectedly small source list.


hasSourceUrl

public boolean hasSourceUrl(SdkSource source)
Returns true if there's already a similar source in the sources list under any category.

Important: The match is NOT done on object identity. Instead, this searches for a similar source, based on SdkSource.equals(Object) which compares the source URLs.

The search is O(N), which should be acceptable on the expectedly small source list.


hasSourceUrl

public boolean hasSourceUrl(SdkSourceCategory category,
                            SdkSource source)
Returns true if there's already a similar source in the sources list under the specified category.

Important: The match is NOT done on object identity. Instead, this searches for a similar source, based on SdkSource.equals(Object) which compares the source URLs.

The search is O(N), which should be acceptable on the expectedly small source list.


loadUserAddons

public void loadUserAddons(com.android.utils.ILogger log)
Loads all user sources. This replaces all existing user sources by the ones from the property file.

This calls notifyChangeListeners() at the end of the operation.


saveUserAddons

public void saveUserAddons(com.android.utils.ILogger log)
Saves all the user sources.

Parameters:
log - Logger. Cannot be null.

addChangeListener

public void addChangeListener(java.lang.Runnable changeListener)
Adds a listener that will be notified when the sources list has changed.

Parameters:
changeListener - A non-null listener to add. Ignored if already present.
See Also:
notifyChangeListeners()

removeChangeListener

public void removeChangeListener(java.lang.Runnable changeListener)
Removes a listener from the list of listeners to notify when the sources change.

Parameters:
changeListener - A listener to remove. Ignored if not previously added.

notifyChangeListeners

public void notifyChangeListeners()
Invoke all the registered change listeners, if any.

This may be called from a worker thread, in which case the runnable should take care of only updating UI from a main thread.