blob: de3077d3a7c09e2e33fee186854fbb2dd4931cff [file] [log] [blame]
Alexandre Lision6d867b92013-10-25 15:36:28 -04001package org.sflphone.utils;
2
3import org.sflphone.service.SipService;
4
5import android.content.Context;
6import android.database.ContentObserver;
7import android.media.AudioManager;
8import android.os.Handler;
9import android.util.Log;
10
11public class SettingsContentObserver extends ContentObserver {
Alexandre Lision63870a72013-10-28 16:33:47 -040012 double previousVolume;
Alexandre Lision6d867b92013-10-25 15:36:28 -040013 SipService context;
14 private static final String TAG = "Settings";
15
16 public SettingsContentObserver(SipService c, Handler handler) {
17 super(handler);
Alexandre Lision63870a72013-10-28 16:33:47 -040018 context=c;
Alexandre Lision6d867b92013-10-25 15:36:28 -040019 AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
Alexandre Lision6d867b92013-10-25 15:36:28 -040020 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 Lision63870a72013-10-28 16:33:47 -040033 double currentVolume = audio.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
Alexandre Lision6d867b92013-10-25 15:36:28 -040034
Alexandre Lision63870a72013-10-28 16:33:47 -040035 double delta=previousVolume-currentVolume;
Alexandre Lision6d867b92013-10-25 15:36:28 -040036
37 if(delta>0)
38 {
39 Log.d(TAG,"Decreased");
40 previousVolume=currentVolume;
Alexandre Lision63870a72013-10-28 16:33:47 -040041// context.changeVolume(currentVolume);
Alexandre Lision6d867b92013-10-25 15:36:28 -040042 }
43 else if(delta<0)
44 {
45 Log.d(TAG,"Increased");
46 previousVolume=currentVolume;
Alexandre Lision63870a72013-10-28 16:33:47 -040047// context.changeVolume(currentVolume);
Alexandre Lision6d867b92013-10-25 15:36:28 -040048 }
49 }
50}