use of android.content.res.AssetManager in project remote-desktop-clients by iiordanov.
the class aSPICE method listFiles.
private List<String> listFiles(String dirFrom) throws IOException {
Resources res = getResources();
AssetManager am = res.getAssets();
String[] fileList = am.list(dirFrom);
if (fileList != null) {
for (int i = 0; i < fileList.length; i++) {
Log.d("", fileList[i]);
}
}
return (List<String>) Arrays.asList(fileList);
}
use of android.content.res.AssetManager in project MyBaseApplication by BanShouWeng.
the class TableAsstesHelper method openDatabase.
private SQLiteDatabase openDatabase(Context context) {
System.out.println("filePath:" + filePath);
File jhPath = new File(filePath);
// 查看数据库文件是否存在
if (jhPath.exists()) {
Log.i("test", "存在数据库");
// 存在则直接返回打开的数据库
return SQLiteDatabase.openOrCreateDatabase(jhPath, null);
} else {
// 不存在先创建文件夹
File path = new File(pathStr);
Log.i("test", "pathStr=" + path);
if (path.mkdirs()) {
Log.i("test", "创建成功");
} else {
Log.i("test", "创建失败");
}
;
try {
// 得到资源
AssetManager am = context.getAssets();
// 得到数据库的输入流
InputStream is = am.open(dbName);
Log.i("test", is + "");
// 用输出流写到SDcard上面
FileOutputStream fos = new FileOutputStream(jhPath);
Log.i("test", "fos=" + fos);
Log.i("test", "jhPath=" + jhPath);
// 创建byte数组 用于1KB写一次
byte[] buffer = new byte[1024];
int count = 0;
while ((count = is.read(buffer)) > 0) {
Log.i("test", "得到");
fos.write(buffer, 0, count);
}
// 最后关闭就可以了
fos.flush();
fos.close();
is.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
// 如果没有这个数据库 我们已经把他写到SD卡上了,然后在执行一次这个方法 就可以返回数据库了
return openDatabase(context);
}
}
use of android.content.res.AssetManager in project AndroidPuzzleGame by dragosholban.
the class PuzzleActivity method setPicFromAsset.
private void setPicFromAsset(String assetName, ImageView imageView) {
// Get the dimensions of the View
int targetW = imageView.getWidth();
int targetH = imageView.getHeight();
AssetManager am = getAssets();
try {
InputStream is = am.open("img/" + assetName);
// Get the dimensions of the bitmap
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, new Rect(-1, -1, -1, -1), bmOptions);
int photoW = bmOptions.outWidth;
int photoH = bmOptions.outHeight;
// Determine how much to scale down the image
int scaleFactor = Math.min(photoW / targetW, photoH / targetH);
is.reset();
// Decode the image file into a Bitmap sized to fill the View
bmOptions.inJustDecodeBounds = false;
bmOptions.inSampleSize = scaleFactor;
bmOptions.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeStream(is, new Rect(-1, -1, -1, -1), bmOptions);
imageView.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
}
}
use of android.content.res.AssetManager in project Auto.js by hyb1996.
the class PFiles method copyAssetDir.
public static boolean copyAssetDir(Context context, String assetsDir, String toDir) {
new File(toDir).mkdirs();
AssetManager manager = context.getAssets();
try {
String[] list = manager.list(assetsDir);
if (list == null)
return false;
for (String file : list) {
InputStream stream;
try {
stream = manager.open(join(assetsDir, file));
} catch (IOException e) {
if (!copyAssetDir(context, join(assetsDir, file), join(toDir, file))) {
return false;
}
continue;
}
copyStream(stream, join(toDir, file));
}
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
use of android.content.res.AssetManager in project UnityModManager by xausky.
the class VirtualCore method getResources.
public Resources getResources(String pkg) throws Resources.NotFoundException {
InstalledAppInfo installedAppInfo = getInstalledAppInfo(pkg, 0);
if (installedAppInfo != null) {
AssetManager assets = mirror.android.content.res.AssetManager.ctor.newInstance();
mirror.android.content.res.AssetManager.addAssetPath.call(assets, installedAppInfo.apkPath);
Resources hostRes = context.getResources();
return new Resources(assets, hostRes.getDisplayMetrics(), hostRes.getConfiguration());
}
throw new Resources.NotFoundException(pkg);
}
Aggregations