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.capstone.transit.trans_it.MapActivity.java

public ArrayList<String> createLatArrayList() {
    // LatV = lat values
    // Used array lists due to dyanmic size setting

    AssetManager mngr;
    String line = null;//from www .j a v  a  2s. co  m
    ArrayList<String> LatV = new ArrayList<String>();
    int count = 0;
    boolean skillcheck = false;

    try {
        mngr = getAssets();
        InputStream is = mngr.open("stops.txt");
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);

        while ((line = br.readLine()) != null) { // Read until last line in .txt file
            if (count > 0) {
                line = line.toUpperCase();
                String[] ArrayValues = line.split(","); // Seperate line by commas into a list
                LatV.add(ArrayValues[0]); // Access first index (latitude) and add to ArrayList
            }
            count++;
        }
        //System.out.print(LatV.get(1));
        System.out.print("Got here");
        br.close();
    } catch (IOException e1) {

    }

    return LatV;
}

From source file:com.capstone.transit.trans_it.MapActivity.java

public ArrayList<String> createLonArrayList() {
    // LonV = lon values
    // Used array lists due to dyanmic size setting

    AssetManager mngr;
    String line = null;/*from   w ww.  j  a va2s.  c  o  m*/
    ArrayList<String> LonV = new ArrayList<String>();
    int count = 0;
    boolean skillcheck = false;

    try {
        mngr = getAssets();
        InputStream is = mngr.open("stops.txt");
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);

        while ((line = br.readLine()) != null) { // Read until last line in .txt file
            if (count > 0) {
                line = line.toUpperCase();
                String[] ArrayValues = line.split(","); // Seperate line by commas into a list
                LonV.add(ArrayValues[3]); // Access first index (latitude) and add to ArrayList
            }
            count++;
        }
        System.out.print(LonV.get(1));

        br.close();
    } catch (IOException e1) {

    }

    return LonV;

}

From source file:jvm.ncatz.netbour.ActivityAbout.java

