Search in sources :

Example 81 with AssetManager

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);
}
Also used : AssetManager(android.content.res.AssetManager) List(java.util.List) Resources(android.content.res.Resources)

Example 82 with AssetManager

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);
    }
}
Also used : AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 83 with AssetManager

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();
    }
}
Also used : Rect(android.graphics.Rect) Bitmap(android.graphics.Bitmap) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) BitmapFactory(android.graphics.BitmapFactory) IOException(java.io.IOException) Paint(android.graphics.Paint)

Example 84 with AssetManager

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;
}
Also used : AssetManager(android.content.res.AssetManager) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 85 with AssetManager

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);
}
Also used : AssetManager(android.content.res.AssetManager) InstalledAppInfo(com.lody.virtual.remote.InstalledAppInfo) Resources(android.content.res.Resources)

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