blob: aab05a6e8caefa9ac376ad765e99304f26050e62 [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
24import com.savoirfairelinux.sflphone.R;
alisionf76de3b2013-04-16 15:35:22 -040025import com.savoirfairelinux.sflphone.account.AccountDetail;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040026
Alexandre Savard68838112012-10-30 11:34:43 -040027import android.util.Log;
28
Alexandre Savardae992932012-10-17 10:26:12 -040029import java.util.ArrayList;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040030import java.util.Collection;
31import java.util.Set;
32import java.util.HashMap;
33
34public class AccountDetailAdvanced implements AccountDetail {
35
Alexandre Savard68838112012-10-30 11:34:43 -040036 private static final String TAG = "AccountDetailAdvanced";
37 public static final String BUNDLE_TAG = "AdvancedPreferenceArrayList";
38
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040039 public static final String CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
40 public static final String CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire";
41 public static final String CONFIG_ACCOUNT_REGISTRATION_STATUS = "Account.registrationStatus";
42 public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode";
43 public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.registrationDescription";
44 public static final String CONFIG_CREDENTIAL_NUMBER = "Credential.count";
45 public static final String CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType";
46 public static final String CONFIG_RINGTONE_PATH = "Account.ringtonePath";
47 public static final String CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled";
48 public static final String CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled";
49
50 public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
51 public static final String CONFIG_LOCAL_INTERFACE = "Account.localInterface";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040052 public static final String CONFIG_PUBLISHED_SAMEAS_LOCAL = "Account.publishedSameAsLocal";
53 public static final String CONFIG_LOCAL_PORT = "Account.localPort";
54 public static final String CONFIG_PUBLISHED_PORT = "Account.publishedPort";
55 public static final String CONFIG_PUBLISHED_ADDRESS = "Account.publishedAddress";
56 public static final String CONFIG_DEFAULT_LOCAL_PORT = "5060";
57 public static final String CONFIG_DEFAULT_PUBLISHED_PORT = "5060";
58 public static final String CONFIG_DEFAULT_PUBLISHED_SAMEAS_LOCAL = "true";
59 public static final String CONFIG_DEFAULT_INTERFACE = "default";
60
61 public static final String CONFIG_DISPLAY_NAME = "Account.displayName";
62 public static final String CONFIG_DEFAULT_ADDRESS = "0.0.0.0";
63
64 public static final String CONFIG_STUN_SERVER = "STUN.server";
65 public static final String CONFIG_STUN_ENABLE = "STUN.enable";
66
Alexandre Savard68838112012-10-30 11:34:43 -040067 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040068
Alexandre Savardae992932012-10-17 10:26:12 -040069 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
70 {
71 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
72
73 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, R.string.account_registration_exp_label));
74 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATUS, R.string.account_registration_status_label));
75 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, R.string.account_registration_code_label));
76 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, R.string.account_registration_state_label));
77 preference.add(new PreferenceEntry(CONFIG_CREDENTIAL_NUMBER, R.string.account_credential_count_label));
78 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_DTMF_TYPE, R.string.account_config_dtmf_type_label));
79 preference.add(new PreferenceEntry(CONFIG_RINGTONE_PATH, R.string.account_ringtone_path_label));
80 preference.add(new PreferenceEntry(CONFIG_RINGTONE_ENABLED, R.string.account_ringtone_enabled_label, true));
81 preference.add(new PreferenceEntry(CONFIG_KEEP_ALIVE_ENABLED, R.string.account_keep_alive_label, true));
alision73424b62013-04-26 11:49:18 -040082 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_AUTOANSWER, R.string.account_autoanswer_label, true));
Alexandre Savardae992932012-10-17 10:26:12 -040083 preference.add(new PreferenceEntry(CONFIG_LOCAL_INTERFACE, R.string.account_local_interface_label));
Alexandre Savardae992932012-10-17 10:26:12 -040084 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_SAMEAS_LOCAL, R.string.account_published_same_as_local_label, true));
85 preference.add(new PreferenceEntry(CONFIG_LOCAL_PORT, R.string.account_local_port_label));
86 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_PORT, R.string.account_published_port_label));
87 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_ADDRESS, R.string.account_published_address_label));
88 preference.add(new PreferenceEntry(CONFIG_DISPLAY_NAME, R.string.account_displayname_label));
89 preference.add(new PreferenceEntry(CONFIG_STUN_SERVER, R.string.account_stun_server_label));
90 preference.add(new PreferenceEntry(CONFIG_STUN_ENABLE, R.string.account_stun_enable_label, true));
91
92 return preference;
93 }
94
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040095 public AccountDetailAdvanced()
96 {
Alexandre Savard68838112012-10-30 11:34:43 -040097 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040098 }
99
Alexandre Savard68838112012-10-30 11:34:43 -0400100 public AccountDetailAdvanced(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400101 {
Alexandre Savard68838112012-10-30 11:34:43 -0400102 privateArray = getPreferenceEntries();
103
104 for(AccountDetail.PreferenceEntry p : privateArray) {
105 p.mValue = pref.get(p.mKey);
106 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400107 }
108
Alexandre Savard68838112012-10-30 11:34:43 -0400109 public AccountDetailAdvanced(ArrayList<String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400110 {
Alexandre Savard68838112012-10-30 11:34:43 -0400111 privateArray = getPreferenceEntries();
112
113 if(pref.size() != privateArray.size()) {
114 Log.i(TAG, "Error list are not of equal size");
115 }
116 else {
117 int index = 0;
118 for(String s : pref) {
119 privateArray.get(index).mValue = s;
alision73424b62013-04-26 11:49:18 -0400120 index++;
Alexandre Savard68838112012-10-30 11:34:43 -0400121 }
122 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400123 }
Alexandre Savard68838112012-10-30 11:34:43 -0400124
125 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues()
126 {
127 return privateArray;
128 }
129
130 public ArrayList<String> getValuesOnly()
131 {
132 ArrayList<String> valueList = new ArrayList<String>();
133
134 for(AccountDetail.PreferenceEntry p : privateArray) {
alision73424b62013-04-26 11:49:18 -0400135 Log.i(TAG,""+p.mValue);
Alexandre Savard68838112012-10-30 11:34:43 -0400136 valueList.add(p.mValue);
137 }
138
139 return valueList;
140 }
141
Alexandre Savard833616f2012-10-30 16:02:30 -0400142 public HashMap<String, String> getDetailsHashMap()
143 {
144 HashMap<String, String> map = new HashMap<String, String>();
145
146 for(AccountDetail.PreferenceEntry p : privateArray) {
147 map.put(p.mKey, p.mValue);
148 }
149
150 return map;
151 }
152
Alexandre Savard68838112012-10-30 11:34:43 -0400153 public String getDetailString(String key)
154 {
155 String value = "";
156
157 for(AccountDetail.PreferenceEntry p : privateArray) {
158 if(p.mKey.equals(key)) {
159 value = p.mValue;
160 return value;
161 }
162 }
163
164 return value;
165 }
166
Alexandre Savard833616f2012-10-30 16:02:30 -0400167 public void setDetailString(int position, String newValue)
168 {
169 privateArray.get(position).mValue = newValue;
170 }
171
Alexandre Savard68838112012-10-30 11:34:43 -0400172 public boolean getDetailBoolean()
173 {
174 return true;
175 }
176
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400177}