@NonNull
@Override/*  w ww.  j a  v a  2  s. c om*/
protected MaterialAboutList getMaterialAboutList(@NonNull Context context) {
    count = 0;

    MaterialAboutCard.Builder builderCardApp = new MaterialAboutCard.Builder();
    builderCardApp.title(R.string.aboutApp);
    MaterialAboutCard.Builder builderCardAuthor = new MaterialAboutCard.Builder();
    builderCardAuthor.title(R.string.aboutAuthor);
    MaterialAboutCard.Builder builderCardSocial = new MaterialAboutCard.Builder();
    builderCardSocial.title(R.string.aboutSocial);
    MaterialAboutCard.Builder builderCardOther = new MaterialAboutCard.Builder();
    builderCardOther.title(R.string.aboutOther);

    IconicsDrawable iconAppVersion = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_info_outline)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconAppRepository = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_github_box)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconAppLicenses = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_file)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconAuthorEmail = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_email)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconAuthorWeb = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_view_web)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconSocialGithub = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_github_alt)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconSocialLinkedin = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_linkedin)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconSocialStack = new IconicsDrawable(this)
            .icon(MaterialDesignIconic.Icon.gmi_stackoverflow)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconSocialTwitter = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_twitter)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);
    IconicsDrawable iconOtherBugs = new IconicsDrawable(this).icon(MaterialDesignIconic.Icon.gmi_bug)
            .color(ContextCompat.getColor(this, R.color.grey_800)).sizeDp(20);

    MaterialAboutTitleItem itemAppName = new MaterialAboutTitleItem(getString(R.string.app_name),
            ContextCompat.getDrawable(this, R.drawable.logo160));
    MaterialAboutActionItem itemAppVersion = new MaterialAboutActionItem(getString(R.string.app_version_title),
            getString(R.string.app_version_sub), iconAppVersion, new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    count++;
                    if (count == 7) {
                        try {
                            stopPlaying();
                            player = MediaPlayer.create(ActivityAbout.this, R.raw.easteregg);
                            player.start();
                            count = 0;
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            });
    MaterialAboutActionItem itemAppRepository = new MaterialAboutActionItem(
            getString(R.string.app_repository_title), getString(R.string.app_repository_sub), iconAppRepository,
            new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    String url = "https://github.com/JMedinilla/Netbour";
                    openUrl(url);
                }
            });
    MaterialAboutActionItem itemAppLicenses = new MaterialAboutActionItem(
            getString(R.string.app_licenses_title), getString(R.string.app_licenses_sub), iconAppLicenses,
            new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    DialogPlus dialogPlus = DialogPlus.newDialog(ActivityAbout.this).setGravity(Gravity.BOTTOM)
                            .setContentHolder(new ViewHolder(R.layout.licenses_dialog)).setCancelable(true)
                            .setExpanded(true, 600).create();

                    View view = dialogPlus.getHolderView();
                    FButton apacheButton = (FButton) view.findViewById(R.id.apacheButton);
                    FButton mitButton = (FButton) view.findViewById(R.id.mitButton);
                    WebView webView = (WebView) view.findViewById(R.id.licensesWeb);
                    apacheButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            try {
                                AssetManager am = getAssets();
                                InputStream is = am.open("apache");

                                Scanner s = new Scanner(is).useDelimiter("\\A");
                                String apache = s.hasNext() ? s.next() : "";

                                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityAbout.this);
                                builder.setTitle(R.string.apache_title);
                                builder.setMessage(apache);
                                builder.create().show();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    mitButton.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            try {
                                AssetManager am = getAssets();
                                InputStream is = am.open("mit");

                                Scanner s = new Scanner(is).useDelimiter("\\A");
                                String mit = s.hasNext() ? s.next() : "";

                                AlertDialog.Builder builder = new AlertDialog.Builder(ActivityAbout.this);
                                builder.setTitle(R.string.mit_title);
                                builder.setMessage(mit);
                                builder.create().show();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    try {
                        AssetManager am = getAssets();
                        InputStream is = am.open("licenses.html");

                        webView.loadData(inputStreamToString(is), "text/html", "UTF-8");
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    dialogPlus.show();
                }
            });
    MaterialAboutTitleItem itemAuthorName = new MaterialAboutTitleItem(getString(R.string.author_name),
            ContextCompat.getDrawable(this, R.drawable.favicon));
    MaterialAboutActionItem itemAuthorEmail = new MaterialAboutActionItem(
            getString(R.string.author_email_title), getString(R.string.author_email_sub), iconAuthorEmail,
            new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    sendEmail(getString(R.string.author_email_subject));
                }
            });
    MaterialAboutActionItem itemAuthorWeb = new MaterialAboutActionItem(getString(R.string.author_web_title),
            getString(R.string.author_web_sub), iconAuthorWeb, new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    String url = "https://jvmedinilla.ncatz.com/";
                    openUrl(url);
                }
            });
    MaterialAboutActionItem itemSocialGithub = new MaterialAboutActionItem(
            getString(R.string.social_github_title), getString(R.string.social_github_sub), iconSocialGithub,
            new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    String url = "https://github.com/JMedinilla";
                    openUrl(url);
                }
            });
    MaterialAboutActionItem itemSocialLinkedin = new MaterialAboutActionItem(
            getString(R.string.social_linkedin_title), getString(R.string.social_linkedin_sub),
            iconSocialLinkedin, new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    String url = "https://www.linkedin.com/in/javier-medinilla-ag%C3%BCera-951749121/";
                    openUrl(url);
                }
            });
    MaterialAboutActionItem itemSocialStackoverflow = new MaterialAboutActionItem(
            getString(R.string.social_stack_title), getString(R.string.social_stack_sub), iconSocialStack,
            new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    String url = "http://stackoverflow.com/users/7426526/jmedinilla?tab=profile";
                    openUrl(url);
                }
            });
    MaterialAboutActionItem itemSocialTwitter = new MaterialAboutActionItem(
            getString(R.string.social_twitter_title), getString(R.string.social_twitter_sub), iconSocialTwitter,
            new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    String url = "https://twitter.com/JMedinillaDev";
                    openUrl(url);
                }
            });
    MaterialAboutActionItem itemOtherBugs = new MaterialAboutActionItem(getString(R.string.other_bug_title),
            getString(R.string.other_bug_sub), iconOtherBugs, new MaterialAboutItemOnClickListener() {
                @Override
                public void onClick(boolean b) {
                    sendEmail(getString(R.string.other_bug_subject));
                }
            });

    builderCardApp.addItem(itemAppName);
    builderCardApp.addItem(itemAppVersion);
    builderCardApp.addItem(itemAppRepository);
    builderCardApp.addItem(itemAppLicenses);
    builderCardAuthor.addItem(itemAuthorName);
    builderCardAuthor.addItem(itemAuthorEmail);
    builderCardAuthor.addItem(itemAuthorWeb);
    builderCardSocial.addItem(itemSocialGithub);
    builderCardSocial.addItem(itemSocialLinkedin);
    builderCardSocial.addItem(itemSocialStackoverflow);
    builderCardSocial.addItem(itemSocialTwitter);
    builderCardOther.addItem(itemOtherBugs);

    MaterialAboutList.Builder builderList = new MaterialAboutList.Builder();
    builderList.addCard(builderCardApp.build());
    builderList.addCard(builderCardAuthor.build());
    builderList.addCard(builderCardSocial.build());
    builderList.addCard(builderCardOther.build());

    return builderList.build();
}

