Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -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 | dd5d8de | 2013-11-18 16:26:14 -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 | |
| 32 | package org.sflphone.account; |
| 33 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 34 | import org.sflphone.fragments.FileExplorerDFragment; |
| 35 | import org.sflphone.fragments.FileExplorerDFragment.onFileSelectedListener; |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 36 | import org.sflphone.model.Account; |
| 37 | |
| 38 | import android.app.Activity; |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 39 | import android.preference.CheckBoxPreference; |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 40 | import android.preference.Preference; |
| 41 | import android.preference.Preference.OnPreferenceChangeListener; |
| 42 | import android.preference.Preference.OnPreferenceClickListener; |
| 43 | import android.preference.PreferenceScreen; |
| 44 | import android.util.Log; |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 45 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 46 | public class TLSManager implements onFileSelectedListener { |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 47 | PreferenceScreen mScreen; |
| 48 | private Account mAccount; |
| 49 | static Activity mContext; |
| 50 | |
| 51 | public void onCreate(Activity con, PreferenceScreen preferenceScreen, Account acc) { |
| 52 | mContext = con; |
| 53 | mScreen = preferenceScreen; |
| 54 | mAccount = acc; |
| 55 | |
| 56 | setDetails(); |
| 57 | } |
| 58 | |
| 59 | private void setDetails() { |
| 60 | for (int i = 0; i < mScreen.getPreferenceCount(); ++i) { |
| 61 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 62 | if (mScreen.getPreference(i) instanceof CheckBoxPreference) { |
| 63 | ((CheckBoxPreference) mScreen.getPreference(i)).setChecked(mAccount.getTlsDetails().getDetailBoolean( |
| 64 | mScreen.getPreference(i).getKey())); |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 65 | } else { |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 66 | mScreen.getPreference(i).setSummary(mAccount.getTlsDetails().getDetailString(mScreen.getPreference(i).getKey())); |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | // ((CheckBoxPreference) |
| 70 | // mScreen.getPreference(i)).setChecked(mAccount.getSrtpDetails().getDetailBoolean(mScreen.getPreference(i).getKey())); |
| 71 | mScreen.getPreference(i).setOnPreferenceClickListener(new OnPreferenceClickListener() { |
| 72 | |
| 73 | @Override |
| 74 | public boolean onPreferenceClick(Preference preference) { |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 75 | if (preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CA_LIST_FILE) |
| 76 | || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_PRIVATE_KEY_FILE) |
| 77 | || preference.getKey().contentEquals(AccountDetailTls.CONFIG_TLS_CERTIFICATE_FILE)) { |
| 78 | FileExplorerDFragment dialog = FileExplorerDFragment.newInstance(); |
| 79 | dialog.show(mContext.getFragmentManager(), "explorerdialog"); |
| 80 | dialog.setOnFileSelectedListener(TLSManager.this, preference.getKey()); |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 81 | } |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 82 | |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 83 | return false; |
| 84 | } |
| 85 | }); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public void setTLSListener() { |
| 90 | for (int i = 0; i < mScreen.getPreferenceCount(); ++i) { |
| 91 | mScreen.getPreference(i).setOnPreferenceChangeListener(tlsListener); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | private OnPreferenceChangeListener tlsListener = new OnPreferenceChangeListener() { |
| 96 | |
| 97 | @Override |
| 98 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 99 | Log.i("TLS", "Setting " + preference.getKey() + " to" + (Boolean) newValue); |
| 100 | mAccount.getTlsDetails().setDetailString(preference.getKey(), Boolean.toString((Boolean) newValue)); |
| 101 | mAccount.notifyObservers(); |
| 102 | return true; |
| 103 | } |
| 104 | }; |
| 105 | |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 106 | @Override |
| 107 | public void onFileSelected(String path, String prefKey) { |
| 108 | mScreen.findPreference(prefKey).setSummary(path); |
| 109 | mAccount.getTlsDetails().setDetailString(prefKey, path); |
| 110 | mAccount.notifyObservers(); |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 111 | } |
Alexandre Lision | 8ad3959 | 2013-11-21 13:23:58 -0500 | [diff] [blame] | 112 | |
Alexandre Lision | dd5d8de | 2013-11-18 16:26:14 -0500 | [diff] [blame] | 113 | } |