Created
September 6, 2013 00:29
-
-
Save masyukun/6458057 to your computer and use it in GitHub Desktop.
Recursively prints the assets in the current Android project's AssetManager.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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