use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.
the class StyleListCellRenderer method customizeCellRenderer.
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (!(value instanceof String)) {
return;
}
String stringValue = (String) value;
if (ThemesListModel.isSpecialOption(stringValue) || ParentRendererEditor.NO_PARENT.equals(stringValue)) {
append(stringValue, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
return;
}
ConfiguredThemeEditorStyle style = myContext.getThemeResolver().getTheme(stringValue);
if (style == null) {
append(stringValue, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
return;
}
ConfiguredThemeEditorStyle parent = style.getParent();
String styleName = style.getName();
String parentName = parent != null ? parent.getName() : null;
String defaultAppThemeResourceUrl = null;
final AndroidFacet facet = AndroidFacet.getInstance(myContext.getCurrentContextModule());
if (facet != null) {
MergedManifest info = MergedManifest.get(facet);
defaultAppThemeResourceUrl = info.getManifestTheme();
}
if (!style.isProjectStyle()) {
String simplifiedName = ThemeEditorUtils.simplifyThemeName(style);
String qualifiedStyleName = (style.isFramework() ? SdkConstants.PREFIX_ANDROID : "") + styleName;
if (StringUtil.isEmpty(simplifiedName)) {
append(qualifiedStyleName, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
} else {
append(simplifiedName, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
append(" [" + qualifiedStyleName + "]", SimpleTextAttributes.GRAY_ATTRIBUTES, false);
}
} else if (!selected && parentName != null && styleName.startsWith(parentName + ".")) {
append(parentName + ".", SimpleTextAttributes.GRAY_ATTRIBUTES, false);
append(styleName.substring(parentName.length() + 1), SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
} else {
append(styleName, SimpleTextAttributes.REGULAR_ATTRIBUTES, true);
}
if (style.getStyleResourceUrl().equals(defaultAppThemeResourceUrl)) {
append(" - Default", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, new JBColor(0xFF4CAF50, 0xFFA5D6A7)), true);
}
}
use of com.android.tools.idea.model.MergedManifest 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.tools.idea.model.MergedManifest in project android by JetBrains.
the class RenderTask method measure.
@Nullable
private RenderSession measure(ILayoutPullParser parser) {
ResourceResolver resolver = getResourceResolver();
if (resolver == null) {
// Abort the rendering if the resources are not found.
return null;
}
myLayoutlibCallback.reset();
HardwareConfig hardwareConfig = myHardwareConfigHelper.getConfig();
Module module = myRenderService.getModule();
final SessionParams params = new SessionParams(parser, RenderingMode.NORMAL, module, /* projectKey */
hardwareConfig, resolver, myLayoutlibCallback, myMinSdkVersion.getApiLevel(), myTargetSdkVersion.getApiLevel(), myLogger);
params.setLayoutOnly();
params.setForceNoDecor();
params.setExtendedViewInfoMode(true);
params.setLocale(myLocale.toLocaleId());
params.setAssetRepository(myAssetRepository);
params.setFlag(RenderParamsFlags.FLAG_KEY_RECYCLER_VIEW_SUPPORT, true);
MergedManifest manifestInfo = MergedManifest.get(module);
try {
params.setRtlSupport(manifestInfo.isRtlSupported());
} catch (Exception e) {
// ignore.
}
try {
myLayoutlibCallback.setLogger(myLogger);
myLayoutlibCallback.setResourceResolver(resolver);
return ApplicationManager.getApplication().runReadAction(new Computable<RenderSession>() {
@Nullable
@Override
public RenderSession compute() {
int retries = 0;
while (retries < 10) {
RenderSession 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++;
session.dispose();
continue;
}
return session;
}
retries++;
}
return null;
}
});
} catch (RuntimeException t) {
// Exceptions from the bridge
myLogger.error(null, t.getLocalizedMessage(), t, null);
throw t;
}
}
use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.
the class MenuPreviewRenderer method createActionBar.
private Element createActionBar() {
Element layout = myDocument.createElement(LINEAR_LAYOUT);
setAndroidAttr(layout, ATTR_LAYOUT_WIDTH, VALUE_FILL_PARENT);
setAndroidAttr(layout, ATTR_LAYOUT_HEIGHT, VALUE_WRAP_CONTENT);
setAndroidAttr(layout, ATTR_LAYOUT_GRAVITY, GRAVITY_VALUE_RIGHT);
setAndroidAttr(layout, ATTR_ORIENTATION, VALUE_HORIZONTAL);
setAndroidAttr(layout, ATTR_GRAVITY, GRAVITY_VALUE_CENTER_VERTICAL + "|" + GRAVITY_VALUE_RIGHT);
if (myApiLevel >= 11 && myResolver.getFrameworkResource(ResourceType.DRAWABLE, "action_bar_background") != null) {
setAndroidAttr(layout, ATTR_BACKGROUND, "@android:drawable/action_bar_background");
} else {
setAndroidAttr(layout, ATTR_BACKGROUND, "#ff85878a");
}
if (myApiLevel >= 11 && myResolver.getFrameworkResource(ResourceType.ATTR, "actionBarSize") != null) {
setAndroidAttr(layout, ATTR_LAYOUT_HEIGHT, "?android:attr/actionBarSize");
} else if (myResolver.getProjectResource(ResourceType.ATTR, "actionBarSize") != null) {
// ActionBarCompat
setAndroidAttr(layout, ATTR_LAYOUT_HEIGHT, "?attr/actionBarSize");
} else {
setAndroidAttr(layout, ATTR_LAYOUT_HEIGHT, "48dp");
}
MergedManifest manifestInfo = MergedManifest.get(myModule);
String applicationIcon = manifestInfo.getApplicationIcon();
if (applicationIcon != null) {
Element imageView = myDocument.createElement(IMAGE_VIEW);
layout.appendChild(imageView);
setAndroidAttr(imageView, ATTR_LAYOUT_WIDTH, VALUE_WRAP_CONTENT);
setAndroidAttr(imageView, ATTR_LAYOUT_HEIGHT, VALUE_WRAP_CONTENT);
setAndroidAttr(imageView, ATTR_SRC, applicationIcon);
// HACK; find out what the real action bar does to the app icon
setAndroidAttr(imageView, "scaleX", "0.9");
setAndroidAttr(imageView, "scaleY", "0.9");
Element dummy = myDocument.createElement(VIEW);
layout.appendChild(dummy);
setAndroidAttr(dummy, ATTR_LAYOUT_WEIGHT, "1");
setAndroidAttr(dummy, ATTR_LAYOUT_WIDTH, VALUE_WRAP_CONTENT);
setAndroidAttr(dummy, ATTR_LAYOUT_HEIGHT, VALUE_WRAP_CONTENT);
}
return layout;
}
use of com.android.tools.idea.model.MergedManifest in project android by JetBrains.
the class FileSystemApkProvider method getApks.
@NotNull
@Override
public Collection<ApkInfo> getApks(@NotNull IDevice device) throws ApkProvisionException {
MergedManifest manifest = MergedManifest.get(myModule);
String id = manifest.getApplicationId();
if (id == null) {
throw new ApkProvisionException("Invalid manifest, no package name specified");
}
List<ApkInfo> apkList = Lists.newArrayList();
apkList.add(new ApkInfo(myApkPath, id));
return apkList;
}
Aggregations