Some adjustments to Speech call

This commit is contained in:
Ziver Koc 2014-08-11 14:30:00 +02:00
parent 97798ababa
commit 10a77ecc96

View file

@ -39,42 +39,48 @@ public class UeBehaviourSpeechCall extends UeBehaviour{
@Override @Override
protected void execute() throws InterruptedException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { protected void execute() throws Exception {
Context context = MainActivity.getContext(); Context context = MainActivity.getContext();
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
// Start Call // Start Call
log.debug("Starting Call"); log.debug("Starting Call");
CallUtil.startCall(phoneNumber); CallUtil.startCall(phoneNumber);
Thread.sleep(1000); Thread.sleep(SLEEP_PERIOD);
// Wait for call to start // Wait for call to start
log.debug("Waiting for an answer"); log.debug("Waiting call to start");
while(tm.getCallState() == TelephonyManager.CALL_STATE_RINGING){ while(tm.getCallState() == TelephonyManager.CALL_STATE_RINGING){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress(0.1f); super.setProgress(0.2f);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
} }
// Start timer
log.debug("Starting call timer"); log.debug("Starting call timer");
int elapsedTime = 0; int elapsedTime = 0;
int lengthMillisec = length*1000; int lengthMillisec = length*1000;
while(elapsedTime < lengthMillisec){ while(elapsedTime < lengthMillisec){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress((float)elapsedTime/lengthMillisec); if(tm.getCallState() == TelephonyManager.CALL_STATE_IDLE) {
log.debug("Call ended prematurely");
return;
}
super.setProgress((float) elapsedTime / lengthMillisec);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
elapsedTime += SLEEP_PERIOD; elapsedTime += SLEEP_PERIOD;
} }
CallUtil.endCall();
log.debug("Waiting for call to end"); // End Call
// Wait for call to end log.debug("Ending call");
CallUtil.endCall();
log.debug("Waiting call to end");
while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){ while(tm.getCallState() != TelephonyManager.CALL_STATE_IDLE){
if(super.stopExecution()) if(super.stopExecution())
return; return;
super.setProgress(0.9f); super.setProgress(0.95f);
Thread.sleep(SLEEP_PERIOD); Thread.sleep(SLEEP_PERIOD);
} }
} }