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 | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 34 | import android.content.Intent; |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 35 | import android.os.RemoteException; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 36 | import org.sflphone.R; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 37 | import org.sflphone.account.CredentialsManager; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 38 | import org.sflphone.account.SRTPManager; |
| 39 | import org.sflphone.account.TLSManager; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 40 | import org.sflphone.model.Account; |
| 41 | |
| 42 | import android.app.Activity; |
| 43 | import android.os.Bundle; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 44 | import android.preference.PreferenceFragment; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 45 | import android.view.LayoutInflater; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 46 | import android.view.Menu; |
| 47 | import android.view.MenuInflater; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 48 | import android.view.View; |
| 49 | import android.view.ViewGroup; |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 50 | import org.sflphone.service.ISipService; |
| 51 | |
| 52 | import java.util.ArrayList; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 53 | |
| 54 | public class NestedSettingsFragment extends PreferenceFragment { |
| 55 | |
Alexandre Lision | f30ff85 | 2013-12-09 17:08:40 -0500 | [diff] [blame] | 56 | @SuppressWarnings("unused") |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 57 | private static final String TAG = AdvancedAccountFragment.class.getSimpleName(); |
| 58 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 59 | private Callbacks mCallbacks = sDummyCallbacks; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 60 | |
| 61 | CredentialsManager mCredsManager; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 62 | SRTPManager mSrtpManager; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 63 | TLSManager mTlsManager; |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 64 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 65 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 66 | |
| 67 | @Override |
| 68 | public Account getAccount() { |
| 69 | return null; |
| 70 | } |
| 71 | |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 72 | @Override |
| 73 | public ISipService getService() { |
| 74 | return null; |
| 75 | } |
| 76 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 77 | }; |
| 78 | |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 79 | public String[] getTlsMethods() { |
| 80 | ArrayList<String> methods = null; |
| 81 | try { |
| 82 | methods = (ArrayList<String>) mCallbacks.getService().getTlsSupportedMethods(); |
| 83 | } catch (RemoteException e) { |
| 84 | e.printStackTrace(); |
| 85 | } |
| 86 | String[] results = new String[methods.size()]; |
| 87 | methods.toArray(results); |
| 88 | return results; |
| 89 | } |
| 90 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 91 | public interface Callbacks { |
| 92 | |
| 93 | public Account getAccount(); |
| 94 | |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 95 | public ISipService getService(); |
| 96 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public void onAttach(Activity activity) { |
| 101 | super.onAttach(activity); |
| 102 | if (!(activity instanceof Callbacks)) { |
| 103 | throw new IllegalStateException("Activity must implement fragment's callbacks."); |
| 104 | } |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 105 | mCallbacks = (Callbacks) activity; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public void onDetach() { |
| 110 | super.onDetach(); |
| 111 | mCallbacks = sDummyCallbacks; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void onCreate(Bundle savedInstanceState) { |
| 116 | super.onCreate(savedInstanceState); |
| 117 | |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 118 | setHasOptionsMenu(true); |
| 119 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 120 | // Load the preferences from an XML resource |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 121 | switch (getArguments().getInt("MODE")) { |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 122 | case 0: // Credentials |
| 123 | addPreferencesFromResource(R.xml.account_credentials); |
| 124 | mCredsManager = new CredentialsManager(); |
| 125 | mCredsManager.onCreate(getActivity(), getPreferenceScreen(), mCallbacks.getAccount()); |
| 126 | mCredsManager.reloadCredentials(); |
| 127 | mCredsManager.setAddCredentialListener(); |
| 128 | break; |
| 129 | case 1: // SRTP |
| 130 | mSrtpManager = new SRTPManager(); |
| 131 | if (mCallbacks.getAccount().hasSDESEnabled()) { // SDES |
| 132 | addPreferencesFromResource(R.xml.account_sdes); |
| 133 | mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount()); |
| 134 | mSrtpManager.setSDESListener(); |
| 135 | } else { // ZRTP |
| 136 | addPreferencesFromResource(R.xml.account_zrtp); |
| 137 | mSrtpManager.onCreate(getPreferenceScreen(), mCallbacks.getAccount()); |
| 138 | mSrtpManager.setZRTPListener(); |
| 139 | } |
| 140 | break; |
| 141 | case 2: |
| 142 | addPreferencesFromResource(R.xml.account_tls); |
| 143 | mTlsManager = new TLSManager(); |
| 144 | mTlsManager.onCreate(this, getPreferenceScreen(), mCallbacks.getAccount()); |
| 145 | mTlsManager.setTLSListener(); |
| 146 | break; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 147 | } |
| 148 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 149 | } |
| 150 | |
Alexandre Lision | 3cefec2 | 2013-11-14 17:26:35 -0500 | [diff] [blame] | 151 | @Override |
| 152 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 153 | super.onCreateOptionsMenu(menu, inflater); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 158 | View view = super.onCreateView(inflater, container, savedInstanceState); |
| 159 | view.setBackgroundColor(getResources().getColor(android.R.color.white)); |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame] | 160 | return view; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 161 | } |
| 162 | |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 163 | @Override |
| 164 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 165 | super.onActivityResult(requestCode, resultCode, data); |
| 166 | |
Alexandre Lision | 509a755 | 2014-03-04 13:37:50 -0500 | [diff] [blame^] | 167 | if (mTlsManager != null) { |
Alexandre Lision | 6a13ac0 | 2014-02-04 15:58:20 -0500 | [diff] [blame] | 168 | mTlsManager.onActivityResult(requestCode, resultCode, data); |
| 169 | } |
| 170 | |
| 171 | } |
| 172 | |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 173 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 174 | } |