FileDocCategorySizeDatePackage
FolderConfiguration.javaAPI DocAndroid 1.5 API17213Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.resources.configurations

FolderConfiguration

public final class FolderConfiguration extends Object implements Comparable
Represents the configuration for Resource Folders. All the properties have a default value which means that the property is not set.

Fields Summary
public static final String
QUALIFIER_SEP
private final ResourceQualifier[]
mQualifiers
private static final int
INDEX_COUNTRY_CODE
private static final int
INDEX_NETWORK_CODE
private static final int
INDEX_LANGUAGE
private static final int
INDEX_REGION
private static final int
INDEX_SCREEN_ORIENTATION
private static final int
INDEX_PIXEL_DENSITY
private static final int
INDEX_TOUCH_TYPE
private static final int
INDEX_KEYBOARD_STATE
private static final int
INDEX_TEXT_INPUT_METHOD
private static final int
INDEX_NAVIGATION_METHOD
private static final int
INDEX_SCREEN_DIMENSION
private static final int
INDEX_COUNT
Constructors Summary
Methods Summary
public voidaddQualifier(ResourceQualifier qualifier)
Adds a qualifier to the {@link FolderConfiguration}

param
qualifier the {@link ResourceQualifier} to add.

        if (qualifier instanceof CountryCodeQualifier) {
            mQualifiers[INDEX_COUNTRY_CODE] = qualifier;
        } else if (qualifier instanceof NetworkCodeQualifier) {
            mQualifiers[INDEX_NETWORK_CODE] = qualifier;
        } else if (qualifier instanceof LanguageQualifier) {
            mQualifiers[INDEX_LANGUAGE] = qualifier;
        } else if (qualifier instanceof RegionQualifier) {
            mQualifiers[INDEX_REGION] = qualifier;
        } else if (qualifier instanceof ScreenOrientationQualifier) {
            mQualifiers[INDEX_SCREEN_ORIENTATION] = qualifier;
        } else if (qualifier instanceof PixelDensityQualifier) {
            mQualifiers[INDEX_PIXEL_DENSITY] = qualifier;
        } else if (qualifier instanceof TouchScreenQualifier) {
            mQualifiers[INDEX_TOUCH_TYPE] = qualifier;
        } else if (qualifier instanceof KeyboardStateQualifier) {
            mQualifiers[INDEX_KEYBOARD_STATE] = qualifier;
        } else if (qualifier instanceof TextInputMethodQualifier) {
            mQualifiers[INDEX_TEXT_INPUT_METHOD] = qualifier;
        } else if (qualifier instanceof NavigationMethodQualifier) {
            mQualifiers[INDEX_NAVIGATION_METHOD] = qualifier;
        } else if (qualifier instanceof ScreenDimensionQualifier) {
            mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier;
        }
    
public booleancheckRegion()
Returns whether the Region qualifier is valid. Region qualifier can only be present if a Language qualifier is present as well.

return
true if the Region qualifier is valid.

        if (mQualifiers[INDEX_LANGUAGE] == null && mQualifiers[INDEX_REGION] != null) {
            return false;
        }

        return true;
    
public intcompareTo(com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration folderConfig)

        // default are always at the top.
        if (isDefault()) {
            if (folderConfig.isDefault()) {
                return 0;
            }
            return -1;
        }
        
        // now we compare the qualifiers
        for (int i = 0 ; i < INDEX_COUNT; i++) {
            ResourceQualifier qualifier1 = mQualifiers[i];
            ResourceQualifier qualifier2 = folderConfig.mQualifiers[i];
            
            if (qualifier1 == null) {
                if (qualifier2 == null) {
                    continue;
                } else {
                    return -1;
                }
            } else {
                if (qualifier2 == null) {
                    return 1;
                } else {
                    int result = qualifier1.compareTo(qualifier2);
                    
                    if (result == 0) {
                        continue;
                    }
                    
                    return result;
                }
            }
        }
        
        // if we arrive here, all the qualifier matches
        return 0;
    
public voidcreateDefault()
Create default qualifiers.

        mQualifiers[INDEX_COUNTRY_CODE] = new CountryCodeQualifier();
        mQualifiers[INDEX_NETWORK_CODE] = new NetworkCodeQualifier();
        mQualifiers[INDEX_LANGUAGE] = new LanguageQualifier();
        mQualifiers[INDEX_REGION] = new RegionQualifier();
        mQualifiers[INDEX_SCREEN_ORIENTATION] = new ScreenOrientationQualifier();
        mQualifiers[INDEX_PIXEL_DENSITY] = new PixelDensityQualifier();
        mQualifiers[INDEX_TOUCH_TYPE] = new TouchScreenQualifier();
        mQualifiers[INDEX_KEYBOARD_STATE] = new KeyboardStateQualifier();
        mQualifiers[INDEX_TEXT_INPUT_METHOD] = new TextInputMethodQualifier();
        mQualifiers[INDEX_NAVIGATION_METHOD] = new NavigationMethodQualifier();
        mQualifiers[INDEX_SCREEN_DIMENSION] = new ScreenDimensionQualifier();
    
