Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1842] Android: Implement spaceAvailable() for File

GitHub Issuen/a
TypeNew Feature
PriorityTrivial
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T01:57:19.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
ComponentsAndroid
Labelsandroid, feature, file, spaceavailable
ReporterMarshall Culpepper
AssigneeMarshall Culpepper
Created2011-04-15T03:03:42.000+0000
Updated2011-04-17T01:57:19.000+0000

Description

right now we just have a place holder of 9999999L

Comments

  1. Marshall Culpepper 2011-04-15

    (from [bdee2871d8f32838edd9840e39ce4035088e3a43]) implement spaceAvailable() for android TiFile [#1842 state:fixed-in-qa] http://github.com/appcelerator/titanium_mobile/commit/bdee2871d8f32838edd9840e39ce4035088e3a43"> http://github.com/appcelerator/titanium_mobile/commit/bdee2871d8f32...

  2. Thomas Huelbert 2011-04-15

    using the code below I get binary return, I believe I should be seeing a value returning the available space?

    var win = Titanium.UI.currentWindow;
    Titanium.UI.setBackgroundColor('white');

    var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory);
    var l = Titanium.UI.createLabel({text:'value should be updated', width:300, height:'auto', textAlign:'center'});
    l.text='spaceAvailable = ' + dir.spaceAvailable();
    win.add(l);

  3. Brion Vibber 2011-04-15

    Commit bdee2871d8f32838edd9840e39ce4035088e3a43 implemented this method using file.getFreeSpace() instead of returning a hardcoded number, but it doesn't appear to actually work in my testing.

    java.io.File.getFreeSpace() is new in JDK 1.6, and although I can compile the runtime just fine, since it isn't actually present in Android, my app fails when attempting to call it.

    http://download.oracle.com/javase/6/docs/api/java/io/File.html#getFreeSpace%28%29"> http://download.oracle.com/javase/6/docs/api/java/io/File.html#getF...

    http://developer.android.com/reference/java/io/File.html">http://developer.android.com/reference/java/io/File.html

       E/AndroidRuntime(  792): FATAL EXCEPTION: kroll$1
       E/AndroidRuntime(  792): java.lang.NoSuchMethodError: java.io.File.getFreeSpace
       E/AndroidRuntime(  792):    at org.appcelerator.titanium.io.TiFile.spaceAvailable(TiFile.java:195)
       E/AndroidRuntime(  792):    at ti.modules.titanium.filesystem.FileProxy.spaceAvailable(FileProxy.java:231)
       E/AndroidRuntime(  792):    at ti.modules.titanium.filesystem.FileProxyBindingGen$15.invoke(FileProxyBindingGen.java:498)
       E/AndroidRuntime(  792):    at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:46)
       E/AndroidRuntime(  792):    at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1711)
       E/AndroidRuntime(  792):    at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
       E/AndroidRuntime(  792):    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
       E/AndroidRuntime(  792):    at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
       E/AndroidRuntime(  792):    at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
       E/AndroidRuntime(  792):    at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
       E/AndroidRuntime(  792):    at org.appcelerator.titanium.kroll.KrollCallback$1.run(KrollCallback.java:97)
       E/AndroidRuntime(  792):    at android.os.Handler.handleCallback(Handler.java:587)
       E/AndroidRuntime(  792):    at android.os.Handler.dispatchMessage(Handler.java:92)
       E/AndroidRuntime(  792):    at android.os.Looper.loop(Looper.java:123)
       E/AndroidRuntime(  792):    at org.appcelerator.titanium.kroll.KrollHandlerThread.run(KrollHandlerThread.java:73)
       
  4. Marshall Culpepper 2011-04-15

    (from [dac0b4dec18678c1f5e9701fe2bdae7f5bb24895]) clean up singleton modules and event managers in context onDestroy, this lets event listeners work when the app has been relaunched. removed impl of File.spaceAvailable() (it was Java6 only, we'll need to find another way) [#1238] [#1842] http://github.com/appcelerator/titanium_mobile/commit/dac0b4dec18678c1f5e9701fe2bdae7f5bb24895"> http://github.com/appcelerator/titanium_mobile/commit/dac0b4dec1867...

  5. Brion Vibber 2011-04-15

    Looks like this can be done with android.os.StatFs:

    http://developer.android.com/reference/android/os/StatFs.html">http://developer.android.com/reference/android/os/StatFs.html

    I'll throw a quick patch together.

  6. Brion Vibber 2011-04-15

    Branch:
    http://github.com/brion/titanium_mobile/tree/spaceAvailable">http://github.com/brion/titanium_mobile/tree/spaceAvailable

    Commit:
    http://github.com/brion/titanium_mobile/commit/ab4deb35f057165dd5a94aa30a994c91ab2781b0"> http://github.com/brion/titanium_mobile/commit/ab4deb35f057165dd5a9...

    Pull request:
    http://github.com/appcelerator/titanium_mobile/pull/10">http://github.com/appcelerator/titanium_mobile/pull/10

    Quick note on something I noticed while testing -- Ti.File.spaceAvailable() is actually documented as returning a boolean rather than returning a numeric byte count. On iOS I'm indeed getting just true/false out of it... Zero/non-zero should act correctly in boolean context, but is there a reason we're returning a number on Android and a boolean on iOS and in the documentation?

  7. Jeff Haynie 2011-04-15

    (from [e9b35665142d28eddc2f73f1aacd6dc37f357732]) [#1842 state:fixed-in-qa] Android implementation of TiFile.spaceAvailable using android.os.StatFs, as java.io.File.getFreeSpace isn't available in current Android.

    Signed-off-by: marshall mculpepper@appcelerator.com
    http://github.com/appcelerator/titanium_mobile/commit/e9b35665142d28eddc2f73f1aacd6dc37f357732"> http://github.com/appcelerator/titanium_mobile/commit/e9b35665142d2...

  8. Thomas Huelbert 2011-04-15

    implemented, logging a new bug about the values being reported and platform/doc inconsistencies.

JSON Source