blob: 2ae83648a8f0c2eb0c64fe854a1a74dc356ea1b6 [file] [log] [blame]
Alexandre Lisionc9c30b72013-11-18 16:27:26 -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 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
51 private static final String TAG = AdvancedAccountFragment.class.getSimpleName();
52
Alexandre Lisiona3650992013-11-13 14:19:35 -050053 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision3cefec22013-11-14 17:26:35 -050054
55 CredentialsManager mCredsManager;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050056 SRTPManager mSrtpManager;
57
58 TLSManager mTlsManager;
Alexandre Lision3cefec22013-11-14 17:26:35 -050059
Alexandre Lisiona3650992013-11-13 14:19:35 -050060 private static Callbacks sDummyCallbacks = new Callbacks() {
61
62 @Override
63 public Account getAccount() {
64 return null;
65 }
66
67 };
68
69 public interface Callbacks {
70
71 public Account getAccount();
72
73 }
74
75 @Override
76 public void onAttach(Activity activity) {
77 super.onAttach(activity);
78 if (!(activity instanceof Callbacks)) {
79 throw new IllegalStateException("Activity must implement fragment's callbacks.");
80 }
Alexandre Lisiona3650992013-11-13 14:19:35 -050081 mCallbacks = (Callbacks) activity;
82 }
83
84 @Override
85 public void onDetach() {
86 super.onDetach();
87 mCallbacks = sDummyCallbacks;
88 }
89
90 @Override
91 public void onCreate(Bundle savedInstanceState) {
92 super.onCreate(savedInstanceState);
93
Alexandre Lision3cefec22013-11-14 17:26:35 -050094 setHasOptionsMenu(true);
95
Alexandre Lisiona3650992013-11-13 14:19:35 -050096 // Load the preferences from an XML resource
Alexandre Lision3b7148e2013-11-13 17:23:06 -050097 switch (getArguments().getInt("MODE")) {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050098 case 0: // Credentials
Alexandre Lision3b7148e2013-11-13 17:23:06 -050099 addPreferencesFromResource(R.xml.account_credentials);
Alexandre Lision3cefec22013-11-14 17:26:35 -0500100 mCredsManager = new CredentialsManager();
101 mCredsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
102 mCredsManager.reloadCredentials();
103 mCredsManager.setAddCredentialListener();
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500104 break;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500105 case 1: // SRTP
106 mSrtpManager = new SRTPManager();
107 if (mCallbacks.getAccount().hasSDESEnabled()) { // SDES
108 addPreferencesFromResource(R.xml.account_sdes);
109 mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount());
110 mSrtpManager.setSDESListener();
111 } else { // ZRTP
112 addPreferencesFromResource(R.xml.account_zrtp);
113 mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount());
114 mSrtpManager.setZRTPListener();
115 }
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500116 break;
117 case 2:
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500118 addPreferencesFromResource(R.xml.account_tls);
119 mTlsManager = new TLSManager();
120 mTlsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount());
121 mTlsManager.setTLSListener();
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500122 break;
123 }
124
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500125 }
126
Alexandre Lision3cefec22013-11-14 17:26:35 -0500127 @Override
128 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
129 super.onCreateOptionsMenu(menu, inflater);
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500130 }
131
132 @Override
133 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
134 View view = super.onCreateView(inflater, container, savedInstanceState);
135 view.setBackgroundColor(getResources().getColor(android.R.color.white));
Alexandre Lision3b7148e2013-11-13 17:23:06 -0500136 return view;
Alexandre Lisiona3650992013-11-13 14:19:35 -0500137 }
138
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500139
140
Alexandre Lisiona3650992013-11-13 14:19:35 -0500141}