blob: b2e9ce004e3826786b390abdb0adfdb7ca71f05b [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 Lision4f906b22013-10-02 10:13:45 -040027import android.util.Log;
28
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040029public class AccountDetailBasic implements AccountDetail {
30
Alexandre Lision451f2a82013-11-12 12:55:55 -050031 private static final String TAG = AccountDetailBasic.class.getSimpleName();
Alexandre Savard68838112012-10-30 11:34:43 -040032
Alexandre Lision451f2a82013-11-12 12:55:55 -050033 public static final String CONFIG_ACCOUNT_ALIAS = "Account.alias";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040034 public static final String CONFIG_ACCOUNT_HOSTNAME = "Account.hostname";
35 public static final String CONFIG_ACCOUNT_USERNAME = "Account.username";
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040036 public static final String CONFIG_ACCOUNT_PASSWORD = "Account.password";
Alexandre Lision451f2a82013-11-12 12:55:55 -050037
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040038 public static final String CONFIG_ACCOUNT_USERAGENT = "Account.useragent";
Alexandre Lision451f2a82013-11-12 12:55:55 -050039 public static final String CONFIG_ACCOUNT_ROUTESET = "Account.routeset";
alision5cfc35d2013-07-11 15:11:39 -040040 public static final String CONFIG_ACCOUNT_AUTOANSWER = "Account.autoAnswer";
Alexandre Lision451f2a82013-11-12 12:55:55 -050041
42 public static final String CONFIG_ACCOUNT_REALM = "Account.realm";
alision5cfc35d2013-07-11 15:11:39 -040043 public static final String CONFIG_ACCOUNT_TYPE = "Account.type";
alision5cfc35d2013-07-11 15:11:39 -040044 public static final String CONFIG_ACCOUNT_ENABLE = "Account.enable";
Alexandre Lision451f2a82013-11-12 12:55:55 -050045
Alexandre Savard68838112012-10-30 11:34:43 -040046 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardae992932012-10-17 10:26:12 -040047
Alexandre Lision451f2a82013-11-12 12:55:55 -050048 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries() {
Alexandre Savardae992932012-10-17 10:26:12 -040049 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
50
Alexandre Lisionab0cc9f2013-12-12 11:27:25 -050051 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ENABLE, true));
52 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_TYPE));
53 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ALIAS));
54 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_HOSTNAME));
55 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERNAME));
56 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ROUTESET));
57 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_PASSWORD));
58 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_AUTOANSWER, true));
59 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_REALM));
60 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERAGENT));
Alexandre Savardae992932012-10-17 10:26:12 -040061
62 return preference;
63 }
64
Alexandre Lision451f2a82013-11-12 12:55:55 -050065 public AccountDetailBasic() {
Alexandre Savard68838112012-10-30 11:34:43 -040066 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040067 }
68
Alexandre Lision451f2a82013-11-12 12:55:55 -050069 public AccountDetailBasic(HashMap<String, String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040070 privateArray = getPreferenceEntries();
71
Alexandre Lision451f2a82013-11-12 12:55:55 -050072 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard68838112012-10-30 11:34:43 -040073 p.mValue = pref.get(p.mKey);
74 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040075 }
76
Alexandre Lision451f2a82013-11-12 12:55:55 -050077 public AccountDetailBasic(ArrayList<String> pref) {
Alexandre Savard68838112012-10-30 11:34:43 -040078 privateArray = getPreferenceEntries();
79
Alexandre Lision451f2a82013-11-12 12:55:55 -050080 if (pref.size() != privateArray.size()) {
Alexandre Savard68838112012-10-30 11:34:43 -040081 Log.i(TAG, "Error list are not of equal size");
Alexandre Lision451f2a82013-11-12 12:55:55 -050082 } else {
83 int index = 0;
84 for (String s : pref) {
85 Log.i(TAG, "Creating " + privateArray.get(index).mKey + " value " + s);
Alexandre Savard68838112012-10-30 11:34:43 -040086 privateArray.get(index).mValue = s;
87 index++;
88 }
89 }
90 }
91
Alexandre Lision451f2a82013-11-12 12:55:55 -050092 public ArrayList<AccountDetail.PreferenceEntry> getDetailValues() {
Alexandre Savard68838112012-10-30 11:34:43 -040093 return privateArray;
94 }
95
Alexandre Lision451f2a82013-11-12 12:55:55 -050096 public ArrayList<String> getValuesOnly() {
Alexandre Savard68838112012-10-30 11:34:43 -040097 ArrayList<String> valueList = new ArrayList<String>();
98
Alexandre Lision451f2a82013-11-12 12:55:55 -050099 for (AccountDetail.PreferenceEntry p : privateArray) {
100 Log.i(TAG, "" + p.mValue);
Alexandre Savard68838112012-10-30 11:34:43 -0400101 valueList.add(p.mValue);
102 }
103
104 return valueList;
105 }
106
Alexandre Lision451f2a82013-11-12 12:55:55 -0500107 public HashMap<String, String> getDetailsHashMap() {
Alexandre Savard833616f2012-10-30 16:02:30 -0400108 HashMap<String, String> map = new HashMap<String, String>();
109
Alexandre Lision451f2a82013-11-12 12:55:55 -0500110 for (AccountDetail.PreferenceEntry p : privateArray) {
Alexandre Savard833616f2012-10-30 16:02:30 -0400111 map.put(p.mKey, p.mValue);
112 }
113
114 return map;
115 }
116
Alexandre Lision451f2a82013-11-12 12:55:55 -0500117 public String getDetailString(String key) {
Alexandre Savard68838112012-10-30 11:34:43 -0400118 String value = "";
Alexandre Lision451f2a82013-11-12 12:55:55 -0500119
120 for (AccountDetail.PreferenceEntry p : privateArray) {
121 if (p.mKey.equals(key)) {
Alexandre Savard68838112012-10-30 11:34:43 -0400122 value = p.mValue;
123 return value;
124 }
125 }
126
127 return value;
128 }
129
Alexandre Lision451f2a82013-11-12 12:55:55 -0500130 public void setDetailString(String key, String newValue) {
131 for (int i = 0; i < privateArray.size(); ++i) {
alision5de91782013-07-10 10:47:30 -0400132 PreferenceEntry p = privateArray.get(i);
Alexandre Lision451f2a82013-11-12 12:55:55 -0500133 if (p.mKey.equals(key)) {
alision5de91782013-07-10 10:47:30 -0400134 privateArray.get(i).mValue = newValue;
135 }
136 }
Alexandre Lision451f2a82013-11-12 12:55:55 -0500137
Alexandre Savard833616f2012-10-30 16:02:30 -0400138 }
139
Alexandre Lision451f2a82013-11-12 12:55:55 -0500140 public boolean getDetailBoolean() {
Alexandre Savard68838112012-10-30 11:34:43 -0400141 return true;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400142 }
143}