Search in sources :

Example 51 with AssetManager

use of android.content.res.AssetManager in project android_frameworks_base by AOSPA.

the class PackageParser method parseMonolithicPackage.

/**
     * Parse the given APK file, treating it as as a single monolithic package.
     * <p>
     * Note that this <em>does not</em> perform signature verification; that
     * must be done separately in {@link #collectCertificates(Package, int)}.
     *
     * @deprecated external callers should move to
     *             {@link #parsePackage(File, int)}. Eventually this method will
     *             be marked private.
     */
@Deprecated
public Package parseMonolithicPackage(File apkFile, int flags) throws PackageParserException {
    final PackageLite lite = parseMonolithicPackageLite(apkFile, flags);
    if (mOnlyCoreApps) {
        if (!lite.coreApp) {
            throw new PackageParserException(INSTALL_PARSE_FAILED_MANIFEST_MALFORMED, "Not a coreApp: " + apkFile);
        }
    }
    final AssetManager assets = new AssetManager();
    try {
        final Package pkg = parseBaseApk(apkFile, assets, flags);
        pkg.setCodePath(apkFile.getAbsolutePath());
        pkg.setUse32bitAbi(lite.use32bitAbi);
        return pkg;
    } finally {
        IoUtils.closeQuietly(assets);
    }
}
Also used : AssetManager(android.content.res.AssetManager)

Example 52 with AssetManager

use of android.content.res.AssetManager in project android_frameworks_base by DirtyUnicorns.

the class ResourcesManager method createResourcesImpl.

@Nullable
private ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
    final DisplayAdjustments daj = new DisplayAdjustments(key.mOverrideConfiguration);
    daj.setCompatibilityInfo(key.mCompatInfo);
    final AssetManager assets = createAssetManager(key);
    if (assets == null) {
        return null;
    }
    final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId, daj);
    final Configuration config = generateConfig(key, dm);
    final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, daj);
    if (DEBUG) {
        Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
    }
    return impl;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics) Nullable(android.annotation.Nullable)

Example 53 with AssetManager

use of android.content.res.AssetManager in project SilkyAnimation by yuyashuai.

the class SilkyAnimation method getPathList.

/**
 * 通过assets资源转换pathList
 *
 * @param assetsPath assets resource path, must be a directory
 * @return if assets  does not exist return a empty list
 */
private List<String> getPathList(String assetsPath) {
    AssetManager assetManager = mContext.getAssets();
    try {
        String[] assetFiles = assetManager.list(assetsPath);
        if (assetFiles.length == 0) {
            Log.e(TAG, "no file in this asset directory");
            return new ArrayList<>(0);
        }
        // 转换真实路径
        for (int i = 0; i < assetFiles.length; i++) {
            assetFiles[i] = assetsPath + File.separator + assetFiles[i];
        }
        List<String> mAssertList = Arrays.asList(assetFiles);
        isAssetResource = true;
        setAssetManager(assetManager);
        return mAssertList;
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
    }
    return new ArrayList<>(0);
}
Also used : AssetManager(android.content.res.AssetManager) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 54 with AssetManager

use of android.content.res.AssetManager in project Rocket by mozilla-tw.

the class TopSitesUtils method loadDefaultSitesFromAssets.

private static String loadDefaultSitesFromAssets(Context context) {
    String json = "[]";
    try {
        final Locale locale = Locale.getDefault();
        final String fileName = "topsites.json";
        final String localPath = "topsites/" + Locales.getLanguage(locale);
        final String defaultPath = "topsites/topsites_default.json";
        final AssetManager assetManager = context.getAssets();
        final List<String> localFiles = Arrays.asList(assetManager.list(localPath));
        InputStream is;
        if (localFiles.contains(fileName)) {
            is = assetManager.open(localPath + "/" + fileName);
        } else {
            is = assetManager.open(defaultPath);
        }
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
        json = new String(buffer, "UTF-8");
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        return json;
    }
}
Also used : Locale(java.util.Locale) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 55 with AssetManager

use of android.content.res.AssetManager in project Rocket by mozilla-tw.

the class UrlAutoCompleteFilter method getAvailableDomainLists.

private Set<String> getAvailableDomainLists(Context context) {
    final Set<String> availableDomains = new HashSet<>();
    final AssetManager assetManager = context.getAssets();
    try {
        Collections.addAll(availableDomains, assetManager.list("domains"));
    } catch (IOException e) {
        Log.w(LOG_TAG, "Could not list domain list directory");
    }
    return availableDomains;
}
Also used : AssetManager(android.content.res.AssetManager) IOException(java.io.IOException) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

AssetManager (android.content.res.AssetManager)346 IOException (java.io.IOException)141 InputStream (java.io.InputStream)121 Resources (android.content.res.Resources)75 File (java.io.File)54 FileOutputStream (java.io.FileOutputStream)34 XmlResourceParser (android.content.res.XmlResourceParser)32 DisplayMetrics (android.util.DisplayMetrics)31 Bitmap (android.graphics.Bitmap)23 Configuration (android.content.res.Configuration)21 BufferedReader (java.io.BufferedReader)21 InputStreamReader (java.io.InputStreamReader)20 ArrayList (java.util.ArrayList)20 FileInputStream (java.io.FileInputStream)18 OutputStream (java.io.OutputStream)17 Context (android.content.Context)16 Intent (android.content.Intent)16 JsonParser (com.google.gson.JsonParser)16 ByteArrayInputStream (java.io.ByteArrayInputStream)16 Method (java.lang.reflect.Method)16