blob: efc617891e835df2f115a18e50d702cc39fc5e77 [file] [log] [blame]
alisionf76de3b2013-04-16 15:35:22 -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 *
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 */
31package com.savoirfairelinux.sflphone.account;
32
33import java.util.ArrayList;
34
35import android.content.Context;
36import android.util.AttributeSet;
37import android.util.Log;
38import android.view.View;
39import android.widget.AdapterView;
alisiona4325152013-04-19 11:10:03 -040040import android.widget.RadioButton;
alisionf76de3b2013-04-16 15:35:22 -040041import android.widget.Spinner;
alisiona4325152013-04-19 11:10:03 -040042
43import com.savoirfairelinux.sflphone.R;
44import com.savoirfairelinux.sflphone.adapters.AccountSelectionAdapter;
45import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver;
46import com.savoirfairelinux.sflphone.service.ISipService;
alisionf76de3b2013-04-16 15:35:22 -040047
alision5f899632013-04-22 17:26:56 -040048public class AccountSelectionSpinner extends Spinner {
alisiona4325152013-04-19 11:10:03 -040049 private static final String TAG = AccountSelectionSpinner.class.getSimpleName();
50 public static final String DEFAULT_ACCOUNT_ID = "IP2IP";
alisionf76de3b2013-04-16 15:35:22 -040051 private Context mContext;
alisionf76de3b2013-04-16 15:35:22 -040052 private AccountListReceiver mAccountList = null;
alisiona4325152013-04-19 11:10:03 -040053 AccountSelectionAdapter mAdapter;
54 ISipService serviceRef;
alisionf76de3b2013-04-16 15:35:22 -040055
56 public AccountSelectionSpinner(Context context) {
57 super(context);
58 mContext = context;
59
60 }
61
62 public AccountSelectionSpinner(Context context, AttributeSet attrs) {
63 super(context, attrs);
64 mContext = context;
65
alisionf76de3b2013-04-16 15:35:22 -040066 }
67
68 public AccountSelectionSpinner(Context context, AttributeSet attrs, int defStyle) {
69 super(context, attrs, defStyle);
70 mContext = context;
alisionf76de3b2013-04-16 15:35:22 -040071
alisionf76de3b2013-04-16 15:35:22 -040072 }
73
74 private AdapterView.OnItemSelectedListener onClick = new AdapterView.OnItemSelectedListener() {
75
76 @Override
alisiona4325152013-04-19 11:10:03 -040077 public void onItemSelected(AdapterView<?> arg0, View view, int pos, long arg3) {
alisionf76de3b2013-04-16 15:35:22 -040078 // public void onClick(DialogInterface dialog, int which) {
79
alisiona4325152013-04-19 11:10:03 -040080 Log.i(TAG, "Selected Account: " + mAdapter.getItem(pos));
81 if (null != view) {
82 ((RadioButton) view.findViewById(R.id.account_checked)).toggle();
83 }
84 mAdapter.setSelectedAccount(pos);
alision5f899632013-04-22 17:26:56 -040085// accountSelectedNotifyAccountList(mAdapter.getItem(pos));
alisionf76de3b2013-04-16 15:35:22 -040086 // setSelection(cursor.getPosition(),true);
87
88 }
89
90 @Override
91 public void onNothingSelected(AdapterView<?> arg0) {
92 // TODO Auto-generated method stub
93
94 }
95
96 };
97
alisiona4325152013-04-19 11:10:03 -040098 public void populate(ISipService service, ArrayList<String> accountList) {
99 Log.i(TAG, "populate");
100 serviceRef = service;
101 mAdapter = new AccountSelectionAdapter(mContext, serviceRef, accountList);
102 setOnItemSelectedListener(onClick);
103 setAdapter(mAdapter);
104 }
alisionf76de3b2013-04-16 15:35:22 -0400105
alisiond9e29442013-04-17 16:10:18 -0400106 /****************************************
107 * AccountManagementUI Interface
108 ****************************************/
alisiona4325152013-04-19 11:10:03 -0400109
alision5f899632013-04-22 17:26:56 -0400110// @Override
111// public void setAccountList(AccountListReceiver accountList) {
112// Log.i(TAG, "setAccountList");
113// mAccountList = accountList;
114//
115// }
116//
117// @Override
118// public void accountSelectedNotifyAccountList(String accountID) {
119// Log.i(TAG, "->accountSelectedNotifyAccountList");
120// if (mAccountList != null) {
121// mAccountList.accountSelected(accountID, this);
122// }
123// }
124//
125// @Override
126// public void setSelectedAccount(String accountID) {
127// Log.i(TAG, "Account Selected");
128// // setText(accountID);
129// }
130//
131// @Override
132// public void accountAdded(ArrayList<String> newList) {
133// mAdapter = new AccountSelectionAdapter(mContext, serviceRef, newList);
134// setOnItemSelectedListener(onClick);
135// setAdapter(mAdapter);
136// // Log.i(TAG, "Account added");
137// // mList = newList;
138// //
139// // if(newList.size() == 1) {
140// // setText(newList.get(0));
141// // }
142// }
143//
144// @Override
145// public void accountRemoved() {
146// Log.i(TAG, "Account Removed");
147// }
148//
149// @Override
150// public void accountUpdated() {
151// Log.i(TAG, "Account Updated");
152// }
alisiona4325152013-04-19 11:10:03 -0400153
alisionf76de3b2013-04-16 15:35:22 -0400154}