From source file:de.appplant.cordova.plugin.emailcomposer.EmailComposer.java

/**
 * The URI for an asset./*ww  w .j  a v a2 s . com*/
 *
 * @param {String} path
 *      The given asset path
 *
 * @return The URI pointing to the given path
 */
private Uri getUriForAssetPath(String path) {
    String resPath = path.replaceFirst("www:/", "www");
    String fileName = resPath.substring(resPath.lastIndexOf('/') + 1);
    String storage = cordova.getActivity().getExternalCacheDir().toString() + STORAGE_FOLDER;

    File file = new File(storage, fileName);

    new File(storage).mkdir();

    try {
        AssetManager assets = cordova.getActivity().getAssets();

        FileOutputStream outStream = new FileOutputStream(file);
        InputStream inputStream = assets.open(resPath);

        copyFile(inputStream, outStream);
        outStream.flush();
        outStream.close();
    } catch (Exception e) {
        System.err.println("Attachment asset not found: assets/" + resPath);
        e.printStackTrace();
    }

    return Uri.fromFile(file);
}

From source file:com.lucapernini.misapp.Registration.java

public void getLicense() {
    class GetLicenseBackground extends AsyncTask<String, Void, String> {

        @Override/*w  w  w  .ja  v a2  s  .c om*/
        protected String doInBackground(String... params) {
            // TODO Auto-generated method stub
            InputStream is;
            String text = "";
            AssetManager am = getAssets();

            try {
                is = am.open("licenzaduso.txt");
                InputStreamReader inputStreamReader = new InputStreamReader(is, "ISO-8859-1");
                BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
                StringBuilder stringBuilder = new StringBuilder();
                String bufferedStrChunk = null;
                while ((bufferedStrChunk = bufferedReader.readLine()) != null) {
                    stringBuilder.append(bufferedStrChunk);
                    stringBuilder.append("\n");
                }
                text = stringBuilder.toString();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            textL = text;

            alert.setTitle("Licenza d'uso");
            alert.setMessage(textL);
            alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    checkLicense.setClickable(true);
                    dialog.dismiss();
                }
            });

            return text;
        }

        @Override
        protected void onPostExecute(String result) {
            // TODO Auto-generated method stub

            super.onPostExecute(result);

            alert.show();
        }

    }
    GetLicenseBackground getLicenceBackground = new GetLicenseBackground();
    getLicenceBackground.execute();
}

