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 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 22 | package org.sflphone.account; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 23 | |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 24 | import java.util.ArrayList; |
| 25 | import java.util.HashMap; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 26 | |
Alexandre Lision | 4f906b2 | 2013-10-02 10:13:45 -0400 | [diff] [blame] | 27 | import android.util.Log; |
| 28 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 29 | public class AccountDetailAdvanced implements AccountDetail { |
| 30 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 31 | private static final String TAG = "AccountDetailAdvanced"; |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 32 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 33 | public static final String CONFIG_ACCOUNT_MAILBOX = "Account.mailbox"; |
| 34 | public static final String CONFIG_ACCOUNT_REGISTRATION_EXPIRE = "Account.registrationExpire"; |
| 35 | public static final String CONFIG_ACCOUNT_REGISTRATION_STATUS = "Account.registrationStatus"; |
| 36 | public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_CODE = "Account.registrationCode"; |
| 37 | public static final String CONFIG_ACCOUNT_REGISTRATION_STATE_DESC = "Account.registrationDescription"; |
| 38 | public static final String CONFIG_CREDENTIAL_NUMBER = "Credential.count"; |
| 39 | public static final String CONFIG_ACCOUNT_DTMF_TYPE = "Account.dtmfType"; |
| 40 | public static final String CONFIG_RINGTONE_PATH = "Account.ringtonePath"; |
| 41 | public static final String CONFIG_RINGTONE_ENABLED = "Account.ringtoneEnabled"; |
| 42 | public static final String CONFIG_KEEP_ALIVE_ENABLED = "Account.keepAliveEnabled"; |
| 43 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 44 | public static final String CONFIG_LOCAL_INTERFACE = "Account.localInterface"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 45 | public static final String CONFIG_PUBLISHED_SAMEAS_LOCAL = "Account.publishedSameAsLocal"; |
| 46 | public static final String CONFIG_LOCAL_PORT = "Account.localPort"; |
| 47 | public static final String CONFIG_PUBLISHED_PORT = "Account.publishedPort"; |
| 48 | public static final String CONFIG_PUBLISHED_ADDRESS = "Account.publishedAddress"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 49 | |
| 50 | public static final String CONFIG_DISPLAY_NAME = "Account.displayName"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 51 | public static final String CONFIG_STUN_SERVER = "STUN.server"; |
| 52 | public static final String CONFIG_STUN_ENABLE = "STUN.enable"; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 53 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 54 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 55 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 56 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 57 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 58 | |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 59 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_EXPIRE)); |
| 60 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATUS)); |
| 61 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_CODE)); |
| 62 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REGISTRATION_STATE_DESC)); |
| 63 | preference.add(new PreferenceEntry(CONFIG_CREDENTIAL_NUMBER)); |
| 64 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_DTMF_TYPE)); |
| 65 | preference.add(new PreferenceEntry(CONFIG_RINGTONE_PATH)); |
| 66 | preference.add(new PreferenceEntry(CONFIG_RINGTONE_ENABLED, true)); |
| 67 | preference.add(new PreferenceEntry(CONFIG_KEEP_ALIVE_ENABLED, true)); |
| 68 | preference.add(new PreferenceEntry(CONFIG_LOCAL_INTERFACE)); |
| 69 | preference.add(new PreferenceEntry(CONFIG_PUBLISHED_SAMEAS_LOCAL, true)); |
| 70 | preference.add(new PreferenceEntry(CONFIG_LOCAL_PORT)); |
| 71 | preference.add(new PreferenceEntry(CONFIG_PUBLISHED_PORT)); |
| 72 | preference.add(new PreferenceEntry(CONFIG_PUBLISHED_ADDRESS)); |
| 73 | preference.add(new PreferenceEntry(CONFIG_DISPLAY_NAME)); |
| 74 | preference.add(new PreferenceEntry(CONFIG_STUN_SERVER)); |
| 75 | preference.add(new PreferenceEntry(CONFIG_STUN_ENABLE, true)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 76 | |
| 77 | return preference; |
| 78 | } |
| 79 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 80 | public AccountDetailAdvanced() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 81 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 84 | public AccountDetailAdvanced(HashMap<String, String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 85 | privateArray = getPreferenceEntries(); |
| 86 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 87 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 88 | p.mValue = pref.get(p.mKey); |
| 89 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 92 | public AccountDetailAdvanced(ArrayList<String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 93 | privateArray = getPreferenceEntries(); |
| 94 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 95 | if (pref.size() != privateArray.size()) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 96 | Log.i(TAG, "Error list are not of equal size"); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 97 | } else { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 98 | int index = 0; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 99 | for (String s : pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 100 | privateArray.get(index).mValue = s; |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 101 | index++; |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 102 | } |
| 103 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 104 | } |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 105 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 106 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 107 | return privateArray; |
| 108 | } |
| 109 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 110 | public ArrayList<String> getValuesOnly() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 111 | ArrayList<String> valueList = new ArrayList<String>(); |
| 112 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 113 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 114 | Log.i(TAG, "" + p.mValue); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 115 | valueList.add(p.mValue); |
| 116 | } |
| 117 | |
| 118 | return valueList; |
| 119 | } |
| 120 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 121 | public HashMap<String, String> getDetailsHashMap() { |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 122 | HashMap<String, String> map = new HashMap<String, String>(); |
| 123 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 124 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 125 | map.put(p.mKey, p.mValue); |
| 126 | } |
| 127 | |
| 128 | return map; |
| 129 | } |
| 130 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 131 | public String getDetailString(String key) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 132 | String value = ""; |
| 133 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 134 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 135 | if (p.mKey.equals(key)) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 136 | value = p.mValue; |
| 137 | return value; |
| 138 | } |
| 139 | } |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 140 | return value; |
| 141 | } |
| 142 | |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 143 | public void setDetailString(String key, String newValue) { |
| 144 | for (int i = 0; i < privateArray.size(); ++i) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 145 | PreferenceEntry p = privateArray.get(i); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 146 | if (p.mKey.equals(key)) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 147 | privateArray.get(i).mValue = newValue; |
| 148 | } |
| 149 | } |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 150 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 151 | } |
| 152 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 153 | } |