diff options
author | Alex Sakhartchouk <alexst@google.com> | 2011-01-07 11:12:08 -0800 |
---|---|---|
committer | Alex Sakhartchouk <alexst@google.com> | 2011-01-07 11:16:08 -0800 |
commit | b0253ea6969bdd27bf574e0da7fa91aa6d09f44f (patch) | |
tree | 2c2c89870052eb05e3d150d8710c7df4d1f3646a /graphics/java/android/renderscript/FileA3D.java | |
parent | 60525c824ccf11302a9b8343e72eba259485edea (diff) |
Additional loading methods for fonts and a3d files.
Cleaned up error messages.
Change-Id: Id33b7149671df23c37cc11375d844a7837dac750
Change-Id: I6663ce54f7b9bbaf285935ca658d93ba417f8179
Diffstat (limited to 'graphics/java/android/renderscript/FileA3D.java')
-rw-r--r-- | graphics/java/android/renderscript/FileA3D.java | 62 |
1 files changed, 36 insertions, 26 deletions
diff --git a/graphics/java/android/renderscript/FileA3D.java b/graphics/java/android/renderscript/FileA3D.java index c3e5fafff9f1..01a9a828ae57 100644 --- a/graphics/java/android/renderscript/FileA3D.java +++ b/graphics/java/android/renderscript/FileA3D.java @@ -167,47 +167,57 @@ public class FileA3D extends BaseObj { return mFileEntries[index]; } - // API cleanup stand-ins - // TODO: implement ermaining loading mechanisms - static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) - throws IllegalArgumentException { - return null; + static public FileA3D createFromAsset(RenderScript rs, AssetManager mgr, String path) { + rs.validate(); + int fileId = rs.nFileA3DCreateFromAsset(mgr, path); + + if(fileId == 0) { + throw new RSRuntimeException("Unable to create a3d file from asset " + path); + } + FileA3D fa3d = new FileA3D(fileId, rs, null); + fa3d.initEntries(); + return fa3d; } - static public FileA3D createFromFile(RenderScript rs, String path) - throws IllegalArgumentException { - return null; + static public FileA3D createFromFile(RenderScript rs, String path) { + int fileId = rs.nFileA3DCreateFromFile(path); + + if(fileId == 0) { + throw new RSRuntimeException("Unable to create a3d file from " + path); + } + FileA3D fa3d = new FileA3D(fileId, rs, null); + fa3d.initEntries(); + return fa3d; } - static public FileA3D createFromFile(RenderScript rs, File path) - throws IllegalArgumentException { + static public FileA3D createFromFile(RenderScript rs, File path) { return createFromFile(rs, path.getAbsolutePath()); } - static public FileA3D createFromResource(RenderScript rs, Resources res, int id) - throws IllegalArgumentException { + static public FileA3D createFromResource(RenderScript rs, Resources res, int id) { rs.validate(); InputStream is = null; try { - final TypedValue value = new TypedValue(); - is = res.openRawResource(id, value); + is = res.openRawResource(id); + } catch (Exception e) { + throw new RSRuntimeException("Unable to open resource " + id); + } + int fileId = 0; + if (is instanceof AssetManager.AssetInputStream) { int asset = ((AssetManager.AssetInputStream) is).getAssetInt(); + fileId = rs.nFileA3DCreateFromAssetStream(asset); + } else { + throw new RSRuntimeException("Unsupported asset stream"); + } - int fileId = rs.nFileA3DCreateFromAssetStream(asset); - - if(fileId == 0) { - throw new IllegalStateException("Load failed."); - } - FileA3D fa3d = new FileA3D(fileId, rs, is); - fa3d.initEntries(); - return fa3d; - - } catch (Exception e) { - // Ignore + if(fileId == 0) { + throw new RSRuntimeException("Unable to create a3d file from resource " + id); } + FileA3D fa3d = new FileA3D(fileId, rs, is); + fa3d.initEntries(); + return fa3d; - return null; } } |