Search in sources :

Example 1 with LayoutDirectionQualifier

use of com.android.ide.common.resources.configuration.LayoutDirectionQualifier 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)

Example 2 with LayoutDirectionQualifier

use of com.android.ide.common.resources.configuration.LayoutDirectionQualifier 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 3 with LayoutDirectionQualifier

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

the class RenderTask method createRenderSession.

/**
   * Renders the model and returns the result as a {@link com.android.ide.common.rendering.api.RenderSession}.
   *
   * @param factory Factory for images which would be used to render layouts to.
   * @return the {@link RenderResult resulting from rendering the current model
   */
@Nullable
private RenderResult createRenderSession(@NotNull IImageFactory factory) {
    if (myPsiFile == null) {
        throw new IllegalStateException("createRenderSession shouldn't be called on RenderTask without PsiFile");
    }
    ResourceResolver resolver = ResourceResolver.copy(getResourceResolver());
    if (resolver == null) {
        // Abort the rendering if the resources are not found.
        return null;
    }
    ILayoutPullParser modelParser = LayoutPullParserFactory.create(this);
    if (modelParser == null) {
        return null;
    }
    if (modelParser instanceof LayoutPsiPullParser) {
        // For regular layouts, if we use appcompat, we have to emulat the app:srcCompat attribute behaviour
        AndroidModuleModel androidModel = AndroidModuleModel.get(myRenderService.getFacet());
        boolean useSrcCompat = androidModel != null && GradleUtil.dependsOn(androidModel, APPCOMPAT_LIB_ARTIFACT);
        ((LayoutPsiPullParser) modelParser).setUseSrcCompat(useSrcCompat);
    }
    myLayoutlibCallback.reset();
    ILayoutPullParser includingParser = getIncludingLayoutParser(resolver, modelParser);
    if (includingParser != null) {
        modelParser = includingParser;
    }
    IAndroidTarget target = myConfiguration.getTarget();
    int simulatedPlatform = target instanceof CompatibilityRenderTarget ? target.getVersion().getApiLevel() : 0;
    Module module = myRenderService.getModule();
    HardwareConfig hardwareConfig = myHardwareConfigHelper.getConfig();
    final SessionParams params = new SessionParams(modelParser, myRenderingMode, module, /* projectKey */
    hardwareConfig, resolver, myLayoutlibCallback, myMinSdkVersion.getApiLevel(), myTargetSdkVersion.getApiLevel(), myLogger, simulatedPlatform);
    params.setAssetRepository(myAssetRepository);
    params.setFlag(RenderParamsFlags.FLAG_KEY_ROOT_TAG, AndroidPsiUtils.getRootTagName(myPsiFile));
    params.setFlag(RenderParamsFlags.FLAG_KEY_RECYCLER_VIEW_SUPPORT, true);
    params.setFlag(RenderParamsFlags.FLAG_KEY_DISABLE_BITMAP_CACHING, true);
    params.setFlag(RenderParamsFlags.FLAG_DO_NOT_RENDER_ON_CREATE, true);
    // Request margin and baseline information.
    // TODO: Be smarter about setting this; start without it, and on the first request
    // for an extended view info, re-render in the same session, and then set a flag
    // which will cause this to create extended view info each time from then on in the
    // same session
    params.setExtendedViewInfoMode(true);
    MergedManifest manifestInfo = MergedManifest.get(module);
    LayoutDirectionQualifier qualifier = myConfiguration.getFullConfig().getLayoutDirectionQualifier();
    if (qualifier != null && qualifier.getValue() == LayoutDirection.RTL && !getLayoutLib().isRtl(myLocale.toLocaleId())) {
        // We don't have a flag to force RTL regardless of locale, so just pick a RTL locale (note that
        // this is decoupled from resource lookup)
        params.setLocale("ur");
    } else {
        params.setLocale(myLocale.toLocaleId());
    }
    try {
        params.setRtlSupport(manifestInfo.isRtlSupported());
    } catch (Exception e) {
    // ignore.
    }
    // Don't show navigation buttons on older platforms
    Device device = myConfiguration.getDevice();
    if (!myShowDecorations || HardwareConfigHelper.isWear(device)) {
        params.setForceNoDecor();
    } else {
        try {
            params.setAppLabel(manifestInfo.getApplicationLabel());
            params.setAppIcon(manifestInfo.getApplicationIcon());
            String activity = myConfiguration.getActivity();
            if (activity != null) {
                params.setActivityName(activity);
                ActivityAttributes attributes = manifestInfo.getActivityAttributes(activity);
                if (attributes != null) {
                    if (attributes.getLabel() != null) {
                        params.setAppLabel(attributes.getLabel());
                    }
                    if (attributes.getIcon() != null) {
                        params.setAppIcon(attributes.getIcon());
                    }
                }
            }
        } catch (Exception e) {
        // ignore.
        }
    }
    if (myOverrideBgColor != null) {
        params.setOverrideBgColor(myOverrideBgColor.intValue());
    } else if (requiresTransparency()) {
        params.setOverrideBgColor(0);
    }
    params.setImageFactory(factory);
    if (myTimeout > 0) {
        params.setTimeout(myTimeout);
    }
    try {
        myLayoutlibCallback.setLogger(myLogger);
        myLayoutlibCallback.setResourceResolver(resolver);
        RenderResult result = ApplicationManager.getApplication().runReadAction(new Computable<RenderResult>() {

            @NotNull
            @Override
            public RenderResult compute() {
                Module module = myRenderService.getModule();
                RenderSecurityManager securityManager = isSecurityManagerEnabled ? RenderSecurityManagerFactory.create(module, getPlatform()) : null;
                if (securityManager != null) {
                    securityManager.setActive(true, myCredential);
                }
                try {
                    int retries = 0;
                    RenderSession session = null;
                    while (retries < 10) {
                        if (session != null) {
                            session.dispose();
                        }
                        session = myLayoutLib.createSession(params);
                        Result result = session.getResult();
                        if (result.getStatus() != Result.Status.ERROR_TIMEOUT) {
                            // Sometimes happens at startup; treat it as a timeout; typically a retry fixes it
                            if (!result.isSuccess() && "The main Looper has already been prepared.".equals(result.getErrorMessage())) {
                                retries++;
                                continue;
                            }
                            break;
                        }
                        retries++;
                    }
                    if (session.getResult().isSuccess()) {
                        // Advance the frame time to display the material progress bars
                        // TODO: Expose this through the RenderTask API to allow callers to customize this value
                        long now = System.nanoTime();
                        session.setSystemBootTimeNanos(now);
                        session.setSystemTimeNanos(now);
                        session.setElapsedFrameTimeNanos(TimeUnit.MILLISECONDS.toNanos(500));
                    }
                    RenderResult result = RenderResult.create(RenderTask.this, session, myPsiFile, myLogger, myImagePool.copyOf(session.getImage()));
                    myRenderSession = session;
                    return result;
                } finally {
                    if (securityManager != null) {
                        securityManager.dispose(myCredential);
                    }
                }
            }
        });
        addDiagnostics(result.getRenderResult());
        return result;
    } catch (RuntimeException t) {
        // Exceptions from the bridge
        myLogger.error(null, t.getLocalizedMessage(), t, null);
        throw t;
    }
}
Also used : MergedManifest(com.android.tools.idea.model.MergedManifest) ActivityAttributes(com.android.tools.idea.model.MergedManifest.ActivityAttributes) NotNull(org.jetbrains.annotations.NotNull) Device(com.android.sdklib.devices.Device) IAndroidTarget(com.android.sdklib.IAndroidTarget) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) CompatibilityRenderTarget(com.android.tools.idea.rendering.multi.CompatibilityRenderTarget) ResourceResolver(com.android.ide.common.resources.ResourceResolver) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with LayoutDirectionQualifier

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

