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 | |
| 35 | import android.content.Context; |
| 36 | import android.util.AttributeSet; |
| 37 | import android.util.Log; |
| 38 | import android.view.View; |
| 39 | import android.widget.AdapterView; |
| 40 | import android.widget.ArrayAdapter; |
| 41 | import android.widget.Spinner; |
| 42 | import android.widget.TextView; |
| 43 | |
| 44 | public class AccountSelectionSpinner extends Spinner implements AccountManagementUI { |
| 45 | private static final String TAG = "AccountSelectionButton"; |
| 46 | private Context mContext; |
| 47 | private ArrayList<String> mList = new ArrayList<String>(); |
| 48 | private AccountListReceiver mAccountList = null; |
| 49 | ArrayAdapter mListAdapter; |
| 50 | |
| 51 | public AccountSelectionSpinner(Context context) { |
| 52 | super(context); |
| 53 | mContext = context; |
| 54 | |
| 55 | } |
| 56 | |
| 57 | public AccountSelectionSpinner(Context context, AttributeSet attrs) { |
| 58 | super(context, attrs); |
| 59 | mContext = context; |
| 60 | |
| 61 | |
| 62 | } |
| 63 | |
| 64 | public AccountSelectionSpinner(Context context, AttributeSet attrs, int defStyle) { |
| 65 | super(context, attrs, defStyle); |
| 66 | mContext = context; |
| 67 | mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, mList.toArray()); |
| 68 | |
| 69 | setOnItemSelectedListener(onClick); |
| 70 | setAdapter(mListAdapter); |
| 71 | } |
| 72 | |
| 73 | private AdapterView.OnItemSelectedListener onClick = new AdapterView.OnItemSelectedListener() { |
| 74 | |
| 75 | @Override |
| 76 | public void onItemSelected(AdapterView<?> arg0, View view, int arg2, long arg3) { |
| 77 | // public void onClick(DialogInterface dialog, int which) { |
| 78 | |
| 79 | Log.i(TAG, "Selected Account: " + ((TextView) view).getText()); |
| 80 | // mButton.setText(((TextView)view).getText()); |
| 81 | accountSelectedNotifyAccountList(((TextView) view).getText().toString()); |
| 82 | // setSelection(cursor.getPosition(),true); |
| 83 | |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public void onNothingSelected(AdapterView<?> arg0) { |
| 88 | // TODO Auto-generated method stub |
| 89 | |
| 90 | } |
| 91 | |
| 92 | }; |
| 93 | |
| 94 | |
| 95 | public void setAccountList(AccountListReceiver accountList) { |
| 96 | Log.i(TAG,"setAccountList"); |
| 97 | mAccountList = accountList; |
| 98 | |
| 99 | } |
| 100 | |
| 101 | public void accountSelectedNotifyAccountList(String accountID) { |
| 102 | Log.i(TAG, "->accountSelectedNotifyAccountList"); |
| 103 | if (mAccountList != null) { |
| 104 | mAccountList.accountSelected(accountID, this); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | public void setSelectedAccount(String accountID) { |
| 109 | Log.i(TAG,"Account Selected"); |
| 110 | // setText(accountID); |
| 111 | } |
| 112 | |
| 113 | public void accountAdded(ArrayList<String> newList) { |
| 114 | mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, newList.toArray()); |
| 115 | |
| 116 | setOnItemSelectedListener(onClick); |
| 117 | setAdapter(mListAdapter); |
| 118 | // Log.i(TAG, "Account added"); |
| 119 | // mList = newList; |
| 120 | // |
| 121 | // if(newList.size() == 1) { |
| 122 | // setText(newList.get(0)); |
| 123 | // } |
| 124 | } |
| 125 | |
| 126 | public void accountRemoved() { |
| 127 | Log.i(TAG,"Account Removed"); |
| 128 | } |
| 129 | |
| 130 | public void accountUpdated() { |
| 131 | Log.i(TAG,"Account Updated"); |
| 132 | } |
| 133 | } |