use of com.android.utils.HtmlBuilder in project android by JetBrains.
the class RenderService method warnIfObsoleteLayoutLib.
private static void warnIfObsoleteLayoutLib(@NotNull final Module module, @NotNull RenderLogger logger, @Nullable final EditorDesignSurface surface, @NotNull IAndroidTarget target) {
if (!ourWarnAboutObsoleteLayoutLibVersions) {
return;
}
if (!LayoutLibraryLoader.USE_SDK_LAYOUTLIB) {
// We are using the version shipped with studio, it can never be obsolete. StudioEmbeddedRenderTarget does not implement getVersion.
ourWarnAboutObsoleteLayoutLibVersions = false;
return;
}
if (target instanceof CompatibilityRenderTarget) {
target = ((CompatibilityRenderTarget) target).getRenderTarget();
}
final AndroidVersion version = target.getVersion();
final int revision;
// are minimum revisions; if a later version is available, it will be installed.
switch(version.getFeatureLevel()) {
case 23:
revision = 2;
break;
case 22:
revision = 2;
break;
case 21:
revision = 2;
break;
case 20:
revision = 2;
break;
case 19:
revision = 4;
break;
case 18:
revision = 3;
break;
case 17:
revision = 3;
break;
case 16:
revision = 5;
break;
case 15:
revision = 5;
break;
case 14:
revision = 4;
break;
case 13:
revision = 1;
break;
case 12:
revision = 3;
break;
case 11:
revision = 2;
break;
case 10:
revision = 2;
break;
case 8:
revision = 3;
break;
default:
revision = -1;
break;
}
if (revision >= 0 && target.getRevision() < revision) {
RenderProblem.Html problem = RenderProblem.create(WARNING);
problem.tag("obsoleteLayoutlib");
HtmlBuilder builder = problem.getHtmlBuilder();
builder.add("Using an obsolete version of the " + target.getVersionName() + " layout library which contains many known bugs: ");
builder.addLink("Install Update", logger.getLinkManager().createRunnableLink(() -> {
// Don't warn again
//noinspection AssignmentToStaticFieldFromInstanceMethod
ourWarnAboutObsoleteLayoutLibVersions = false;
List<String> requested = Lists.newArrayList();
// The revision to install. Note that this will install a higher version than this if available;
// e.g. even if we ask for version 4, if revision 7 is available it will be installed, not revision 4.
requested.add(DetailsTypes.getPlatformPath(version));
ModelWizardDialog dialog = SdkQuickfixUtils.createDialogForPaths(module.getProject(), requested);
if (dialog != null && dialog.showAndGet()) {
if (surface != null) {
// Force the target to be recomputed; this will pick up the new revision object from the local sdk.
Configuration configuration = surface.getConfiguration();
if (configuration != null) {
configuration.getConfigurationManager().setTarget(null);
}
surface.requestRender();
// However, due to issue https://code.google.com/p/android/issues/detail?id=76096 it may not yet
// take effect.
Messages.showInfoMessage(module.getProject(), "Note: Due to a bug you may need to restart the IDE for the new layout library to fully take effect", "Restart Recommended");
}
}
}));
builder.addLink(", ", "Ignore For Now", null, logger.getLinkManager().createRunnableLink(() -> {
//noinspection AssignmentToStaticFieldFromInstanceMethod
ourWarnAboutObsoleteLayoutLibVersions = false;
if (surface != null) {
surface.requestRender();
}
}));
logger.addMessage(problem);
}
}
use of com.android.utils.HtmlBuilder in project android by JetBrains.
the class RenderErrorContributor method reportTagResourceFormat.
private void reportTagResourceFormat(@NotNull RenderResult result, @NotNull RenderProblem message) {
Object clientData = message.getClientData();
if (!(clientData instanceof String[])) {
return;
}
String[] strings = (String[]) clientData;
if (strings.length != 2) {
return;
}
RenderTask renderTask = result.getRenderTask();
if (renderTask == null) {
return;
}
IAndroidTarget target = renderTask.getConfiguration().getRealTarget();
if (target == null) {
return;
}
AndroidPlatform platform = renderTask.getPlatform();
if (platform == null) {
return;
}
AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
AttributeDefinitions definitionLookup = targetData.getPublicAttrDefs(result.getFile().getProject());
final String attributeName = strings[0];
final String currentValue = strings[1];
if (definitionLookup == null) {
return;
}
AttributeDefinition definition = definitionLookup.getAttrDefByName(attributeName);
if (definition == null) {
return;
}
Set<AttributeFormat> formats = definition.getFormats();
if (formats.contains(AttributeFormat.Flag) || formats.contains(AttributeFormat.Enum)) {
String[] values = definition.getValues();
if (values.length > 0) {
HtmlBuilder builder = new HtmlBuilder();
builder.add("Change ").add(currentValue).add(" to: ");
boolean first = true;
for (String value : values) {
if (first) {
first = false;
} else {
builder.add(", ");
}
builder.addLink(value, myLinkManager.createReplaceAttributeValueUrl(attributeName, currentValue, value));
}
addRefreshAction(builder);
addIssue().setSummary("Incorrect resource value format").setHtmlContent(builder).build();
}
}
}
use of com.android.utils.HtmlBuilder in project android by JetBrains.
the class RenderLogger method checkForIssue164378.
/**
* Check if this is possibly an instance of http://b.android.com/164378. If likely, this adds a message with the recommended workaround.
*/
private boolean checkForIssue164378(@Nullable Throwable throwable) {
if (isIssue164378(throwable)) {
RenderProblem.Html problem = RenderProblem.create(ERROR);
HtmlBuilder builder = problem.getHtmlBuilder();
addHtmlForIssue164378(throwable, myModule, getLinkManager(), builder, true);
addMessage(problem);
return true;
}
return false;
}
use of com.android.utils.HtmlBuilder in project android by JetBrains.
the class DeveloperServicePanel method initializeFooterPanel.
private void initializeFooterPanel(@NotNull DeveloperServiceMetadata developerServiceMetadata) {
boolean panelHasContent = false;
JPanel verticalFlowPanel = new JPanel();
verticalFlowPanel.setLayout(new BoxLayout(verticalFlowPanel, BoxLayout.PAGE_AXIS));
verticalFlowPanel.add(Box.createRigidArea(new Dimension(0, JBUI.scale(30))));
final HtmlBuilder htmlBuilder = new HtmlBuilder();
htmlBuilder.openHtmlBody();
htmlBuilder.add("Enabling this service will...");
htmlBuilder.beginList();
List<String> dependencies = developerServiceMetadata.getDependencies();
if (!dependencies.isEmpty()) {
htmlBuilder.listItem().add("Add dependencies: ").addItalic(Joiner.on(", ").join(dependencies));
panelHasContent = true;
}
List<String> permissions = developerServiceMetadata.getPermissions();
if (!permissions.isEmpty()) {
htmlBuilder.listItem().add("Add permissions: ").addItalic(Joiner.on(", ").join(permissions));
panelHasContent = true;
}
List<String> modifiedFiles = developerServiceMetadata.getModifiedFiles();
if (!modifiedFiles.isEmpty()) {
htmlBuilder.listItem().add("Create/modify files: ").addItalic(Joiner.on(", ").join(modifiedFiles));
panelHasContent = true;
}
htmlBuilder.endList();
htmlBuilder.closeHtmlBody();
if (panelHasContent) {
verticalFlowPanel.add(new JLabel(htmlBuilder.getHtml()));
mySummaryPanel.add(verticalFlowPanel);
}
}
use of com.android.utils.HtmlBuilder in project android by JetBrains.
the class DeveloperServicePanel method initializeHeaderPanel.
private void initializeHeaderPanel(@NotNull DeveloperServiceMetadata developerServiceMetadata) {
HtmlBuilder htmlBuilder = new HtmlBuilder();
htmlBuilder.openHtmlBody();
htmlBuilder.addBold(developerServiceMetadata.getName()).newline();
htmlBuilder.add(developerServiceMetadata.getDescription());
htmlBuilder.closeHtmlBody();
myHeaderLabel.setText(htmlBuilder.getHtml());
myIcon.setIcon(IconUtil.toSize(developerServiceMetadata.getIcon(), myIcon.getWidth(), myIcon.getHeight()));
URI learnMoreLink = developerServiceMetadata.getLearnMoreLink();
if (learnMoreLink != null) {
addToLinkPanel("Learn More", learnMoreLink);
}
URI apiLink = developerServiceMetadata.getApiLink();
if (apiLink != null) {
addToLinkPanel("API Documentation", apiLink);
}
}
Aggregations