mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
Added directoryManager for android
This commit is contained in:
parent
a7f45f18d6
commit
aba625b6a9
@ -306,7 +306,30 @@ var Device = {
|
||||
get: function(url, file) {
|
||||
window.DroidGap.httpGet(url, file);
|
||||
}
|
||||
}
|
||||
},
|
||||
storage: {
|
||||
result: "",
|
||||
testSDCard: function(){
|
||||
Device.storage.result = window.DroidGap.testSaveLocationExists();
|
||||
return Device.storage.result;
|
||||
},
|
||||
testExistence: function(file){
|
||||
Device.storage.result = window.DroidGap.testDirOrFileExists(file);
|
||||
return Device.storage.result;
|
||||
},
|
||||
delFile: function(file){
|
||||
Device.storage.result = window.DroidGap.deleteFile(file);
|
||||
return Device.storage.result;
|
||||
},
|
||||
delDir: function(file){
|
||||
Device.storage.result = window.DroidGap.deleteDirectory(file);
|
||||
return Device.storage.result;
|
||||
},
|
||||
createDir: function(file){
|
||||
Device.storage.result = window.DroidGap.createDirectory(file);
|
||||
return Device.storage.result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function gotLocation(lat, lon) {
|
||||
|
@ -108,7 +108,23 @@ http = function(func)
|
||||
Device.http.get($('httpGetUrl').value, $('httpGetFile').value)
|
||||
}
|
||||
}
|
||||
|
||||
fileManagement = function(x){
|
||||
if (x == 'testSDCard'){
|
||||
$('file_status').value = Device.storage.testSDCard();
|
||||
}else
|
||||
if (x == 'testExistence'){
|
||||
$('file_status').value = Device.storage.testExistence($('checkfile').value);
|
||||
}else
|
||||
if (x == 'createDir'){
|
||||
$('file_status').value = Device.storage.createDir($('createfile').value);
|
||||
}else
|
||||
if (x == 'delFile'){
|
||||
$('file_status').value = Device.storage.delFile($('delfile').value);
|
||||
}else
|
||||
if (x == 'delDir'){
|
||||
$('file_status').value = Device.storage.delDir($('deldir').value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
addLoadEvent(initGap);
|
||||
@ -132,6 +148,7 @@ addLoadEvent(initGap);
|
||||
<li><a href="#photo" onclick="Device.Image.getFromPhotoLibrary();">Photo...</a></li>
|
||||
<li><a href="#notification" onclick="notification();">Notification...</a></li>
|
||||
<li><a href="#http" onclick="http();">HTTP...</a></li>
|
||||
<li><a href="#esm" onclick="">External Storage</a></li>
|
||||
<li><a href="http://phonegap.com/" target="_self">About</a></li>
|
||||
</ul>
|
||||
|
||||
@ -288,5 +305,32 @@ addLoadEvent(initGap);
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
<div id="esm" title="Storage" class="panel" >
|
||||
<h2>Storage Management</h2>
|
||||
<fieldset>
|
||||
<div class="row">
|
||||
<label>File Status</label>
|
||||
<input disabled="enabled" name="file_status" id="file_status" value="" type="text"></input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="fileManagement('testSDCard');">Check Status</a>
|
||||
</div> <div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="fileManagement('testExistence')">Check File</a>
|
||||
<input type=text name="checkfile" id="checkfile" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="fileManagement('createDir');">Create Directory</a>
|
||||
<input type=text name="createfile" id="createfile" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<a class="button leftButton" type="submit" onclick="fileManagement('delFile');">Delete File</a>
|
||||
<input type=text name="delfile" id="delfile" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||
</div>
|
||||
<div class="row">
|
||||
<input type=text name="deldir" id="deldir" size=60 maxlength=2048 value="" style="width: 30ex"></input>
|
||||
<a class="button leftButton" type="submit" onclick="fileManagement('delDir');">Delete Directory</a>
|
||||
</div>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<div id="preloader"></div></body></html>
|
||||
|
BIN
bin/DroidGap.apk
BIN
bin/DroidGap.apk
Binary file not shown.
BIN
bin/classes.dex
BIN
bin/classes.dex
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -49,6 +49,7 @@ public class PhoneGap{
|
||||
private NetworkListener mNetwork;
|
||||
protected LocationProvider provider;
|
||||
SmsListener mSmsListener;
|
||||
DirectoryManager fileManager;
|
||||
|
||||
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
||||
this.mCtx = ctx;
|
||||
@ -57,6 +58,7 @@ public class PhoneGap{
|
||||
mGps = new GpsListener(ctx);
|
||||
mNetwork = new NetworkListener(ctx);
|
||||
mSmsListener = new SmsListener(ctx,mAppView);
|
||||
fileManager = new DirectoryManager();
|
||||
}
|
||||
|
||||
public void updateAccel(){
|
||||
@ -244,5 +246,35 @@ public class PhoneGap{
|
||||
HttpHandler http = new HttpHandler();
|
||||
http.get(url, file);
|
||||
}
|
||||
public String testSaveLocationExists(){
|
||||
if (fileManager.testSaveLocationExists())
|
||||
return "SD Card available";
|
||||
else
|
||||
return "SD Card unavailable";
|
||||
}
|
||||
public String testDirOrFileExists(String file){
|
||||
if (fileManager.isDirtoryOrFileExists(file))
|
||||
return "File exists";
|
||||
else
|
||||
return "No this file";
|
||||
}
|
||||
public String deleteDirectory (String dir){
|
||||
if (fileManager.deleteDir(dir))
|
||||
return "Completed";
|
||||
else
|
||||
return "Not completed";
|
||||
}
|
||||
public String deleteFile (String file){
|
||||
if (fileManager.deleteFile(file))
|
||||
return "Completed";
|
||||
else
|
||||
return "Not completed";
|
||||
}
|
||||
public String createDirectory(String dir){
|
||||
if (fileManager.createDirectory(dir))
|
||||
return "Completed";
|
||||
else
|
||||
return "Not completed";
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user