blob: ca6376742b2645a25f3e5800274614b858c8910f [file] [log] [blame]
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -04001/**
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 */
alisionf76de3b2013-04-16 15:35:22 -040022package com.savoirfairelinux.sflphone.account;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040023
Alexandre Lision6e8931e2013-09-19 16:49:34 -040024import java.util.ArrayList;
25import java.util.HashMap;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040026
Alexandre Savard68838112012-10-30 11:34:43 -040027import android.util.Log;
28
Alexandre Lision6e8931e2013-09-19 16:49:34 -040029import com.savoirfairelinux.sflphone.R;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040030
31public class AccountDetailAdvanced implements AccountDetail {
32
Alexandre Savard68838112012-10-30 11:34:43 -040033 private static final String TAG = "AccountDetailAdvanced";
34 public static final String BUNDLE_TAG = "AdvancedPreferenceArrayList";
35
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040036 public static final String CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
37 public static final String CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire";
38 public static final String CONFIG_ACCOUNT_REGISTRATION_STATUS = "Account.registrationStatus";
39 public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode";
40 public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.registrationDescription";
41 public static final String CONFIG_CREDENTIAL_NUMBER = "Credential.count";
42 public static final String CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType";
43 public static final String CONFIG_RINGTONE_PATH = "Account.ringtonePath";
44 public static final String CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled";
45 public static final String CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled";
46
47 public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
48 public static final String CONFIG_LOCAL_INTERFACE = "Account.localInterface";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040049 public static final String CONFIG_PUBLISHED_SAMEAS_LOCAL = "Account.publishedSameAsLocal";
50 public static final String CONFIG_LOCAL_PORT = "Account.localPort";
51 public static final String CONFIG_PUBLISHED_PORT = "Account.publishedPort";
52 public static final String CONFIG_PUBLISHED_ADDRESS = "Account.publishedAddress";
alision5cfc35d2013-07-11 15:11:39 -040053
Tristan Matthews671a6d12013-07-24 16:53:32 -040054 // FIXME: Why isn't this 5060?
Alexandre Lision6e8931e2013-09-19 16:49:34 -040055 public static final String CONFIG_DEFAULT_LOCAL_PORT = "5060";
56 public static final String CONFIG_DEFAULT_PUBLISHED_PORT = "5060";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040057 public static final String CONFIG_DEFAULT_PUBLISHED_SAMEAS_LOCAL = "true";
Tristan Matthews671a6d12013-07-24 16:53:32 -040058 // FIXME: Why isn't this "default"?
Alexandre Lision6e8931e2013-09-19 16:49:34 -040059 public static final String CONFIG_DEFAULT_INTERFACE = "default";
alision5cfc35d2013-07-11 15:11:39 -040060 public static final String CONFIG_DEFAULT_REGISTRATION_EXPIRE = "60";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040061
62 public static final String CONFIG_DISPLAY_NAME = "Account.displayName";
63 public static final String CONFIG_DEFAULT_ADDRESS = "0.0.0.0";
64
65 public static final String CONFIG_STUN_SERVER = "STUN.server";
66 public static final String CONFIG_STUN_ENABLE = "STUN.enable";
67
Alexandre Savard68838112012-10-30 11:34:43 -040068 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040069
Alexandre Savardae992932012-10-17 10:26:12 -040070 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
71 {
72 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
73
74 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, R.string.account_registration_exp_label));
75 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATUS, R.string.account_registration_status_label));
76 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, R.string.account_registration_code_label));
77 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, R.string.account_registration_state_label));
78 preference.add(new PreferenceEntry(CONFIG_CREDENTIAL_NUMBER, R.string.account_credential_count_label));
79 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_DTMF_TYPE, R.string.account_config_dtmf_type_label));
80 preference.add(new PreferenceEntry(CONFIG_RINGTONE_PATH, R.string.account_ringtone_path_label));
81 preference.add(new PreferenceEntry(CONFIG_RINGTONE_ENABLED, R.string.account_ringtone_enabled_label, true));
82 preference.add(new PreferenceEntry(CONFIG_KEEP_ALIVE_ENABLED, R.string.account_keep_alive_label, true));
alision73424b62013-04-26 11:49:18 -040083 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_AUTOANSWER, R.string.account_autoanswer_label, true));
Alexandre Savardae992932012-10-17 10:26:12 -040084 preference.add(new PreferenceEntry(CONFIG_LOCAL_INTERFACE, R.string.account_local_interface_label));
Alexandre Savardae992932012-10-17 10:26:12 -040085 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_SAMEAS_LOCAL, R.string.account_published_same_as_local_label, true));
86 preference.add(new PreferenceEntry(CONFIG_LOCAL_PORT, R.string.account_local_port_label));
87 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_PORT, R.string.account_published_port_label));
88 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_ADDRESS, R.string.account_published_address_label));
89 preference.add(new PreferenceEntry(CONFIG_DISPLAY_NAME, R.string.account_displayname_label));
90 preference.add(new PreferenceEntry(CONFIG_STUN_SERVER, R.string.account_stun_server_label));
91 preference.add(new PreferenceEntry(CONFIG_STUN_ENABLE, R.string.account_stun_enable_label, true));
92
93 return preference;
94 }
95
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040096 public AccountDetailAdvanced()
97 {
Alexandre Savard68838112012-10-30 11:34:43 -040098 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040099 }
100
Alexandre Savard68838112012-10-30 11:34:43 -0400101 public AccountDetailAdvanced(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400102 {
Alexandre Savard68838112012-10-30 11:34:43 -0400103 privateArray = getPreferenceEntries();
104
105 for(AccountDetail.PreferenceEntry p : privateArray) {
106 p.mValue = pref.get(p.mKey);
107 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400108 }
109
Alexandre Savard68838112012-10-30 11:34:43 -0400110 public AccountDetailAdvanced(ArrayList<String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400111 {
Alexandre Savard68838112012-10-30 11:34:43 -0400112 privateArray = getPreferenceEntries();
113
114 if(pref.size() != privateArray.size()) {
115 Log.i(TAG, "Error list are not of equal size");
116 }
117 else {
118 int index = 0;
119 for(String s : pref) {
120 privateArray.get(index).mValue = s;
alision73424b62013-04-26 11:49:18 -0400121 index++;
Alexandre Savard68838112012-10-30 11:34:43 -0400122 }
123 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400124 }
Alexandre Savard68838112012-10-30 11:34:43 -0400125
126 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues()
127 {
128 return privateArray;
129 }
130
131 public ArrayList<String> getValuesOnly()
132 {
133 ArrayList<String> valueList = new ArrayList<String>();
134
135 for(AccountDetail.PreferenceEntry p : privateArray) {
alision73424b62013-04-26 11:49:18 -0400136 Log.i(TAG,""+p.mValue);
Alexandre Savard68838112012-10-30 11:34:43 -0400137 valueList.add(p.mValue);
138 }
139
140 return valueList;
141 }
142
Alexandre Savard833616f2012-10-30 16:02:30 -0400143 public HashMap<String, String> getDetailsHashMap()
144 {
145 HashMap<String, String> map = new HashMap<String, String>();
146
147 for(AccountDetail.PreferenceEntry p : privateArray) {
148 map.put(p.mKey, p.mValue);
149 }
150
151 return map;
152 }
153
Alexandre Savard68838112012-10-30 11:34:43 -0400154 public String getDetailString(String key)
155 {
156 String value = "";
157
158 for(AccountDetail.PreferenceEntry p : privateArray) {
159 if(p.mKey.equals(key)) {
160 value = p.mValue;
161 return value;
162 }
163 }
164
165 return value;
166 }
167
alision5de91782013-07-10 10:47:30 -0400168 public void setDetailString(String key, String newValue)
Alexandre Savard833616f2012-10-30 16:02:30 -0400169 {
alision5de91782013-07-10 10:47:30 -0400170 for(int i = 0 ; i < privateArray.size() ; ++i) {
171 PreferenceEntry p = privateArray.get(i);
172 if(p.mKey.equals(key)) {
173 privateArray.get(i).mValue = newValue;
174 }
175 }
176
Alexandre Savard833616f2012-10-30 16:02:30 -0400177 }
178
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400179}