Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 1 | package org.sflphone.utils; |
| 2 | |
| 3 | import org.sflphone.service.SipService; |
| 4 | |
| 5 | import android.content.Context; |
| 6 | import android.database.ContentObserver; |
| 7 | import android.media.AudioManager; |
| 8 | import android.os.Handler; |
| 9 | import android.util.Log; |
| 10 | |
| 11 | public class SettingsContentObserver extends ContentObserver { |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 12 | double previousVolume; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 13 | SipService context; |
| 14 | private static final String TAG = "Settings"; |
| 15 | |
| 16 | public SettingsContentObserver(SipService c, Handler handler) { |
| 17 | super(handler); |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 18 | context=c; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 19 | AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 20 | previousVolume = audio.getStreamVolume(AudioManager.STREAM_VOICE_CALL); |
| 21 | } |
| 22 | |
| 23 | @Override |
| 24 | public boolean deliverSelfNotifications() { |
| 25 | return super.deliverSelfNotifications(); |
| 26 | } |
| 27 | |
| 28 | @Override |
| 29 | public void onChange(boolean selfChange) { |
| 30 | super.onChange(selfChange); |
| 31 | |
| 32 | AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 33 | double currentVolume = audio.getStreamVolume(AudioManager.STREAM_VOICE_CALL); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 34 | |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 35 | double delta=previousVolume-currentVolume; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 36 | |
| 37 | if(delta>0) |
| 38 | { |
| 39 | Log.d(TAG,"Decreased"); |
| 40 | previousVolume=currentVolume; |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 41 | // context.changeVolume(currentVolume); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 42 | } |
| 43 | else if(delta<0) |
| 44 | { |
| 45 | Log.d(TAG,"Increased"); |
| 46 | previousVolume=currentVolume; |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 47 | // context.changeVolume(currentVolume); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | } |