FileDocCategorySizeDatePackage
ConfigGenerator.javaAPI DocAndroid 5.1 API13637Thu Mar 12 22:22:44 GMT 2015com.android.layoutlib.bridge.intensive.setup

ConfigGenerator

public class ConfigGenerator extends Object
Provides {@link FolderConfiguration} and {@link HardwareConfig} for various devices. Also provides utility methods to parse build.prop and attrs.xml to generate the appropriate maps.

Fields Summary
public static final ConfigGenerator
NEXUS_4
public static final ConfigGenerator
NEXUS_5
public static final ConfigGenerator
NEXUS_7
public static final ConfigGenerator
NEXUS_10
private static final String
TAG_ATTR
private static final String
TAG_ENUM
private static final String
TAG_FLAG
private static final String
ATTR_NAME
private static final String
ATTR_VALUE
private int
mScreenHeight
private int
mScreenWidth
private int
mXdpi
private int
mYdpi
private com.android.resources.ScreenOrientation
mOrientation
private com.android.resources.Density
mDensity
private com.android.resources.ScreenRatio
mRatio
private com.android.resources.ScreenSize
mSize
private com.android.resources.Keyboard
mKeyboard
private com.android.resources.TouchScreen
mTouchScreen
private com.android.resources.KeyboardState
mKeyboardState
private boolean
mSoftButtons
private com.android.resources.Navigation
mNavigation
Constructors Summary
Methods Summary
public static java.util.MapgetEnumMap(java.io.File path)

        Map<String, Map<String, Integer>> map = Maps.newHashMap();
        try {
            XmlPullParser xmlPullParser = XmlPullParserFactory.newInstance().newPullParser();
            xmlPullParser.setInput(new FileInputStream(path), null);
            int eventType = xmlPullParser.getEventType();
            String attr = null;
            while (eventType != XmlPullParser.END_DOCUMENT) {
                if (eventType == XmlPullParser.START_TAG) {
                    if (TAG_ATTR.equals(xmlPullParser.getName())) {
                        attr = xmlPullParser.getAttributeValue(null, ATTR_NAME);
                    } else if (TAG_ENUM.equals(xmlPullParser.getName())
                            || TAG_FLAG.equals(xmlPullParser.getName())) {
                        String name = xmlPullParser.getAttributeValue(null, ATTR_NAME);
                        String value = xmlPullParser.getAttributeValue(null, ATTR_VALUE);
                        // Integer.decode cannot handle "ffffffff", see JDK issue 6624867
                        int i = (int) (long) Long.decode(value);
                        assert attr != null;
                        Map<String, Integer> attributeMap = map.get(attr);
                        if (attributeMap == null) {
                            attributeMap = Maps.newHashMap();
                            map.put(attr, attributeMap);
                        }
                        attributeMap.put(name, i);
                    }
                } else if (eventType == XmlPullParser.END_TAG) {
                    if (TAG_ATTR.equals(xmlPullParser.getName())) {
                        attr = null;
                    }
                }
                eventType = xmlPullParser.next();
            }
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    
public com.android.ide.common.resources.configuration.FolderConfigurationgetFolderConfig()


       
        FolderConfiguration config = new FolderConfiguration();
        config.createDefault();
        config.setDensityQualifier(new DensityQualifier(mDensity));
        config.setNavigationMethodQualifier(new NavigationMethodQualifier(mNavigation));
        if (mScreenWidth > mScreenHeight) {
            config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenWidth,
                    mScreenHeight));
        } else {
            config.setScreenDimensionQualifier(new ScreenDimensionQualifier(mScreenHeight,
                    mScreenWidth));
        }
        config.setScreenRatioQualifier(new ScreenRatioQualifier(mRatio));
        config.setScreenSizeQualifier(new ScreenSizeQualifier(mSize));
        config.setTextInputMethodQualifier(new TextInputMethodQualifier(mKeyboard));
        config.setTouchTypeQualifier(new TouchScreenQualifier(mTouchScreen));
        config.setKeyboardStateQualifier(new KeyboardStateQualifier(mKeyboardState));
        config.setScreenOrientationQualifier(new ScreenOrientationQualifier(mOrientation));

        config.updateScreenWidthAndHeight();

        // some default qualifiers.
        config.setUiModeQualifier(new UiModeQualifier(UiMode.NORMAL));
        config.setNightModeQualifier(new NightModeQualifier(NightMode.NOTNIGHT));
        config.setCountryCodeQualifier(new CountryCodeQualifier());
        config.setLanguageQualifier(new LanguageQualifier());
        config.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
        config.setNetworkCodeQualifier(new NetworkCodeQualifier());
        config.setRegionQualifier(new RegionQualifier());
        config.setVersionQualifier(new VersionQualifier());
        return config;
    
public com.android.ide.common.rendering.api.HardwareConfiggetHardwareConfig()

        return new HardwareConfig(mScreenWidth, mScreenHeight, mDensity, mXdpi, mYdpi, mSize,
                mOrientation, mSoftButtons);
    
public static java.util.MaploadProperties(java.io.File path)

        Properties p = new Properties();
        Map<String, String> map = Maps.newHashMap();
        try {
            p.load(new FileInputStream(path));
            for (String key : p.stringPropertyNames()) {
                map.put(key, p.getProperty(key));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetDensity(com.android.resources.Density density)

        mDensity = density;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetKeyboard(com.android.resources.Keyboard keyboard)

        mKeyboard = keyboard;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetKeyboardState(com.android.resources.KeyboardState state)

        mKeyboardState = state;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetNavigation(com.android.resources.Navigation navigation)

        mNavigation = navigation;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetOrientation(com.android.resources.ScreenOrientation orientation)

        mOrientation = orientation;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetRatio(com.android.resources.ScreenRatio ratio)

        mRatio = ratio;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetScreenHeight(int height)

        mScreenHeight = height;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetScreenWidth(int width)

        mScreenWidth = width;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetSize(com.android.resources.ScreenSize size)

        mSize = size;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetSoftButtons(boolean softButtons)

        mSoftButtons = softButtons;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetTouchScreen(com.android.resources.TouchScreen touchScreen)

        mTouchScreen = touchScreen;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetXdpi(int xdpi)

        mXdpi = xdpi;
        return this;
    
public com.android.layoutlib.bridge.intensive.setup.ConfigGeneratorsetYdpi(int ydpi)

        mYdpi = ydpi;
        return this;