mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-96015 use 'match_parent' instead of 'fill_parent' when create new layouts if API 8+ is used
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
android:layout_width="${LAYOUT_WIDTH}"
|
||||
android:layout_height="${LAYOUT_HEIGHT}">
|
||||
|
||||
</${ROOT_TAG}>
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
android:layout_width="${LAYOUT_WIDTH}"
|
||||
android:layout_height="${LAYOUT_HEIGHT}">
|
||||
|
||||
</${ROOT_TAG}>
|
||||
@@ -26,6 +26,8 @@ import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.InputValidatorEx;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
@@ -38,6 +40,7 @@ import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.PsiNavigateUtil;
|
||||
import com.intellij.xml.refactoring.XmlTagInplaceRenamer;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.sdk.AndroidPlatform;
|
||||
import org.jetbrains.android.util.AndroidBundle;
|
||||
import org.jetbrains.android.util.AndroidResourceUtil;
|
||||
import org.jetbrains.android.util.AndroidUtils;
|
||||
|
||||
@@ -182,6 +182,10 @@ public class AndroidPlatform {
|
||||
|
||||
public boolean needToAddAnnotationsJarToClasspath() {
|
||||
// todo: check if we really don't need to add this
|
||||
return myTarget.getVersion().getApiLevel() <= 15;
|
||||
return getApiLevel() <= 15;
|
||||
}
|
||||
|
||||
public int getApiLevel() {
|
||||
return myTarget.getVersion().getApiLevel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ModulePackageIndex;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
@@ -51,6 +52,7 @@ import org.jetbrains.android.dom.resources.Item;
|
||||
import org.jetbrains.android.dom.resources.ResourceElement;
|
||||
import org.jetbrains.android.dom.resources.Resources;
|
||||
import org.jetbrains.android.facet.AndroidFacet;
|
||||
import org.jetbrains.android.sdk.AndroidPlatform;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -78,6 +80,8 @@ public class AndroidResourceUtil {
|
||||
ResourceType.MENU, ResourceType.XML, ResourceType.COLOR,
|
||||
ResourceType.DRAWABLE);
|
||||
static final String ROOT_TAG_PROPERTY = "ROOT_TAG";
|
||||
static final String LAYOUT_WIDTH_PROPERTY = "LAYOUT_WIDTH";
|
||||
static final String LAYOUT_HEIGHT_PROPERTY = "LAYOUT_HEIGHT";
|
||||
|
||||
private AndroidResourceUtil() {
|
||||
}
|
||||
@@ -801,6 +805,17 @@ public class AndroidResourceUtil {
|
||||
if (!valuesResourceFile) {
|
||||
properties.setProperty(ROOT_TAG_PROPERTY, rootTagName);
|
||||
}
|
||||
|
||||
if (ResourceType.LAYOUT.getName().equals(resourceType)) {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(resSubdir);
|
||||
final AndroidPlatform platform = module != null ? AndroidPlatform.getInstance(module) : null;
|
||||
final int apiLevel = platform != null ? platform.getApiLevel() : -1;
|
||||
|
||||
final String value = apiLevel == -1 || apiLevel >= 8
|
||||
? "match_parent" : "fill_parent";
|
||||
properties.setProperty(LAYOUT_WIDTH_PROPERTY, value);
|
||||
properties.setProperty(LAYOUT_HEIGHT_PROPERTY, value);
|
||||
}
|
||||
PsiElement createdElement = FileTemplateUtil.createFromTemplate(template, fileName, properties, resSubdir);
|
||||
assert createdElement instanceof XmlFile;
|
||||
return (XmlFile)createdElement;
|
||||
|
||||
Reference in New Issue
Block a user