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);
}
}
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;
}
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);
}
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;
}
}
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;
}
Aggregations