Search in sources :

Example 1 with LocaleQualifier

use of com.android.ide.common.resources.configuration.LocaleQualifier in project android_frameworks_base by ResurrectionRemix.

the class ConfigGenerator method getFolderConfig.

public FolderConfiguration getFolderConfig() {
    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.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
    config.setNetworkCodeQualifier(new NetworkCodeQualifier());
    config.setLocaleQualifier(new LocaleQualifier());
    config.setVersionQualifier(new VersionQualifier());
    return config;
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) NavigationMethodQualifier(com.android.ide.common.resources.configuration.NavigationMethodQualifier) ScreenSizeQualifier(com.android.ide.common.resources.configuration.ScreenSizeQualifier) KeyboardStateQualifier(com.android.ide.common.resources.configuration.KeyboardStateQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) NightModeQualifier(com.android.ide.common.resources.configuration.NightModeQualifier) ScreenOrientationQualifier(com.android.ide.common.resources.configuration.ScreenOrientationQualifier) UiModeQualifier(com.android.ide.common.resources.configuration.UiModeQualifier) TouchScreenQualifier(com.android.ide.common.resources.configuration.TouchScreenQualifier) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) ScreenDimensionQualifier(com.android.ide.common.resources.configuration.ScreenDimensionQualifier) ScreenRatioQualifier(com.android.ide.common.resources.configuration.ScreenRatioQualifier) TextInputMethodQualifier(com.android.ide.common.resources.configuration.TextInputMethodQualifier) DensityQualifier(com.android.ide.common.resources.configuration.DensityQualifier) NetworkCodeQualifier(com.android.ide.common.resources.configuration.NetworkCodeQualifier) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) CountryCodeQualifier(com.android.ide.common.resources.configuration.CountryCodeQualifier)

Example 2 with LocaleQualifier

use of com.android.ide.common.resources.configuration.LocaleQualifier in project android by JetBrains.

the class ConfigurationManager method getLocales.

@NotNull
public List<Locale> getLocales() {
    // Get locales from modules, but not libraries!
    LocalResourceRepository projectResources = ProjectResourceRepository.getProjectResources(myModule, true);
    assert projectResources != null;
    if (projectResources.getModificationCount() != myLocaleCacheStamp) {
        myLocales = null;
    }
    if (myLocales == null) {
        List<Locale> locales = new ArrayList<Locale>();
        for (LocaleQualifier locale : projectResources.getLocales()) {
            locales.add(Locale.create(locale));
        }
        myLocales = locales;
        myLocaleCacheStamp = projectResources.getModificationCount();
    }
    return myLocales;
}
Also used : Locale(com.android.tools.idea.rendering.Locale) LocalResourceRepository(com.android.tools.idea.res.LocalResourceRepository) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with LocaleQualifier

use of com.android.ide.common.resources.configuration.LocaleQualifier in project android by JetBrains.

the class ResourceResolverCache method getFrameworkResources.

/**
   * Returns a {@link LocalResourceRepository} for the framework resources based on the current configuration selection.
   *
   * @return the framework resources or {@code null} if not found.
   */
@Nullable
public ResourceRepository getFrameworkResources(@NotNull FolderConfiguration configuration, @NotNull IAndroidTarget target) {
    int apiLevel = target.getVersion().getFeatureLevel();
    LocaleQualifier locale = configuration.getLocaleQualifier();
    boolean needLocales = locale != null && !locale.hasFakeValue() || myManager.getLocale() != Locale.ANY;
    AndroidTargetData targetData = myFrameworkResources.get(apiLevel);
    if (targetData == null) {
        AndroidPlatform platform = AndroidPlatform.getInstance(myManager.getModule());
        if (platform == null) {
            return null;
        }
        // uses soft ref
        targetData = platform.getSdkData().getTargetData(target);
        myFrameworkResources.put(apiLevel, targetData);
    }
    try {
        return targetData.getFrameworkResources(needLocales);
    } catch (IOException e) {
        LOG.error(e);
    }
    return null;
}
Also used : AndroidPlatform(org.jetbrains.android.sdk.AndroidPlatform) IOException(java.io.IOException) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) AndroidTargetData(org.jetbrains.android.sdk.AndroidTargetData) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LocaleQualifier

use of com.android.ide.common.resources.configuration.LocaleQualifier in project android by JetBrains.

the class VariantItemListener method itemStateChanged.

