blob: 2311674afd6727b8166dec75792e01df0b752a7e [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;
alisiona4325152013-04-19 11:10:03 -040045import com.savoirfairelinux.sflphone.service.ISipService;
alisionf76de3b2013-04-16 15:35:22 -040046
alision5f899632013-04-22 17:26:56 -040047public class AccountSelectionSpinner extends Spinner {
alisiona4325152013-04-19 11:10:03 -040048 private static final String TAG = AccountSelectionSpinner.class.getSimpleName();
49 public static final String DEFAULT_ACCOUNT_ID = "IP2IP";
alisionf76de3b2013-04-16 15:35:22 -040050 private Context mContext;
alisiona4325152013-04-19 11:10:03 -040051 AccountSelectionAdapter mAdapter;
52 ISipService serviceRef;
alisionf76de3b2013-04-16 15:35:22 -040053
54 public AccountSelectionSpinner(Context context) {
55 super(context);
56 mContext = context;
57
58 }
59
60 public AccountSelectionSpinner(Context context, AttributeSet attrs) {
61 super(context, attrs);
62 mContext = context;
63
alisionf76de3b2013-04-16 15:35:22 -040064 }
65
66 public AccountSelectionSpinner(Context context, AttributeSet attrs, int defStyle) {
67 super(context, attrs, defStyle);
68 mContext = context;
alisionf76de3b2013-04-16 15:35:22 -040069
alisionf76de3b2013-04-16 15:35:22 -040070 }
71
72 private AdapterView.OnItemSelectedListener onClick = new AdapterView.OnItemSelectedListener() {
73
74 @Override
alisiona4325152013-04-19 11:10:03 -040075 public void onItemSelected(AdapterView<?> arg0, View view, int pos, long arg3) {
alisionf76de3b2013-04-16 15:35:22 -040076 // public void onClick(DialogInterface dialog, int which) {
77
alisiona4325152013-04-19 11:10:03 -040078 Log.i(TAG, "Selected Account: " + mAdapter.getItem(pos));
79 if (null != view) {
80 ((RadioButton) view.findViewById(R.id.account_checked)).toggle();
81 }
82 mAdapter.setSelectedAccount(pos);
alision5f899632013-04-22 17:26:56 -040083// accountSelectedNotifyAccountList(mAdapter.getItem(pos));
alisionf76de3b2013-04-16 15:35:22 -040084 // setSelection(cursor.getPosition(),true);
85
86 }
87
88 @Override
89 public void onNothingSelected(AdapterView<?> arg0) {
90 // TODO Auto-generated method stub
91
92 }
93
94 };
95
alisiona4325152013-04-19 11:10:03 -040096 public void populate(ISipService service, ArrayList<String> accountList) {
97 Log.i(TAG, "populate");
98 serviceRef = service;
99 mAdapter = new AccountSelectionAdapter(mContext, serviceRef, accountList);
100 setOnItemSelectedListener(onClick);
101 setAdapter(mAdapter);
102 }
alisionf76de3b2013-04-16 15:35:22 -0400103
alision371b77e2013-04-23 14:51:26 -0400104 public String getAccount() {
105 return mAdapter.getSelectedAccount();
106 }
107
alisiond9e29442013-04-17 16:10:18 -0400108 /****************************************
109 * AccountManagementUI Interface
110 ****************************************/
alisiona4325152013-04-19 11:10:03 -0400111
alision5f899632013-04-22 17:26:56 -0400112// @Override
113// public void setAccountList(AccountListReceiver accountList) {
114// Log.i(TAG, "setAccountList");
115// mAccountList = accountList;
116//
117// }
118//
119// @Override
120// public void accountSelectedNotifyAccountList(String accountID) {
121// Log.i(TAG, "->accountSelectedNotifyAccountList");
122// if (mAccountList != null) {
123// mAccountList.accountSelected(accountID, this);
124// }
125// }
126//
127// @Override
128// public void setSelectedAccount(String accountID) {
129// Log.i(TAG, "Account Selected");
130// // setText(accountID);
131// }
132//
133// @Override
134// public void accountAdded(ArrayList<String> newList) {
135// mAdapter = new AccountSelectionAdapter(mContext, serviceRef, newList);
136// setOnItemSelectedListener(onClick);
137// setAdapter(mAdapter);
138// // Log.i(TAG, "Account added");
139// // mList = newList;
140// //
141// // if(newList.size() == 1) {
142// // setText(newList.get(0));
143// // }
144// }
145//
146// @Override
147// public void accountRemoved() {
148// Log.i(TAG, "Account Removed");
149// }
150//
151// @Override
152// public void accountUpdated() {
153// Log.i(TAG, "Account Updated");
154// }
alisiona4325152013-04-19 11:10:03 -0400155
alisionf76de3b2013-04-16 15:35:22 -0400156}