public booleanequals(java.lang.Object obj)
Returns whether an object is equals to the receiver.

        if (obj == this) {
            return true;
        }
        
        if (obj instanceof FolderConfiguration) {
            FolderConfiguration fc = (FolderConfiguration)obj;
            for (int i = 0 ; i < INDEX_COUNT ; i++) {
                ResourceQualifier qualifier = mQualifiers[i];
                ResourceQualifier fcQualifier = fc.mQualifiers[i];
                if (qualifier != null) {
                    if (qualifier.equals(fcQualifier) == false) {
                        return false;
                    }
                } else if (fcQualifier != null) {
                    return false;
                }
            }

            return true;
        }
        
        return false;
    
public CountryCodeQualifiergetCountryCodeQualifier()

        return (CountryCodeQualifier)mQualifiers[INDEX_COUNTRY_CODE];
    
public java.lang.StringgetFolderName(com.android.ide.eclipse.editors.resources.manager.ResourceFolderType folder)
Returns the name of a folder with the configuration.

        StringBuilder result = new StringBuilder(folder.getName());
        
        for (ResourceQualifier qualifier : mQualifiers) {
            if (qualifier != null) {
                result.append(QUALIFIER_SEP);
                result.append(qualifier.toString());
            }
        }
        
        return result.toString();
    
public intgetHighestPriorityQualifier(int startIndex)
Returns the index of the first non null {@link ResourceQualifier} starting at index startIndex

param
startIndex
return
-1 if no qualifier was found.

        for (int i = startIndex ; i < INDEX_COUNT ; i++) {
            if (mQualifiers[i] != null) {
                return i;
            }
        }
        
        return -1;
    
public ResourceQualifiergetInvalidQualifier()
Returns the first invalid qualifier, or null if they are all valid (or if none exists).

        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            if (mQualifiers[i] != null && mQualifiers[i].isValid() == false) {
                return mQualifiers[i];
            }
        }
        
        // all allocated qualifiers are valid, we return null.
        return null;
    
public KeyboardStateQualifiergetKeyboardStateQualifier()

        return (KeyboardStateQualifier)mQualifiers[INDEX_KEYBOARD_STATE];
    
public LanguageQualifiergetLanguageQualifier()

        return (LanguageQualifier)mQualifiers[INDEX_LANGUAGE];
    
public NavigationMethodQualifiergetNavigationMethodQualifier()

        return (NavigationMethodQualifier)mQualifiers[INDEX_NAVIGATION_METHOD];
    
public NetworkCodeQualifiergetNetworkCodeQualifier()

        return (NetworkCodeQualifier)mQualifiers[INDEX_NETWORK_CODE];
    
public PixelDensityQualifiergetPixelDensityQualifier()

        return (PixelDensityQualifier)mQualifiers[INDEX_PIXEL_DENSITY];
    
public ResourceQualifier[]getQualifiers()
Returns an array of all the non null qualifiers.

        int count = 0;
        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            if (mQualifiers[i] != null) {
                count++;
            }
        }
        
        ResourceQualifier[] array = new ResourceQualifier[count];
        int index = 0;
        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            if (mQualifiers[i] != null) {
                array[index++] = mQualifiers[i];
            }
        }
        
        return array;
    
public RegionQualifiergetRegionQualifier()

        return (RegionQualifier)mQualifiers[INDEX_REGION];
    
public ScreenDimensionQualifiergetScreenDimensionQualifier()

        return (ScreenDimensionQualifier)mQualifiers[INDEX_SCREEN_DIMENSION];
    
public ScreenOrientationQualifiergetScreenOrientationQualifier()

        return (ScreenOrientationQualifier)mQualifiers[INDEX_SCREEN_ORIENTATION];
    
public TextInputMethodQualifiergetTextInputMethodQualifier()

        return (TextInputMethodQualifier)mQualifiers[INDEX_TEXT_INPUT_METHOD];
    
public TouchScreenQualifiergetTouchTypeQualifier()

        return (TouchScreenQualifier)mQualifiers[INDEX_TOUCH_TYPE];
    
public inthashCode()

        return toString().hashCode();
    
public booleanisDefault()
Returns whether the Configuration has only default values.

        for (ResourceQualifier irq : mQualifiers) {
            if (irq != null) {
                return false;
            }
        }
        
        return true;
    
public intmatch(com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration referenceConfig)
Returns whether the configuration match the given reference config.

A match means that:

  • This config does not use any qualifier not used by the reference config
  • The qualifier used by this config have the same values as the qualifiers of the reference config.

param
referenceConfig The reference configuration to test against.
return
the number of matching qualifiers or -1 if the configurations are not compatible.

        int matchCount = 0;
        
        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            ResourceQualifier testQualifier = mQualifiers[i];
            ResourceQualifier referenceQualifier = referenceConfig.mQualifiers[i];
            
            // we only care if testQualifier is non null. If it's null, it's a match but
            // without increasing the matchCount.
            if (testQualifier != null) {
                if (referenceQualifier == null) {
                    return -1;
                } else if (testQualifier.equals(referenceQualifier) == false) {
                    return -1;
                }
                
                // the qualifier match, increment the count
                matchCount++;
            }
        }
        return matchCount;
    
