Search in sources :

Example 96 with AssetManager

use of android.content.res.AssetManager in project Osmand by osmandapp.

the class DownloadOsmandIndexesHelper method getIndexesList.

public static IndexFileList getIndexesList(OsmandApplication app) {
    PackageManager pm = app.getPackageManager();
    AssetManager amanager = app.getAssets();
    IndexFileList result = downloadIndexesListFromInternet(app);
    if (result == null) {
        result = new IndexFileList();
    } else {
        result.setDownloadedFromInternet(true);
    }
    // add all tts files from assets
    listVoiceAssets(result, amanager, pm, app.getSettings());
    return result;
}
Also used : AssetManager(android.content.res.AssetManager) PackageManager(android.content.pm.PackageManager)

Example 97 with AssetManager

use of android.content.res.AssetManager in project MagiskManager by topjohnwu.

the class Utils method getAssets.

public static AssetManager getAssets(String apk) {
    try {
        AssetManager asset = AssetManager.class.newInstance();
        AssetManager.class.getMethod("addAssetPath", String.class).invoke(asset, apk);
        return asset;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : AssetManager(android.content.res.AssetManager) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 98 with AssetManager

use of android.content.res.AssetManager in project sample-tensorflow-imageclassifier by androidthings.

the class TensorFlowHelper method readLabels.

public static List<String> readLabels(Context context, String labelsFile) {
    AssetManager assetManager = context.getAssets();
    ArrayList<String> result = new ArrayList<>();
    try (InputStream is = assetManager.open(labelsFile);
        BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
        String line;
        while ((line = br.readLine()) != null) {
            result.add(line);
        }
        return result;
    } catch (IOException ex) {
        throw new IllegalStateException("Cannot read labels from " + labelsFile);
    }
}
Also used : AssetManager(android.content.res.AssetManager) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 99 with AssetManager

use of android.content.res.AssetManager in project AndroidAsync by koush.

the class AsyncHttpServerRouter method directory.

public void directory(Context context, String regex, final String assetPath) {
    AssetManager am = context.getAssets();
    addAction(AsyncHttpGet.METHOD, regex, (request, response) -> {
        String path = request.getMatcher().replaceAll("");
        Asset pair = getAssetStream(am, assetPath + path);
        if (pair == null || pair.inputStream == null) {
            response.code(404);
            response.end();
            return;
        }
        if (isClientCached(context, request, response, pair.path)) {
            StreamUtility.closeQuietly(pair.inputStream);
            response.code(304);
            response.end();
            return;
        }
        response.getHeaders().set("Content-Length", String.valueOf(pair.available));
        response.getHeaders().add("Content-Type", getContentType(pair.path));
        response.code(200);
        Util.pump(pair.inputStream, pair.available, response, ex -> {
            response.end();
            StreamUtility.closeQuietly(pair.inputStream);
        });
    });
    addAction(AsyncHttpHead.METHOD, regex, (request, response) -> {
        String path = request.getMatcher().replaceAll("");
        Asset pair = getAssetStream(am, assetPath + path);
        if (pair == null || pair.inputStream == null) {
            response.code(404);
            response.end();
            return;
        }
        StreamUtility.closeQuietly(pair.inputStream);
        if (isClientCached(context, request, response, pair.path)) {
            response.code(304);
        } else {
            response.getHeaders().set("Content-Length", String.valueOf(pair.available));
            response.getHeaders().add("Content-Type", getContentType(pair.path));
            response.code(200);
        }
        response.end();
    });
}
Also used : AssetManager(android.content.res.AssetManager)

Example 100 with AssetManager

use of android.content.res.AssetManager in project anitrend-app by AniTrend.

the class SingleLineFontTextView method onInit.

/**
 * Optionally included when constructing custom views
 */
@Override
public void onInit() {
    super.onInit();
    AssetManager assetManager = getContext().getAssets();
    setTypeface(Typeface.createFromAsset(assetManager, "fonts/Lobster-Regular.ttf"));
}
Also used : AssetManager(android.content.res.AssetManager)

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