Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2010-2012 Regis Montoya (aka r3gis - www.r3gis.fr) |
| 3 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 4 | * |
| 5 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
| 6 | * |
| 7 | * This program is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * If you own a pjsip commercial license you can also redistribute it |
| 12 | * and/or modify it under the terms of the GNU Lesser General Public License |
| 13 | * as an android library. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | package com.savoirfairelinux.sflphone.service; |
| 24 | |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
| 27 | import android.support.v4.content.LocalBroadcastManager; |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 28 | import android.util.Log; |
| 29 | |
| 30 | public class ConfigurationManagerCallback extends ConfigurationCallback { |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 31 | private static final String TAG = "ConfigurationManagerCallback"; |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 32 | private Context mContext; |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 33 | |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 34 | static public final String SIGNAL_NAME = "signal-name"; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 35 | static public final String ACCOUNTS_LOADED = "accounts-loaded"; |
| 36 | static public final String ACCOUNTS_CHANGED = "accounts-changed"; |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 37 | static public final String ACCOUNT_STATE_CHANGED = "account-state-changed"; |
| 38 | |
Alexandre Savard | 74c1cad | 2012-10-24 16:39:00 -0400 | [diff] [blame] | 39 | public ConfigurationManagerCallback(Context context) { |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 40 | mContext = context; |
| 41 | } |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 42 | |
| 43 | @Override |
| 44 | public void on_account_state_changed() { |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 45 | sendAccountsChangedMessage(); |
| 46 | } |
| 47 | |
| 48 | private void sendAccountsChangedMessage() { |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 49 | Log.d(TAG, "Broadcast Accounts Changed signal"); |
| 50 | Intent intent = new Intent(ACCOUNTS_CHANGED); |
| 51 | intent.putExtra(SIGNAL_NAME, ACCOUNTS_CHANGED); |
Alexandre Savard | 4f11d7a | 2012-10-18 13:15:36 -0400 | [diff] [blame] | 52 | intent.putExtra("message", "Accounts Changed"); |
| 53 | LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 54 | } |
Alexandre Savard | bb6f187 | 2012-11-01 17:25:55 -0400 | [diff] [blame] | 55 | |
| 56 | private void sendAccountStateChangedMessage() { |
| 57 | Log.d(TAG, "Broadcast Account State Changed signal"); |
| 58 | Intent intent = new Intent(ACCOUNT_STATE_CHANGED); |
| 59 | intent.putExtra(SIGNAL_NAME, ACCOUNTS_CHANGED); |
| 60 | intent.putExtra("message", "Account State Changed"); |
| 61 | LocalBroadcastManager.getInstance(mContext).sendBroadcast(intent); |
| 62 | } |
Alexandre Savard | fccd1dc | 2012-10-17 17:31:38 -0400 | [diff] [blame] | 63 | } |