Added directoryManager for android

This commit is contained in:
addios 2009-02-26 11:50:11 +07:00
parent a7f45f18d6
commit aba625b6a9
9 changed files with 101 additions and 2 deletions

View File

@ -306,6 +306,29 @@ var Device = {
get: function(url, file) { get: function(url, file) {
window.DroidGap.httpGet(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;
}
} }
} }

View File

@ -108,7 +108,23 @@ http = function(func)
Device.http.get($('httpGetUrl').value, $('httpGetFile').value) 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); addLoadEvent(initGap);
@ -132,6 +148,7 @@ addLoadEvent(initGap);
<li><a href="#photo" onclick="Device.Image.getFromPhotoLibrary();">Photo...</a></li> <li><a href="#photo" onclick="Device.Image.getFromPhotoLibrary();">Photo...</a></li>
<li><a href="#notification" onclick="notification();">Notification...</a></li> <li><a href="#notification" onclick="notification();">Notification...</a></li>
<li><a href="#http" onclick="http();">HTTP...</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> <li><a href="http://phonegap.com/" target="_self">About</a></li>
</ul> </ul>
@ -288,5 +305,32 @@ addLoadEvent(initGap);
</div> </div>
</fieldset> </fieldset>
</div> </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> <div id="preloader"></div></body></html>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -49,6 +49,7 @@ public class PhoneGap{
private NetworkListener mNetwork; private NetworkListener mNetwork;
protected LocationProvider provider; protected LocationProvider provider;
SmsListener mSmsListener; SmsListener mSmsListener;
DirectoryManager fileManager;
public PhoneGap(Context ctx, Handler handler, WebView appView) { public PhoneGap(Context ctx, Handler handler, WebView appView) {
this.mCtx = ctx; this.mCtx = ctx;
@ -57,6 +58,7 @@ public class PhoneGap{
mGps = new GpsListener(ctx); mGps = new GpsListener(ctx);
mNetwork = new NetworkListener(ctx); mNetwork = new NetworkListener(ctx);
mSmsListener = new SmsListener(ctx,mAppView); mSmsListener = new SmsListener(ctx,mAppView);
fileManager = new DirectoryManager();
} }
public void updateAccel(){ public void updateAccel(){
@ -244,5 +246,35 @@ public class PhoneGap{
HttpHandler http = new HttpHandler(); HttpHandler http = new HttpHandler();
http.get(url, file); 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";
}
} }