@Override
public void itemStateChanged(ItemEvent e) {
    if (e.getStateChange() != ItemEvent.SELECTED) {
        return;
    }
    VariantsComboItem item = (VariantsComboItem) e.getItem();
    Configuration oldConfiguration = myContext.getConfiguration();
    ConfigurationManager manager = oldConfiguration.getConfigurationManager();
    Configuration newConfiguration = Configuration.create(manager, null, null, item.getRestrictedConfiguration());
    // Target and locale are global so we need to set them in the configuration manager when updated
    VersionQualifier newVersionQualifier = item.getRestrictedConfiguration().getVersionQualifier();
    if (newVersionQualifier != null) {
        IAndroidTarget realTarget = manager.getHighestApiTarget() != null ? manager.getHighestApiTarget() : manager.getTarget();
        assert realTarget != null;
        manager.setTarget(new CompatibilityRenderTarget(realTarget, newVersionQualifier.getVersion(), null));
    } else {
        manager.setTarget(null);
    }
    LocaleQualifier newLocaleQualifier = item.getRestrictedConfiguration().getLocaleQualifier();
    manager.setLocale(newLocaleQualifier != null ? Locale.create(newLocaleQualifier) : Locale.ANY);
    oldConfiguration.setDevice(null, false);
    Configuration.copyCompatible(newConfiguration, oldConfiguration);
    oldConfiguration.updated(ConfigurationListener.MASK_FOLDERCONFIG);
}
Also used : Configuration(com.android.tools.idea.configurations.Configuration) VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) IAndroidTarget(com.android.sdklib.IAndroidTarget) ConfigurationManager(com.android.tools.idea.configurations.ConfigurationManager) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier)

Example 5 with LocaleQualifier

use of com.android.ide.common.resources.configuration.LocaleQualifier in project platform_frameworks_base by android.

the class ConfigGenerator method getFolderConfig.

public FolderConfiguration getFolderConfig() {
    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.setLayoutDirectionQualifier(new LayoutDirectionQualifier());
    config.setNetworkCodeQualifier(new NetworkCodeQualifier());
    config.setLocaleQualifier(new LocaleQualifier());
    config.setVersionQualifier(new VersionQualifier());
    return config;
}
Also used : VersionQualifier(com.android.ide.common.resources.configuration.VersionQualifier) NavigationMethodQualifier(com.android.ide.common.resources.configuration.NavigationMethodQualifier) ScreenSizeQualifier(com.android.ide.common.resources.configuration.ScreenSizeQualifier) KeyboardStateQualifier(com.android.ide.common.resources.configuration.KeyboardStateQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) NightModeQualifier(com.android.ide.common.resources.configuration.NightModeQualifier) ScreenOrientationQualifier(com.android.ide.common.resources.configuration.ScreenOrientationQualifier) UiModeQualifier(com.android.ide.common.resources.configuration.UiModeQualifier) TouchScreenQualifier(com.android.ide.common.resources.configuration.TouchScreenQualifier) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) ScreenDimensionQualifier(com.android.ide.common.resources.configuration.ScreenDimensionQualifier) ScreenRatioQualifier(com.android.ide.common.resources.configuration.ScreenRatioQualifier) TextInputMethodQualifier(com.android.ide.common.resources.configuration.TextInputMethodQualifier) DensityQualifier(com.android.ide.common.resources.configuration.DensityQualifier) NetworkCodeQualifier(com.android.ide.common.resources.configuration.NetworkCodeQualifier) LocaleQualifier(com.android.ide.common.resources.configuration.LocaleQualifier) CountryCodeQualifier(com.android.ide.common.resources.configuration.CountryCodeQualifier)

Aggregations

LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)17 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)11 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)6 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)6 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5 KeyboardStateQualifier (com.android.ide.common.resources.configuration.KeyboardStateQualifier)5 LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)5 NavigationMethodQualifier (com.android.ide.common.resources.configuration.NavigationMethodQualifier)5 NetworkCodeQualifier (com.android.ide.common.resources.configuration.NetworkCodeQualifier)5 NightModeQualifier (com.android.ide.common.resources.configuration.NightModeQualifier)5 ScreenDimensionQualifier (com.android.ide.common.resources.configuration.ScreenDimensionQualifier)5 ScreenOrientationQualifier (com.android.ide.common.resources.configuration.ScreenOrientationQualifier)5 ScreenRatioQualifier (com.android.ide.common.resources.configuration.ScreenRatioQualifier)5 ScreenSizeQualifier (com.android.ide.common.resources.configuration.ScreenSizeQualifier)5 TextInputMethodQualifier (com.android.ide.common.resources.configuration.TextInputMethodQualifier)5 TouchScreenQualifier (com.android.ide.common.resources.configuration.TouchScreenQualifier)5 UiModeQualifier (com.android.ide.common.resources.configuration.UiModeQualifier)5 Locale (com.android.tools.idea.rendering.Locale)5 NotNull (org.jetbrains.annotations.NotNull)4 LocalResourceRepository (com.android.tools.idea.res.LocalResourceRepository)3