alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 31 | package com.savoirfairelinux.sflphone.account; |
| 32 | |
| 33 | import java.util.ArrayList; |
| 34 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 35 | import com.savoirfairelinux.sflphone.client.receiver.AccountListReceiver; |
| 36 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 37 | import android.content.Context; |
| 38 | import android.util.AttributeSet; |
| 39 | import android.util.Log; |
| 40 | import android.view.View; |
| 41 | import android.widget.AdapterView; |
| 42 | import android.widget.ArrayAdapter; |
| 43 | import android.widget.Spinner; |
| 44 | import android.widget.TextView; |
| 45 | |
| 46 | public 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 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 97 | /**************************************** |
| 98 | * AccountManagementUI Interface |
| 99 | ****************************************/ |
| 100 | |
| 101 | @Override |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 102 | public void setAccountList(AccountListReceiver accountList) { |
| 103 | Log.i(TAG,"setAccountList"); |
| 104 | mAccountList = accountList; |
| 105 | |
| 106 | } |
| 107 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 108 | @Override |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 109 | public void accountSelectedNotifyAccountList(String accountID) { |
| 110 | Log.i(TAG, "->accountSelectedNotifyAccountList"); |
| 111 | if (mAccountList != null) { |
| 112 | mAccountList.accountSelected(accountID, this); |
| 113 | } |
| 114 | } |
| 115 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 116 | @Override |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 117 | public void setSelectedAccount(String accountID) { |
| 118 | Log.i(TAG,"Account Selected"); |
| 119 | // setText(accountID); |
| 120 | } |
| 121 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 122 | @Override |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 123 | 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 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 136 | @Override |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 137 | public void accountRemoved() { |
| 138 | Log.i(TAG,"Account Removed"); |
| 139 | } |
| 140 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame^] | 141 | @Override |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 142 | public void accountUpdated() { |
| 143 | Log.i(TAG,"Account Updated"); |
| 144 | } |
| 145 | } |