当前位置: 首页>>代码示例>>Java>>正文


Java ResourceUrl类代码示例

本文整理汇总了Java中com.android.ide.common.resources.ResourceUrl的典型用法代码示例。如果您正苦于以下问题:Java ResourceUrl类的具体用法?Java ResourceUrl怎么用?Java ResourceUrl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ResourceUrl类属于com.android.ide.common.resources包,在下文中一共展示了ResourceUrl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replaceUrlWithValue

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
private static String replaceUrlWithValue(@NonNull XmlContext context,
        @NonNull String str) {
    Project project = context.getProject();
    LintClient client = context.getClient();
    if (!client.supportsProjectResources()) {
        return str;
    }
    ResourceUrl style = ResourceUrl.parse(str);
    if (style == null || style.type != ResourceType.STRING || style.framework) {
        return str;
    }
    AbstractResourceRepository resources = client.getProjectResources(project, true);
    if (resources == null) {
        return str;
    }
    List<ResourceItem> items = resources.getResourceItem(ResourceType.STRING, style.name);
    if (items == null || items.isEmpty()) {
        return str;
    }
    ResourceValue resourceValue = items.get(0).getResourceValue(false);
    if (resourceValue == null) {
        return str;
    }
    return resourceValue.getValue() == null ? str : resourceValue.getValue();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:AppIndexingApiDetector.java

示例2: getQuickFixes

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AndroidLintInspectionToolProvider.java

示例3: invoke

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
  if (file == null || editor == null) {
    return;
  }
  final XmlTag tag = AndroidUsagesTargetProvider.findValueResourceTagInContext(editor, file);

  if (tag != null) {
    // See if you've actually pointed at an XML value inside the value definition, e.g.
    //   <string name="my_alias">@string/my_string</string>
    // If the caret is on my_string, you expect to rename my_string, not my_alias (the XmlTag)
    ResourceUrl url = findResourceReferenceUnderCaret(editor, file);
    if (url != null && !url.framework) {
      performResourceReferenceRenaming(project, editor, dataContext, file, url);
    }
    else {
      performValueResourceRenaming(project, editor, dataContext, tag);
    }
  }
  else {
    performApplicationPackageRenaming(project, editor, dataContext);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AndroidRenameHandler.java

示例4: performResourceReferenceRenaming

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
private static void performResourceReferenceRenaming(Project project,
                                                     Editor editor,
                                                     DataContext dataContext,
                                                     PsiFile file,
                                                     ResourceUrl url) {
  assert !url.framework;

  final AndroidFacet facet = AndroidFacet.getInstance(file);
  if (facet != null) {
    // Treat the resource reference as if the user renamed the R field instead
    PsiField[] resourceFields = AndroidResourceUtil.findResourceFields(facet, url.type.getName(), url.name, false);
    if (resourceFields.length == 1) {
      RenameDialog.showRenameDialog(dataContext, new RenameDialog(project, resourceFields[0], null, editor));
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AndroidRenameHandler.java

示例5: getViewClassNameFromLayoutReferenceTag

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
private static String getViewClassNameFromLayoutReferenceTag(XmlTag tag, AndroidFacet facet) {
  String layout = tag.getAttributeValue(SdkConstants.ATTR_LAYOUT);
  if (layout == null) {
    return null;
  }
  LocalResourceRepository moduleResources = facet.getModuleResources(false);
  if (moduleResources == null) {
    return null;
  }
  ResourceUrl resourceUrl = ResourceUrl.parse(layout);
  if (resourceUrl == null || resourceUrl.type != ResourceType.LAYOUT) {
    return null;
  }
  DataBindingInfo info = moduleResources.getDataBindingInfoForLayout(resourceUrl.name);
  if (info == null) {
    return null;
  }
  return info.getQualifiedName();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:DataBindingUtil.java

示例6: visitAttribute

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
/** Check resource references: accessing a private resource from an upstream library? */
@Override
public void visitAttribute(@NonNull XmlContext context, @NonNull Attr attribute) {
    String value = attribute.getNodeValue();
    if (context.getProject().isGradleProject()) {
        ResourceUrl url = ResourceUrl.parse(value);
        if (isPrivate(context, url)) {
            String message = createUsageErrorMessage(context, url.type, url.name);
            context.report(ISSUE, attribute, context.getValueLocation(attribute), message);
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:PrivateResourceDetector.java

示例7: test

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
public void test() throws IOException {
    AndroidLibrary library = createMockLibrary(
            ""
                    + "int dimen activity_horizontal_margin 0x7f030000\n"
                    + "int dimen activity_vertical_margin 0x7f030001\n"
                    + "int id action_settings 0x7f060000\n"
                    + "int layout activity_main 0x7f020000\n"
                    + "int menu menu_main 0x7f050000\n"
                    + "int string action_settings 0x7f040000\n"
                    + "int string app_name 0x7f040001\n"
                    + "int string hello_world 0x7f040002",
            ""
                    + ""
                    + "dimen activity_vertical\n"
                    + "id action_settings\n"
                    + "layout activity_main\n"
    );

    ResourceVisibilityLookup visibility = ResourceVisibilityLookup.create(library);
    assertTrue(visibility.isPrivate(ResourceType.DIMEN, "activity_horizontal_margin"));
    assertFalse(visibility.isPrivate(ResourceType.ID, "action_settings"));
    assertFalse(visibility.isPrivate(ResourceType.LAYOUT, "activity_main"));
    //noinspection ConstantConditions
    assertTrue(visibility.isPrivate(ResourceUrl.parse("@dimen/activity_horizontal_margin")));

    assertFalse(visibility.isPrivate(ResourceType.DIMEN, "activity_vertical")); // public
    assertFalse(visibility.isPrivate(ResourceType.DIMEN, "unknown")); // not in this library
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:ResourceVisibilityLookupTest.java

示例8: getResourceDocumentation

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Nullable
private static String getResourceDocumentation(PsiElement element, String value) {
  ResourceUrl url = ResourceUrl.parse(value);
  if (url != null) {
    return generateDoc(element, url);
  } else {
    // See if it's in a resource file definition: This allows you to invoke
    // documentation on <string name="cursor_here">...</string>
    // and see the various translations etc of the string
    XmlAttribute attribute = PsiTreeUtil.getParentOfType(element, XmlAttribute.class, false);
    if (attribute != null && ATTR_NAME.equals(attribute.getName())) {
      XmlTag tag = attribute.getParent();
      String typeName = tag.getName();
      if (TAG_ITEM.equals(typeName)) {
        typeName = tag.getAttributeValue(ATTR_TYPE);
        if (typeName == null) {
          return null;
        }
      }
      ResourceType type = ResourceType.getEnum(typeName);
      if (type != null) {
        return generateDoc(element, type, value, false);
      }
    }
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:AndroidXmlDocumentationProvider.java

示例9: generateDoc

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Nullable
private static String generateDoc(PsiElement originalElement, ResourceUrl url) {
  Module module = ModuleUtilCore.findModuleForPsiElement(originalElement);
  if (module == null) {
    return null;
  }

  return AndroidJavaDocRenderer.render(module, url);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:AndroidXmlDocumentationProvider.java

示例10: findResourceReferenceUnderCaret

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Nullable
private static ResourceUrl findResourceReferenceUnderCaret(@NotNull Editor editor, @NotNull PsiFile file) {
  if (!(file instanceof XmlFile)) {
    return null;
  }

  final AndroidFacet facet = AndroidFacet.getInstance(file);
  if (facet == null) {
    return null;
  }

  if (!AndroidResourceUtil.isInResourceSubdirectory(file, ResourceFolderType.VALUES.getName())) {
    return null;
  }

  final PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
  if (element == null) {
    return null;
  }

  if (element instanceof XmlToken && ((XmlToken)element).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
    XmlText text = PsiTreeUtil.getParentOfType(element, XmlText.class);
    if (text != null) {
      return ResourceUrl.parse(text.getText().trim());
    }
  }

  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:AndroidRenameHandler.java

示例11: getValue

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Override
public Object getValue() {
  JTextField text = getComboText();
  if (text == null) {
    return myBooleanResourceValue == null ? Boolean.toString(myCheckBox.isSelected()) : myBooleanResourceValue;
  }
  String value = text.getText();
  if (value == StringsComboEditor.UNSET || StringUtil.isEmpty(value)) {
    return null;
  }
  if (myIsDimension &&
      !value.startsWith(PREFIX_RESOURCE_REF) &&
      !value.endsWith(UNIT_DIP) &&
      !value.equalsIgnoreCase(VALUE_WRAP_CONTENT) &&
      !value.equalsIgnoreCase(VALUE_FILL_PARENT) &&
      !value.equalsIgnoreCase(VALUE_MATCH_PARENT)) {
    if (value.length() <= 2) {
      return value + UNIT_DP;
    }
    int index = value.length() - 2;
    String dimension = value.substring(index);
    if (ArrayUtil.indexOf(ResourceRenderer.DIMENSIONS, dimension) == -1) {
      return value + UNIT_DP;
    }
  }

  // If it looks like a reference, don't escape it.
  if (myIsString &&
      (value.startsWith(PREFIX_RESOURCE_REF) || value.startsWith(PREFIX_THEME_REF)) &&
      ResourceUrl.parse(value) == null) {
    return "\\" + value;
  }
  return value;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:ResourceEditor.java

示例12: getResourceFromUrl

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Nullable
Resource getResourceFromUrl(@NonNull String possibleUrlReference) {
  ResourceUrl url = ResourceUrl.parse(possibleUrlReference);
  if (url != null && !url.framework) {
    return addResource(url.type, LintUtils.getFieldName(url.name), null);
  }
  return null;
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:9,代码来源:ResourceUsageAnalyzer.java

示例13: isPrivate

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
private static boolean isPrivate(@NonNull Context context, @Nullable ResourceUrl url) {
    return url != null && !url.framework && isPrivate(context, url.type, url.name);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:PrivateResourceDetector.java

示例14: MigrateDrawableToMipmapFix

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
MigrateDrawableToMipmapFix(@NotNull ResourceUrl url) {
  myUrl = url;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:4,代码来源:MigrateDrawableToMipmapFix.java

示例15: childAdded

import com.android.ide.common.resources.ResourceUrl; //导入依赖的package包/类
@Override
public void childAdded(@NotNull PsiTreeChangeEvent event) {
  myIgnoreChildrenChanged = true;

  if (isIgnorable(event)) {
    return;
  }

  if (isRelevantFile(event)) {
    PsiElement child = event.getChild();
    PsiElement parent = event.getParent();

    if (child instanceof XmlAttribute && parent instanceof XmlTag) {
      // Typing in a new attribute. Don't need to do any rendering until there
      // is an actual value
      if (((XmlAttribute)child).getValueElement() == null) {
        return;
      }
    }
    else if (parent instanceof XmlAttribute && child instanceof XmlAttributeValue) {
      XmlAttributeValue attributeValue = (XmlAttributeValue)child;
      if (attributeValue.getValue() == null || attributeValue.getValue().isEmpty()) {
        // Just added a new blank attribute; nothing to render yet
        return;
      }
    }
    else if (parent instanceof XmlAttributeValue && child instanceof XmlToken && event.getOldChild() == null) {
      // Just added attribute value
      String text = child.getText();
      // See if this is an attribute that takes a resource!
      if (text.startsWith(PREFIX_RESOURCE_REF) && !text.startsWith(PREFIX_BINDING_EXPR)) {
        if (text.equals(PREFIX_RESOURCE_REF) || text.equals(ANDROID_PREFIX)) {
          // Using code completion to insert resource reference; not yet done
          return;
        }
        ResourceUrl url = ResourceUrl.parse(text);
        if (url != null && url.name.isEmpty()) {
          // Using code completion to insert resource reference; not yet done
          return;
        }
      }
    }
    notice(Reason.EDIT);
  }
  else {
    notice(Reason.RESOURCE_EDIT);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:49,代码来源:ResourceNotificationManager.java


注:本文中的com.android.ide.common.resources.ResourceUrl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。