[TIMOB-1842] Android: Implement spaceAvailable() for File
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Trivial |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-04-17T01:57:19.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 1.5.0 |
Components | Android |
Labels | android, feature, file, spaceavailable |
Reporter | Marshall Culpepper |
Assignee | Marshall Culpepper |
Created | 2011-04-15T03:03:42.000+0000 |
Updated | 2011-04-17T01:57:19.000+0000 |
Description
right now we just have a place holder of 9999999L
(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...
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);
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
(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...
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.
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?
(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...
implemented, logging a new bug about the values being reported and platform/doc inconsistencies.