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;
}
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;
}
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;
}
}
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));
}
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;
}
Aggregations