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; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 40 | import android.widget.RadioButton; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 41 | import android.widget.Spinner; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 42 | |
| 43 | import com.savoirfairelinux.sflphone.R; |
| 44 | import com.savoirfairelinux.sflphone.adapters.AccountSelectionAdapter; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 45 | import com.savoirfairelinux.sflphone.service.ISipService; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 46 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 47 | public class AccountSelectionSpinner extends Spinner { |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 48 | private static final String TAG = AccountSelectionSpinner.class.getSimpleName(); |
| 49 | public static final String DEFAULT_ACCOUNT_ID = "IP2IP"; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 50 | private Context mContext; |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 51 | AccountSelectionAdapter mAdapter; |
| 52 | ISipService serviceRef; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 53 | |
| 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 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | public AccountSelectionSpinner(Context context, AttributeSet attrs, int defStyle) { |
| 67 | super(context, attrs, defStyle); |
| 68 | mContext = context; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 69 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | private AdapterView.OnItemSelectedListener onClick = new AdapterView.OnItemSelectedListener() { |
| 73 | |
| 74 | @Override |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 75 | public void onItemSelected(AdapterView<?> arg0, View view, int pos, long arg3) { |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 76 | // public void onClick(DialogInterface dialog, int which) { |
| 77 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 78 | 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); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 83 | // accountSelectedNotifyAccountList(mAdapter.getItem(pos)); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 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 | |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 96 | 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 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 103 | |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 104 | public String getAccount() { |
| 105 | return mAdapter.getSelectedAccount(); |
| 106 | } |
| 107 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 108 | /**************************************** |
| 109 | * AccountManagementUI Interface |
| 110 | ****************************************/ |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 111 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 112 | // @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 | // } |
alision | a432515 | 2013-04-19 11:10:03 -0400 | [diff] [blame] | 155 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 156 | } |