mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
PhoneGap Media and File
This commit is contained in:
parent
4b3e3140f4
commit
470ad5efc4
@ -46,6 +46,7 @@ public class DroidGap extends Activity {
|
|||||||
private GeoBroker geo;
|
private GeoBroker geo;
|
||||||
private AccelListener accel;
|
private AccelListener accel;
|
||||||
private CameraLauncher launcher;
|
private CameraLauncher launcher;
|
||||||
|
private FileUtils fs;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
@ -98,11 +99,14 @@ public class DroidGap extends Activity {
|
|||||||
geo = new GeoBroker(appView, this);
|
geo = new GeoBroker(appView, this);
|
||||||
accel = new AccelListener(this, appView);
|
accel = new AccelListener(this, appView);
|
||||||
launcher = new CameraLauncher(appView, this);
|
launcher = new CameraLauncher(appView, this);
|
||||||
|
fs = new FileUtils();
|
||||||
|
|
||||||
// This creates the new javascript interfaces for PhoneGap
|
// This creates the new javascript interfaces for PhoneGap
|
||||||
appView.addJavascriptInterface(gap, "DroidGap");
|
appView.addJavascriptInterface(gap, "DroidGap");
|
||||||
appView.addJavascriptInterface(geo, "Geo");
|
appView.addJavascriptInterface(geo, "Geo");
|
||||||
appView.addJavascriptInterface(accel, "Accel");
|
appView.addJavascriptInterface(accel, "Accel");
|
||||||
appView.addJavascriptInterface(launcher, "GapCam");
|
appView.addJavascriptInterface(launcher, "GapCam");
|
||||||
|
appView.addJavascriptInterface(fs, "FileUtil");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
104
src/com/phonegap/demo/FileUtils.java
Normal file
104
src/com/phonegap/demo/FileUtils.java
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
package com.phonegap.demo;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
public class FileUtils {
|
||||||
|
|
||||||
|
DirectoryManager fileManager;
|
||||||
|
FileReader f_in;
|
||||||
|
FileWriter f_out;
|
||||||
|
|
||||||
|
public int testSaveLocationExists(){
|
||||||
|
if (fileManager.testSaveLocationExists())
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getFreeDiskSpace(){
|
||||||
|
long freeDiskSpace=fileManager.getFreeDiskSpace();
|
||||||
|
return freeDiskSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int testFileExists(String file){
|
||||||
|
if (fileManager.testFileExists(file))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int testDirectoryExists(String file){
|
||||||
|
if (fileManager.testFileExists(file))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a specific directory.
|
||||||
|
* Everyting in side the directory would be gone.
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int deleteDirectory (String dir){
|
||||||
|
if (fileManager.deleteDirectory(dir))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a specific file.
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int deleteFile (String file){
|
||||||
|
if (fileManager.deleteFile(file))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new directory.
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int createDirectory(String dir){
|
||||||
|
if (fileManager.createDirectory(dir))
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String read(String filename)
|
||||||
|
{
|
||||||
|
String data = "";
|
||||||
|
String output = "";
|
||||||
|
try {
|
||||||
|
FileInputStream fstream = new FileInputStream(filename);
|
||||||
|
DataInputStream in = new DataInputStream(fstream);
|
||||||
|
while (in.available() !=0)
|
||||||
|
{
|
||||||
|
data += in.readLine();
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
data = "FAIL: File not found";
|
||||||
|
} catch (IOException e) {
|
||||||
|
data = "FAIL: IO ERROR";
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int write(String filename, String data)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
FileOutputStream out = new FileOutputStream(filename);
|
||||||
|
PrintStream p = new PrintStream(out);
|
||||||
|
p.print(data);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -21,13 +21,12 @@ package com.phonegap.demo;
|
|||||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -41,7 +40,7 @@ public class PhoneGap{
|
|||||||
* UUID, version and availability
|
* UUID, version and availability
|
||||||
*/
|
*/
|
||||||
public boolean droid = true;
|
public boolean droid = true;
|
||||||
public static String version = "0.2";
|
public static String version = "0.8.0";
|
||||||
public static String platform = "Android";
|
public static String platform = "Android";
|
||||||
public static String uuid;
|
public static String uuid;
|
||||||
private Context mCtx;
|
private Context mCtx;
|
||||||
@ -62,9 +61,8 @@ public class PhoneGap{
|
|||||||
|
|
||||||
public void beep(long pattern)
|
public void beep(long pattern)
|
||||||
{
|
{
|
||||||
RingtoneManager beeper = new RingtoneManager(mCtx);
|
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||||
Uri ringtone = beeper.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
Ringtone notification = RingtoneManager.getRingtone(mCtx, ringtone);
|
||||||
Ringtone notification = beeper.getRingtone(mCtx, ringtone);
|
|
||||||
for (long i = 0; i < pattern; ++i)
|
for (long i = 0; i < pattern; ++i)
|
||||||
{
|
{
|
||||||
notification.play();
|
notification.play();
|
||||||
@ -162,9 +160,6 @@ public class PhoneGap{
|
|||||||
http.get(url, file);
|
http.get(url, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AUDIO
|
* AUDIO
|
||||||
* TODO: Basic functions done but needs more work on error handling and call backs, remove record hack
|
* TODO: Basic functions done but needs more work on error handling and call backs, remove record hack
|
||||||
|
Loading…
Reference in New Issue
Block a user