forked from github/cordova-android
Merge branch 'master' of git://github.com/addios/phonegap
Conflicts: android/src/com/nitobi/phonegap/AudioHandler.java android/src/com/nitobi/phonegap/PhoneGap.java
This commit is contained in:
commit
a463aa2400
@ -14,6 +14,7 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
<uses-permission android:name="android.permission.RECEIVE_SMS" />
|
||||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||||
|
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||||
android:debuggable="true">
|
android:debuggable="true">
|
||||||
|
@ -351,6 +351,12 @@ var Device = {
|
|||||||
},
|
},
|
||||||
getDuration: function(file) {
|
getDuration: function(file) {
|
||||||
return window.DroidGap.getDurationAudio(file);
|
return window.DroidGap.getDurationAudio(file);
|
||||||
|
},
|
||||||
|
setAudioOutputDevice: function(output){
|
||||||
|
window.DroidGap.setAudioOutputDevice(output);
|
||||||
|
},
|
||||||
|
getAudioOutputDevice: function (){
|
||||||
|
return window.DroidGap.getAudioOutputDevice();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
information: {
|
information: {
|
||||||
|
@ -146,7 +146,17 @@ audio = function(func)
|
|||||||
} else
|
} else
|
||||||
if (func == 'getDuration') {
|
if (func == 'getDuration') {
|
||||||
$('posdur').value = Device.audio.getDuration($('audioFile').value);
|
$('posdur').value = Device.audio.getDuration($('audioFile').value);
|
||||||
|
}else
|
||||||
|
if (func == 'setEarpiece') {
|
||||||
|
Device.audio.setAudioOutputDevice(func);
|
||||||
|
} else
|
||||||
|
if (func == 'setSpeaker') {
|
||||||
|
Device.audio.setAudioOutputDevice(func);
|
||||||
|
}else
|
||||||
|
if (func == 'getAudioOutputDevice') {
|
||||||
|
$('audoutput').value = Device.audio.getAudioOutputDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
phInformation = function(){
|
phInformation = function(){
|
||||||
@ -392,6 +402,18 @@ addLoadEvent(initGap);
|
|||||||
<a class="button blueButton" type="submit" onclick="audio('getCurrentPosition');">getPosition</a>
|
<a class="button blueButton" type="submit" onclick="audio('getCurrentPosition');">getPosition</a>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<div class="row">
|
||||||
|
<a class="button leftButton" type="submit" onclick="audio('setEarpiece');">Earpiece</a>
|
||||||
|
<a class="button blueButton" type="submit" onclick="audio('setSpeaker');">Speaker</a>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset>
|
||||||
|
<div class="row">
|
||||||
|
<a class="button leftButton" type="submit" onclick="audio('getAudioOutputDevice');">Audio Output</a>
|
||||||
|
<input disabled="enabled" id="audoutput" type="text" style="width: 30ex"/>
|
||||||
|
</div>
|
||||||
|
</fieldset>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="pi" title="Phone Information" class="panel">
|
<div id="pi" title="Phone Information" class="panel">
|
||||||
|
@ -2,6 +2,7 @@ package com.nitobi.phonegap;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.media.MediaPlayer.OnErrorListener;
|
import android.media.MediaPlayer.OnErrorListener;
|
||||||
@ -18,9 +19,11 @@ public class AudioHandler implements OnCompletionListener, OnPreparedListener, O
|
|||||||
private boolean isPlaying = false;
|
private boolean isPlaying = false;
|
||||||
private String recording;
|
private String recording;
|
||||||
private String saveFile;
|
private String saveFile;
|
||||||
|
private Context mCtx;
|
||||||
|
|
||||||
public AudioHandler(String file) {
|
public AudioHandler(String file, Context ctx) {
|
||||||
this.recording = file;
|
this.recording = file;
|
||||||
|
this.mCtx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRecording(String file){
|
public void startRecording(String file){
|
||||||
@ -87,7 +90,6 @@ public class AudioHandler implements OnCompletionListener, OnPreparedListener, O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCompletion(MediaPlayer mPlayer) {
|
public void onCompletion(MediaPlayer mPlayer) {
|
||||||
mPlayer.stop();
|
mPlayer.stop();
|
||||||
mPlayer.release();
|
mPlayer.release();
|
||||||
@ -154,4 +156,25 @@ public class AudioHandler implements OnCompletionListener, OnPreparedListener, O
|
|||||||
Log.e("AUDIO onError", "error " + arg1 + " " + arg2);
|
Log.e("AUDIO onError", "error " + arg1 + " " + arg2);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setAudioOutputDevice(String output){
|
||||||
|
System.out.println ("Change audio setting to be "+output);
|
||||||
|
AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
if (output.contains("Speaker"))
|
||||||
|
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
|
||||||
|
else if (output.contains("Earpiece")){
|
||||||
|
audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
|
||||||
|
}else
|
||||||
|
System.out.println("input error");
|
||||||
|
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ public class PhoneGap{
|
|||||||
protected LocationProvider provider;
|
protected LocationProvider provider;
|
||||||
SmsListener mSmsListener;
|
SmsListener mSmsListener;
|
||||||
DirectoryManager fileManager;
|
DirectoryManager fileManager;
|
||||||
|
AudioHandler audio;
|
||||||
|
|
||||||
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
@ -60,6 +61,7 @@ public class PhoneGap{
|
|||||||
mNetwork = new NetworkListener(ctx);
|
mNetwork = new NetworkListener(ctx);
|
||||||
mSmsListener = new SmsListener(ctx,mAppView);
|
mSmsListener = new SmsListener(ctx,mAppView);
|
||||||
fileManager = new DirectoryManager();
|
fileManager = new DirectoryManager();
|
||||||
|
audio = new AudioHandler("/sdcard/tmprecording.mp3", ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAccel(){
|
public void updateAccel(){
|
||||||
@ -248,48 +250,96 @@ public class PhoneGap{
|
|||||||
http.get(url, file);
|
http.get(url, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
/*
|
/*
|
||||||
* TODO: FIX! These should not be returning arbitrary Strings!
|
* TODO: FIX! These should not be returning arbitrary Strings!
|
||||||
*/
|
*/
|
||||||
public String testSaveLocationExists(){
|
public String testSaveLocationExists(){
|
||||||
|
=======
|
||||||
|
/**
|
||||||
|
* Check if SD card is ready and already mounted
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int testSaveLocationExists(){
|
||||||
|
>>>>>>> 6959002f1187829f33e279633e0446cc750ab6d3:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
if (fileManager.testSaveLocationExists())
|
if (fileManager.testSaveLocationExists())
|
||||||
return "SD Card available";
|
return 0;
|
||||||
else
|
else
|
||||||
return "SD Card unavailable";
|
return 1;
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
public String testFileExists(String file){
|
public String testFileExists(String file){
|
||||||
if (fileManager.testFileExists(file))
|
if (fileManager.testFileExists(file))
|
||||||
return "File exists";
|
return "File exists";
|
||||||
|
=======
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a specific directory of file exists
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int testDirOrFileExists(String file){
|
||||||
|
if (fileManager.isDirtoryOrFileExists(file))
|
||||||
|
return 0;
|
||||||
|
>>>>>>> 6959002f1187829f33e279633e0446cc750ab6d3:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
else
|
else
|
||||||
return "No this file";
|
return 1;
|
||||||
}
|
}
|
||||||
|
<<<<<<< HEAD:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
|
|
||||||
public String deleteDirectory (String dir){
|
public String deleteDirectory (String dir){
|
||||||
if (fileManager.deleteDirectory(dir))
|
if (fileManager.deleteDirectory(dir))
|
||||||
return "Completed";
|
return "Completed";
|
||||||
|
=======
|
||||||
|
/**
|
||||||
|
* 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.deleteDir(dir))
|
||||||
|
return 0;
|
||||||
|
>>>>>>> 6959002f1187829f33e279633e0446cc750ab6d3:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
else
|
else
|
||||||
return "Not completed";
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
public String deleteFile (String file){
|
public String deleteFile (String file){
|
||||||
|
=======
|
||||||
|
/**
|
||||||
|
* Delete a specific file.
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int deleteFile (String file){
|
||||||
|
>>>>>>> 6959002f1187829f33e279633e0446cc750ab6d3:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
if (fileManager.deleteFile(file))
|
if (fileManager.deleteFile(file))
|
||||||
return "Completed";
|
return 0;
|
||||||
else
|
else
|
||||||
return "Not completed";
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<<<<<<< HEAD:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
public String createDirectory(String dir){
|
public String createDirectory(String dir){
|
||||||
if (fileManager.createDirectory(dir))
|
if (fileManager.createDirectory(dir))
|
||||||
return "Completed";
|
return "Completed";
|
||||||
|
=======
|
||||||
|
/**
|
||||||
|
* Create a new directory.
|
||||||
|
* TODO: JavaScript Call backs for success and error handling
|
||||||
|
*/
|
||||||
|
public int createDirectory(String dir){
|
||||||
|
if (fileManager.createDirectory(dir))
|
||||||
|
return 0;
|
||||||
|
>>>>>>> 6959002f1187829f33e279633e0446cc750ab6d3:android/src/com/nitobi/phonegap/PhoneGap.java
|
||||||
else
|
else
|
||||||
return "Not completed";
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
AudioHandler audio = new AudioHandler("/sdcard/tmprecording.mp3");
|
|
||||||
public void startRecordingAudio(String file)
|
public void startRecordingAudio(String file)
|
||||||
{
|
{
|
||||||
/* for this to work the recording needs to be specified in the constructor,
|
/* for this to work the recording needs to be specified in the constructor,
|
||||||
@ -325,6 +375,13 @@ public class PhoneGap{
|
|||||||
return(audio.getDuration(file));
|
return(audio.getDuration(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAudioOutputDevice(String output){
|
||||||
|
audio.setAudioOutputDevice(output);
|
||||||
|
}
|
||||||
|
public int getAudioOutputDevice(){
|
||||||
|
return audio.getAudioOutputDevice();
|
||||||
|
}
|
||||||
|
|
||||||
public String getLine1Number() {
|
public String getLine1Number() {
|
||||||
TelephonyManager tm =
|
TelephonyManager tm =
|
||||||
(TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
(TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user