public voidremoveQualifier(ResourceQualifier qualifier)
Removes a given qualifier from the {@link FolderConfiguration}.

param
qualifier the {@link ResourceQualifier} to remove.

        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            if (mQualifiers[i] == qualifier) {
                mQualifiers[i] = null;
                return;
            }
        }
    
public voidset(com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config)
Sets the config from the qualifiers of a given config.

param
config

    
                     
        
        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            mQualifiers[i] = config.mQualifiers[i];
        }
    
public voidsetCountryCodeQualifier(CountryCodeQualifier qualifier)

        mQualifiers[INDEX_COUNTRY_CODE] = qualifier;
    
public voidsetKeyboardStateQualifier(KeyboardStateQualifier qualifier)

        mQualifiers[INDEX_KEYBOARD_STATE] = qualifier;
    
public voidsetLanguageQualifier(LanguageQualifier qualifier)

        mQualifiers[INDEX_LANGUAGE] = qualifier;
    
public voidsetNavigationMethodQualifier(NavigationMethodQualifier qualifier)

        mQualifiers[INDEX_NAVIGATION_METHOD] = qualifier;
    
public voidsetNetworkCodeQualifier(NetworkCodeQualifier qualifier)

        mQualifiers[INDEX_NETWORK_CODE] = qualifier;
    
public voidsetPixelDensityQualifier(PixelDensityQualifier qualifier)

        mQualifiers[INDEX_PIXEL_DENSITY] = qualifier;
    
public voidsetRegionQualifier(RegionQualifier qualifier)

        mQualifiers[INDEX_REGION] = qualifier;
    
public voidsetScreenDimensionQualifier(ScreenDimensionQualifier qualifier)

        mQualifiers[INDEX_SCREEN_DIMENSION] = qualifier;
    
public voidsetScreenOrientationQualifier(ScreenOrientationQualifier qualifier)

        mQualifiers[INDEX_SCREEN_ORIENTATION] = qualifier;
    
public voidsetTextInputMethodQualifier(TextInputMethodQualifier qualifier)

        mQualifiers[INDEX_TEXT_INPUT_METHOD] = qualifier;
    
public voidsetTouchTypeQualifier(TouchScreenQualifier qualifier)

        mQualifiers[INDEX_TOUCH_TYPE] = qualifier;
    
public voidsubstract(com.android.ide.eclipse.editors.resources.configurations.FolderConfiguration config)
Removes the qualifiers from the receiver if they are present (and valid) in the given configuration.

        for (int i = 0 ; i < INDEX_COUNT ; i++) {
            if (config.mQualifiers[i] != null && config.mQualifiers[i].isValid()) {
                mQualifiers[i] = null;
            }
        }
    
public java.lang.StringtoDisplayString()
Returns a string valid for display purpose.

        if (isDefault()) {
            return "default";
        }

        StringBuilder result = null;
        int index = 0;
        ResourceQualifier qualifier = null;
        
        // pre- language/region qualifiers
        while (index < INDEX_LANGUAGE) {
            qualifier = mQualifiers[index++];
            if (qualifier != null) {
                if (result == null) {
                    result = new StringBuilder();
                } else {
                    result.append(", "); //$NON-NLS-1$
                }
                result.append(qualifier.getStringValue());
                
            }
        }
        
        // process the language/region qualifier in a custom way, if there are both non null.
        if (mQualifiers[INDEX_LANGUAGE] != null && mQualifiers[INDEX_REGION] != null) {
            String language = mQualifiers[INDEX_LANGUAGE].getStringValue();
            String region = mQualifiers[INDEX_REGION].getStringValue();

            if (result == null) {
                result = new StringBuilder();
            } else {
                result.append(", "); //$NON-NLS-1$
            }
            result.append(String.format("%s_%s", language, region)); //$NON-NLS-1$
            
            index += 2;
        }
        
        // post language/region qualifiers.
        while (index < INDEX_COUNT) {
            qualifier = mQualifiers[index++];
            if (qualifier != null) {
                if (result == null) {
                    result = new StringBuilder();
                } else {
                    result.append(", "); //$NON-NLS-1$
                }
                result.append(qualifier.getStringValue());
                
            }
        }

        return result.toString();
    
public java.lang.StringtoString()
Returns a string valid for usage in a folder name, or null if the configuration is default.

        StringBuilder result = null;
        
        for (ResourceQualifier irq : mQualifiers) {
            if (irq != null) {
                if (result == null) {
                    result = new StringBuilder();
                } else {
                    result.append(QUALIFIER_SEP);
                }
                result.append(irq.toString());
            }
        }
        
        if (result != null) {
            return result.toString();
        } else {
            return null;
        }