Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 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 Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 32 | package org.sflphone.utils; |
| 33 | |
| 34 | import org.sflphone.service.SipService; |
| 35 | |
| 36 | import android.content.Context; |
| 37 | import android.database.ContentObserver; |
| 38 | import android.media.AudioManager; |
| 39 | import android.os.Handler; |
| 40 | import android.util.Log; |
| 41 | |
| 42 | public class SettingsContentObserver extends ContentObserver { |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 43 | double previousVolume; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 44 | SipService context; |
| 45 | private static final String TAG = "Settings"; |
| 46 | |
| 47 | public SettingsContentObserver(SipService c, Handler handler) { |
| 48 | super(handler); |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 49 | context=c; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 50 | AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 51 | 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 Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 64 | double currentVolume = audio.getStreamVolume(AudioManager.STREAM_VOICE_CALL); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 65 | |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 66 | double delta=previousVolume-currentVolume; |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 67 | |
| 68 | if(delta>0) |
| 69 | { |
| 70 | Log.d(TAG,"Decreased"); |
| 71 | previousVolume=currentVolume; |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 72 | // context.changeVolume(currentVolume); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 73 | } |
| 74 | else if(delta<0) |
| 75 | { |
| 76 | Log.d(TAG,"Increased"); |
| 77 | previousVolume=currentVolume; |
Alexandre Lision | 63870a7 | 2013-10-28 16:33:47 -0400 | [diff] [blame] | 78 | // context.changeVolume(currentVolume); |
Alexandre Lision | 6d867b9 | 2013-10-25 15:36:28 -0400 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | } |