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 | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 27 | import org.sflphone.R; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 28 | |
Alexandre Lision | 4f906b2 | 2013-10-02 10:13:45 -0400 | [diff] [blame] | 29 | import android.util.Log; |
| 30 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 31 | public class AccountDetailBasic implements AccountDetail { |
| 32 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 33 | private static final String TAG = "AccountDetailBasic"; |
| 34 | public static final String BUNDLE_TAG = "BasicPreferenceArrayList"; |
| 35 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 36 | public static final String CONFIG_ACCOUNT_HOSTNAME = "Account.hostname"; |
| 37 | public static final String CONFIG_ACCOUNT_USERNAME = "Account.username"; |
| 38 | public static final String CONFIG_ACCOUNT_ROUTESET = "Account.routeset"; |
| 39 | public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password"; |
| 40 | public static final String CONFIG_ACCOUNT_REALM = "Account.realm"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 41 | public static final String CONFIG_ACCOUNT_USERAGENT = "Account.useragent"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 42 | public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer"; |
| 43 | public static final String CONFIG_ACCOUNT_TYPE = "Account.type"; |
| 44 | public static final String CONFIG_ACCOUNT_ALIAS = "Account.alias"; |
| 45 | public static final String CONFIG_ACCOUNT_ENABLE = "Account.enable"; |
| 46 | |
| 47 | |
| 48 | public static final String CONFIG_ACCOUNT_DEFAULT_TYPE = "SIP"; |
| 49 | public static final String CONFIG_ACCOUNT_DEFAULT_ENABLE = "true"; |
| 50 | public static final String CONFIG_ACCOUNT_DEFAULT_REALM = "*"; |
| 51 | public static final String CONFIG_ACCOUNT_DEFAULT_USERAGENT = "SFLphone"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 52 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 53 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 54 | |
| 55 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() |
| 56 | { |
| 57 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 58 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 59 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ENABLE, R.string.account_enabled_label, true)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 60 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_TYPE, R.string.account_type_label)); |
| 61 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ALIAS, R.string.account_alias_label)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 62 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_HOSTNAME, R.string.account_hostname_label)); |
| 63 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME, R.string.account_username_label)); |
| 64 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ROUTESET, R.string.account_routeset_label)); |
| 65 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD, R.string.account_password_label)); |
| 66 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM, R.string.account_realm_label)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 67 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERAGENT, R.string.account_autoanswer_label)); |
| 68 | |
| 69 | return preference; |
| 70 | } |
| 71 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 72 | public AccountDetailBasic() |
| 73 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 74 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 75 | } |
| 76 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 77 | public AccountDetailBasic(HashMap<String, String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 78 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 79 | privateArray = getPreferenceEntries(); |
| 80 | |
| 81 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 82 | p.mValue = pref.get(p.mKey); |
| 83 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 84 | } |
| 85 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 86 | public AccountDetailBasic(ArrayList<String> pref) |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 87 | { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 88 | privateArray = getPreferenceEntries(); |
| 89 | |
| 90 | if(pref.size() != privateArray.size()) { |
| 91 | Log.i(TAG, "Error list are not of equal size"); |
| 92 | } |
| 93 | else { |
| 94 | int index = 0; |
| 95 | for(String s : pref) { |
alision | 7f18fc8 | 2013-05-01 09:37:33 -0400 | [diff] [blame] | 96 | Log.i(TAG, "Creating "+privateArray.get(index).mKey+" value "+s); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 97 | privateArray.get(index).mValue = s; |
| 98 | index++; |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() |
| 104 | { |
| 105 | return privateArray; |
| 106 | } |
| 107 | |
| 108 | public ArrayList<String> getValuesOnly() |
| 109 | { |
| 110 | ArrayList<String> valueList = new ArrayList<String>(); |
| 111 | |
| 112 | for(AccountDetail.PreferenceEntry p : privateArray) { |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 113 | Log.i(TAG,""+p.mValue); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 114 | valueList.add(p.mValue); |
| 115 | } |
| 116 | |
| 117 | return valueList; |
| 118 | } |
| 119 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 120 | public HashMap<String, String> getDetailsHashMap() |
| 121 | { |
| 122 | HashMap<String, String> map = new HashMap<String, String>(); |
| 123 | |
| 124 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 125 | map.put(p.mKey, p.mValue); |
| 126 | } |
| 127 | |
| 128 | return map; |
| 129 | } |
| 130 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 131 | public String getDetailString(String key) |
| 132 | { |
| 133 | String value = ""; |
| 134 | |
| 135 | for(AccountDetail.PreferenceEntry p : privateArray) { |
| 136 | if(p.mKey.equals(key)) { |
| 137 | value = p.mValue; |
| 138 | return value; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return value; |
| 143 | } |
| 144 | |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 145 | public void setDetailString(String key, String newValue) |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 146 | { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 147 | for(int i = 0 ; i < privateArray.size() ; ++i) { |
| 148 | PreferenceEntry p = privateArray.get(i); |
| 149 | if(p.mKey.equals(key)) { |
| 150 | privateArray.get(i).mValue = newValue; |
| 151 | } |
| 152 | } |
| 153 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 157 | public boolean getDetailBoolean() |
| 158 | { |
| 159 | return true; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 160 | } |
| 161 | } |