FileDocCategorySizeDatePackage
IconLoader.javaAPI DocAndroid 5.1 API4580Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.bars

IconLoader

public class IconLoader extends Object

Fields Summary
private final String
mIconName
private final com.android.resources.Density
mDesiredDensity
private final int
mPlatformVersion
private final com.android.resources.LayoutDirection
mDirection
private com.android.resources.Density
mCurrentDensity
private StringBuilder
mCurrentPath
Constructors Summary
IconLoader(String iconName, com.android.resources.Density density, int platformVersion, com.android.resources.LayoutDirection direction)

        mIconName = iconName;
        mDesiredDensity = density;
        mPlatformVersion = platformVersion;
        mDirection = direction;
        // An upper bound on the length of the path for the icon: /bars/v21/ldrtl-xxxhdpi/
        final int iconPathLength = 24;
        mCurrentPath = new StringBuilder(iconPathLength + iconName.length());
    
Methods Summary
public com.android.resources.DensitygetDensity()
Should only be called after {@link #getIcon()}. Returns the density of the icon, if found by {@code getIcon()}. If no icon was found, then the return value has no meaning.

        return mCurrentDensity;
    
public java.io.InputStreamgetIcon()

        for (String resourceDir : Config.getResourceDirs(mPlatformVersion)) {
            mCurrentDensity = null;
            InputStream stream = getIcon(resourceDir);
            if (stream != null) {
                return stream;
            }
        }
        return null;
    
private java.io.InputStreamgetIcon(java.lang.String resourceDir)
Search for icon in the resource directory. This iterates over all densities. If a match is found, mCurrentDensity will be set to the icon's density.

        // First check for the desired density.
        InputStream stream = getIcon(resourceDir, mDesiredDensity);
        if (stream != null) {
            mCurrentDensity = mDesiredDensity;
            return stream;
        }
        // Didn't find in the desired density. Search in all.
        for (Density density : Density.values()) {
            if (density == mDesiredDensity) {
                // Skip the desired density since it's already been checked.
                continue;
            }
            stream = getIcon(resourceDir, density);
            if (stream != null) {
                mCurrentDensity = density;
                return stream;
            }
        }
        return null;
    
private java.io.InputStreamgetIcon(java.lang.String resourceDir, com.android.resources.Density density)
Returns the icon for given density present in the given resource directory, taking layout direction into consideration.

        mCurrentPath.setLength(0);
        // Currently we don't have any LTR only resources and hence the check is skipped. If they
        // are ever added, change to:
        // if (mDirection == LayoutDirection.RTL || mDirection == LayoutDirection.LTR) {
        if (mDirection == LayoutDirection.RTL) {
            mCurrentPath.append(resourceDir)
                    .append(mDirection.getResourceValue())
                    .append('-")
                    .append(density.getResourceValue())
                    .append('/")
                    .append(mIconName);
            InputStream stream = getClass().getResourceAsStream(mCurrentPath.toString());
            if (stream != null) {
                return stream;
            }
            mCurrentPath.setLength(0);
        }
        mCurrentPath.append(resourceDir)
                .append(density.getResourceValue())
                .append('/")
                .append(mIconName);
        return getClass().getResourceAsStream(mCurrentPath.toString());
    
public java.lang.StringgetPath()
Should only be called after {@link #getIcon()}. Returns the path to the icon, if found by {@code getIcon()}. If no icon was found, then the return value has no meaning.

        return mCurrentPath.toString();