Skip to content

Instantly share code, notes, and snippets.

@masyukun
Created September 6, 2013 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masyukun/6458057 to your computer and use it in GitHub Desktop.
Save masyukun/6458057 to your computer and use it in GitHub Desktop.
Recursively prints the assets in the current Android project's AssetManager.
String repeatString(String string, int repetitions) {
StringBuilder sb = new StringBuilder();
if (repetitions <= 0) {
return sb.toString();
}
for (int ii = 0; ii <= repetitions; ++ii) {
sb.append(string);
}
return sb.toString();
}
boolean printAsset(String assetPath, int depth) {
final AssetManager assets = getContext().getAssets();
String[] names;
if (null == assetPath) {
assetPath = "";
}
try {
names = assets.list( assetPath );
if (names.length > 0) {
Log.d("ShowcaseView", String.format("%sAssets for \"%s\":", repeatString(" ", depth), assetPath));
for (String name : names) {
Log.d("ShowcaseView", String.format("%s%s", repeatString(" ", depth + 1), name));
if (depth >= 1) {
printAsset(assetPath + "/" + name, depth + 1);
} else {
printAsset(assetPath + name, depth + 1);
}
}
} else {
Log.d("ShowcaseView", String.format("%s\"%s\" is empty", repeatString(" ", depth), assetPath));
}
} catch (IOException e1) {
e1.printStackTrace();
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment