blob: 6562d28a1d66220c742d94d0baf90c057e7b24de [file] [log] [blame]
Alexandre Savarddcd37402012-09-06 18:36:48 -04001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
Alexandre Savarddcd37402012-09-06 18:36:48 -04003 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
alision2ec64f92013-06-17 17:28:58 -04005 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Alexandre Savarddcd37402012-09-06 18:36:48 -04006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * Additional permission under GNU GPL version 3 section 7:
22 *
23 * If you modify this program, or any covered work, by linking or
24 * combining it with the OpenSSL project's OpenSSL library (or a
25 * modified version of that library), containing parts covered by the
26 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
27 * grants you additional permission to convey the resulting work.
28 * Corresponding Source for a non-source form of such a combination
29 * shall include the source code for the parts of OpenSSL used as well
30 * as that of the covered work.
31 */
32
Alexandre Lision064e1e02013-10-01 16:18:42 -040033package org.sflphone.fragments;
34
Alexandre Lision4cb73f52014-02-06 15:14:19 -050035import java.io.File;
36import java.net.URI;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040037import java.util.ArrayList;
38
Alexandre Lision4cb73f52014-02-06 15:14:19 -050039import android.content.Intent;
40import android.database.Cursor;
41import android.net.Uri;
Alexandre Lision064e1e02013-10-01 16:18:42 -040042import org.sflphone.R;
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050043import org.sflphone.account.AccountDetail;
Alexandre Lision4cb73f52014-02-06 15:14:19 -050044import org.sflphone.account.AccountDetailAdvanced;
45import org.sflphone.account.AccountDetailBasic;
46import org.sflphone.account.AccountDetailTls;
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050047import org.sflphone.model.Account;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040048import org.sflphone.model.Codec;
49import org.sflphone.service.ISipService;
Alexandre Lisionc1849932013-10-24 10:09:32 -040050import org.sflphone.views.dragsortlv.DragSortListView;
Alexandre Savarddcd37402012-09-06 18:36:48 -040051
Alexandre Savard393ccab2012-09-11 15:01:20 -040052import android.app.Activity;
Alexandre Savard5e0b9472012-09-11 17:56:30 -040053import android.content.Context;
Alexandre Lision6e8931e2013-09-19 16:49:34 -040054import android.os.Bundle;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040055import android.os.RemoteException;
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050056import android.preference.CheckBoxPreference;
Alexandre Savard393ccab2012-09-11 15:01:20 -040057import android.preference.Preference;
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050058import android.preference.Preference.OnPreferenceChangeListener;
Alexandre Savard393ccab2012-09-11 15:01:20 -040059import android.preference.PreferenceFragment;
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050060import android.util.Log;
Alexandre Lisionc1849932013-10-24 10:09:32 -040061import android.view.LayoutInflater;
Alexandre Savarddcd37402012-09-06 18:36:48 -040062import android.view.View;
Alexandre Lisiona3650992013-11-13 14:19:35 -050063import android.view.View.MeasureSpec;
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050064import android.view.ViewGroup;
Alexandre Lisionc1849932013-10-24 10:09:32 -040065import android.widget.AdapterView;
66import android.widget.AdapterView.OnItemClickListener;
67import android.widget.BaseAdapter;
68import android.widget.CheckBox;
Alexandre Lisiona3650992013-11-13 14:19:35 -050069import android.widget.LinearLayout;
70import android.widget.ListAdapter;
71import android.widget.ListView;
Alexandre Savard5e0b9472012-09-11 17:56:30 -040072import android.widget.TextView;
Alexandre Savarddcd37402012-09-06 18:36:48 -040073
Alexandre Lision933ef0a2013-10-15 17:28:40 -040074public class AudioManagementFragment extends PreferenceFragment {
Alexandre Lisiona3650992013-11-13 14:19:35 -050075 static final String TAG = AudioManagementFragment.class.getSimpleName();
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040076
Alexandre Lision933ef0a2013-10-15 17:28:40 -040077 protected Callbacks mCallbacks = sDummyCallbacks;
78 ArrayList<Codec> codecs;
Alexandre Lisionc9c30b72013-11-18 16:27:26 -050079 private DragSortListView mCodecList;
Alexandre Lisiona3650992013-11-13 14:19:35 -050080 CodecAdapter listAdapter;
Alexandre Lision933ef0a2013-10-15 17:28:40 -040081 private static Callbacks sDummyCallbacks = new Callbacks() {
82
83 @Override
84 public ISipService getService() {
85 return null;
86 }
87
88 @Override
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050089 public Account getAccount() {
Alexandre Lision933ef0a2013-10-15 17:28:40 -040090 return null;
91 }
92
93 };
94
95 public interface Callbacks {
96
97 public ISipService getService();
98
Alexandre Lision68ee0ac2013-12-06 15:06:19 -050099 public Account getAccount();
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400100
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400101 }
Alexandre Savarddcd37402012-09-06 18:36:48 -0400102
103 @Override
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400104 public void onAttach(Activity activity) {
105 super.onAttach(activity);
106 if (!(activity instanceof Callbacks)) {
107 throw new IllegalStateException("Activity must implement fragment's callbacks.");
108 }
109
110 mCallbacks = (Callbacks) activity;
111 try {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500112 codecs = (ArrayList<Codec>) mCallbacks.getService().getAudioCodecList(mCallbacks.getAccount().getAccountID());
Alexandre Lision4b4233a2013-10-16 17:24:17 -0400113 mCallbacks.getService().getRingtoneList();
Alexandre Lision933ef0a2013-10-15 17:28:40 -0400114 } catch (RemoteException e) {
115 e.printStackTrace();
116 }
117 }
118
119 @Override
120 public void onDetach() {
121 super.onDetach();
122 mCallbacks = sDummyCallbacks;
123 }
124
Alexandre Lisionc1849932013-10-24 10:09:32 -0400125 private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() {
126 @Override
127 public void drop(int from, int to) {
128 if (from != to) {
129 Codec item = listAdapter.getItem(from);
130 listAdapter.remove(item);
131 listAdapter.insert(item, to);
Alexandre Lision4df961d2013-10-16 13:44:49 -0400132 try {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500133 mCallbacks.getService().setActiveCodecList(getActiveCodecList(), mCallbacks.getAccount().getAccountID());
Alexandre Lision4df961d2013-10-16 13:44:49 -0400134 } catch (RemoteException e) {
135 e.printStackTrace();
136 }
Alexandre Lisionc1849932013-10-24 10:09:32 -0400137 }
138 }
139 };
Alexandre Lisiona3650992013-11-13 14:19:35 -0500140
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500141 private ListView mPrefsList;
142
Alexandre Lisionc1849932013-10-24 10:09:32 -0400143 public ArrayList<String> getActiveCodecList() {
144 ArrayList<String> results = new ArrayList<String>();
145 for (int i = 0; i < listAdapter.getCount(); ++i) {
146 if (listAdapter.getItem(i).isEnabled()) {
147 results.add(listAdapter.getItem(i).getPayload().toString());
148 }
149 }
150 return results;
151 }
Alexandre Lisiona3650992013-11-13 14:19:35 -0500152
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500153 private static final int SELECT_RINGTONE_PATH = 40;
154 private Preference.OnPreferenceClickListener filePickerListener = new Preference.OnPreferenceClickListener() {
155 @Override
156 public boolean onPreferenceClick(Preference preference) {
157 performFileSearch(SELECT_RINGTONE_PATH);
158 return true;
159 }
160 };
161
162 @Override
163 public void onActivityResult(int requestCode, int resultCode, Intent data) {
164 super.onActivityResult(requestCode, resultCode, data);
165 if (resultCode == Activity.RESULT_CANCELED)
166 return;
167
168 File myFile = new File(data.getData().getPath());
169 Log.i(TAG, "file selected:" + data.getData());
170 if (requestCode == SELECT_RINGTONE_PATH) {
171 findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_PATH).setSummary(myFile.getName());
172 mCallbacks.getAccount().getAdvancedDetails().setDetailString(AccountDetailAdvanced.CONFIG_RINGTONE_PATH, myFile.getAbsolutePath());
173 mCallbacks.getAccount().notifyObservers();
174 }
175
176 }
177
178 public void performFileSearch(int requestCodeToSet) {
179 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
180 intent.addCategory(Intent.CATEGORY_OPENABLE);
181 intent.setType("audio/*");
182 startActivityForResult(intent, requestCodeToSet);
183 }
184
Alexandre Lisionc1849932013-10-24 10:09:32 -0400185 @Override
Alexandre Lisiona3650992013-11-13 14:19:35 -0500186 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Alexandre Lisionc1849932013-10-24 10:09:32 -0400187 super.onCreateView(inflater, container, savedInstanceState);
Alexandre Lisiona3650992013-11-13 14:19:35 -0500188 View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.frag_audio_mgmt, null);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500189
190 mPrefsList = (ListView) rootView.findViewById(android.R.id.list);
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500191 mCodecList = (DragSortListView) rootView.findViewById(R.id.dndlistview);
192 mCodecList.setAdapter(listAdapter);
193 mCodecList.setDropListener(onDrop);
194 mCodecList.setOnItemClickListener(new OnItemClickListener() {
Alexandre Lisionc1849932013-10-24 10:09:32 -0400195
196 @Override
197 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
198 listAdapter.getItem(pos).toggleState();
199 listAdapter.notifyDataSetChanged();
200 try {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500201 mCallbacks.getService().setActiveCodecList(getActiveCodecList(), mCallbacks.getAccount().getAccountID());
Alexandre Lisionc1849932013-10-24 10:09:32 -0400202 } catch (RemoteException e) {
203 e.printStackTrace();
204 }
205
Alexandre Lision4df961d2013-10-16 13:44:49 -0400206 }
207 });
Alexandre Lisionc1849932013-10-24 10:09:32 -0400208 return rootView;
209 }
210
211 @Override
Alexandre Lisiona3650992013-11-13 14:19:35 -0500212 public void onViewCreated(View view, Bundle savedInstanceState) {
213 super.onViewCreated(view, savedInstanceState);
214 final LinearLayout holder = (LinearLayout) getView().findViewById(R.id.lv_holder);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500215 final LinearLayout holder_prefs = (LinearLayout) getView().findViewById(R.id.lv_holder_prefs);
Alexandre Lisiona3650992013-11-13 14:19:35 -0500216 holder.post(new Runnable() {
217
218 @Override
219 public void run() {
Alexandre Lisionc9c30b72013-11-18 16:27:26 -0500220 setListViewHeight(mCodecList, holder);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500221 setListViewHeight(mPrefsList, holder_prefs);
Alexandre Lisiona3650992013-11-13 14:19:35 -0500222 }
223 });
224
225 }
226
227 // Sets the ListView holder's height
228 public void setListViewHeight(ListView listView, LinearLayout llMain) {
229 ListAdapter listAdapter = listView.getAdapter();
230 if (listAdapter == null) {
231 return;
232 }
233
234 int totalHeight = 0;
Alexandre Lision14fa8452014-03-04 15:21:53 -0500235 int firstHeight;
Alexandre Lisiona3650992013-11-13 14:19:35 -0500236 int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST);
237
238 for (int i = 0; i < listAdapter.getCount(); i++) {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500239 View listItem = listAdapter.getView(i, null, listView);
240 listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
241 firstHeight = listItem.getMeasuredHeight();
Alexandre Lisiona3650992013-11-13 14:19:35 -0500242 totalHeight += firstHeight;
243 }
244
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500245 totalHeight += getView().findViewById(R.id.list_header_title).getMeasuredHeight();
Alexandre Lisiona3650992013-11-13 14:19:35 -0500246 LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) llMain.getLayoutParams();
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500247 params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount()));
Alexandre Lisiona3650992013-11-13 14:19:35 -0500248 llMain.setLayoutParams(params);
249 getView().requestLayout();
250 }
251
252 @Override
Alexandre Lisionc1849932013-10-24 10:09:32 -0400253 public void onCreate(Bundle savedInstanceState) {
Alexandre Lisiona3650992013-11-13 14:19:35 -0500254 super.onCreate(savedInstanceState);
255
Alexandre Lisionc48c36a2013-11-12 16:26:10 -0500256 addPreferencesFromResource(R.xml.account_audio_prefs);
Alexandre Lisionc1849932013-10-24 10:09:32 -0400257 listAdapter = new CodecAdapter(getActivity());
258 listAdapter.setDataset(codecs);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500259
260 setPreferenceDetails(mCallbacks.getAccount().getAdvancedDetails());
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500261 findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_PATH).setEnabled(
262 ((CheckBoxPreference) findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED)).isChecked());
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500263 addPreferenceListener(mCallbacks.getAccount().getAdvancedDetails(), changeAudioPreferenceListener);
Alexandre Savarddcd37402012-09-06 18:36:48 -0400264 }
265
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500266 Preference.OnPreferenceChangeListener changeAudioPreferenceListener = new Preference.OnPreferenceChangeListener() {
267 @Override
Alexandre Savard393ccab2012-09-11 15:01:20 -0400268 public boolean onPreferenceChange(Preference preference, Object newValue) {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500269 if (preference instanceof CheckBoxPreference) {
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500270 if (preference.getKey().contentEquals(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED))
271 getPreferenceScreen().findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_PATH).setEnabled((Boolean) newValue);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500272 mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString());
273 } else {
274 preference.setSummary((CharSequence) newValue);
275 Log.i(TAG, "Changing" + preference.getKey() + " value:" + newValue);
276 mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString());
277 }
278 mCallbacks.getAccount().notifyObservers();
279
Alexandre Savard393ccab2012-09-11 15:01:20 -0400280 return true;
281 }
282 };
283
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500284 private void setPreferenceDetails(AccountDetail details) {
285 for (AccountDetail.PreferenceEntry p : details.getDetailValues()) {
286 Log.i(TAG, "setPreferenceDetails: pref " + p.mKey + " value " + p.mValue);
287 Preference pref = findPreference(p.mKey);
288 if (pref != null) {
289 if (!p.isTwoState) {
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500290 if (p.mKey.contentEquals("Account.dtmfType")) {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500291 pref.setDefaultValue(p.mValue.contentEquals("overrtp") ? "RTP" : "SIP");
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500292 pref.setSummary(p.mValue.contentEquals("overrtp") ? "RTP" : "SIP");
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500293 } else {
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500294 if(pref.getKey().contentEquals(AccountDetailAdvanced.CONFIG_RINGTONE_PATH)){
295 File tmp = new File(p.mValue);
296 pref.setSummary(tmp.getName());
297 } else
298 pref.setSummary(p.mValue);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500299 }
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500300
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500301 } else {
302 ((CheckBoxPreference) pref).setChecked(p.mValue.contentEquals("true"));
303 }
304
305 } else {
306 Log.w(TAG, "pref not found");
307 }
308 }
309 }
310
311 private void addPreferenceListener(AccountDetail details, OnPreferenceChangeListener listener) {
312 for (AccountDetail.PreferenceEntry p : details.getDetailValues()) {
313 Log.i(TAG, "addPreferenceListener: pref " + p.mKey + p.mValue);
314 Preference pref = findPreference(p.mKey);
315 if (pref != null) {
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500316 pref.setOnPreferenceChangeListener(listener);
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500317 if (pref.getKey().contentEquals(AccountDetailAdvanced.CONFIG_RINGTONE_PATH))
318 pref.setOnPreferenceClickListener(filePickerListener);
Alexandre Lision68ee0ac2013-12-06 15:06:19 -0500319 } else {
320 Log.w(TAG, "addPreferenceListener: pref not found");
321 }
322 }
323 }
324
Alexandre Lisionc1849932013-10-24 10:09:32 -0400325 public static class CodecAdapter extends BaseAdapter {
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400326
Alexandre Lisionc1849932013-10-24 10:09:32 -0400327 ArrayList<Codec> items;
328 private Context mContext;
329
330 public CodecAdapter(Context context) {
331 items = new ArrayList<Codec>();
332 mContext = context;
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400333 }
334
Alexandre Lisionc1849932013-10-24 10:09:32 -0400335 public void insert(Codec item, int to) {
336 items.add(to, item);
337 notifyDataSetChanged();
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400338 }
339
Alexandre Lisionc1849932013-10-24 10:09:32 -0400340 public void remove(Codec item) {
341 items.remove(item);
342 notifyDataSetChanged();
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400343 }
344
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400345 @Override
Alexandre Lisionc1849932013-10-24 10:09:32 -0400346 public int getCount() {
347 return items.size();
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400348 }
349
Alexandre Lisionc1849932013-10-24 10:09:32 -0400350 @Override
351 public Codec getItem(int position) {
352 return items.get(position);
353 }
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400354
Alexandre Lisionc1849932013-10-24 10:09:32 -0400355 @Override
356 public long getItemId(int position) {
357 return 0;
358 }
359
360 @Override
361 public int getItemViewType(int position) {
362 return 0;
363 }
364
365 @Override
366 public View getView(int pos, View convertView, ViewGroup parent) {
367 View rowView = convertView;
Alexandre Lisionede1a632014-02-11 15:03:42 -0500368 CodecView entryView;
Alexandre Lisionc1849932013-10-24 10:09:32 -0400369
370 if (rowView == null) {
371 LayoutInflater inflater = LayoutInflater.from(mContext);
372 rowView = inflater.inflate(R.layout.item_codec, null);
373
374 entryView = new CodecView();
375 entryView.name = (TextView) rowView.findViewById(R.id.codec_name);
Alexandre Lisionc1849932013-10-24 10:09:32 -0400376 entryView.samplerate = (TextView) rowView.findViewById(R.id.codec_samplerate);
Alexandre Lisionc1849932013-10-24 10:09:32 -0400377 entryView.enabled = (CheckBox) rowView.findViewById(R.id.codec_checked);
378 rowView.setTag(entryView);
379 } else {
380 entryView = (CodecView) rowView.getTag();
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400381 }
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500382
383 if (items.get(pos).isSpeex())
Alexandre Lision423aa132013-12-10 17:31:10 -0500384 entryView.samplerate.setVisibility(View.VISIBLE);
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500385 else
Alexandre Lision423aa132013-12-10 17:31:10 -0500386 entryView.samplerate.setVisibility(View.GONE);
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400387
Alexandre Lisionc1849932013-10-24 10:09:32 -0400388 entryView.name.setText(items.get(pos).getName());
389 entryView.samplerate.setText(items.get(pos).getSampleRate());
Alexandre Lisionc1849932013-10-24 10:09:32 -0400390 entryView.enabled.setChecked(items.get(pos).isEnabled());
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500391
Alexandre Lisionc1849932013-10-24 10:09:32 -0400392 return rowView;
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400393
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400394 }
395
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400396 @Override
Alexandre Lisionc1849932013-10-24 10:09:32 -0400397 public int getViewTypeCount() {
398 return 1;
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400399 }
400
401 @Override
Alexandre Lisionc1849932013-10-24 10:09:32 -0400402 public boolean hasStableIds() {
403 return true;
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400404 }
405
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400406 @Override
Alexandre Lisionc1849932013-10-24 10:09:32 -0400407 public boolean isEmpty() {
408 return getCount() == 0;
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400409 }
410
Alexandre Lisionc1849932013-10-24 10:09:32 -0400411 @Override
412 public boolean areAllItemsEnabled() {
413 return true;
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400414 }
415
Alexandre Lisionc1849932013-10-24 10:09:32 -0400416 @Override
417 public boolean isEnabled(int position) {
418 return true;
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400419 }
420
Alexandre Lisionc1849932013-10-24 10:09:32 -0400421 public void setDataset(ArrayList<Codec> codecs) {
422 items = new ArrayList<Codec>(codecs);
423 }
Alexandre Savarde2bb2592012-09-11 18:39:57 -0400424
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500425 /**
426 * ******************
Alexandre Lisionc1849932013-10-24 10:09:32 -0400427 * ViewHolder Pattern
Alexandre Lision4cb73f52014-02-06 15:14:19 -0500428 * *******************
429 */
Alexandre Lisionc1849932013-10-24 10:09:32 -0400430 public class CodecView {
431 public TextView name;
432 public TextView samplerate;
Alexandre Lisionc1849932013-10-24 10:09:32 -0400433 public CheckBox enabled;
Alexandre Savard5e0b9472012-09-11 17:56:30 -0400434 }
435 }
Alexandre Savarddcd37402012-09-06 18:36:48 -0400436}