blob: 427cbd74c4547b2d75e9ccc800a23aa985fd7959 [file] [log] [blame]
Alexandre Lisiona8b78722013-12-13 10:18:33 -05001/*
2 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
Alexandre Lision6d867b92013-10-25 15:36:28 -040032package org.sflphone.utils;
33
34import org.sflphone.service.SipService;
35
36import android.content.Context;
37import android.database.ContentObserver;
38import android.media.AudioManager;
39import android.os.Handler;
40import android.util.Log;
41
42public class SettingsContentObserver extends ContentObserver {
Alexandre Lision63870a72013-10-28 16:33:47 -040043 double previousVolume;
Alexandre Lision6d867b92013-10-25 15:36:28 -040044 SipService context;
45 private static final String TAG = "Settings";
46
47 public SettingsContentObserver(SipService c, Handler handler) {
48 super(handler);
Alexandre Lision63870a72013-10-28 16:33:47 -040049 context=c;
Alexandre Lision6d867b92013-10-25 15:36:28 -040050 AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
Alexandre Lision6d867b92013-10-25 15:36:28 -040051 previousVolume = audio.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
52 }
53
54 @Override
55 public boolean deliverSelfNotifications() {
56 return super.deliverSelfNotifications();
57 }
58
59 @Override
60 public void onChange(boolean selfChange) {
61 super.onChange(selfChange);
62
63 AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
Alexandre Lision63870a72013-10-28 16:33:47 -040064 double currentVolume = audio.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
Alexandre Lision6d867b92013-10-25 15:36:28 -040065
Alexandre Lision63870a72013-10-28 16:33:47 -040066 double delta=previousVolume-currentVolume;
Alexandre Lision6d867b92013-10-25 15:36:28 -040067
68 if(delta>0)
69 {
70 Log.d(TAG,"Decreased");
71 previousVolume=currentVolume;
Alexandre Lision63870a72013-10-28 16:33:47 -040072// context.changeVolume(currentVolume);
Alexandre Lision6d867b92013-10-25 15:36:28 -040073 }
74 else if(delta<0)
75 {
76 Log.d(TAG,"Increased");
77 previousVolume=currentVolume;
Alexandre Lision63870a72013-10-28 16:33:47 -040078// context.changeVolume(currentVolume);
Alexandre Lision6d867b92013-10-25 15:36:28 -040079 }
80 }
81}