Example usage for android.content.res AssetManager open

List of usage examples for android.content.res AssetManager open

Introduction

In this page you can find the example usage for android.content.res AssetManager open.

Prototype

public @NonNull InputStream open(@NonNull String fileName) throws IOException 

Source Link

Document

Open an asset using ACCESS_STREAMING mode.

Usage

From source file:com.micro.utils.F.java

/**
 * ???Asset?.//ww  w  .ja v  a 2  s  .c o m
 *
 * @param context the context
 * @param fileName the file name
 * @return Drawable 
 */
public static Drawable getDrawableFromAsset(Context context, String fileName) {
    Drawable drawable = null;
    try {
        AssetManager assetManager = context.getAssets();
        InputStream is = assetManager.open(fileName);
        drawable = Drawable.createFromStream(is, null);
    } catch (Exception e) {
        L.D("?" + e.getMessage());
    }
    return drawable;
}

From source file:com.conceptberria.wattion.viewprice.AboutActivity.java

private String htmlFromManager() {
    StringBuilder prompt = new StringBuilder();
    InputStream inputStream = null;
    AssetManager assetManager = EnergyControlApp.getContext().getAssets();
    try {// ww  w.java 2 s . co  m
        inputStream = assetManager.open("html/about.html");

        BufferedReader r = new BufferedReader(new InputStreamReader(inputStream));

        String line;
        while ((line = r.readLine()) != null) {
            prompt.append(line);
        }
        inputStream.close();
    } catch (IOException e) {

    }
    return prompt.toString();
}

From source file:in.rab.bildkort.ImageFragment.java

private String getImagePickerJs() {
    if (mImagePickerJs != null) {
        return mImagePickerJs;
    }/*from  w w  w.  ja v a  2 s  .  c  o m*/

    try {
        AssetManager am = getActivity().getAssets();
        InputStream is = am.open("imagepicker.js");
        mImagePickerJs = Utils.inputStreamToString(is);
    } catch (java.io.IOException e) {
        mImagePickerJs = "document.body.innerHtml='Error';";
    }

    return mImagePickerJs;
}

From source file:eu.geopaparazzi.library.core.fragments.AboutFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    try {//from w  ww .  jav a2s  . c  o m
        AssetManager assetManager = getActivity().getAssets();
        InputStream inputStream = assetManager.open("about.html");
        String htmlText = new Scanner(inputStream).useDelimiter("\\A").next();

        String applicationName = "Geopaparazzi";
        try {
            applicationName = ResourcesManager.getInstance(getActivity()).getApplicationName();
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (packageName != null) {
            String version = "";
            try {
                PackageInfo pInfo = getActivity().getPackageManager().getPackageInfo(packageName,
                        PackageManager.GET_META_DATA);
                version = pInfo.versionName;
            } catch (NameNotFoundException e) {
                e.printStackTrace();
            }

            htmlText = htmlText.replaceFirst("VERSION", version);
        } else {
            htmlText = htmlText.replaceFirst("VERSION", "");
        }

        htmlText = htmlText.replaceAll("Geopaparazzi", applicationName);

        WebView aboutView = (WebView) view;
        aboutView.loadData(htmlText, "text/html", "utf-8");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.acrylicgoat.houstonbicyclemuseum.fragment.AboutUsFragment.java

private AboutList readJson() {
    AssetManager assets = getActivity().getAssets();
    AboutList aboutList = new AboutList();

    Gson gson = new Gson();

    try {/*from  www.j ava  2  s. c  o m*/
        InputStream is = assets.open("about.json");
        BufferedReader bf = new BufferedReader(new InputStreamReader(is));
        aboutList = gson.fromJson(bf, AboutList.class);
    } catch (IOException ioe) {
        Log.d("json", "Some problem: " + ioe.toString());
    }

    return aboutList;
}

From source file:org.cnx.openstaxcnxmusic.fragments.AboutFragment.java

private AboutList readJson() {
    AssetManager assets = getActivity().getAssets();
    AboutList aboutList = new AboutList();

    Gson gson = new Gson();

    try {/*from  ww w  .  j  a  v  a2s . c  om*/
        InputStream is = assets.open("aboutList.json");
        BufferedReader bf = new BufferedReader(new InputStreamReader(is));
        aboutList = gson.fromJson(bf, AboutList.class);
    } catch (IOException ioe) {
        Log.d("json", "Some problem: " + ioe.toString());
    }

    return aboutList;
}

From source file:org.odk.collect.android.FormNavigationTestCase.java

/**
 * FormLoaderTask loads forms from SD card so we need to put each form there
 *//*from w  w  w . jav  a  2 s  .  c o m*/
private void copyToSdCard(String formName) throws IOException {
    String pathname = formPath(formName);

    AssetManager assetManager = InstrumentationRegistry.getContext().getAssets();
    InputStream inputStream = assetManager.open("forms/formNavigationTestForms/" + formName);

    File outFile = new File(pathname);
    OutputStream outputStream = new FileOutputStream(outFile);

    IOUtils.copy(inputStream, outputStream);
}

From source file:com.madgag.agit.RDTypeListActivityStoryTest.java

private Repository unpackRepo(String fileName) throws IOException, ArchiveException {
    AssetManager am = getInstrumentation().getContext().getAssets();
    File repoParentFolder = newFolder();
    InputStream rawZipFileInputStream = am.open(fileName);
    return unzipRepoFromStreamToFolder(rawZipFileInputStream, repoParentFolder);
}

From source file:com.bluekai.sampleapp.BlueKaiTab.java

@Override
protected void onResume() {
    super.onResume();
    database = DataSource.getInstance(context);
    DevSettings devSettings = database.getDevSettings();
    if (devSettings == null) {
        try {/*from www.j  av a2 s . c  om*/
            Resources resources = this.getResources();
            AssetManager assetManager = resources.getAssets();
            InputStream inputStream = assetManager.open("settings.properties");
            Properties properties = new Properties();
            properties.load(inputStream);
            useHttps = Boolean.parseBoolean(properties.getProperty("useHttps"));
            devMode = Boolean.parseBoolean(properties.getProperty("devmode"));
            siteId = properties.getProperty("siteid");
        } catch (IOException e) {
            Log.e("BlueKaiSampleApp", "Error loading properties. Default values will be loaded from SDK", e);
        }
    } else {
        siteId = devSettings.getBkurl();
        devMode = devSettings.isDevMode();
        useHttps = devSettings.isHttpsEnabled();
    }
    Log.d("BlueKaiSampleApp", "On Resume --> DevMode ---> " + devMode + " -- Site ID --> " + siteId
            + " -- Use Https --> " + useHttps);
    bk = BlueKai.getInstance(this, this, devMode, useHttps, siteId, appVersion, this, new Handler());
    bk.resume();
}

From source file:org.mobiledeeplinking.android.MobileDeepLinking.java

private String readConfigFile() throws IOException {
    Resources resources = this.getApplicationContext().getResources();
    AssetManager assetManager = resources.getAssets();

    InputStream inputStream = assetManager.open("MobileDeepLinkingConfig.json");
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
    StringBuilder sb = new StringBuilder();

    String line;//from  w  w w  . j a v a  2s  .co  m
    while ((line = reader.readLine()) != null) {
        sb.append(line + "\n");
    }
    return sb.toString();
}