From source file:com.door43.translationstudio.core.TargetTranslation.java

/**
 * make sure the license file is present in folder
 * @param targetTranslationDir/*from  w  w w .jav a  2  s  . c o m*/
 */
private static void ensureLicenseFilePresent(File targetTranslationDir) {
    //ensure that there is a license file
    try {
        File license = new File(targetTranslationDir, LICENSE_FILE);
        if (!license.exists()) {
            AssetManager am = AppContext.context().getAssets();
            String licenseSource = "LICENSE.md";
            InputStream is = am.open(licenseSource);
            if (is != null) {
                FileUtils.copyInputStreamToFile(is, license);
            } else {
                Logger.e(TAG, "Failed to open license resource: " + licenseSource);
            }
        }
    } catch (Exception e) {
        Logger.e(TAG, "Failed to copy license file", e);
    }
}

From source file:com.funzio.pure2D.atlas.JsonAtlas.java

/**
 * Load from assets/*from   w  w w . java  2s . c  om*/
 * 
 * @param assets
 * @param filePath
 * @param scale
 * @throws IOException
 * @throws JSONException
 */
public void load(final AssetManager assets, final String filePath, final float scale)
        throws IOException, JSONException {
    Log.v(TAG, "load(): " + filePath);

    if (assets == null) {
        load(new FileInputStream(new File(filePath)), scale);
    } else {
        load(assets.open(filePath), scale);
    }

    // listener
    if (mListener != null) {
        mListener.onAtlasLoad(JsonAtlas.this);
    }
}

From source file:com.linkbubble.util.PageInspector.java

public String getFileContents(String pageScript) {
    String fullPageScript = "pagescripts/" + pageScript + ".js";
    AssetManager assetManager = mContext.getResources().getAssets();
    InputStream inputStream = null;
    final StringBuilder stringBuilder = new StringBuilder();

    try {//from w  w w. ja  v a 2s .c  o m
        inputStream = assetManager.open(fullPageScript);

        final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        boolean done = false;

        while (!done) {
            final String line = reader.readLine();
            done = (line == null);

            if (line != null) {
                stringBuilder.append(line);
            }
        }

        reader.close();
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return stringBuilder.toString();
}

From source file:in.animeshpathak.nextbus.NextBusMain.java

/**
 * Creates the Application Info dialog with clickable links.
 * /* www.  j a v a  2 s .c om*/
 * @throws UnsupportedEncodingException
 * @throws IOException
 */
private void showVersionInfoDialog() throws UnsupportedEncodingException, IOException {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(getString(R.string.app_name) + " " + getString(R.string.version_name));

    AssetManager assetManager = getResources().getAssets();
    String versionInfoFile = getString(R.string.versioninfo_asset);
    InputStreamReader reader = new InputStreamReader(assetManager.open(versionInfoFile), "UTF-8");
    BufferedReader br = new BufferedReader(reader);
    StringBuffer sbuf = new StringBuffer();
    String line;
    while ((line = br.readLine()) != null) {
        sbuf.append(line);
        sbuf.append("\r\n");
    }

    final ScrollView scroll = new ScrollView(this);
    final TextView message = new TextView(this);
    final SpannableString sWlinks = new SpannableString(sbuf.toString());
    Linkify.addLinks(sWlinks, Linkify.WEB_URLS);
    message.setText(sWlinks);
    message.setMovementMethod(LinkMovementMethod.getInstance());
    message.setPadding(15, 15, 15, 15);
    scroll.addView(message);
    alertDialog.setView(scroll);
    alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // nothing to do, just dismiss dialog
        }
    });
    alertDialog.show();
}