Java Code Examples for android.telephony.PhoneStateListener#onCallStateChanged()

The following examples show how to use android.telephony.PhoneStateListener#onCallStateChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 6 votes vote down vote up
public void testRun_ringWhileSpeaking() throws Exception {
  startTask(TextToSpeech.SUCCESS);

  expect(tts.isSpeaking()).andStubReturn(true);
  expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);

  AndroidMock.replay(tts);

  // Update the state to ringing - this should stop the current announcement.
  PhoneStateListener phoneListener = phoneListenerCapture.getValue();
  phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);

  // Run the announcement - this should do nothing.
  task.run(null);

  AndroidMock.verify(mockTask, tts);
}
 
Example 2
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public void testRun_duringCall() throws Exception {
  startTask(TextToSpeech.SUCCESS);

  expect(tts.isSpeaking()).andStubReturn(false);

  // Run the announcement
  AndroidMock.replay(tts);
  PhoneStateListener phoneListener = phoneListenerCapture.getValue();
  phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, null);
  task.run(null);
  AndroidMock.verify(mockTask, tts);
}
 
Example 3
Source File: AnnouncementPeriodicTaskTest.java    From mytracks with Apache License 2.0 5 votes vote down vote up
public void testRun_whileRinging() throws Exception {
  startTask(TextToSpeech.SUCCESS);

  expect(tts.isSpeaking()).andStubReturn(false);

  // Run the announcement
  AndroidMock.replay(tts);
  PhoneStateListener phoneListener = phoneListenerCapture.getValue();
  phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
  task.run(null);
  AndroidMock.verify(mockTask, tts);
}