Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -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 | c9c30b7 | 2013-11-18 16:27:26 -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 | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 32 | package org.sflphone.fragments; |
| 33 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 34 | import org.sflphone.R; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 35 | import org.sflphone.account.CredentialsManager; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 36 | import org.sflphone.account.SRTPManager; |
| 37 | import org.sflphone.account.TLSManager; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 38 | import org.sflphone.model.Account; |
| 39 | |
| 40 | import android.app.Activity; |
| 41 | import android.os.Bundle; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 42 | import android.preference.PreferenceFragment; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 43 | import android.view.LayoutInflater; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 44 | import android.view.Menu; |
| 45 | import android.view.MenuInflater; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 46 | import android.view.View; |
| 47 | import android.view.ViewGroup; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 48 | |
| 49 | public class NestedSettingsFragment extends PreferenceFragment { |
| 50 | |
Alexandre Lision | f30ff85 | 2013-12-09 17:08:40 -0500 | [diff] [blame] | 51 | @SuppressWarnings("unused") |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 52 | private static final String TAG = AdvancedAccountFragment.class.getSimpleName(); |
| 53 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 54 | private Callbacks mCallbacks = sDummyCallbacks; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 55 | |
| 56 | CredentialsManager mCredsManager; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 57 | SRTPManager mSrtpManager; |
| 58 | |
| 59 | TLSManager mTlsManager; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 60 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 61 | 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 Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 82 | 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 Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 95 | setHasOptionsMenu(true); |
| 96 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 97 | // Load the preferences from an XML resource |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 98 | switch (getArguments().getInt("MODE")) { |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 99 | case 0: // Credentials |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 100 | addPreferencesFromResource(R.xml.account_credentials); |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 101 | mCredsManager = new CredentialsManager(); |
| 102 | mCredsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount()); |
| 103 | mCredsManager.reloadCredentials(); |
| 104 | mCredsManager.setAddCredentialListener(); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 105 | break; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 106 | 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 Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 117 | break; |
| 118 | case 2: |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 119 | addPreferencesFromResource(R.xml.account_tls); |
| 120 | mTlsManager = new TLSManager(); |
| 121 | mTlsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount()); |
| 122 | mTlsManager.setTLSListener(); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 128 | @Override |
| 129 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 130 | super.onCreateOptionsMenu(menu, inflater); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 131 | } |
| 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 Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 137 | return view; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 138 | } |
| 139 | |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 140 | |
| 141 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 142 | } |