Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 1 | /* |
Alexandre Lision | c1024c0 | 2014-01-06 11:12:53 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 5 | * Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 6 | * |
| 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 33 | package org.sflphone.fragments; |
| 34 | |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 35 | import java.io.File; |
| 36 | import java.net.URI; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 37 | import java.util.ArrayList; |
| 38 | |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 39 | import android.content.Intent; |
| 40 | import android.database.Cursor; |
| 41 | import android.net.Uri; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 42 | import org.sflphone.R; |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 43 | import org.sflphone.account.AccountDetail; |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 44 | import org.sflphone.account.AccountDetailAdvanced; |
| 45 | import org.sflphone.account.AccountDetailBasic; |
| 46 | import org.sflphone.account.AccountDetailTls; |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 47 | import org.sflphone.model.Account; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 48 | import org.sflphone.model.Codec; |
| 49 | import org.sflphone.service.ISipService; |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 50 | import org.sflphone.views.dragsortlv.DragSortListView; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 51 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 52 | import android.app.Activity; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 53 | import android.content.Context; |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 54 | import android.os.Bundle; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 55 | import android.os.RemoteException; |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 56 | import android.preference.CheckBoxPreference; |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 57 | import android.preference.Preference; |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 58 | import android.preference.Preference.OnPreferenceChangeListener; |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 59 | import android.preference.PreferenceFragment; |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 60 | import android.util.Log; |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 61 | import android.view.LayoutInflater; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 62 | import android.view.View; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 63 | import android.view.View.MeasureSpec; |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 64 | import android.view.ViewGroup; |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 65 | import android.widget.AdapterView; |
| 66 | import android.widget.AdapterView.OnItemClickListener; |
| 67 | import android.widget.BaseAdapter; |
| 68 | import android.widget.CheckBox; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 69 | import android.widget.LinearLayout; |
| 70 | import android.widget.ListAdapter; |
| 71 | import android.widget.ListView; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 72 | import android.widget.TextView; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 73 | |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 74 | public class AudioManagementFragment extends PreferenceFragment { |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 75 | static final String TAG = AudioManagementFragment.class.getSimpleName(); |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 76 | |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 77 | protected Callbacks mCallbacks = sDummyCallbacks; |
| 78 | ArrayList<Codec> codecs; |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 79 | private DragSortListView mCodecList; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 80 | CodecAdapter listAdapter; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 81 | private static Callbacks sDummyCallbacks = new Callbacks() { |
| 82 | |
| 83 | @Override |
| 84 | public ISipService getService() { |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | @Override |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 89 | public Account getAccount() { |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 90 | return null; |
| 91 | } |
| 92 | |
| 93 | }; |
| 94 | |
| 95 | public interface Callbacks { |
| 96 | |
| 97 | public ISipService getService(); |
| 98 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 99 | public Account getAccount(); |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 100 | |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 101 | } |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 102 | |
| 103 | @Override |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 104 | 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 Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 112 | codecs = (ArrayList<Codec>) mCallbacks.getService().getAudioCodecList(mCallbacks.getAccount().getAccountID()); |
Alexandre Lision | 4b4233a | 2013-10-16 17:24:17 -0400 | [diff] [blame] | 113 | mCallbacks.getService().getRingtoneList(); |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 114 | } catch (RemoteException e) { |
| 115 | e.printStackTrace(); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public void onDetach() { |
| 121 | super.onDetach(); |
| 122 | mCallbacks = sDummyCallbacks; |
| 123 | } |
| 124 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 125 | 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 Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 132 | try { |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 133 | mCallbacks.getService().setActiveCodecList(getActiveCodecList(), mCallbacks.getAccount().getAccountID()); |
Alexandre Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 134 | } catch (RemoteException e) { |
| 135 | e.printStackTrace(); |
| 136 | } |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | }; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 140 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 141 | private ListView mPrefsList; |
| 142 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 143 | 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 Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 152 | |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 153 | 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 Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 185 | @Override |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 186 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 187 | super.onCreateView(inflater, container, savedInstanceState); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 188 | View rootView = LayoutInflater.from(getActivity()).inflate(R.layout.frag_audio_mgmt, null); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 189 | |
| 190 | mPrefsList = (ListView) rootView.findViewById(android.R.id.list); |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 191 | mCodecList = (DragSortListView) rootView.findViewById(R.id.dndlistview); |
| 192 | mCodecList.setAdapter(listAdapter); |
| 193 | mCodecList.setDropListener(onDrop); |
| 194 | mCodecList.setOnItemClickListener(new OnItemClickListener() { |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 195 | |
| 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 Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 201 | mCallbacks.getService().setActiveCodecList(getActiveCodecList(), mCallbacks.getAccount().getAccountID()); |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 202 | } catch (RemoteException e) { |
| 203 | e.printStackTrace(); |
| 204 | } |
| 205 | |
Alexandre Lision | 4df961d | 2013-10-16 13:44:49 -0400 | [diff] [blame] | 206 | } |
| 207 | }); |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 208 | return rootView; |
| 209 | } |
| 210 | |
| 211 | @Override |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 212 | public void onViewCreated(View view, Bundle savedInstanceState) { |
| 213 | super.onViewCreated(view, savedInstanceState); |
| 214 | final LinearLayout holder = (LinearLayout) getView().findViewById(R.id.lv_holder); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 215 | final LinearLayout holder_prefs = (LinearLayout) getView().findViewById(R.id.lv_holder_prefs); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 216 | holder.post(new Runnable() { |
| 217 | |
| 218 | @Override |
| 219 | public void run() { |
Alexandre Lision | c9c30b7 | 2013-11-18 16:27:26 -0500 | [diff] [blame] | 220 | setListViewHeight(mCodecList, holder); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 221 | setListViewHeight(mPrefsList, holder_prefs); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 222 | } |
| 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; |
| 235 | int firstHeight = 0; |
| 236 | int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST); |
| 237 | |
| 238 | for (int i = 0; i < listAdapter.getCount(); i++) { |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 239 | View listItem = listAdapter.getView(i, null, listView); |
| 240 | listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED); |
| 241 | firstHeight = listItem.getMeasuredHeight(); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 242 | totalHeight += firstHeight; |
| 243 | } |
| 244 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 245 | totalHeight += getView().findViewById(R.id.list_header_title).getMeasuredHeight(); |
| 246 | Log.w(TAG, "totalHeight:" + totalHeight); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 247 | |
| 248 | LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) llMain.getLayoutParams(); |
| 249 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 250 | params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount())); |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 251 | llMain.setLayoutParams(params); |
| 252 | getView().requestLayout(); |
| 253 | } |
| 254 | |
| 255 | @Override |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 256 | public void onCreate(Bundle savedInstanceState) { |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 257 | super.onCreate(savedInstanceState); |
| 258 | |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 259 | addPreferencesFromResource(R.xml.account_audio_prefs); |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 260 | listAdapter = new CodecAdapter(getActivity()); |
| 261 | listAdapter.setDataset(codecs); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 262 | |
| 263 | setPreferenceDetails(mCallbacks.getAccount().getAdvancedDetails()); |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 264 | findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_PATH).setEnabled( |
| 265 | ((CheckBoxPreference) findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED)).isChecked()); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 266 | addPreferenceListener(mCallbacks.getAccount().getAdvancedDetails(), changeAudioPreferenceListener); |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 267 | } |
| 268 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 269 | Preference.OnPreferenceChangeListener changeAudioPreferenceListener = new Preference.OnPreferenceChangeListener() { |
| 270 | @Override |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 271 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 272 | if (preference instanceof CheckBoxPreference) { |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 273 | if (preference.getKey().contentEquals(AccountDetailAdvanced.CONFIG_RINGTONE_ENABLED)) |
| 274 | getPreferenceScreen().findPreference(AccountDetailAdvanced.CONFIG_RINGTONE_PATH).setEnabled((Boolean) newValue); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 275 | mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((Boolean) newValue).toString()); |
| 276 | } else { |
| 277 | preference.setSummary((CharSequence) newValue); |
| 278 | Log.i(TAG, "Changing" + preference.getKey() + " value:" + newValue); |
| 279 | mCallbacks.getAccount().getAdvancedDetails().setDetailString(preference.getKey(), ((CharSequence) newValue).toString()); |
| 280 | } |
| 281 | mCallbacks.getAccount().notifyObservers(); |
| 282 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 283 | return true; |
| 284 | } |
| 285 | }; |
| 286 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 287 | private void setPreferenceDetails(AccountDetail details) { |
| 288 | for (AccountDetail.PreferenceEntry p : details.getDetailValues()) { |
| 289 | Log.i(TAG, "setPreferenceDetails: pref " + p.mKey + " value " + p.mValue); |
| 290 | Preference pref = findPreference(p.mKey); |
| 291 | if (pref != null) { |
| 292 | if (!p.isTwoState) { |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 293 | if (p.mKey.contentEquals("Account.dtmfType")) { |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 294 | pref.setDefaultValue(p.mValue.contentEquals("overrtp") ? "RTP" : "SIP"); |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 295 | pref.setSummary(p.mValue.contentEquals("overrtp") ? "RTP" : "SIP"); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 296 | } else { |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 297 | if(pref.getKey().contentEquals(AccountDetailAdvanced.CONFIG_RINGTONE_PATH)){ |
| 298 | File tmp = new File(p.mValue); |
| 299 | pref.setSummary(tmp.getName()); |
| 300 | } else |
| 301 | pref.setSummary(p.mValue); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 302 | } |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 303 | |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 304 | } else { |
| 305 | ((CheckBoxPreference) pref).setChecked(p.mValue.contentEquals("true")); |
| 306 | } |
| 307 | |
| 308 | } else { |
| 309 | Log.w(TAG, "pref not found"); |
| 310 | } |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | private void addPreferenceListener(AccountDetail details, OnPreferenceChangeListener listener) { |
| 315 | for (AccountDetail.PreferenceEntry p : details.getDetailValues()) { |
| 316 | Log.i(TAG, "addPreferenceListener: pref " + p.mKey + p.mValue); |
| 317 | Preference pref = findPreference(p.mKey); |
| 318 | if (pref != null) { |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 319 | pref.setOnPreferenceChangeListener(listener); |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 320 | if (pref.getKey().contentEquals(AccountDetailAdvanced.CONFIG_RINGTONE_PATH)) |
| 321 | pref.setOnPreferenceClickListener(filePickerListener); |
Alexandre Lision | 68ee0ac | 2013-12-06 15:06:19 -0500 | [diff] [blame] | 322 | } else { |
| 323 | Log.w(TAG, "addPreferenceListener: pref not found"); |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 328 | public static class CodecAdapter extends BaseAdapter { |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 329 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 330 | ArrayList<Codec> items; |
| 331 | private Context mContext; |
| 332 | |
| 333 | public CodecAdapter(Context context) { |
| 334 | items = new ArrayList<Codec>(); |
| 335 | mContext = context; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 338 | public void insert(Codec item, int to) { |
| 339 | items.add(to, item); |
| 340 | notifyDataSetChanged(); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 343 | public void remove(Codec item) { |
| 344 | items.remove(item); |
| 345 | notifyDataSetChanged(); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 348 | public ArrayList<Codec> getDataset() { |
| 349 | return items; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | @Override |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 353 | public int getCount() { |
| 354 | return items.size(); |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 357 | @Override |
| 358 | public Codec getItem(int position) { |
| 359 | return items.get(position); |
| 360 | } |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 361 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 362 | @Override |
| 363 | public long getItemId(int position) { |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | @Override |
| 368 | public int getItemViewType(int position) { |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public View getView(int pos, View convertView, ViewGroup parent) { |
| 374 | View rowView = convertView; |
| 375 | CodecView entryView = null; |
| 376 | |
| 377 | if (rowView == null) { |
| 378 | LayoutInflater inflater = LayoutInflater.from(mContext); |
| 379 | rowView = inflater.inflate(R.layout.item_codec, null); |
| 380 | |
| 381 | entryView = new CodecView(); |
| 382 | entryView.name = (TextView) rowView.findViewById(R.id.codec_name); |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 383 | entryView.samplerate = (TextView) rowView.findViewById(R.id.codec_samplerate); |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 384 | entryView.enabled = (CheckBox) rowView.findViewById(R.id.codec_checked); |
| 385 | rowView.setTag(entryView); |
| 386 | } else { |
| 387 | entryView = (CodecView) rowView.getTag(); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 388 | } |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 389 | |
| 390 | if (items.get(pos).isSpeex()) |
Alexandre Lision | 423aa13 | 2013-12-10 17:31:10 -0500 | [diff] [blame] | 391 | entryView.samplerate.setVisibility(View.VISIBLE); |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 392 | else |
Alexandre Lision | 423aa13 | 2013-12-10 17:31:10 -0500 | [diff] [blame] | 393 | entryView.samplerate.setVisibility(View.GONE); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 394 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 395 | entryView.name.setText(items.get(pos).getName()); |
| 396 | entryView.samplerate.setText(items.get(pos).getSampleRate()); |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 397 | entryView.enabled.setChecked(items.get(pos).isEnabled()); |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 398 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 399 | return rowView; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 400 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 403 | @Override |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 404 | public int getViewTypeCount() { |
| 405 | return 1; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | @Override |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 409 | public boolean hasStableIds() { |
| 410 | return true; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 411 | } |
| 412 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 413 | @Override |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 414 | public boolean isEmpty() { |
| 415 | return getCount() == 0; |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 418 | @Override |
| 419 | public boolean areAllItemsEnabled() { |
| 420 | return true; |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 421 | } |
| 422 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 423 | @Override |
| 424 | public boolean isEnabled(int position) { |
| 425 | return true; |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 428 | public void setDataset(ArrayList<Codec> codecs) { |
| 429 | items = new ArrayList<Codec>(codecs); |
| 430 | } |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 431 | |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 432 | /** |
| 433 | * ****************** |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 434 | * ViewHolder Pattern |
Alexandre Lision | 4cb73f5 | 2014-02-06 15:14:19 -0500 | [diff] [blame] | 435 | * ******************* |
| 436 | */ |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 437 | public class CodecView { |
| 438 | public TextView name; |
| 439 | public TextView samplerate; |
Alexandre Lision | c184993 | 2013-10-24 10:09:32 -0400 | [diff] [blame] | 440 | public CheckBox enabled; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 441 | } |
| 442 | } |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 443 | } |