Search in sources :

Example 61 with AssetManager

use of android.content.res.AssetManager in project KeePassDX by Kunzisoft.

the class Kdb4 method testSaving.

private void testSaving(String inputFile, String password, String outputFile) throws IOException, InvalidDBException, PwDbOutputException {
    Context ctx = getContext();
    AssetManager am = ctx.getAssets();
    InputStream is = am.open(inputFile, AssetManager.ACCESS_STREAMING);
    ImporterV4 importer = new ImporterV4();
    PwDatabaseV4 db = importer.openDatabase(is, password, null);
    is.close();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PwDbV4Output output = (PwDbV4Output) PwDbOutput.getInstance(db, bos);
    output.output();
    byte[] data = bos.toByteArray();
    FileOutputStream fos = new FileOutputStream(TestUtil.getSdPath(outputFile), false);
    InputStream bis = new ByteArrayInputStream(data);
    bis = new CopyInputStream(bis, fos);
    importer = new ImporterV4();
    db = importer.openDatabase(bis, password, null);
    bis.close();
    fos.close();
}
Also used : Context(android.content.Context) PwDbV4Output(com.keepassdroid.database.save.PwDbV4Output) AssetManager(android.content.res.AssetManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) InputStream(java.io.InputStream) ImporterV4(com.keepassdroid.database.load.ImporterV4) FileOutputStream(java.io.FileOutputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PwDatabaseV4(com.keepassdroid.database.PwDatabaseV4)

Example 62 with AssetManager

use of android.content.res.AssetManager in project KeePassDX by Kunzisoft.

the class Kdb4 method testKeyfile.

public void testKeyfile() throws IOException, InvalidDBException {
    Context ctx = getContext();
    AssetManager am = ctx.getAssets();
    InputStream is = am.open("key-only.kdbx", AssetManager.ACCESS_STREAMING);
    ImporterV4 importer = new ImporterV4();
    importer.openDatabase(is, "", TestUtil.getKeyFileInputStream(ctx, TestUtil.getSdPath("key")));
    is.close();
}
Also used : Context(android.content.Context) AssetManager(android.content.res.AssetManager) ByteArrayInputStream(java.io.ByteArrayInputStream) CopyInputStream(com.keepassdroid.stream.CopyInputStream) InputStream(java.io.InputStream) ImporterV4(com.keepassdroid.database.load.ImporterV4)

Example 63 with AssetManager

use of android.content.res.AssetManager in project BaseProject by fly803.

the class AppImageMgr method getImageFromAssetsFile.

/**
 * 从Assets中读取图片
 * @param filepath 相对路径
 * @return Bitmap
 */
public static Bitmap getImageFromAssetsFile(String filepath, Context context) {
    Bitmap image = null;
    InputStream is = null;
    AssetManager am = context.getResources().getAssets();
    try {
        is = am.open(filepath);
        image = BitmapFactory.decodeStream(is);
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (is != null)
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return image;
}
Also used : AssetManager(android.content.res.AssetManager)

Example 64 with AssetManager

use of android.content.res.AssetManager in project VirtualXposed by android-hacker.

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)

Example 65 with AssetManager

use of android.content.res.AssetManager in project browser by scoute-dich.

the class Cookie method loadHosts.

private static void loadHosts(final Context context) {
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            AssetManager manager = context.getAssets();
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(manager.open(FILE)));
                String line;
                while ((line = reader.readLine()) != null) {
                    hostsCookie.add(line.toLowerCase(locale));
                }
            } catch (IOException i) {
                Log.w("Browser", "Error loading hosts");
            }
        }
    });
    thread.start();
}
Also used : AssetManager(android.content.res.AssetManager) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

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