Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 1 | /** |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame^] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 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 AccountDetailBasic implements AccountDetail { |
| 30 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 31 | private static final String TAG = AccountDetailBasic.class.getSimpleName(); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 32 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 33 | public static final String CONFIG_ACCOUNT_ALIAS = "Account.alias"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 34 | public static final String CONFIG_ACCOUNT_HOSTNAME = "Account.hostname"; |
| 35 | public static final String CONFIG_ACCOUNT_USERNAME = "Account.username"; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 36 | public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password"; |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 37 | |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 38 | public static final String CONFIG_ACCOUNT_USERAGENT = "Account.useragent"; |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 39 | public static final String CONFIG_ACCOUNT_ROUTESET = "Account.routeset"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 40 | public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer"; |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 41 | |
| 42 | public static final String CONFIG_ACCOUNT_REALM = "Account.realm"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 43 | public static final String CONFIG_ACCOUNT_TYPE = "Account.type"; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 44 | public static final String CONFIG_ACCOUNT_ENABLE = "Account.enable"; |
Alexandre Lision | 420b257 | 2014-01-10 11:37:18 -0500 | [diff] [blame] | 45 | public static final String CONFIG_PRESENCE_ENABLE = "Account.presenceEnabled"; |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 46 | |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 47 | private ArrayList<AccountDetail.PreferenceEntry> privateArray; |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 48 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 49 | public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() { |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 50 | ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>(); |
| 51 | |
Alexandre Lision | ab0cc9f | 2013-12-12 11:27:25 -0500 | [diff] [blame] | 52 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ENABLE, true)); |
| 53 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_TYPE)); |
| 54 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ALIAS)); |
| 55 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_HOSTNAME)); |
| 56 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME)); |
| 57 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ROUTESET)); |
| 58 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD)); |
| 59 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_AUTOANSWER, true)); |
| 60 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM)); |
| 61 | preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERAGENT)); |
Alexandre Lision | 420b257 | 2014-01-10 11:37:18 -0500 | [diff] [blame] | 62 | preference.add(new PreferenceEntry(CONFIG_PRESENCE_ENABLE)); |
Alexandre Savard | ae99293 | 2012-10-17 10:26:12 -0400 | [diff] [blame] | 63 | |
| 64 | return preference; |
| 65 | } |
| 66 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 67 | public AccountDetailBasic() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 68 | privateArray = getPreferenceEntries(); |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 69 | } |
| 70 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 71 | public AccountDetailBasic(HashMap<String, String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 72 | privateArray = getPreferenceEntries(); |
| 73 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 74 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 75 | p.mValue = pref.get(p.mKey); |
| 76 | } |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 77 | } |
| 78 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 79 | public AccountDetailBasic(ArrayList<String> pref) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 80 | privateArray = getPreferenceEntries(); |
| 81 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 82 | if (pref.size() != privateArray.size()) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 83 | Log.i(TAG, "Error list are not of equal size"); |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 84 | } else { |
| 85 | int index = 0; |
| 86 | for (String s : pref) { |
| 87 | Log.i(TAG, "Creating " + privateArray.get(index).mKey + " value " + s); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 88 | privateArray.get(index).mValue = s; |
| 89 | index++; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 94 | public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 95 | return privateArray; |
| 96 | } |
| 97 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 98 | public ArrayList<String> getValuesOnly() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 99 | ArrayList<String> valueList = new ArrayList<String>(); |
| 100 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 101 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 102 | Log.i(TAG, "" + p.mValue); |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 103 | valueList.add(p.mValue); |
| 104 | } |
| 105 | |
| 106 | return valueList; |
| 107 | } |
| 108 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 109 | public HashMap<String, String> getDetailsHashMap() { |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 110 | HashMap<String, String> map = new HashMap<String, String>(); |
| 111 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 112 | for (AccountDetail.PreferenceEntry p : privateArray) { |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 113 | map.put(p.mKey, p.mValue); |
| 114 | } |
| 115 | |
| 116 | return map; |
| 117 | } |
| 118 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 119 | public String getDetailString(String key) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 120 | String value = ""; |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 121 | |
| 122 | for (AccountDetail.PreferenceEntry p : privateArray) { |
| 123 | if (p.mKey.equals(key)) { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 124 | value = p.mValue; |
| 125 | return value; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | return value; |
| 130 | } |
| 131 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 132 | public void setDetailString(String key, String newValue) { |
| 133 | for (int i = 0; i < privateArray.size(); ++i) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 134 | PreferenceEntry p = privateArray.get(i); |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 135 | if (p.mKey.equals(key)) { |
alision | 5de9178 | 2013-07-10 10:47:30 -0400 | [diff] [blame] | 136 | privateArray.get(i).mValue = newValue; |
| 137 | } |
| 138 | } |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 139 | |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 140 | } |
| 141 | |
Alexandre Lision | 451f2a8 | 2013-11-12 12:55:55 -0500 | [diff] [blame] | 142 | public boolean getDetailBoolean() { |
Alexandre Savard | 6883811 | 2012-10-30 11:34:43 -0400 | [diff] [blame] | 143 | return true; |
Alexandre Savard | f7f9e0b | 2012-10-15 17:24:07 -0400 | [diff] [blame] | 144 | } |
| 145 | } |