Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -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.client; |
| 32 | |
| 33 | import android.app.AlertDialog; |
| 34 | import android.app.Dialog; |
| 35 | import android.content.Context; |
| 36 | import android.content.DialogInterface; |
| 37 | import android.os.Bundle; |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 38 | import android.util.Log; |
| 39 | import android.view.View; |
| 40 | import android.widget.AdapterView; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 41 | import android.widget.ArrayAdapter; |
| 42 | import android.widget.ListView; |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 43 | import android.widget.TextView; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 44 | |
| 45 | import java.util.ArrayList; |
| 46 | |
Alexandre Savard | 5ea84ae | 2012-10-31 16:41:44 -0400 | [diff] [blame] | 47 | import com.savoirfairelinux.sflphone.utils.AccountSelectionButton; |
| 48 | |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 49 | public class AccountSelectionDialog extends AlertDialog |
| 50 | { |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 51 | private static final String TAG = "AccountSelectionDialog"; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 52 | Context mContext; |
| 53 | ListView mListView; |
| 54 | ArrayAdapter mListAdapter; |
| 55 | ArrayList<String> mItems; |
Alexandre Savard | 5ea84ae | 2012-10-31 16:41:44 -0400 | [diff] [blame] | 56 | AccountSelectionButton mButton; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 57 | |
Alexandre Savard | 5ea84ae | 2012-10-31 16:41:44 -0400 | [diff] [blame] | 58 | public AccountSelectionDialog(Context context, ArrayList<String> items, AccountSelectionButton b) |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 59 | { |
| 60 | super(context); |
| 61 | mContext = context; |
| 62 | mItems = items; |
Alexandre Savard | 5ea84ae | 2012-10-31 16:41:44 -0400 | [diff] [blame] | 63 | mButton = b; |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 64 | } |
| 65 | |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 66 | private AdapterView.OnItemClickListener onClick = new AdapterView.OnItemClickListener() |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 67 | { |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 68 | // public void onClick(DialogInterface dialog, int which) { |
| 69 | public void onItemClick (AdapterView<?> parent, View view, int position, long id) { |
| 70 | Log.i(TAG, "Selected Account: " + ((TextView)view).getText()); |
Alexandre Savard | 5ea84ae | 2012-10-31 16:41:44 -0400 | [diff] [blame] | 71 | mButton.setText(((TextView)view).getText()); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 72 | } |
| 73 | }; |
| 74 | |
| 75 | public void onCreate(Bundle savedInstanceState) |
| 76 | { |
| 77 | mListView = new ListView(mContext); |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 78 | |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 79 | mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, mItems.toArray()); |
Alexandre Savard | cf15b94 | 2012-10-31 16:27:46 -0400 | [diff] [blame] | 80 | |
| 81 | mListView.setOnItemClickListener(onClick); |
Alexandre Savard | 817dc50 | 2012-10-22 11:47:29 -0400 | [diff] [blame] | 82 | mListView.setAdapter(mListAdapter); |
| 83 | setContentView(mListView); |
| 84 | } |
| 85 | |
| 86 | public Dialog onCreateDialog(Bundle savedInstanceState) |
| 87 | { |
| 88 | AlertDialog.Builder builder = new AlertDialog.Builder(mContext); |
| 89 | builder.setTitle("Account Selection"); |
| 90 | |
| 91 | return builder.create(); |
| 92 | } |
| 93 | } |