the class TextDirectionTest method test.

public void test() {
    assertSame(LEFT_TO_RIGHT, TextDirection.fromConfiguration(null));
    Configuration configuration = mock(Configuration.class);
    FolderConfiguration folderConfig = new FolderConfiguration();
    when(configuration.getFullConfig()).thenReturn(folderConfig);
    // Nothing specified
    assertSame(LEFT_TO_RIGHT, TextDirection.fromConfiguration(configuration));
    // LTR specified
    folderConfig.setLayoutDirectionQualifier(new LayoutDirectionQualifier(LayoutDirection.LTR));
    assertSame(LEFT_TO_RIGHT, TextDirection.fromConfiguration(configuration));
    // RTL specified
    folderConfig.setLayoutDirectionQualifier(new LayoutDirectionQualifier(LayoutDirection.RTL));
    assertSame(RIGHT_TO_LEFT, TextDirection.fromConfiguration(configuration));
    assertSame(SegmentType.START, LEFT_TO_RIGHT.getLeftSegment());
    assertSame(SegmentType.END, RIGHT_TO_LEFT.getLeftSegment());
    assertSame(SegmentType.END, LEFT_TO_RIGHT.getRightSegment());
    assertSame(SegmentType.START, RIGHT_TO_LEFT.getRightSegment());
    assertTrue(LEFT_TO_RIGHT.isLeftSegment(SegmentType.START));
    assertFalse(LEFT_TO_RIGHT.isLeftSegment(SegmentType.END));
    assertTrue(RIGHT_TO_LEFT.isLeftSegment(SegmentType.END));
    assertFalse(RIGHT_TO_LEFT.isLeftSegment(SegmentType.START));
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) LayoutDirectionQualifier(com.android.ide.common.resources.configuration.LayoutDirectionQualifier) FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration)

Example 5 with LayoutDirectionQualifier

use of com.android.ide.common.resources.configuration.LayoutDirectionQualifier in project android_frameworks_base by crdroidandroid.

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

LayoutDirectionQualifier (com.android.ide.common.resources.configuration.LayoutDirectionQualifier)7 FolderConfiguration (com.android.ide.common.resources.configuration.FolderConfiguration)6 CountryCodeQualifier (com.android.ide.common.resources.configuration.CountryCodeQualifier)5 DensityQualifier (com.android.ide.common.resources.configuration.DensityQualifier)5 KeyboardStateQualifier (com.android.ide.common.resources.configuration.KeyboardStateQualifier)5 LocaleQualifier (com.android.ide.common.resources.configuration.LocaleQualifier)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 VersionQualifier (com.android.ide.common.resources.configuration.VersionQualifier)5 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 Device (com.android.sdklib.devices.Device)1