Example usage for android.content.res AssetManager list

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

Introduction

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

Prototype

public @Nullable String[] list(@NonNull String path) throws IOException 

Source Link

Document

Return a String array of all the assets at the given path.

Usage

From source file:at.aec.solutions.checkmkagent.AgentService.java

private static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) {
    try {//from   w  w  w  . j a  va 2s.  c  o m
        String[] files = assetManager.list(fromAssetPath);
        new File(toPath).mkdirs();
        boolean res = true;
        for (String file : files)
            if (file.contains("."))
                res &= copyAsset(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
            else
                res &= copyAssetFolder(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.protocoderrunner.utils.FileIO.java

public static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) {
    try {/*from   w  w  w  .j  a v  a 2  s  .  c o m*/
        String[] files = assetManager.list(fromAssetPath);
        new File(toPath).mkdirs();
        boolean res = true;
        for (String file : files) {
            if (file.contains(".")) {
                res &= copyAsset(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
            } else {
                res &= copyAssetFolder(assetManager, fromAssetPath + "/" + file, toPath + "/" + file);
            }
        }
        return res;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}

From source file:org.protocoderrunner.utils.FileIO.java

public static void copyFileOrDir(Context c, String path) {
    AssetManager assetManager = c.getAssets();
    String assets[] = null;//from  www  .j  a  v a  2s  .com
    try {
        assets = assetManager.list(path);
        if (assets.length == 0) {
            copyFile(c, path);
        } else {
            String fullPath = ProjectManager.getInstance().getBaseDir() + path;
            File dir = new File(fullPath);
            if (!dir.exists()) {
                dir.mkdir();
            }
            for (String asset : assets) {
                copyFileOrDir(c, path + "/" + asset);
            }
        }
    } catch (IOException ex) {
        Log.e("tag", "I/O Exception", ex);
    }
}

From source file:Main.java

private static void copyAssetFolder(AssetManager am, String src, String dest) throws IOException {

    Log.i("Copy ", src);
    InputStream srcIS = null;// w  ww  .j a  v a 2s  . co  m
    File destfh;

    // this is the only way we can tell if this is a file or a
    // folder - we have to open the asset, and if the open fails,
    // it's a folder...
    boolean isDir = false;
    try {
        srcIS = am.open(src);
    } catch (FileNotFoundException e) {
        isDir = true;
    }

    // either way, we'll use the dest as a File
    destfh = new File(dest);

    // and now, depending on ..
    if (isDir) {

        // If the directory doesn't yet exist, create it
        if (!destfh.exists()) {
            destfh.mkdir();
        }

        // list the assets in the directory...
        String assets[] = am.list(src);

        // and copy them all using same.
        for (String asset : assets) {
            copyAssetFolder(am, src + "/" + asset, dest + "/" + asset);
        }

    } else {
        int count, buffer_len = 2048;
        byte[] data = new byte[buffer_len];

        // copy the file from the assets subsystem to the filesystem
        FileOutputStream destOS = new FileOutputStream(destfh);

        //copy the file content in bytes
        while ((count = srcIS.read(data, 0, buffer_len)) != -1) {
            destOS.write(data, 0, count);
        }

        // and close the two files
        srcIS.close();
        destOS.close();
    }
}

From source file:com.commonsware.cwac.richtextutils.demo.AssetPagerAdapter.java

public AssetPagerAdapter(AssetManager assets, FragmentManager fragmentManager) throws IOException {
    super(fragmentManager);
    testFiles = assets.list("testFiles");
}

From source file:com.adsoft.girls_tatoos_gallery.MainActivity.java

private List<String> getImage() throws IOException {
    AssetManager assetManager = getAssets();
    String[] files = assetManager.list("images");
    List<String> it = Arrays.asList(files);
    return it;//ww  w .  j av a  2 s . c o  m
}

From source file:jahirfiquitiva.iconshowcase.tasks.CopyFilesToStorage.java

@Override
protected Boolean doInBackground(Void... params) {
    Boolean worked;/* www  . j a v  a  2 s. c  o m*/
    try {
        AssetManager assetManager = context.get().getAssets();
        String[] files = assetManager.list(folder);

        if (files != null) {
            for (String filename : files) {
                InputStream in;
                OutputStream out;
                if (filename.contains(".")) {
                    try {
                        in = assetManager.open(folder + "/" + filename);
                        out = new FileOutputStream(Environment.getExternalStorageDirectory().toString()
                                + "/ZooperWidget/" + getFolderName(folder) + "/" + filename);
                        copyFiles(in, out);
                        in.close();
                        out.close();
                    } catch (Exception e) {
                        //Do nothing
                    }
                }
            }
        }
        worked = true;
    } catch (Exception e2) {
        worked = false;
    }
    return worked;
}

From source file:com.orange.ocara.model.SitesLoaderImpl.java

@Override
public Set<String> getUninstalledSitePackages() {
    Set<String> result = new HashSet<String>();

    final AssetManager assetManager = context.getAssets();

    try {/*from   www .  ja va2s. c  o  m*/
        String[] assetsList = assetManager.list(SITES_FOLDER);
        for (String asset : assetsList) {
            if (isJsonFile(asset)) {
                Timber.i("site package : %s", asset);
                File packagesDir = getInstalledSitePackageDir();
                File target = new File(packagesDir, asset);
                if (!target.exists()) {
                    result.add(asset);
                    Timber.i("site package is not installed %s", asset);
                }
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return result;
}

From source file:com.mikecorrigan.trainscorekeeper.ActivityNewGame.java

private void addContent() {
    Log.vc(VERBOSE, TAG, "addContent");

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear_layout);

    Resources res = getResources();
    AssetManager am = res.getAssets();
    String files[];/*from   w  w  w .  ja  v a2  s . c o m*/
    try {
        files = am.list(ASSETS_BASE);
        if (files == null || files.length == 0) {
            Log.e(TAG, "addContent: empty asset list");
            return;
        }

        for (final String file : files) {
            final String path = ASSETS_BASE + File.separator + file;

            JSONObject jsonRoot = JsonUtils.readFromAssets(this /* context */, path);
            if (jsonRoot == null) {
                Log.e(file, "addContent: failed to read read asset");
                continue;
            }

            final String name = jsonRoot.optString(JsonSpec.ROOT_NAME);
            if (TextUtils.isEmpty(name)) {
                Log.e(file, "addContent: failed to read asset name");
                continue;
            }

            final String description = jsonRoot.optString(JsonSpec.ROOT_DESCRIPTION, name);

            TextView textView = new TextView(this /* context */);
            textView.setText(name);
            linearLayout.addView(textView);

            Button button = new Button(this /* context */);
            button.setText(description);
            button.setOnClickListener(new OnRulesClickListener(path));
            linearLayout.addView(button);
        }
    } catch (IOException e) {
        Log.th(TAG, e, "addContent: asset list failed");
    }
}

From source file:com.duy.ascii.sharedcode.bigtext.BigFontFragment.java

private void createPresenter() {
    if (mPresenter != null)
        return;/*from ww w .ja  v a2s .c  o  m*/
    try {
        AssetManager assets = getContext().getAssets();
        String[] names = assets.list("bigtext");
        InputStream[] inputStreams = new InputStream[names.length];
        for (int i = 0; i < names.length; i++) {
            String name = names[i];
            inputStreams[i] = assets.open("bigtext" + "/" + name);
        }
        mPresenter = new BigFontPresenter(inputStreams, this);
    } catch (Exception e) {
        e.printStackTrace();
    }
}