blob: b2766edb308823b2ad172b78cb8506ad6e1aa38e [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 */
alisionf76de3b2013-04-16 15:35:22 -040022package com.savoirfairelinux.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 Savard68838112012-10-30 11:34:43 -040027import android.util.Log;
28
Alexandre Lision6e8931e2013-09-19 16:49:34 -040029import com.savoirfairelinux.sflphone.R;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040030
31public class AccountDetailBasic implements AccountDetail {
32
Alexandre Savard68838112012-10-30 11:34:43 -040033 private static final String TAG = "AccountDetailBasic";
34 public static final String BUNDLE_TAG = "BasicPreferenceArrayList";
35
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040036 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 Savardf7f9e0b2012-10-15 17:24:07 -040041 public static final String CONFIG_ACCOUNT_USERAGENT = "Account.useragent";
alision5cfc35d2013-07-11 15:11:39 -040042 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 Savardf7f9e0b2012-10-15 17:24:07 -040052
Alexandre Savard68838112012-10-30 11:34:43 -040053 private ArrayList<AccountDetail.PreferenceEntry> privateArray;
Alexandre Savardae992932012-10-17 10:26:12 -040054
55 public static ArrayList<AccountDetail.PreferenceEntry> getPreferenceEntries()
56 {
57 ArrayList<AccountDetail.PreferenceEntry> preference = new ArrayList<AccountDetail.PreferenceEntry>();
58
Alexandre Savard68838112012-10-30 11:34:43 -040059 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_ENABLE, R.string.account_enabled_label, true));
Alexandre Savardae992932012-10-17 10:26:12 -040060 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 Savardae992932012-10-17 10:26:12 -040062 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 Savardae992932012-10-17 10:26:12 -040067 preference.add(new PreferenceEntry(CONFIG_ACCOUNT_USERAGENT, R.string.account_autoanswer_label));
68
69 return preference;
70 }
71
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040072 public AccountDetailBasic()
73 {
Alexandre Savard68838112012-10-30 11:34:43 -040074 privateArray = getPreferenceEntries();
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040075 }
76
Alexandre Savard68838112012-10-30 11:34:43 -040077 public AccountDetailBasic(HashMap<String, String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040078 {
Alexandre Savard68838112012-10-30 11:34:43 -040079 privateArray = getPreferenceEntries();
80
81 for(AccountDetail.PreferenceEntry p : privateArray) {
82 p.mValue = pref.get(p.mKey);
83 }
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040084 }
85
Alexandre Savard68838112012-10-30 11:34:43 -040086 public AccountDetailBasic(ArrayList<String> pref)
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -040087 {
Alexandre Savard68838112012-10-30 11:34:43 -040088 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) {
alision7f18fc82013-05-01 09:37:33 -040096 Log.i(TAG, "Creating "+privateArray.get(index).mKey+" value "+s);
Alexandre Savard68838112012-10-30 11:34:43 -040097 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) {
alisiond9e29442013-04-17 16:10:18 -0400113 Log.i(TAG,""+p.mValue);
Alexandre Savard68838112012-10-30 11:34:43 -0400114 valueList.add(p.mValue);
115 }
116
117 return valueList;
118 }
119
Alexandre Savard833616f2012-10-30 16:02:30 -0400120 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 Savard68838112012-10-30 11:34:43 -0400131 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
alision5de91782013-07-10 10:47:30 -0400145 public void setDetailString(String key, String newValue)
Alexandre Savard833616f2012-10-30 16:02:30 -0400146 {
alision5de91782013-07-10 10:47:30 -0400147 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 Savard833616f2012-10-30 16:02:30 -0400154 }
155
156
Alexandre Savard68838112012-10-30 11:34:43 -0400157 public boolean getDetailBoolean()
158 {
159 return true;
Alexandre Savardf7f9e0b2012-10-15 17:24:07 -0400160 }
161}