• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SdkUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: parseSizeToBytes

import com.android.utils.SdkUtils; //导入依赖的package包/类
/**
 * Returns an Optional<Long> that is present when the size can be parsed successfully, and
 * empty otherwise.
 */
@VisibleForTesting
@NonNull
static Optional<Long> parseSizeToBytes(@NonNull String sizeParameter) {
    long multiplier = 1;
    if (SdkUtils.endsWithIgnoreCase(sizeParameter, "k")) {
        multiplier = 1024;
    } else if (SdkUtils.endsWithIgnoreCase(sizeParameter, "m")) {
        multiplier = 1024 * 1024;
    } else if (SdkUtils.endsWithIgnoreCase(sizeParameter, "g")) {
        multiplier = 1024 * 1024 * 1024;
    }

    if (multiplier != 1) {
        sizeParameter = sizeParameter.substring(0, sizeParameter.length() - 1);
    }

    try {
        return Optional.of(multiplier * Long.parseLong(sizeParameter));
    } catch (NumberFormatException e) {
        return Optional.empty();
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:27,代码来源:DexByteCodeConverterHook.java


示例2: validateAttributes

import com.android.utils.SdkUtils; //导入依赖的package包/类
/**
 * Validates the associated resource file to make sure the attribute references are valid
 *
 * @return true if parsing succeeds and false if it fails
 */
private boolean validateAttributes(ScanningContext context) {
    // We only need to check if it's a non-framework file (and an XML file; skip .png's)
    if (!isFramework() && SdkUtils.endsWith(getFile().getName(), DOT_XML)) {
        ValidatingResourceParser parser = new ValidatingResourceParser(context, false);
        try {
            IAbstractFile file = getFile();
            return parser.parse(file.getOsLocation(), file.getContents());
        } catch (Exception e) {
            context.needsFullAapt();
        }

        return false;
    }

    return true;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:22,代码来源:SingleResourceFile.java


示例3: getAaptOutput

import com.android.utils.SdkUtils; //导入依赖的package包/类
/**
 * Returns the aapt output.
 * @param apkFile the apk file to call aapt on.
 * @return the output as a list of files.
 * @throws ProcessException
 */
@NonNull
private List<String> getAaptOutput(@NonNull File apkFile)
        throws ProcessException {
    ProcessInfoBuilder builder = new ProcessInfoBuilder();

    builder.setExecutable(mAaptFile);
    builder.addArgs("dump", "badging", apkFile.getPath());

    CachedProcessOutputHandler processOutputHandler = new CachedProcessOutputHandler();

    mProcessExecutor.execute(
            builder.createProcess(), processOutputHandler)
            .rethrowFailure().assertNormalExitValue();

    BaseProcessOutputHandler.BaseProcessOutput output = processOutputHandler.getProcessOutput();

    return Splitter.on(SdkUtils.getLineSeparator()).splitToList(output.getStandardOutputAsString());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ApkInfoParser.java


示例4: testLoadLibrary

import com.android.utils.SdkUtils; //导入依赖的package包/类
public void testLoadLibrary() throws Exception {
    RenderSecurityManager manager = new RenderSecurityManager(null, null);
    try {
        manager.setActive(true, myCredential);

        // Unit test only runs on OSX
        if (SdkUtils.startsWithIgnoreCase(System.getProperty("os.name"), "Mac")
                && new File("/usr/lib/libc.dylib").exists()) {
            System.load("/usr/lib/libc.dylib");
            fail("Should have thrown security exception");
        }
    } catch (SecurityException exception) {
        assertEquals("Link access not allowed during rendering (/usr/lib/libc.dylib)",
                exception.toString());
        // pass
    } finally {
        manager.dispose(myCredential);
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:RenderSecurityManagerTest.java


示例5: write

import com.android.utils.SdkUtils; //导入依赖的package包/类
void write(@NotNull ConsoleViewContentType contentType, @NotNull byte[] b, int off, int len) {
  boolean addNewLine = false;
  // We are combining input from stdout and stderr and that we want to make sure that whenever the output is mixed it starts on a new
  // line.
  if (contentType != myPreviousContentType) {
    addNewLine = myPreviousContentType != null;
    myPreviousContentType = contentType;
  }
  String lineSeparator = SdkUtils.getLineSeparator();
  boolean newLineAdded = false;
  if (addNewLine) {
    byte[] bytes = lineSeparator.getBytes();
    myOutput.write(bytes, 0, bytes.length);
    myConsoleView.print(lineSeparator, contentType);
    newLineAdded = true;
  }
  String text = new String(b, off, len);
  if (lineSeparator.equals(text) && newLineAdded) {
    return;
  }
  myOutput.write(b, off, len);
  if (contentType == ERROR_OUTPUT) {
    myStdErr.write(b, off, len);
  }
  myConsoleView.print(text, contentType);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:GradleOutputForwarder.java


示例6: createFilePositionUrl

import com.android.utils.SdkUtils; //导入依赖的package包/类
/** Creates a file url for the given file and line position
 *
 * @param file the file
 * @param line the line, or -1 if not known
 * @param column the column, or 0 if not known
 * @return a URL which points to a given position in a file
 */
@Nullable
public static String createFilePositionUrl(@NotNull File file, int line, int column) {
  try {
    String fileUrl = SdkUtils.fileToUrlString(file);
    if (line != -1) {
      if (column > 0) {
        return fileUrl + ':' + line + ':' + column;
      } else {
        return fileUrl + ':' + line;
      }
    }
    return fileUrl;
  }
  catch (MalformedURLException e) {
    // Ignore
    Logger.getInstance(HtmlLinkManager.class).error(e);
    return null;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:27,代码来源:HtmlLinkManager.java


示例7: stripActivitySuffix

import com.android.utils.SdkUtils; //导入依赖的package包/类
private static String stripActivitySuffix(@NotNull String activityName) {
  // Does the name end with Activity<Number> ? If so, we don't want to
  // for example turn "MainActivity2" into "activity_main_activity2"
  int lastCharIndex = activityName.length() - 1;
  if (Character.isDigit(activityName.charAt(lastCharIndex))) {
    for (int i = lastCharIndex - 1; i > 0; i--) {
      if (!Character.isDigit(activityName.charAt(i))) {
        i++;
        if (SdkUtils.endsWith(activityName, i, ACTIVITY_NAME_SUFFIX)) {
          return activityName.substring(0, i - ACTIVITY_NAME_SUFFIX.length()) + activityName.substring(i);
        }
        break;
      }
    }
  }

  return stripSuffix(activityName, ACTIVITY_NAME_SUFFIX, true /* recursive strip */);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:FmActivityToLayoutMethod.java


示例8: getRootDir

import com.android.utils.SdkUtils; //导入依赖的package包/类
/**
 * Returns the Android source tree root dir.
 *
 * @return the root dir or null if it couldn't be computed.
 */
private File getRootDir() {
    CodeSource source = getClass().getProtectionDomain().getCodeSource();
    if (source != null) {
        URL location = source.getLocation();
        try {
            File dir = SdkUtils.urlToFile(location);
            assertTrue(dir.getPath(), dir.exists());
            while (dir != null) {
                File lint = new File(dir, getRulesProjectName());
                if (lint.exists() && new File(lint, "src").exists()) {
                    return lint;
                }
                File settingsGradle = new File(dir, "settings.gradle");
                if (settingsGradle.exists()) {
                    return dir.getParentFile().getParentFile();
                }
                dir = dir.getParentFile();
            }
            return null;
        } catch (MalformedURLException e) {
            fail(e.getLocalizedMessage());
        }
    }
    return null;
}
 
开发者ID:winterDroid,项目名称:droidcon_lint,代码行数:31,代码来源:AbstractCheckTest.java


示例9: getTestDataRootDir

import com.android.utils.SdkUtils; //导入依赖的package包/类
@Nullable private File getTestDataRootDir() {
  CodeSource source = getClass().getProtectionDomain().getCodeSource();
  if (source != null) {
    URL location = source.getLocation();
    try {
      File classesDir = SdkUtils.urlToFile(location);
      return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile();
    } catch (MalformedURLException e) {
      fail(e.getLocalizedMessage());
    }
  }
  return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:LintDetectorTestBase.java


示例10: XmlPrettyPrinter

import com.android.utils.SdkUtils; //导入依赖的package包/类
/**
 * Creates a new {@link XmlPrettyPrinter}
 *
 * @param prefs the preferences to format with
 * @param style the style to format with
 * @param lineSeparator the line separator to use, such as "\n" (can be null, in which
 *            case the system default is looked up via the line.separator property)
 */
public XmlPrettyPrinter(XmlFormatPreferences prefs, XmlFormatStyle style,
        String lineSeparator) {
    mPrefs = prefs;
    mStyle = style;
    if (lineSeparator == null) {
        lineSeparator = SdkUtils.getLineSeparator();
    }
    mLineSeparator = lineSeparator;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:18,代码来源:XmlPrettyPrinter.java


示例11: hasBlankLineAbove

import com.android.utils.SdkUtils; //导入依赖的package包/类
private boolean hasBlankLineAbove() {
    if (mOut.length() < 2 * mLineSeparator.length()) {
        return false;
    }

    return SdkUtils.endsWith(mOut, mLineSeparator) &&
            SdkUtils.endsWith(mOut, mOut.length() - mLineSeparator.length(), mLineSeparator);
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:9,代码来源:XmlPrettyPrinter.java


示例12: getTestDataRootDir

import com.android.utils.SdkUtils; //导入依赖的package包/类
private File getTestDataRootDir() {
    CodeSource source = getClass().getProtectionDomain().getCodeSource();
    if (source != null) {
        URL location = source.getLocation();
        try {
            File classesDir = SdkUtils.urlToFile(location);
            return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile();
        } catch (MalformedURLException e) {
            fail(e.getLocalizedMessage());
        }
    }
    return null;
}
 
开发者ID:vincetreur,项目名称:Ristretto,代码行数:14,代码来源:BaseLintDetectorTest.java


示例13: getTestDataRootDir

import com.android.utils.SdkUtils; //导入依赖的package包/类
private File getTestDataRootDir() {
  CodeSource source = getClass().getProtectionDomain().getCodeSource();

  if (source != null) {
    URL location = source.getLocation();
    try {
      File classesDir = SdkUtils.urlToFile(location);
      return classesDir.getParentFile().getAbsoluteFile().getParentFile().getParentFile();
    } catch (MalformedURLException e) {
      fail(e.getLocalizedMessage());
    }
  }

  return null;
}
 
开发者ID:ashdavies,项目名称:dagger-lint,代码行数:16,代码来源:AbstractDetectorTest.java


示例14: JarFileIssueRegistry

import com.android.utils.SdkUtils; //导入依赖的package包/类
private JarFileIssueRegistry(@NonNull LintClient client, @NonNull File file)
        throws IOException, ClassNotFoundException, IllegalAccessException,
                InstantiationException {
    myIssues = Lists.newArrayList();
    JarFile jarFile = null;
    try {
        jarFile = new JarFile(file);
        Manifest manifest = jarFile.getManifest();
        Attributes attrs = manifest.getMainAttributes();
        Object object = attrs.get(new Attributes.Name(MF_LINT_REGISTRY));
        if (object instanceof String) {
            String className = (String) object;
            // Make a class loader for this jar
            URL url = SdkUtils.fileToUrl(file);
            URLClassLoader loader = new URLClassLoader(new URL[]{url},
                    JarFileIssueRegistry.class.getClassLoader());
            Class<?> registryClass = Class.forName(className, true, loader);
            IssueRegistry registry = (IssueRegistry) registryClass.newInstance();
            myIssues.addAll(registry.getIssues());
        } else {
            client.log(Severity.ERROR, null,
                "Custom lint rule jar %1$s does not contain a valid registry manifest key " +
                "(%2$s).\n" +
                "Either the custom jar is invalid, or it uses an outdated API not supported " +
                "this lint client", file.getPath(), MF_LINT_REGISTRY);
        }
    } finally {
        if (jarFile != null) {
            jarFile.close();
        }
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:33,代码来源:JarFileIssueRegistry.java


示例15: getRootDir

import com.android.utils.SdkUtils; //导入依赖的package包/类
/**
 * Returns the Android source tree root dir.
 * @return the root dir or null if it couldn't be computed.
 */
protected File getRootDir() {
    CodeSource source = getClass().getProtectionDomain().getCodeSource();
    if (source != null) {
        URL location = source.getLocation();
        try {
            File dir = SdkUtils.urlToFile(location);
            assertTrue(dir.getPath(), dir.exists());
            while (dir != null) {
                File settingsGradle = new File(dir, "settings.gradle"); //$NON-NLS-1$
                if (settingsGradle.exists()) {
                    return dir.getParentFile().getParentFile();
                }
                File lint = new File(dir, "lint");  //$NON-NLS-1$
                if (lint.exists() && new File(lint, "cli").exists()) { //$NON-NLS-1$
                    return dir.getParentFile().getParentFile();
                }
                dir = dir.getParentFile();
            }

            return null;
        } catch (MalformedURLException e) {
            fail(e.getLocalizedMessage());
        }
    }

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


示例16: explainIssue

import com.android.utils.SdkUtils; //导入依赖的package包/类
private void explainIssue(@NonNull StringBuilder output, @Nullable Issue issue)
        throws IOException {
    if (issue == null || !mFlags.isExplainIssues() || issue == IssueRegistry.LINT_ERROR) {
        return;
    }

    String explanation = issue.getExplanation(TextFormat.TEXT);
    if (explanation.trim().isEmpty()) {
        return;
    }

    String indent = "   ";
    String formatted = SdkUtils.wrap(explanation, Main.MAX_LINE_WIDTH - indent.length(), null);
    output.append('\n');
    output.append(indent);
    output.append("Explanation for issues of type \"").append(issue.getId()).append("\":\n");
    for (String line : Splitter.on('\n').split(formatted)) {
        if (!line.isEmpty()) {
            output.append(indent);
            output.append(line);
        }
        output.append('\n');
    }
    List<String> moreInfo = issue.getMoreInfo();
    if (!moreInfo.isEmpty()) {
        for (String url : moreInfo) {
            if (formatted.contains(url)) {
                continue;
            }
            output.append(indent);
            output.append(url);
            output.append('\n');
        }
        output.append('\n');
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:TextReporter.java


示例17: getUrl

import com.android.utils.SdkUtils; //导入依赖的package包/类
String getUrl(File file) {
    if (mBundleResources && !mSimpleFormat) {
        String url = getRelativeResourceUrl(file);
        if (url != null) {
            return url;
        }
    }

    if (mUrlMap != null) {
        String path = file.getAbsolutePath();
        // Perform the comparison using URLs such that we properly escape spaces etc.
        String pathUrl = encodeUrl(path);
        for (Map.Entry<String, String> entry : mUrlMap.entrySet()) {
            String prefix = entry.getKey();
            String prefixUrl = encodeUrl(prefix);
            if (pathUrl.startsWith(prefixUrl)) {
                String relative = pathUrl.substring(prefixUrl.length());
                return entry.getValue() + relative;
            }
        }
    }

    if (file.isAbsolute()) {
        String relativePath = getRelativePath(mOutput.getParentFile(), file);
        if (relativePath != null) {
            relativePath = relativePath.replace(separatorChar, '/');
            return encodeUrl(relativePath);
        }
    }

    try {
        return SdkUtils.fileToUrlString(file);
    } catch (MalformedURLException e) {
        return null;
    }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:37,代码来源:Reporter.java


示例18: oneOfStartsWithIgnoreCase

import com.android.utils.SdkUtils; //导入依赖的package包/类
private static boolean oneOfStartsWithIgnoreCase(List<String> strings, String prefix) {
    boolean matches = false;
    for (String allowedString : strings) {
        if (SdkUtils.startsWithIgnoreCase(allowedString, prefix)) {
            matches = true;
            break;
        }
    }
    return matches;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:FileResourceNameValidator.java


示例19: testAppendedSourceComment

import com.android.utils.SdkUtils; //导入依赖的package包/类
public void testAppendedSourceComment() throws Exception {
    ResourceMerger merger = getResourceMerger(false /*normalize*/);
    RecordingLogger logger =  new RecordingLogger();
    File folder = getWrittenResources();
    ResourceSet writtenSet = new ResourceSet("unused");
    writtenSet.addSource(folder);
    writtenSet.loadFromFiles(logger);
    compareResourceMaps(merger, writtenSet, false /*full compare*/);
    checkLogger(logger);

    File layout = new File(folder, FD_RES_LAYOUT + File.separator + "main.xml");
    assertTrue(layout.exists());
    String layoutXml = Files.toString(layout, Charsets.UTF_8);
    assertTrue(layoutXml.contains("main.xml")); // in <!-- From: /full/path/to/main.xml -->
    int index = layoutXml.indexOf("From: ");
    assertTrue(index != -1);
    String path = layoutXml.substring(index + 6, layoutXml.indexOf(' ', index + 6));
    File file = SdkUtils.urlToFile(path);
    assertTrue(path, file.exists());
    assertFalse(Arrays.equals(Files.toByteArray(file), Files.toByteArray(layout)));

    // Also make sure .png files were NOT modified
    File root = TestUtils.getRoot("resources", "baseMerge");
    assertNotNull(root);
    File original = new File(root,
            "overlay/drawable-ldpi/icon.png".replace('/', File.separatorChar));
    File copied = new File(folder, FD_RES_DRAWABLE + File.separator + "icon.png");
    assertTrue(Arrays.equals(Files.toByteArray(original), Files.toByteArray(copied)));
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:ResourceMergerTest.java


示例20: getExternalJars

import com.android.utils.SdkUtils; //导入依赖的package包/类
@Override
protected List<URL> getExternalJars() {
  final List<URL> result = new ArrayList<URL>();

  if (ThemeEditorProvider.THEME_EDITOR_ENABLE) {
    URL customWidgetsUrl = ThemeEditorUtils.getCustomWidgetsJarUrl();

    if (customWidgetsUrl != null) {
      result.add(customWidgetsUrl);
    }
  }
  for (VirtualFile libFile : AndroidRootUtil.getExternalLibraries(myModule)) {
    if (EXT_JAR.equals(libFile.getExtension())) {
      final File file = new File(libFile.getPath());
      if (file.exists()) {
        try {
          result.add(SdkUtils.fileToUrl(file));

          File aarDir = file.getParentFile();
          if (aarDir != null && (aarDir.getPath().endsWith(DOT_AAR) ||
            aarDir.getPath().contains(EXPLODED_AAR))) {
            if (aarDir.getPath().contains(EXPLODED_AAR) && FD_JARS.equals(aarDir.getName())) {
              // Gradle plugin version 1.2.x and later has classes in aar-dir/jars/
              aarDir = aarDir.getParentFile();
            }
            AppResourceRepository appResources = AppResourceRepository.getAppResources(myModule, true);
            if (appResources != null) {
              AarResourceClassRegistry.get(myModule.getProject()).addLibrary(appResources, aarDir);
            }
          }
        }
        catch (MalformedURLException e) {
          LOG.error(e);
        }
      }
    }
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:40,代码来源:ModuleClassLoader.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RefreshServiceAclsResponse类代码示例发布时间:2022-05-22
下一篇:
Java ScannerBase类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap