Alexandre Savard | 14323be | 2012-10-24 10:02:13 -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 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | |
| 32 | package com.savoirfairelinux.sflphone.utils; |
| 33 | |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 34 | import android.content.BroadcastReceiver; |
| 35 | import android.content.Intent; |
| 36 | import android.content.Context; |
| 37 | import android.os.RemoteException; |
| 38 | import android.util.Log; |
| 39 | |
| 40 | import java.util.ArrayList; |
| 41 | |
| 42 | import com.savoirfairelinux.sflphone.service.ConfigurationManagerCallback; |
| 43 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 44 | |
| 45 | public class AccountList extends BroadcastReceiver |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 46 | { |
| 47 | static final String TAG = "AccountList"; |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 48 | private String currentAccountID = ""; |
| 49 | private ArrayList<String> mList = new ArrayList<String>(); |
| 50 | private ArrayList<AccountManagementUI> mUserInterfaceList = new ArrayList<AccountManagementUI>(); |
| 51 | private ISipService mService; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 52 | // private HashMap<String, AccountPreferenceScreen> mAccountList = new HashMap<String, AccountPreferenceScreen>(); |
| 53 | |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 54 | public static final String DEFAULT_ACCOUNT_ID = "IP2IP"; |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 55 | |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 56 | public AccountList() { |
| 57 | } |
| 58 | |
| 59 | public void setSipService(ISipService service) { |
| 60 | mService = service; |
| 61 | mList = getAccountListFromService(); |
| 62 | } |
| 63 | |
| 64 | |
| 65 | public void addManagementUI(AccountManagementUI ui) { |
| 66 | mUserInterfaceList.add(ui); |
| 67 | } |
| 68 | |
Alexandre Savard | af0f3c6 | 2012-11-01 18:35:56 -0400 | [diff] [blame] | 69 | public void accountSelected(String accountID, AccountManagementUI userInterface) { |
| 70 | if(!mUserInterfaceList.isEmpty()) { |
| 71 | for(AccountManagementUI ui : mUserInterfaceList) { |
| 72 | ui.setSelectedAccount(accountID); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 77 | @Override |
| 78 | public void onReceive(Context context, Intent intent) |
| 79 | { |
| 80 | String signalName = intent.getStringExtra(ConfigurationManagerCallback.SIGNAL_NAME); |
| 81 | Log.d(TAG, "Signal received: " + signalName); |
| 82 | |
| 83 | if(signalName.equals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) { |
| 84 | processAccountsChangedSignal(intent); |
| 85 | } else if(signalName.equals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) { |
| 86 | processAccountStateChanged(intent); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private ArrayList<String> getAccountListFromService() { |
| 91 | ArrayList<String> list = null; |
| 92 | |
| 93 | try { |
| 94 | list = (ArrayList<String>)mService.getAccountList(); |
| 95 | } |
| 96 | catch (RemoteException e) { |
| 97 | Log.e(TAG, "Remote exception", e); |
| 98 | } |
| 99 | |
| 100 | list.remove(DEFAULT_ACCOUNT_ID); |
| 101 | |
| 102 | return list; |
| 103 | } |
| 104 | |
| 105 | |
| 106 | private void processAccountsChangedSignal(Intent intent) { |
| 107 | ArrayList<String> newList = getAccountListFromService(); |
| 108 | |
| 109 | Log.i(TAG, "Process AccountsChanged signal in AccountList"); |
| 110 | |
| 111 | newList.remove(DEFAULT_ACCOUNT_ID); |
| 112 | |
| 113 | if(!mUserInterfaceList.isEmpty()) { |
| 114 | |
| 115 | if(newList.size() > mList.size()) { |
| 116 | for(AccountManagementUI ui : mUserInterfaceList) { |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 117 | ui.accountAdded(newList); |
| 118 | } |
| 119 | } |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | mList = newList; |
| 123 | } |
| 124 | |
| 125 | private void processAccountStateChanged(Intent intent) { |
| 126 | if(!mUserInterfaceList.isEmpty()) { |
| 127 | } |
Alexandre Savard | 14323be | 2012-10-24 10:02:13 -0400 | [diff] [blame] | 128 | } |
| 129 | } |