FileDocCategorySizeDatePackage
AddOnTarget.javaAPI DocAndroid 1.5 API8773Wed May 06 22:41:10 BST 2009com.android.sdklib

AddOnTarget

public final class AddOnTarget extends Object implements IAndroidTarget
Represents an add-on target in the SDK. An add-on extends a standard {@link PlatformTarget}.

Fields Summary
private static final String
ADD_ON_FORMAT
String to compute hash for add-on targets. Format is vendor:name:apiVersion
private final String
mLocation
private final PlatformTarget
mBasePlatform
private final String
mName
private final String
mVendor
private final String
mDescription
private String[]
mSkins
private String
mDefaultSkin
private IOptionalLibrary[]
mLibraries
Constructors Summary
AddOnTarget(String location, String name, String vendor, String description, Map libMap, PlatformTarget basePlatform)
Creates a new add-on

param
location the OS path location of the add-on
param
name the name of the add-on
param
vendor the vendor name of the add-on
param
description the add-on description
param
libMap A map containing the optional libraries. The map key is the fully-qualified library name. The value is a 2 string array with the .jar filename, and the description.
param
basePlatform the platform the add-on is extending.

        if (location.endsWith(File.separator) == false) {
            location = location + File.separator;
        }

        mLocation = location;
        mName = name;
        mVendor = vendor;
        mDescription = description;
        mBasePlatform = basePlatform;
        
        // handle the optional libraries.
        if (libMap != null) {
            mLibraries = new IOptionalLibrary[libMap.size()];
            int index = 0;
            for (Entry<String, String[]> entry : libMap.entrySet()) {
                String jarFile = entry.getValue()[0];
                String desc = entry.getValue()[1];
                mLibraries[index++] = new OptionalLibrary(jarFile,
                        mLocation + SdkConstants.OS_ADDON_LIBS_FOLDER + jarFile,
                        entry.getKey(), desc);
            }
        }
    
Methods Summary
public intcompareTo(IAndroidTarget target)

        if (target.isPlatform()) {
            return +1;
        }
        
        // vendor
        int value = mVendor.compareTo(target.getVendor());

        // name
        if (value == 0) {
            value = mName.compareTo(target.getName());
        }
        
        // api version
        if (value == 0) {
            value = getApiVersionNumber() - target.getApiVersionNumber();
        }
        
        return value;
    
public booleanequals(java.lang.Object obj)

        if (obj instanceof AddOnTarget) {
            AddOnTarget addon = (AddOnTarget)obj;
            
            return mVendor.equals(addon.mVendor) && mName.equals(addon.mName) &&
                mBasePlatform.getApiVersionNumber() == addon.mBasePlatform.getApiVersionNumber();
        }

        return super.equals(obj);
    
public java.lang.StringgetApiVersionName()

        // this is always defined by the base platform
        return mBasePlatform.getApiVersionName();
    
public intgetApiVersionNumber()

        // this is always defined by the base platform
        return mBasePlatform.getApiVersionNumber();
    
public java.lang.StringgetClasspathName()

        return String.format("%1$s [%2$s]", mName, mBasePlatform.getName());
    
public java.lang.StringgetDefaultSkin()

        return mDefaultSkin;
    
public java.lang.StringgetDescription()

        return mDescription;
    
public java.lang.StringgetFullName()

        return String.format("%1$s (%2$s)", mName, mVendor);
    
public java.lang.StringgetLocation()

        return mLocation;
    
public java.lang.StringgetName()

        return mName;
    
public IOptionalLibrary[]getOptionalLibraries()

        return mLibraries;
    
public IAndroidTargetgetParent()

        return mBasePlatform;
    
public java.lang.StringgetPath(int pathId)

        switch (pathId) {
            case IMAGES:
                return mLocation + SdkConstants.OS_IMAGES_FOLDER;
            case SKINS:
                return mLocation + SdkConstants.OS_SKINS_FOLDER;
            case DOCS:
                return mLocation + SdkConstants.FD_DOCS + File.separator
                        + SdkConstants.FD_DOCS_REFERENCE;
            case SAMPLES:
                // only return the add-on samples folder if there is actually a sample (or more)
                File sampleLoc = new File(mLocation, SdkConstants.FD_SAMPLES);
                if (sampleLoc.isDirectory()) {
                    File[] files = sampleLoc.listFiles(new FileFilter() {
                        public boolean accept(File pathname) {
                            return pathname.isDirectory();
                        }
                        
                    });
                    if (files != null && files.length > 0) {
                        return sampleLoc.getAbsolutePath();
                    }
                }
                // INTENT FALL-THROUGH
            default :
                return mBasePlatform.getPath(pathId);
        }
    
public java.lang.String[]getSkins()

        return mSkins;
    
public java.lang.StringgetVendor()

        return mVendor;
    
public inthashCode()

        return hashString().hashCode();
    
public java.lang.StringhashString()

        return String.format(ADD_ON_FORMAT, mVendor, mName, mBasePlatform.getApiVersionNumber());
    
public booleanisCompatibleBaseFor(IAndroidTarget target)

        // basic test
        if (target == this) {
            return true;
        }

        // if the receiver has no optional library, then anything with api version number >= to
        // the receiver is compatible.
        if (mLibraries.length == 0) {
            return target.getApiVersionNumber() >= getApiVersionNumber();
        }

        // Otherwise, target is only compatible if the vendor and name are equals with the api
        // number greater or equal (ie target is a newer version of this add-on).
        if (target.isPlatform() == false) {
            return (mVendor.equals(target.getVendor()) && mName.equals(target.getName()) &&
                    target.getApiVersionNumber() >= getApiVersionNumber());
        }

        return false;
    
public booleanisPlatform()

        return false;
    
public voidsetSkins(java.lang.String[] skins, java.lang.String defaultSkin)

        mDefaultSkin = defaultSkin;

        // we mix the add-on and base platform skins
        HashSet<String> skinSet = new HashSet<String>();
        skinSet.addAll(Arrays.asList(skins));
        skinSet.addAll(Arrays.asList(mBasePlatform.getSkins()));
        
        mSkins = skinSet.toArray(new String[skinSet.size()]);