blob: 646f0e0c35d4420ae864a6cc78a92d206c17ef07 [file] [log] [blame]
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -05001/*
2 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@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
Alexandre Lision5f144b82014-02-11 09:59:36 -050032package org.sflphone.fragments;
33
34import android.content.BroadcastReceiver;
35import android.content.Context;
36import android.content.Intent;
37import android.content.IntentFilter;
38import android.os.Bundle;
39import android.support.v4.app.Fragment;
40import android.util.Log;
41import org.sflphone.interfaces.AccountsInterface;
42import org.sflphone.service.ConfigurationManagerCallback;
43
Alexandre Lisiona7ab2e32014-02-14 15:33:33 -050044public abstract class AccountWrapperFragment extends Fragment implements AccountsInterface {
Alexandre Lision5f144b82014-02-11 09:59:36 -050045
46
47 private AccountsReceiver mReceiver;
48
49
50 @Override
51 public void onCreate(Bundle savedInstanceState) {
52 super.onCreate(savedInstanceState);
53 mReceiver = new AccountsReceiver();
54 }
55
56 @Override
57 public void onResume() {
Alexandre Lision48b49eb2014-02-11 13:37:33 -050058 super.onResume();
59 IntentFilter intentFilter = new IntentFilter();
60 intentFilter.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
61 intentFilter.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
Alexandre Lision5f144b82014-02-11 09:59:36 -050062 getActivity().registerReceiver(mReceiver, intentFilter);
63 }
64
65 @Override
66 public void accountsChanged() {
67
68 }
69
70 @Override
Alexandre Lision48b49eb2014-02-11 13:37:33 -050071 public void accountStateChanged(String accoundID, String state, int code) {
Alexandre Lision5f144b82014-02-11 09:59:36 -050072
73 }
74
75
76 @Override
77 public void onPause() {
78 super.onPause();
79 getActivity().unregisterReceiver(mReceiver);
80 }
81
82 public class AccountsReceiver extends BroadcastReceiver {
83
84 private final String TAG = AccountsReceiver.class.getSimpleName();
85
86 @Override
87 public void onReceive(Context context, Intent intent) {
88 if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED)) {
89 Log.i(TAG, "Received" + intent.getAction());
Alexandre Lision48b49eb2014-02-11 13:37:33 -050090 accountStateChanged(intent.getStringExtra("Account"), intent.getStringExtra("state"), intent.getIntExtra("code", 0));
Alexandre Lision5f144b82014-02-11 09:59:36 -050091 } else if (intent.getAction().contentEquals(ConfigurationManagerCallback.ACCOUNTS_CHANGED)) {
92 Log.i(TAG, "Received" + intent.getAction());
93 accountsChanged();
94
95 }
96
97 }
98 }
99
100
101}