blob: f2c13c85b913cbf118ddfb8b5b28f4be43e4c35a [file] [log] [blame]
Alexandre Savard817dc502012-10-22 11:47:29 -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.client;
32
33import android.app.AlertDialog;
34import android.app.Dialog;
35import android.content.Context;
36import android.content.DialogInterface;
37import android.os.Bundle;
Alexandre Savardcf15b942012-10-31 16:27:46 -040038import android.util.Log;
39import android.view.View;
40import android.widget.AdapterView;
Alexandre Savard817dc502012-10-22 11:47:29 -040041import android.widget.ArrayAdapter;
42import android.widget.ListView;
Alexandre Savardcf15b942012-10-31 16:27:46 -040043import android.widget.TextView;
Alexandre Savard817dc502012-10-22 11:47:29 -040044
45import java.util.ArrayList;
46
Alexandre Savard5ea84ae2012-10-31 16:41:44 -040047import com.savoirfairelinux.sflphone.utils.AccountSelectionButton;
48
Alexandre Savard817dc502012-10-22 11:47:29 -040049public class AccountSelectionDialog extends AlertDialog
50{
Alexandre Savardcf15b942012-10-31 16:27:46 -040051 private static final String TAG = "AccountSelectionDialog";
Alexandre Savard817dc502012-10-22 11:47:29 -040052 Context mContext;
53 ListView mListView;
54 ArrayAdapter mListAdapter;
55 ArrayList<String> mItems;
Alexandre Savard5ea84ae2012-10-31 16:41:44 -040056 AccountSelectionButton mButton;
Alexandre Savard817dc502012-10-22 11:47:29 -040057
Alexandre Savard5ea84ae2012-10-31 16:41:44 -040058 public AccountSelectionDialog(Context context, ArrayList<String> items, AccountSelectionButton b)
Alexandre Savard817dc502012-10-22 11:47:29 -040059 {
60 super(context);
61 mContext = context;
62 mItems = items;
Alexandre Savard5ea84ae2012-10-31 16:41:44 -040063 mButton = b;
Alexandre Savard817dc502012-10-22 11:47:29 -040064 }
65
Alexandre Savardcf15b942012-10-31 16:27:46 -040066 private AdapterView.OnItemClickListener onClick = new AdapterView.OnItemClickListener()
Alexandre Savard817dc502012-10-22 11:47:29 -040067 {
Alexandre Savardcf15b942012-10-31 16:27:46 -040068 // 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 Savard5ea84ae2012-10-31 16:41:44 -040071 mButton.setText(((TextView)view).getText());
Alexandre Savard817dc502012-10-22 11:47:29 -040072 }
73 };
74
75 public void onCreate(Bundle savedInstanceState)
76 {
77 mListView = new ListView(mContext);
Alexandre Savardcf15b942012-10-31 16:27:46 -040078
Alexandre Savard817dc502012-10-22 11:47:29 -040079 mListAdapter = new ArrayAdapter(mContext, android.R.layout.simple_expandable_list_item_1, mItems.toArray());
Alexandre Savardcf15b942012-10-31 16:27:46 -040080
81 mListView.setOnItemClickListener(onClick);
Alexandre Savard817dc502012-10-22 11:47:29 -040082 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}