Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@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 | * If you own a pjsip commercial license you can also redistribute it |
| 11 | * and/or modify it under the terms of the GNU Lesser General Public License |
| 12 | * as an android library. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | */ |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 22 | package com.savoirfairelinux.sflphone.account; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 23 | |
| 24 | import com.savoirfairelinux.sflphone.R; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 25 | import com.savoirfairelinux.sflphone.account.AccountDetail; |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 26 | import com.savoirfairelinux.sflphone.account.AccountDetail.PreferenceEntry; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 27 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 30 | import java.util.ArrayList; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 31 | import java.util.Collection; |
| 32 | import java.util.Set; |
| 33 | import java.util.HashMap; |
| 34 | |
| 35 | public class AccountDetailAdvanced implements AccountDetail { |
| 36 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 37 | private static final String TAG = "AccountDetailAdvanced"; |
| 38 | public static final String BUNDLE_TAG = "AdvancedPreferenceArrayList"; |
| 39 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 40 | public static final String CONFIG_ACCOUNT_MAILBOX = "Account.mailbox"; |
| 41 | public static final String CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire"; |
| 42 | public static final String CONFIG_ACCOUNT_REGISTRATION_STATUS = "Account.registrationStatus"; |
| 43 | public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode"; |
| 44 | public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.registrationDescription"; |
| 45 | public static final String CONFIG_CREDENTIAL_NUMBER = "Credential.count"; |
| 46 | public static final String CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType"; |
| 47 | public static final String CONFIG_RINGTONE_PATH = "Account.ringtonePath"; |
| 48 | public static final String CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled"; |
| 49 | public static final String CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled"; |
| 50 | |
| 51 | public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer"; |
| 52 | public static final String CONFIG_LOCAL_INTERFACE = "Account.localInterface"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 53 | public static final String CONFIG_PUBLISHED_SAMEAS_LOCAL = "Account.publishedSameAsLocal"; |
| 54 | public static final String CONFIG_LOCAL_PORT = "Account.localPort"; |
| 55 | public static final String CONFIG_PUBLISHED_PORT = "Account.publishedPort"; |
| 56 | public static final String CONFIG_PUBLISHED_ADDRESS = "Account.publishedAddress"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 57 | |
Tristan Matthews | 671a6d1 | 2013-07-24 16:53:32 -0400 | [diff] [blame] | 58 | // FIXME: Why isn't this 5060? |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 59 | public static final String CONFIG_DEFAULT_LOCAL_PORT = "5070"; |
| 60 | public static final String CONFIG_DEFAULT_PUBLISHED_PORT = "5070"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 61 | public static final String CONFIG_DEFAULT_PUBLISHED_SAMEAS_LOCAL = "true"; |
Tristan Matthews | 671a6d1 | 2013-07-24 16:53:32 -0400 | [diff] [blame] | 62 | // FIXME: Why isn't this "default"? |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 63 | public static final String CONFIG_DEFAULT_INTERFACE = "wlan0"; |
| 64 | public static final String CONFIG_DEFAULT_REGISTRATION_EXPIRE = "60"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 65 | |
| 66 | public static final String CONFIG_DISPLAY_NAME = "Account.displayName"; |
| 67 | public static final String CONFIG_DEFAULT_ADDRESS = "0.0.0.0"; |
| 68 | |
| 69 | public static final String CONFIG_STUN_SERVER = "STUN.server"; |
| 70 | public static final String CONFIG_STUN_ENABLE = "STUN.enable"; |
| 71 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 72 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 73 | |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 74 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() |
| 75 | { |
| 76 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 77 | |
| 78 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, R.string.account_registration_exp_label)); |
| 79 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATUS, R.string.account_registration_status_label)); |
| 80 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, R.string.account_registration_code_label)); |
| 81 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, R.string.account_registration_state_label)); |
| 82 | preference.add(new PreferenceEntry(CONFIG_CREDENTIAL_NUMBER, R.string.account_credential_count_label)); |
| 83 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_DTMF_TYPE, R.string.account_config_dtmf_type_label)); |
| 84 | preference.add(new PreferenceEntry(CONFIG_RINGTONE_PATH, R.string.account_ringtone_path_label)); |
| 85 | preference.add(new PreferenceEntry(CONFIG_RINGTONE_ENABLED, R.string.account_ringtone_enabled_label, true)); |
| 86 | preference.add(new PreferenceEntry(CONFIG_KEEP_ALIVE_ENABLED, R.string.account_keep_alive_label, true)); |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 87 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_AUTOANSWER, R.string.account_autoanswer_label, true)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 88 | preference.add(new PreferenceEntry(CONFIG_LOCAL_INTERFACE, R.string.account_local_interface_label)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 89 | preference.add(new PreferenceEntry(CONFIG_PUBLISHED_SAMEAS_LOCAL, R.string.account_published_same_as_local_label, true)); |
| 90 | preference.add(new PreferenceEntry(CONFIG_LOCAL_PORT, R.string.account_local_port_label)); |
| 91 | preference.add(new PreferenceEntry(CONFIG_PUBLISHED_PORT, R.string.account_published_port_label)); |
| 92 | preference.add(new PreferenceEntry(CONFIG_PUBLISHED_ADDRESS, R.string.account_published_address_label)); |
| 93 | preference.add(new PreferenceEntry(CONFIG_DISPLAY_NAME, R.string.account_displayname_label)); |
| 94 | preference.add(new PreferenceEntry(CONFIG_STUN_SERVER, R.string.account_stun_server_label)); |
| 95 | preference.add(new PreferenceEntry(CONFIG_STUN_ENABLE, R.string.account_stun_enable_label, true)); |
| 96 | |
| 97 | return preference; |
| 98 | } |
| 99 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 100 | public AccountDetailAdvanced() |
| 101 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 102 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 103 | } |
| 104 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 105 | public AccountDetailAdvanced(HashMap<String, String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 106 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 107 | privateArray = getPreferenceEntries(); |
| 108 | |
| 109 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 110 | p.mValue = pref.get(p.mKey); |
| 111 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 112 | } |
| 113 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 114 | public AccountDetailAdvanced(ArrayList<String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 115 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 116 | privateArray = getPreferenceEntries(); |
| 117 | |
| 118 | if(pref.size() != privateArray.size()) { |
| 119 | Log.i(TAG, "Error list are not of equal size"); |
| 120 | } |
| 121 | else { |
| 122 | int index = 0; |
| 123 | for(String s : pref) { |
| 124 | privateArray.get(index).mValue = s; |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 125 | index++; |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 126 | } |
| 127 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 128 | } |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 129 | |
| 130 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() |
| 131 | { |
| 132 | return privateArray; |
| 133 | } |
| 134 | |
| 135 | public ArrayList<String> getValuesOnly() |
| 136 | { |
| 137 | ArrayList<String> valueList = new ArrayList<String>(); |
| 138 | |
| 139 | for(AccountDetail.PreferenceEntry p : privateArray) { |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 140 | Log.i(TAG,""+p.mValue); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 141 | valueList.add(p.mValue); |
| 142 | } |
| 143 | |
| 144 | return valueList; |
| 145 | } |
| 146 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 147 | public HashMap<String, String> getDetailsHashMap() |
| 148 | { |
| 149 | HashMap<String, String> map = new HashMap<String, String>(); |
| 150 | |
| 151 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 152 | map.put(p.mKey, p.mValue); |
| 153 | } |
| 154 | |
| 155 | return map; |
| 156 | } |
| 157 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 158 | public String getDetailString(String key) |
| 159 | { |
| 160 | String value = ""; |
| 161 | |
| 162 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 163 | if(p.mKey.equals(key)) { |
| 164 | value = p.mValue; |
| 165 | return value; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return value; |
| 170 | } |
| 171 | |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 172 | public void setDetailString(String key, String newValue) |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 173 | { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 174 | for(int i = 0 ; i < privateArray.size() ; ++i) { |
| 175 | PreferenceEntry p = privateArray.get(i); |
| 176 | if(p.mKey.equals(key)) { |
| 177 | privateArray.get(i).mValue = newValue; |
| 178 | } |
| 179 | } |
| 180 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 181 | } |
| 182 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 183 | public boolean getDetailBoolean() |
| 184 | { |
| 185 | return true; |
| 186 | } |
| 187 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 188 | } |