blob: 8bfd0b954d39a0575a68650db76890f2dd24797d [file] [log] [blame]
Alexandre Lisionc9c30b72013-11-18 16:27:26 -05001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Lisionc9c30b72013-11-18 16:27:26 -05003 *
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 Lisiona3650992013-11-13 14:19:35 -050032package org.sflphone.fragments;
33
Alexandre Lisiona3650992013-11-13 14:19:35 -050034import org.sflphone.R;
Alexandre Lision3cefec22013-11-14 17:26:35 -050035import org.sflphone.account.CredentialsManager;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050036import org.sflphone.account.SRTPManager;
37import org.sflphone.account.TLSManager;
Alexandre Lisiona3650992013-11-13 14:19:35 -050038import org.sflphone.model.Account;
39
40import android.app.Activity;
41import android.os.Bundle;
Alexandre Lisiona3650992013-11-13 14:19:35 -050042import android.preference.PreferenceFragment;
Alexandre Lision3b7148e2013-11-13 17:23:06 -050043import android.view.LayoutInflater;
Alexandre Lision3cefec22013-11-14 17:26:35 -050044import android.view.Menu;
45import android.view.MenuInflater;
Alexandre Lision3b7148e2013-11-13 17:23:06 -050046import android.view.View;
47import android.view.ViewGroup;
Alexandre Lisiona3650992013-11-13 14:19:35 -050048
49public class NestedSettingsFragment extends PreferenceFragment {
50
Alexandre Lisionf30ff852013-12-09 17:08:40 -050051 @SuppressWarnings("unused")
Alexandre Lisiona3650992013-11-13 14:19:35 -050052 private static final String TAG = AdvancedAccountFragment.class.getSimpleName();
53
Alexandre Lisiona3650992013-11-13 14:19:35 -050054 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision3cefec22013-11-14 17:26:35 -050055
56 CredentialsManager mCredsManager;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050057 SRTPManager mSrtpManager;
58
59 TLSManager mTlsManager;
Alexandre Lision3cefec22013-11-14 17:26:35 -050060
Alexandre Lisiona3650992013-11-13 14:19:35 -050061 private static Callbacks sDummyCallbacks = new Callbacks() {
62
63 @Override
64 public Account getAccount() {
65 return null;
66 }
67
68 };
69
70 public interface Callbacks {
71
72 public Account getAccount();
73
74 }
75
76 @Override
77 public void onAttach(Activity activity) {
78 super.onAttach(activity);
79 if (!(activity instanceof Callbacks)) {
80 throw new IllegalStateException("Activity must implement fragment's callbacks.");
81 }
Alexandre Lisiona3650992013-11-13 14:19:35 -050082 mCallbacks = (Callbacks) activity;
83 }
84
85 @Override
86 public void onDetach() {
87 super.onDetach();
88 mCallbacks = sDummyCallbacks;
89 }
90
91 @Override
92 public void onCreate(Bundle savedInstanceState) {
93 super.onCreate(savedInstanceState);
94
Alexandre Lision3cefec22013-11-14 17:26:35 -050095 setHasOptionsMenu(true);
96
Alexandre Lisiona3650992013-11-13 14:19:35 -050097 // Load the preferences from an XML resource
Alexandre Lision3b7148e2013-11-13 17:23:06 -050098 switch (getArguments().getInt("MODE")) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050099 case 0: // Credentials
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500100 addPreferencesFromResource(R.xml.account_credentials);
Alexandre Lision3cefec22013-11-14 17:26:35 -0500101 mCredsManager = new CredentialsManager();
102 mCredsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
103 mCredsManager.reloadCredentials();
104 mCredsManager.setAddCredentialListener();
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500105 break;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500106 case 1: // SRTP
107 mSrtpManager = new SRTPManager();
108 if (mCallbacks.getAccount().hasSDESEnabled()) { // SDES
109 addPreferencesFromResource(R.xml.account_sdes);
110 mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount());
111 mSrtpManager.setSDESListener();
112 } else { // ZRTP
113 addPreferencesFromResource(R.xml.account_zrtp);
114 mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount());
115 mSrtpManager.setZRTPListener();
116 }
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500117 break;
118 case 2:
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500119 addPreferencesFromResource(R.xml.account_tls);
120 mTlsManager = new TLSManager();
121 mTlsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
122 mTlsManager.setTLSListener();
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500123 break;
124 }
125
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500126 }
127
Alexandre Lision3cefec22013-11-14 17:26:35 -0500128 @Override
129 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
130 super.onCreateOptionsMenu(menu, inflater);
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500131 }
132
133 @Override
134 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
135 View view = super.onCreateView(inflater, container, savedInstanceState);
136 view.setBackgroundColor(getResources().getColor(android.R.color.white));
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500137 return view;
Alexandre Lisiona3650992013-11-13 14:19:35 -0500138 }
139
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500140
141
Alexandre Lisiona3650992013-11-13 14:19:35 -0500142}