mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Removed PhoneGap.java, renaming to device and audio
This commit is contained in:
parent
bb501de22c
commit
945c0d95e6
@ -1,193 +1,68 @@
|
|||||||
package com.phonegap;
|
package com.phonegap;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.webkit.WebView;
|
||||||
import android.media.MediaPlayer;
|
|
||||||
import android.media.MediaPlayer.OnErrorListener;
|
|
||||||
import android.media.MediaRecorder;
|
|
||||||
import android.media.MediaPlayer.OnBufferingUpdateListener;
|
|
||||||
import android.media.MediaPlayer.OnCompletionListener;
|
|
||||||
import android.media.MediaPlayer.OnPreparedListener;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class AudioHandler implements OnCompletionListener, OnPreparedListener, OnErrorListener {
|
public class AudioHandler {
|
||||||
private MediaRecorder recorder;
|
|
||||||
private boolean isRecording = false;
|
|
||||||
MediaPlayer mPlayer;
|
|
||||||
private boolean isPlaying = false;
|
|
||||||
private String recording;
|
|
||||||
private String saveFile;
|
|
||||||
private Context mCtx;
|
|
||||||
|
|
||||||
public AudioHandler(String file, Context ctx) {
|
AudioPlayer audio;
|
||||||
this.recording = file;
|
WebView mAppView;
|
||||||
this.mCtx = ctx;
|
Context mCtx;
|
||||||
}
|
|
||||||
|
|
||||||
protected void startRecording(String file){
|
AudioHandler(WebView view, Context ctx)
|
||||||
if (!isRecording){
|
|
||||||
saveFile=file;
|
|
||||||
recorder = new MediaRecorder();
|
|
||||||
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
|
||||||
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
|
||||||
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
|
|
||||||
recorder.setOutputFile(this.recording);
|
|
||||||
try {
|
|
||||||
recorder.prepare();
|
|
||||||
} catch (IllegalStateException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
isRecording = true;
|
|
||||||
recorder.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveFile(String file) {
|
|
||||||
/* this is a hack to save the file as the specified name */
|
|
||||||
File f = new File (this.recording);
|
|
||||||
f.renameTo(new File("/sdcard" + file));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void stopRecording(){
|
|
||||||
try{
|
|
||||||
if((recorder != null)&&(isRecording))
|
|
||||||
{
|
|
||||||
isRecording = false;
|
|
||||||
recorder.stop();
|
|
||||||
recorder.release();
|
|
||||||
}
|
|
||||||
moveFile(saveFile);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void startPlaying(String file) {
|
|
||||||
if (isPlaying==false) {
|
|
||||||
try {
|
|
||||||
mPlayer = new MediaPlayer();
|
|
||||||
isPlaying=true;
|
|
||||||
Log.d("Audio startPlaying", "audio: " + file);
|
|
||||||
if (isStreaming(file))
|
|
||||||
{
|
|
||||||
Log.d("AudioStartPlaying", "Streaming");
|
|
||||||
// Streaming prepare async
|
|
||||||
mPlayer.setDataSource(file);
|
|
||||||
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
|
||||||
mPlayer.prepareAsync();
|
|
||||||
} else {
|
|
||||||
Log.d("AudioStartPlaying", "File");
|
|
||||||
// Not streaming prepare synchronous, abstract base directory
|
|
||||||
mPlayer.setDataSource("/sdcard/" + file);
|
|
||||||
mPlayer.prepare();
|
|
||||||
}
|
|
||||||
mPlayer.setOnPreparedListener(this);
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopPlaying() {
|
|
||||||
if (isPlaying) {
|
|
||||||
mPlayer.stop();
|
|
||||||
mPlayer.release();
|
|
||||||
isPlaying=false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onCompletion(MediaPlayer mPlayer) {
|
|
||||||
mPlayer.stop();
|
|
||||||
mPlayer.release();
|
|
||||||
isPlaying=false;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected long getCurrentPosition() {
|
|
||||||
if (isPlaying)
|
|
||||||
{
|
|
||||||
return(mPlayer.getCurrentPosition());
|
|
||||||
} else { return(-1); }
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isStreaming(String file)
|
|
||||||
{
|
{
|
||||||
if (file.contains("http://")) {
|
mAppView = view;
|
||||||
return true;
|
mCtx = ctx;
|
||||||
} else {
|
// YES, I know this is bad, but I can't do it the right way because Google didn't have the
|
||||||
return false;
|
// foresight to add android.os.environment.getExternalDataDirectory until Android 2.2
|
||||||
}
|
audio = new AudioPlayer("/sdcard/tmprecording.mp3", mCtx);
|
||||||
}
|
|
||||||
|
|
||||||
protected long getDuration(String file) {
|
|
||||||
long duration = -2;
|
|
||||||
if (!isPlaying & !isStreaming(file)) {
|
|
||||||
try {
|
|
||||||
mPlayer = new MediaPlayer();
|
|
||||||
mPlayer.setDataSource("/sdcard/" + file);
|
|
||||||
mPlayer.prepare();
|
|
||||||
duration = mPlayer.getDuration();
|
|
||||||
mPlayer.release();
|
|
||||||
} catch (Exception e) { e.printStackTrace(); return(-3); }
|
|
||||||
} else
|
|
||||||
if (isPlaying & !isStreaming(file)) {
|
|
||||||
duration = mPlayer.getDuration();
|
|
||||||
} else
|
|
||||||
if (isPlaying & isStreaming(file)) {
|
|
||||||
try {
|
|
||||||
duration = mPlayer.getDuration();
|
|
||||||
} catch (Exception e) { e.printStackTrace(); return(-4); }
|
|
||||||
}else { return -1; }
|
|
||||||
return duration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPrepared(MediaPlayer mPlayer) {
|
/**
|
||||||
if (isPlaying) {
|
* AUDIO
|
||||||
mPlayer.setOnCompletionListener(this);
|
* TODO: Basic functions done but needs more work on error handling and call backs, remove record hack
|
||||||
mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener()
|
*/
|
||||||
{
|
|
||||||
public void onBufferingUpdate(MediaPlayer mPlayer, int percent)
|
public void startRecordingAudio(String file)
|
||||||
{
|
{
|
||||||
/* TODO: call back, e.g. update outer progress bar */
|
/* for this to work the recording needs to be specified in the constructor,
|
||||||
Log.d("AudioOnBufferingUpdate", "percent: " + percent);
|
* a hack to get around this, I'm moving the recording after it's complete
|
||||||
}
|
*/
|
||||||
});
|
audio.startRecording(file);
|
||||||
mPlayer.start();
|
}
|
||||||
}
|
|
||||||
}
|
public void stopRecordingAudio()
|
||||||
|
{
|
||||||
public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) {
|
audio.stopRecording();
|
||||||
Log.e("AUDIO onError", "error " + arg1 + " " + arg2);
|
}
|
||||||
return false;
|
|
||||||
}
|
public void startPlayingAudio(String file)
|
||||||
|
{
|
||||||
protected void setAudioOutputDevice(int output){
|
audio.startPlaying(file);
|
||||||
// Changes the default audio output device to speaker or earpiece
|
}
|
||||||
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
|
||||||
if (output == (2))
|
public void stopPlayingAudio()
|
||||||
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
{
|
||||||
else if (output == (1)){
|
audio.stopPlaying();
|
||||||
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
}
|
||||||
}else
|
|
||||||
Log.e("AudioHandler setAudioOutputDevice", " unknown output device");
|
public long getCurrentPositionAudio()
|
||||||
}
|
{
|
||||||
|
System.out.println(audio.getCurrentPosition());
|
||||||
protected int getAudioOutputDevice(){
|
return(audio.getCurrentPosition());
|
||||||
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
}
|
||||||
if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE)
|
|
||||||
return 1;
|
public long getDurationAudio(String file)
|
||||||
else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER)
|
{
|
||||||
return 2;
|
System.out.println(audio.getDuration(file));
|
||||||
else
|
return(audio.getDuration(file));
|
||||||
return -1;
|
}
|
||||||
}
|
|
||||||
|
public void setAudioOutputDevice(int output){
|
||||||
|
audio.setAudioOutputDevice(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAudioOutputDevice(){
|
||||||
|
return audio.getAudioOutputDevice();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
193
framework/src/com/phonegap/AudioPlayer.java
Normal file
193
framework/src/com/phonegap/AudioPlayer.java
Normal file
@ -0,0 +1,193 @@
|
|||||||
|
package com.phonegap;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.media.AudioManager;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
|
import android.media.MediaPlayer.OnErrorListener;
|
||||||
|
import android.media.MediaRecorder;
|
||||||
|
import android.media.MediaPlayer.OnBufferingUpdateListener;
|
||||||
|
import android.media.MediaPlayer.OnCompletionListener;
|
||||||
|
import android.media.MediaPlayer.OnPreparedListener;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class AudioPlayer implements OnCompletionListener, OnPreparedListener, OnErrorListener {
|
||||||
|
private MediaRecorder recorder;
|
||||||
|
private boolean isRecording = false;
|
||||||
|
MediaPlayer mPlayer;
|
||||||
|
private boolean isPlaying = false;
|
||||||
|
private String recording;
|
||||||
|
private String saveFile;
|
||||||
|
private Context mCtx;
|
||||||
|
|
||||||
|
public AudioPlayer(String file, Context ctx) {
|
||||||
|
this.recording = file;
|
||||||
|
this.mCtx = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startRecording(String file){
|
||||||
|
if (!isRecording){
|
||||||
|
saveFile=file;
|
||||||
|
recorder = new MediaRecorder();
|
||||||
|
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
|
||||||
|
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
|
||||||
|
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
|
||||||
|
recorder.setOutputFile(this.recording);
|
||||||
|
try {
|
||||||
|
recorder.prepare();
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
isRecording = true;
|
||||||
|
recorder.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void moveFile(String file) {
|
||||||
|
/* this is a hack to save the file as the specified name */
|
||||||
|
File f = new File (this.recording);
|
||||||
|
f.renameTo(new File("/sdcard" + file));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void stopRecording(){
|
||||||
|
try{
|
||||||
|
if((recorder != null)&&(isRecording))
|
||||||
|
{
|
||||||
|
isRecording = false;
|
||||||
|
recorder.stop();
|
||||||
|
recorder.release();
|
||||||
|
}
|
||||||
|
moveFile(saveFile);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void startPlaying(String file) {
|
||||||
|
if (isPlaying==false) {
|
||||||
|
try {
|
||||||
|
mPlayer = new MediaPlayer();
|
||||||
|
isPlaying=true;
|
||||||
|
Log.d("Audio startPlaying", "audio: " + file);
|
||||||
|
if (isStreaming(file))
|
||||||
|
{
|
||||||
|
Log.d("AudioStartPlaying", "Streaming");
|
||||||
|
// Streaming prepare async
|
||||||
|
mPlayer.setDataSource(file);
|
||||||
|
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
|
mPlayer.prepareAsync();
|
||||||
|
} else {
|
||||||
|
Log.d("AudioStartPlaying", "File");
|
||||||
|
// Not streaming prepare synchronous, abstract base directory
|
||||||
|
mPlayer.setDataSource("/sdcard/" + file);
|
||||||
|
mPlayer.prepare();
|
||||||
|
}
|
||||||
|
mPlayer.setOnPreparedListener(this);
|
||||||
|
} catch (Exception e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopPlaying() {
|
||||||
|
if (isPlaying) {
|
||||||
|
mPlayer.stop();
|
||||||
|
mPlayer.release();
|
||||||
|
isPlaying=false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onCompletion(MediaPlayer mPlayer) {
|
||||||
|
mPlayer.stop();
|
||||||
|
mPlayer.release();
|
||||||
|
isPlaying=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected long getCurrentPosition() {
|
||||||
|
if (isPlaying)
|
||||||
|
{
|
||||||
|
return(mPlayer.getCurrentPosition());
|
||||||
|
} else { return(-1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStreaming(String file)
|
||||||
|
{
|
||||||
|
if (file.contains("http://")) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected long getDuration(String file) {
|
||||||
|
long duration = -2;
|
||||||
|
if (!isPlaying & !isStreaming(file)) {
|
||||||
|
try {
|
||||||
|
mPlayer = new MediaPlayer();
|
||||||
|
mPlayer.setDataSource("/sdcard/" + file);
|
||||||
|
mPlayer.prepare();
|
||||||
|
duration = mPlayer.getDuration();
|
||||||
|
mPlayer.release();
|
||||||
|
} catch (Exception e) { e.printStackTrace(); return(-3); }
|
||||||
|
} else
|
||||||
|
if (isPlaying & !isStreaming(file)) {
|
||||||
|
duration = mPlayer.getDuration();
|
||||||
|
} else
|
||||||
|
if (isPlaying & isStreaming(file)) {
|
||||||
|
try {
|
||||||
|
duration = mPlayer.getDuration();
|
||||||
|
} catch (Exception e) { e.printStackTrace(); return(-4); }
|
||||||
|
}else { return -1; }
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPrepared(MediaPlayer mPlayer) {
|
||||||
|
if (isPlaying) {
|
||||||
|
mPlayer.setOnCompletionListener(this);
|
||||||
|
mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener()
|
||||||
|
{
|
||||||
|
public void onBufferingUpdate(MediaPlayer mPlayer, int percent)
|
||||||
|
{
|
||||||
|
/* TODO: call back, e.g. update outer progress bar */
|
||||||
|
Log.d("AudioOnBufferingUpdate", "percent: " + percent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mPlayer.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) {
|
||||||
|
Log.e("AUDIO onError", "error " + arg1 + " " + arg2);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setAudioOutputDevice(int output){
|
||||||
|
// Changes the default audio output device to speaker or earpiece
|
||||||
|
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
if (output == (2))
|
||||||
|
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
||||||
|
else if (output == (1)){
|
||||||
|
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
||||||
|
}else
|
||||||
|
Log.e("AudioHandler setAudioOutputDevice", " unknown output device");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int getAudioOutputDevice(){
|
||||||
|
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE)
|
||||||
|
return 1;
|
||||||
|
else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER)
|
||||||
|
return 2;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
46
framework/src/com/phonegap/BrowserKey.java
Normal file
46
framework/src/com/phonegap/BrowserKey.java
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package com.phonegap;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This class literally exists to protect DroidGap from Javascript directly.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
public class BrowserKey {
|
||||||
|
|
||||||
|
DroidGap mAction;
|
||||||
|
boolean bound;
|
||||||
|
|
||||||
|
WebView mView;
|
||||||
|
|
||||||
|
BrowserKey(WebView view, DroidGap action)
|
||||||
|
{
|
||||||
|
bound = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void override()
|
||||||
|
{
|
||||||
|
Log.d("PhoneGap", "WARNING: Back Button Default Behaviour will be overridden. The backKeyDown event will be fired!");
|
||||||
|
bound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBound()
|
||||||
|
{
|
||||||
|
return bound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset()
|
||||||
|
{
|
||||||
|
bound = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void exitApp()
|
||||||
|
{
|
||||||
|
mAction.finish();
|
||||||
|
}
|
||||||
|
}
|
@ -25,8 +25,6 @@ package com.phonegap;
|
|||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.hardware.SensorManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@ -35,24 +33,23 @@ import android.webkit.WebView;
|
|||||||
import android.media.Ringtone;
|
import android.media.Ringtone;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
|
|
||||||
public class PhoneGap{
|
public class Device{
|
||||||
|
|
||||||
private static final String LOG_TAG = "PhoneGap";
|
private static final String LOG_TAG = "PhoneGap";
|
||||||
/*
|
/*
|
||||||
* UUID, version and availability
|
* UUID, version and availability
|
||||||
*/
|
*/
|
||||||
public boolean droid = true;
|
public boolean droid = true;
|
||||||
public static String version = "0.9.99999";
|
public static String version = "0.91";
|
||||||
public static String platform = "Android";
|
public static String platform = "Android";
|
||||||
public static String uuid;
|
public static String uuid;
|
||||||
private Context mCtx;
|
private Context mCtx;
|
||||||
private WebView mAppView;
|
private WebView mAppView;
|
||||||
AudioHandler audio;
|
AudioPlayer audio;
|
||||||
|
|
||||||
public PhoneGap(WebView appView, Context ctx) {
|
public Device(WebView appView, Context ctx) {
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mAppView = appView;
|
this.mAppView = appView;
|
||||||
audio = new AudioHandler("/sdcard/tmprecording.mp3", ctx);
|
|
||||||
uuid = getUuid();
|
uuid = getUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,22 +84,25 @@ public class PhoneGap{
|
|||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLine1Number(){
|
public String getLine1Number(){
|
||||||
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
return operator.getLine1Number();
|
return operator.getLine1Number();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeviceId(){
|
public String getDeviceId(){
|
||||||
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
return operator.getDeviceId();
|
return operator.getDeviceId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSimSerialNumber(){
|
public String getSimSerialNumber(){
|
||||||
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
return operator.getSimSerialNumber();
|
return operator.getSimSerialNumber();
|
||||||
}
|
}
|
||||||
public String getSubscriberId(){
|
|
||||||
|
public String getSubscriberId(){
|
||||||
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
return operator.getSubscriberId();
|
return operator.getSubscriberId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getModel()
|
public String getModel()
|
||||||
{
|
{
|
||||||
@ -129,66 +129,6 @@ public class PhoneGap{
|
|||||||
{
|
{
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void httpGet(String url, String file)
|
|
||||||
/**
|
|
||||||
* grabs a file from specified url and saves it to a name and location
|
|
||||||
* the base directory /sdcard is abstracted so that paths may be the same from one mobile OS to another
|
|
||||||
* TODO: JavaScript call backs and error handling
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
HttpHandler http = new HttpHandler();
|
|
||||||
http.get(url, file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AUDIO
|
|
||||||
* TODO: Basic functions done but needs more work on error handling and call backs, remove record hack
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void startRecordingAudio(String file)
|
|
||||||
{
|
|
||||||
/* for this to work the recording needs to be specified in the constructor,
|
|
||||||
* a hack to get around this, I'm moving the recording after it's complete
|
|
||||||
*/
|
|
||||||
audio.startRecording(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopRecordingAudio()
|
|
||||||
{
|
|
||||||
audio.stopRecording();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startPlayingAudio(String file)
|
|
||||||
{
|
|
||||||
audio.startPlaying(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stopPlayingAudio()
|
|
||||||
{
|
|
||||||
audio.stopPlaying();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getCurrentPositionAudio()
|
|
||||||
{
|
|
||||||
System.out.println(audio.getCurrentPosition());
|
|
||||||
return(audio.getCurrentPosition());
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getDurationAudio(String file)
|
|
||||||
{
|
|
||||||
System.out.println(audio.getDuration(file));
|
|
||||||
return(audio.getDuration(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAudioOutputDevice(int output){
|
|
||||||
audio.setAudioOutputDevice(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAudioOutputDevice(){
|
|
||||||
return audio.getAudioOutputDevice();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTimeZoneID() {
|
public String getTimeZoneID() {
|
||||||
TimeZone tz = TimeZone.getDefault();
|
TimeZone tz = TimeZone.getDefault();
|
@ -59,7 +59,7 @@ public class DroidGap extends Activity {
|
|||||||
protected WebView appView;
|
protected WebView appView;
|
||||||
private LinearLayout root;
|
private LinearLayout root;
|
||||||
|
|
||||||
private PhoneGap gap;
|
private Device gap;
|
||||||
private GeoBroker geo;
|
private GeoBroker geo;
|
||||||
private AccelBroker accel;
|
private AccelBroker accel;
|
||||||
private CameraLauncher launcher;
|
private CameraLauncher launcher;
|
||||||
@ -70,6 +70,7 @@ public class DroidGap extends Activity {
|
|||||||
private Storage cupcakeStorage;
|
private Storage cupcakeStorage;
|
||||||
private CryptoHandler crypto;
|
private CryptoHandler crypto;
|
||||||
private BrowserKey mKey;
|
private BrowserKey mKey;
|
||||||
|
private AudioHandler audio;
|
||||||
|
|
||||||
private Uri imageUri;
|
private Uri imageUri;
|
||||||
|
|
||||||
@ -142,7 +143,7 @@ public class DroidGap extends Activity {
|
|||||||
|
|
||||||
private void bindBrowser(WebView appView)
|
private void bindBrowser(WebView appView)
|
||||||
{
|
{
|
||||||
gap = new PhoneGap(appView, this);
|
gap = new Device(appView, this);
|
||||||
geo = new GeoBroker(appView, this);
|
geo = new GeoBroker(appView, this);
|
||||||
accel = new AccelBroker(appView, this);
|
accel = new AccelBroker(appView, this);
|
||||||
launcher = new CameraLauncher(appView, this);
|
launcher = new CameraLauncher(appView, this);
|
||||||
@ -152,6 +153,7 @@ public class DroidGap extends Activity {
|
|||||||
mCompass = new CompassListener(appView, this);
|
mCompass = new CompassListener(appView, this);
|
||||||
crypto = new CryptoHandler(appView);
|
crypto = new CryptoHandler(appView);
|
||||||
mKey = new BrowserKey(appView, this);
|
mKey = new BrowserKey(appView, this);
|
||||||
|
audio = new AudioHandler(appView, this);
|
||||||
|
|
||||||
// This creates the new javascript interfaces for PhoneGap
|
// This creates the new javascript interfaces for PhoneGap
|
||||||
appView.addJavascriptInterface(gap, "DroidGap");
|
appView.addJavascriptInterface(gap, "DroidGap");
|
||||||
@ -164,6 +166,7 @@ public class DroidGap extends Activity {
|
|||||||
appView.addJavascriptInterface(mCompass, "CompassHook");
|
appView.addJavascriptInterface(mCompass, "CompassHook");
|
||||||
appView.addJavascriptInterface(crypto, "GapCrypto");
|
appView.addJavascriptInterface(crypto, "GapCrypto");
|
||||||
appView.addJavascriptInterface(mKey, "BackButton");
|
appView.addJavascriptInterface(mKey, "BackButton");
|
||||||
|
appView.addJavascriptInterface(audio, "GapAudio");
|
||||||
|
|
||||||
|
|
||||||
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
if (android.os.Build.VERSION.RELEASE.startsWith("1."))
|
||||||
|
Loading…
Reference in New Issue
Block a user