use of org.jetbrains.android.facet.AndroidFacet 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 org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class MergedManifest method syncWithReadPermission.
protected void syncWithReadPermission() {
AndroidFacet facet = AndroidFacet.getInstance(myModule);
assert facet != null : "Attempt to obtain manifest info from a non Android module: " + myModule.getName();
if (myManifestFile == null) {
myManifestFile = ManifestInfo.ManifestFile.create(facet);
}
// Check to see if our data is up to date
boolean refresh = myManifestFile.refresh();
if (!refresh) {
// Already have up to date data
return;
}
myActivityAttributesMap = new HashMap<String, ActivityAttributes>();
myManifestTheme = null;
myTargetSdk = AndroidVersion.DEFAULT;
myMinSdk = AndroidVersion.DEFAULT;
//$NON-NLS-1$
myPackage = "";
//$NON-NLS-1$
myApplicationId = "";
myVersionCode = null;
myApplicationIcon = null;
myApplicationLabel = null;
myApplicationSupportsRtl = false;
myNodeKeys = null;
myActivities = Lists.newArrayList();
myActivityAliases = Lists.newArrayListWithExpectedSize(4);
myServices = Lists.newArrayListWithExpectedSize(4);
Set<String> permissions = Sets.newHashSetWithExpectedSize(30);
Set<String> revocable = Sets.newHashSetWithExpectedSize(2);
try {
Document document = myManifestFile.getXmlDocument();
if (document == null) {
return;
}
myDocument = document;
myManifestFiles = myManifestFile.getManifestFiles();
Element root = document.getDocumentElement();
if (root == null) {
return;
}
myApplicationId = getAttributeValue(root, null, ATTRIBUTE_PACKAGE);
// The package comes from the main manifest, NOT from the merged manifest.
Manifest manifest = facet.getManifest();
myPackage = manifest == null ? myApplicationId : manifest.getPackage().getValue();
String versionCode = getAttributeValue(root, ANDROID_URI, SdkConstants.ATTR_VERSION_CODE);
try {
myVersionCode = Integer.valueOf(versionCode);
} catch (NumberFormatException ignored) {
}
Node node = root.getFirstChild();
while (node != null) {
if (node.getNodeType() == Node.ELEMENT_NODE) {
String nodeName = node.getNodeName();
if (NODE_APPLICATION.equals(nodeName)) {
Element application = (Element) node;
myApplicationIcon = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_ICON);
myApplicationLabel = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_LABEL);
myManifestTheme = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_THEME);
myApplicationSupportsRtl = VALUE_TRUE.equals(getAttributeValue(application, ANDROID_URI, ATTRIBUTE_SUPPORTS_RTL));
String debuggable = getAttributeValue(application, ANDROID_URI, ATTRIBUTE_DEBUGGABLE);
myApplicationDebuggable = debuggable == null ? null : VALUE_TRUE.equals(debuggable);
Node child = node.getFirstChild();
while (child != null) {
if (child.getNodeType() == Node.ELEMENT_NODE) {
String childNodeName = child.getNodeName();
if (NODE_ACTIVITY.equals(childNodeName)) {
Element element = (Element) child;
ActivityAttributes attributes = new ActivityAttributes(element, myApplicationId);
myActivityAttributesMap.put(attributes.getName(), attributes);
myActivities.add(element);
} else if (NODE_ACTIVITY_ALIAS.equals(childNodeName)) {
myActivityAliases.add((Element) child);
} else if (NODE_SERVICE.equals(childNodeName)) {
myServices.add((Element) child);
}
}
child = child.getNextSibling();
}
} else if (NODE_USES_SDK.equals(nodeName)) {
// Look up target SDK
Element usesSdk = (Element) node;
myMinSdk = getApiVersion(usesSdk, ATTRIBUTE_MIN_SDK_VERSION, AndroidVersion.DEFAULT);
myTargetSdk = getApiVersion(usesSdk, ATTRIBUTE_TARGET_SDK_VERSION, myMinSdk);
} else if (TAG_USES_PERMISSION.equals(nodeName) || TAG_USES_PERMISSION_SDK_23.equals(nodeName) || TAG_USES_PERMISSION_SDK_M.equals(nodeName)) {
Element element = (Element) node;
String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
if (!name.isEmpty()) {
permissions.add(name);
}
} else if (nodeName.equals(TAG_PERMISSION)) {
Element element = (Element) node;
String protectionLevel = element.getAttributeNS(ANDROID_URI, ATTR_PROTECTION_LEVEL);
if (VALUE_DANGEROUS.equals(protectionLevel)) {
String name = element.getAttributeNS(ANDROID_URI, ATTR_NAME);
if (!name.isEmpty()) {
revocable.add(name);
}
}
}
}
node = node.getNextSibling();
}
myPermissionHolder = new ModulePermissions(ImmutableSet.copyOf(permissions), ImmutableSet.copyOf(revocable));
} catch (ProcessCanceledException e) {
// clear the file, to make sure we reload everything on next call to this method
myManifestFile = null;
myDocument = null;
throw e;
} catch (Exception e) {
Logger.getInstance(MergedManifest.class).warn("Could not read Manifest data", e);
}
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class RenderErrorContributor method reportInstantiationProblems.
private void reportInstantiationProblems(@NotNull final RenderLogger logger) {
Map<String, Throwable> classesWithIncorrectFormat = logger.getClassesWithIncorrectFormat();
if (classesWithIncorrectFormat == null || classesWithIncorrectFormat.isEmpty()) {
return;
}
HtmlBuilder builder = new HtmlBuilder();
builder.add("Preview might be incorrect: unsupported class version.").newline().addIcon(HtmlBuilderHelper.getTipIconPath()).add("Tip: ");
builder.add("You need to run the IDE with the highest JDK version that you are compiling custom views with. ");
int highest = ClassConverter.findHighestMajorVersion(classesWithIncorrectFormat.values());
if (highest > 0 && highest > ClassConverter.getCurrentClassVersion()) {
String required = ClassConverter.classVersionToJdk(highest);
builder.add("One or more views have been compiled with JDK ").add(required).add(", but you are running the IDE on JDK ").add(ClassConverter.getCurrentJdkVersion()).add(". ");
} else {
builder.add("For example, if you are compiling with sourceCompatibility 1.7, you must run the IDE with JDK 1.7. ");
}
builder.add("Running on a higher JDK is necessary such that these classes can be run in the layout renderer. " + "(Or, extract your custom views into a library which you compile with a lower JDK version.)").newline().newline().addLink("If you have just accidentally built your code with a later JDK, try to ", "build", " the project.", myLinkManager.createBuildProjectUrl()).newline().newline().add("Classes with incompatible format:");
builder.beginList();
List<String> names = Lists.newArrayList(classesWithIncorrectFormat.keySet());
Collections.sort(names);
for (String className : names) {
builder.listItem();
builder.add(className);
//noinspection ThrowableResultOfMethodCallIgnored
Throwable throwable = classesWithIncorrectFormat.get(className);
if (throwable instanceof InconvertibleClassError) {
InconvertibleClassError error = (InconvertibleClassError) throwable;
builder.add(" (Compiled with ").add(ClassConverter.classVersionToJdk(error.getMajor())).add(")");
}
}
builder.endList();
Module module = logger.getModule();
if (module == null) {
return;
}
final List<Module> problemModules = getProblemModules(module);
if (!problemModules.isEmpty()) {
builder.add("The following modules are built with incompatible JDK:").newline();
for (Iterator<Module> it = problemModules.iterator(); it.hasNext(); ) {
Module problemModule = it.next();
builder.add(problemModule.getName());
if (it.hasNext()) {
builder.add(", ");
}
}
builder.newline();
}
AndroidFacet facet = AndroidFacet.getInstance(logger.getModule());
if (facet != null && !facet.requiresAndroidModel()) {
Project project = logger.getModule().getProject();
builder.addLink("Rebuild project with '-target 1.6'", myLinkManager.createRunnableLink(new RebuildWith16Fix(project))).newline();
if (!problemModules.isEmpty()) {
builder.addLink("Change Java SDK to 1.6", myLinkManager.createRunnableLink(new SwitchTo16Fix(project, problemModules))).newline();
}
}
addIssue().setSeverity(HighlightSeverity.WARNING).setSummary("Some classes have an unsupported version").setHtmlContent(builder).build();
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class TemplateManager method updateAction.
private static void updateAction(AnActionEvent event, String text, boolean visible) {
IdeView view = LangDataKeys.IDE_VIEW.getData(event.getDataContext());
final Module module = LangDataKeys.MODULE.getData(event.getDataContext());
final AndroidFacet facet = module != null ? AndroidFacet.getInstance(module) : null;
Presentation presentation = event.getPresentation();
boolean isProjectReady = facet != null && facet.getAndroidModel() != null;
presentation.setText(text + (isProjectReady ? "" : " (Project not ready)"));
presentation.setVisible(visible && view != null && facet != null && facet.requiresAndroidModel());
}
use of org.jetbrains.android.facet.AndroidFacet in project android by JetBrains.
the class TemplateManager method fillCategory.
private void fillCategory(NonEmptyActionGroup categoryGroup, final String category, ActionManager am) {
Map<String, File> categoryRow = myCategoryTable.row(category);
if (CATEGORY_ACTIVITY.equals(category)) {
AnAction galleryAction = new AnAction() {
@Override
public void update(AnActionEvent e) {
updateAction(e, "Gallery...", true);
}
@Override
public void actionPerformed(AnActionEvent e) {
// TODO: before submitting this code, change this to only use the new wizard
if (Boolean.getBoolean("use.npw.modelwizard") && (e.getModifiers() & InputEvent.SHIFT_MASK) == 0) {
DataContext dataContext = e.getDataContext();
Module module = LangDataKeys.MODULE.getData(dataContext);
assert module != null;
VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
assert targetFile != null;
VirtualFile targetDirectory = targetFile;
if (!targetDirectory.isDirectory()) {
targetDirectory = targetFile.getParent();
assert targetDirectory != null;
}
AndroidFacet facet = AndroidFacet.getInstance(module);
assert facet != null && facet.getAndroidModel() != null;
List<TemplateHandle> templateList = getTemplateList(FormFactor.MOBILE);
List<AndroidSourceSet> sourceSets = AndroidSourceSet.getSourceSets(facet, targetDirectory);
assert (sourceSets.size() > 0);
String initialPackageSuggestion = AndroidPackageUtils.getPackageForPath(facet, sourceSets, targetDirectory);
Project project = facet.getModule().getProject();
// TODO: Missing logic to select the default template
RenderTemplateModel renderModel = new RenderTemplateModel(project, templateList.get(0), initialPackageSuggestion, sourceSets.get(0), AndroidBundle.message("android.wizard.activity.add"));
NewModuleModel moduleModel = new NewModuleModel(project);
ChooseActivityTypeStep chooseActivityTypeStep = new ChooseActivityTypeStep(moduleModel, renderModel, facet, templateList, targetDirectory);
ModelWizard wizard = new ModelWizard.Builder().addStep(chooseActivityTypeStep).build();
new StudioWizardDialogBuilder(wizard, "New Android Activity").build().show();
} else {
DataContext dataContext = e.getDataContext();
final Module module = LangDataKeys.MODULE.getData(dataContext);
VirtualFile targetFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
NewAndroidActivityWizard wizard = new NewAndroidActivityWizard(module, targetFile, null);
wizard.init();
wizard.show();
}
}
};
categoryGroup.add(galleryAction);
categoryGroup.addSeparator();
setPresentation(category, galleryAction);
}
for (String templateName : categoryRow.keySet()) {
if (EXCLUDED_TEMPLATES.contains(templateName)) {
continue;
}
TemplateMetadata metadata = getTemplateMetadata(myCategoryTable.get(category, templateName));
NewAndroidComponentAction templateAction = new NewAndroidComponentAction(category, templateName, metadata);
String actionId = ACTION_ID_PREFIX + category + templateName;
am.unregisterAction(actionId);
am.registerAction(actionId, templateAction);
categoryGroup.add(templateAction);
}
}
Aggregations