blob: 9642fdf4291c1a3cfa28bd82058d36ae949beb1a [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
alisiond9e29442013-04-17 16:10:18 -040035import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver;
36
alisionf76de3b2013-04-16 15:35:22 -040037import android.content.Context;
38import android.util.AttributeSet;
39import android.util.Log;
40import android.view.View;
41import android.widget.AdapterView;
42import android.widget.ArrayAdapter;
43import android.widget.Spinner;
44import android.widget.TextView;
45
46public class AccountSelectionSpinner extends Spinner implements AccountManagementUI {
47 private static final String TAG = "AccountSelectionButton";
48 private Context mContext;
49 private ArrayList<String> mList = new ArrayList<String>();
50 private AccountListReceiver mAccountList = null;
51 ArrayAdapter mListAdapter;
52
53 public AccountSelectionSpinner(Context context) {
54 super(context);
55 mContext = context;
56
57 }
58
59 public AccountSelectionSpinner(Context context, AttributeSet attrs) {
60 super(context, attrs);
61 mContext = context;
62
63
64 }
65
66 public AccountSelectionSpinner(Context context, AttributeSet attrs, int defStyle) {
67 super(context, attrs, defStyle);
68 mContext = context;
69 mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, mList.toArray());
70
71 setOnItemSelectedListener(onClick);
72 setAdapter(mListAdapter);
73 }
74
75 private AdapterView.OnItemSelectedListener onClick = new AdapterView.OnItemSelectedListener() {
76
77 @Override
78 public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) {
79 // public void onClick(DialogInterface dialog, int which) {
80
81 Log.i(TAG, "Selected Account: " + ((TextView) view).getText());
82 // mButton.setText(((TextView)view).getText());
83 accountSelectedNotifyAccountList(((TextView) view).getText().toString());
84 // 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
96
alisiond9e29442013-04-17 16:10:18 -040097 /****************************************
98 * AccountManagementUI Interface
99 ****************************************/
100
101 @Override
alisionf76de3b2013-04-16 15:35:22 -0400102 public void setAccountList(AccountListReceiver accountList) {
103 Log.i(TAG,"setAccountList");
104 mAccountList = accountList;
105
106 }
107
alisiond9e29442013-04-17 16:10:18 -0400108 @Override
alisionf76de3b2013-04-16 15:35:22 -0400109 public void accountSelectedNotifyAccountList(String accountID) {
110 Log.i(TAG, "->accountSelectedNotifyAccountList");
111 if (mAccountList != null) {
112 mAccountList.accountSelected(accountID, this);
113 }
114 }
115
alisiond9e29442013-04-17 16:10:18 -0400116 @Override
alisionf76de3b2013-04-16 15:35:22 -0400117 public void setSelectedAccount(String accountID) {
118 Log.i(TAG,"Account Selected");
119 // setText(accountID);
120 }
121
alisiond9e29442013-04-17 16:10:18 -0400122 @Override
alisionf76de3b2013-04-16 15:35:22 -0400123 public void accountAdded(ArrayList<String> newList) {
124 mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, newList.toArray());
125
126 setOnItemSelectedListener(onClick);
127 setAdapter(mListAdapter);
128 // Log.i(TAG, "Account added");
129 // mList = newList;
130 //
131 // if(newList.size() == 1) {
132 // setText(newList.get(0));
133 // }
134 }
135
alisiond9e29442013-04-17 16:10:18 -0400136 @Override
alisionf76de3b2013-04-16 15:35:22 -0400137 public void accountRemoved() {
138 Log.i(TAG,"Account Removed");
139 }
140
alisiond9e29442013-04-17 16:10:18 -0400141 @Override
alisionf76de3b2013-04-16 15:35:22 -0400142 public void accountUpdated() {
143 Log.i(TAG,"Account Updated");
144 }
145}