blob: 1414d0d98c47ba6e872fffc3e2a544e51f022952 [file] [log] [blame]
Adrien BĂ©raud04d822c2015-04-02 17:44:36 -04001/*
2 * Copyright (C) 2004-2014 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
32package cx.ring.model.account;
33
34import android.preference.CheckBoxPreference;
35import android.preference.Preference;
36import android.preference.Preference.OnPreferenceChangeListener;
37import android.preference.PreferenceScreen;
38import android.util.Log;
39
40public class SRTPManager {
41 PreferenceScreen mScreen;
42 private Account mAccount;
43
44 public void onCreate(PreferenceScreen preferenceScreen, Account acc) {
45 mScreen = preferenceScreen;
46 mAccount = acc;
47
48 setDetails();
49 }
50
51 private void setDetails() {
52 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
53 ((CheckBoxPreference) mScreen.getPreference(i)).setChecked(mAccount.getSrtpDetails().getDetailBoolean(mScreen.getPreference(i).getKey()));
54 }
55 }
56
57 public void setSDESListener() {
58 mScreen.findPreference("SRTP.rtpFallback").setOnPreferenceChangeListener(toggleFallbackListener);
59 }
60
61 private OnPreferenceChangeListener toggleFallbackListener = new OnPreferenceChangeListener() {
62
63 @Override
64 public boolean onPreferenceChange(Preference preference, Object newValue) {
65 mAccount.getSrtpDetails().setDetailString(AccountDetailSrtp.CONFIG_SRTP_RTP_FALLBACK, Boolean.toString((Boolean) newValue));
66 mAccount.notifyObservers();
67 return true;
68 }
69 };
70
71 public void setZRTPListener() {
72 for (int i = 0; i < mScreen.getPreferenceCount(); ++i) {
73 mScreen.getPreference(i).setOnPreferenceChangeListener(zrtpListener);
74 }
75 }
76
77 private OnPreferenceChangeListener zrtpListener = new OnPreferenceChangeListener() {
78
79 @Override
80 public boolean onPreferenceChange(Preference preference, Object newValue) {
81 Log.i("SRTP", "Setting " + preference.getKey() + " to" + (Boolean) newValue);
82 mAccount.getSrtpDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue));
83 mAccount.notifyObservers();
84 return true;
85 }
86 };
87
88}