blob: e2a08e2ccaadcb89f6450f249e49cad156341a74 [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 */
Alexandre Lision064e1e02013-10-01 16:18:42 -040022package org.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 Lision064e1e02013-10-01 16:18:42 -040027import org.sflphone.R;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040028
Alexandre Lision4f906b22013-10-02 10:13:45 -040029import android.util.Log;
30
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040031public class AccountDetailAdvanced implements AccountDetail {
32
Alexandre Savard68838112012-10-30 11:34:43 -040033 private static final String TAG = "AccountDetailAdvanced";
Alexandre Savard68838112012-10-30 11:34:43 -040034
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040035 public static final String CONFIG_ACCOUNT_MAILBOX = "Account.mailbox";
36 public static final String CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire";
37 public static final String CONFIG_ACCOUNT_REGISTRATION_STATUS = "Account.registrationStatus";
38 public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode";
39 public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.registrationDescription";
40 public static final String CONFIG_CREDENTIAL_NUMBER = "Credential.count";
41 public static final String CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType";
42 public static final String CONFIG_RINGTONE_PATH = "Account.ringtonePath";
43 public static final String CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled";
44 public static final String CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled";
45
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040046 public static final String CONFIG_LOCAL_INTERFACE = "Account.localInterface";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040047 public static final String CONFIG_PUBLISHED_SAMEAS_LOCAL = "Account.publishedSameAsLocal";
48 public static final String CONFIG_LOCAL_PORT = "Account.localPort";
49 public static final String CONFIG_PUBLISHED_PORT = "Account.publishedPort";
50 public static final String CONFIG_PUBLISHED_ADDRESS = "Account.publishedAddress";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040051
52 public static final String CONFIG_DISPLAY_NAME = "Account.displayName";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040053 public static final String CONFIG_STUN_SERVER = "STUN.server";
54 public static final String CONFIG_STUN_ENABLE = "STUN.enable";
Alexandre Lisiona3650992013-11-13 14:19:35 -050055
Alexandre Savard68838112012-10-30 11:34:43 -040056 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040057
Alexandre Lisiona3650992013-11-13 14:19:35 -050058 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
Alexandre Savardae992932012-10-17 10:26:12 -040059 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
60
61 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_EXPIRE, R.string.account_registration_exp_label));
62 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATUS, R.string.account_registration_status_label));
63 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_CODE, R.string.account_registration_code_label));
64 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_DESC, R.string.account_registration_state_label));
65 preference.add(new PreferenceEntry(CONFIG_CREDENTIAL_NUMBER, R.string.account_credential_count_label));
66 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_DTMF_TYPE, R.string.account_config_dtmf_type_label));
67 preference.add(new PreferenceEntry(CONFIG_RINGTONE_PATH, R.string.account_ringtone_path_label));
68 preference.add(new PreferenceEntry(CONFIG_RINGTONE_ENABLED, R.string.account_ringtone_enabled_label, true));
69 preference.add(new PreferenceEntry(CONFIG_KEEP_ALIVE_ENABLED, R.string.account_keep_alive_label, true));
Alexandre Savardae992932012-10-17 10:26:12 -040070 preference.add(new PreferenceEntry(CONFIG_LOCAL_INTERFACE, R.string.account_local_interface_label));
Alexandre Savardae992932012-10-17 10:26:12 -040071 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_SAMEAS_LOCAL, R.string.account_published_same_as_local_label, true));
72 preference.add(new PreferenceEntry(CONFIG_LOCAL_PORT, R.string.account_local_port_label));
73 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_PORT, R.string.account_published_port_label));
74 preference.add(new PreferenceEntry(CONFIG_PUBLISHED_ADDRESS, R.string.account_published_address_label));
75 preference.add(new PreferenceEntry(CONFIG_DISPLAY_NAME, R.string.account_displayname_label));
76 preference.add(new PreferenceEntry(CONFIG_STUN_SERVER, R.string.account_stun_server_label));
77 preference.add(new PreferenceEntry(CONFIG_STUN_ENABLE, R.string.account_stun_enable_label, true));
78
79 return preference;
80 }
81
Alexandre Lisiona3650992013-11-13 14:19:35 -050082 public AccountDetailAdvanced() {
Alexandre Savard68838112012-10-30 11:34:43 -040083 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040084 }
85
Alexandre Lisiona3650992013-11-13 14:19:35 -050086 public AccountDetailAdvanced(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040087 privateArray = getPreferenceEntries();
88
Alexandre Lisiona3650992013-11-13 14:19:35 -050089 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040090 p.mValue = pref.get(p.mKey);
91 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040092 }
93
Alexandre Lisiona3650992013-11-13 14:19:35 -050094 public AccountDetailAdvanced(ArrayList<String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040095 privateArray = getPreferenceEntries();
96
Alexandre Lisiona3650992013-11-13 14:19:35 -050097 if (pref.size() != privateArray.size()) {
Alexandre Savard68838112012-10-30 11:34:43 -040098 Log.i(TAG, "Error list are not of equal size");
Alexandre Lisiona3650992013-11-13 14:19:35 -050099 } else {
Alexandre Savard68838112012-10-30 11:34:43 -0400100 int index = 0;
Alexandre Lisiona3650992013-11-13 14:19:35 -0500101 for (String s : pref) {
Alexandre Savard68838112012-10-30 11:34:43 -0400102 privateArray.get(index).mValue = s;
alision73424b62013-04-26 11:49:18 -0400103 index++;
Alexandre Savard68838112012-10-30 11:34:43 -0400104 }
105 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400106 }
Alexandre Savard68838112012-10-30 11:34:43 -0400107
Alexandre Lisiona3650992013-11-13 14:19:35 -0500108 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -0400109 return privateArray;
110 }
111
Alexandre Lisiona3650992013-11-13 14:19:35 -0500112 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -0400113 ArrayList<String> valueList = new ArrayList<String>();
114
Alexandre Lisiona3650992013-11-13 14:19:35 -0500115 for (AccountDetail.PreferenceEntry p : privateArray) {
116 Log.i(TAG, "" + p.mValue);
Alexandre Savard68838112012-10-30 11:34:43 -0400117 valueList.add(p.mValue);
118 }
119
120 return valueList;
121 }
122
Alexandre Lisiona3650992013-11-13 14:19:35 -0500123 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -0400124 HashMap<String, String> map = new HashMap<String, String>();
125
Alexandre Lisiona3650992013-11-13 14:19:35 -0500126 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard833616f2012-10-30 16:02:30 -0400127 map.put(p.mKey, p.mValue);
128 }
129
130 return map;
131 }
132
Alexandre Lisiona3650992013-11-13 14:19:35 -0500133 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -0400134 String value = "";
135
Alexandre Lisiona3650992013-11-13 14:19:35 -0500136 for (AccountDetail.PreferenceEntry p : privateArray) {
137 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -0400138 value = p.mValue;
139 return value;
140 }
141 }
Alexandre Savard68838112012-10-30 11:34:43 -0400142 return value;
143 }
144
Alexandre Lisiona3650992013-11-13 14:19:35 -0500145 public void setDetailString(String key, String newValue) {
146 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400147 PreferenceEntry p = privateArray.get(i);
Alexandre Lisiona3650992013-11-13 14:19:35 -0500148 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400149 privateArray.get(i).mValue = newValue;
150 }
151 }
Alexandre Lisiona3650992013-11-13 14:19:35 -0500152
Alexandre Savard833616f2012-10-30 16:02:30 -0400153 }
154
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400155}