use of com.android.ide.common.resources.ResourceUrl in project kotlin by JetBrains.
the class LintUtils method getInheritedStyles.
@Nullable
public static List<StyleResourceValue> getInheritedStyles(@NonNull Project project, @NonNull LintClient client, @NonNull String styleUrl) {
if (!client.supportsProjectResources()) {
return null;
}
AbstractResourceRepository resources = client.getProjectResources(project, true);
if (resources == null) {
return null;
}
ResourceUrl style = ResourceUrl.parse(styleUrl);
if (style == null || style.framework) {
return null;
}
List<StyleResourceValue> result = null;
Queue<ResourceValue> queue = new ArrayDeque<ResourceValue>();
queue.add(new ResourceValue(style.type, style.name, false));
Set<String> seen = Sets.newHashSet();
int count = 0;
while (count < 30 && !queue.isEmpty()) {
ResourceValue front = queue.remove();
String name = front.getName();
seen.add(name);
List<ResourceItem> items = resources.getResourceItem(front.getResourceType(), name);
if (items != null) {
for (ResourceItem item : items) {
ResourceValue rv = item.getResourceValue(false);
if (rv instanceof StyleResourceValue) {
StyleResourceValue srv = (StyleResourceValue) rv;
if (result == null) {
result = Lists.newArrayList();
}
result.add(srv);
String parent = srv.getParentStyle();
if (parent != null && !parent.startsWith(ANDROID_PREFIX)) {
ResourceUrl p = ResourceUrl.parse(parent);
if (p != null && !p.framework && !seen.contains(p.name)) {
seen.add(p.name);
queue.add(new ResourceValue(ResourceType.STYLE, p.name, false));
}
}
int index = name.lastIndexOf('.');
if (index > 0) {
String parentName = name.substring(0, index);
if (!seen.contains(parentName)) {
seen.add(parentName);
queue.add(new ResourceValue(ResourceType.STYLE, parentName, false));
}
}
}
}
}
count++;
}
return result;
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class AndroidLintMipmapIconsInspection method getQuickFixes.
@NotNull
@Override
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
PsiElement parent = startElement.getParent();
if (parent instanceof XmlAttribute) {
XmlAttribute attribute = (XmlAttribute) parent;
String value = attribute.getValue();
if (value != null) {
ResourceUrl url = ResourceUrl.parse(value);
if (url != null && !url.framework) {
return new AndroidLintQuickFix[] { new MigrateDrawableToMipmapFix(url) };
}
}
}
return AndroidLintQuickFix.EMPTY_ARRAY;
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class ThemeEditorUtils method generateToolTipText.
@NotNull
public static String generateToolTipText(@NotNull final ItemResourceValue resValue, @NotNull final Module module, @NotNull final Configuration configuration) {
final LocalResourceRepository repository = AppResourceRepository.getAppResources(module, true);
if (repository == null) {
return "";
}
String tooltipKey = resValue.toString() + module.toString() + configuration.toString() + repository.getModificationCount();
String cachedTooltip = ourTooltipCache.getIfPresent(tooltipKey);
if (cachedTooltip != null) {
return cachedTooltip;
}
ResourceUrl url = ResourceUrl.parse(ResolutionUtils.getResourceUrlFromQualifiedName(ResolutionUtils.getQualifiedItemName(resValue), SdkConstants.TAG_ATTR));
assert url != null;
String tooltipContents = AndroidJavaDocRenderer.render(module, configuration, url);
assert tooltipContents != null;
ourTooltipCache.put(tooltipKey, tooltipContents);
return tooltipContents;
}
use of com.android.ide.common.resources.ResourceUrl in project android by JetBrains.
the class GradleInstantRunContextTest method getAppResourceReferences.
@Test
public void getAppResourceReferences() throws Exception {
@Language("XML") String manifest = "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"com.google.samples.apps.topeka\">\n" + "\n" + " <application android:allowBackup=\"@bool/allowBackup\"\n" + " android:icon=\"@mipmap/ic_launcher\"\n" + " android:label=\"@string/app_name\"\n" + " android:supportsRtl=\"false\"\n" + " android:theme=\"@style/Topeka\"\n" + " android:name=\".MyApplication\">\n" + "\n" + " <activity android:name=\".activity.SignInActivity\"\n" + " android:theme=\"@style/Topeka.SignInActivity\">\n" + " <intent-filter>\n" + " <action android:name=\"android.intent.action.MAIN\" />\n" + " <category android:name=\"android.intent.category.LAUNCHER\" />\n" + " </intent-filter>\n" + " </activity>\n" + "\n" + " <activity android:name=\".activity.QuizActivity\"\n" + " android:theme=\"@style/Topeka.QuizActivity\"/>\n" + "\n" + " </application>\n" + "</manifest>";
Document document = XmlUtils.parseDocument(manifest, false);
Set<ResourceUrl> appResourceReferences = GradleInstantRunContext.getAppResourceReferences(document.getDocumentElement());
//noinspection ConstantConditions
assertEquals(ImmutableList.copyOf(appResourceReferences), ImmutableList.of(ResourceUrl.parse("@bool/allowBackup"), ResourceUrl.parse("@mipmap/ic_launcher"), ResourceUrl.parse("@string/app_name"), ResourceUrl.parse("@style/Topeka"), ResourceUrl.parse("@style/Topeka.QuizActivity"), ResourceUrl.parse("@style/Topeka.SignInActivity")));
}
Aggregations