Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 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 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 33 | package com.savoirfairelinux.sflphone.fragments; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 34 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 35 | import android.app.Activity; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 36 | import android.content.Context; |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 37 | import android.content.res.TypedArray; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 38 | import android.graphics.Typeface; |
| 39 | import android.preference.EditTextPreference; |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 40 | import android.preference.ListPreference; |
| 41 | import android.preference.Preference; |
| 42 | import android.preference.PreferenceCategory; |
| 43 | import android.preference.PreferenceFragment; |
| 44 | import android.preference.PreferenceScreen; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 45 | import android.os.Bundle; |
| 46 | import android.util.Log; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 47 | import android.util.AttributeSet; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 48 | import android.view.View; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 49 | import android.view.ViewGroup; |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 50 | import android.widget.LinearLayout; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 51 | import android.widget.SeekBar; |
| 52 | import android.widget.SeekBar.OnSeekBarChangeListener; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 53 | import android.widget.TextView; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 54 | |
| 55 | import com.savoirfairelinux.sflphone.R; |
| 56 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 57 | public class AudioManagementFragment extends PreferenceFragment |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 58 | { |
| 59 | static final String TAG = "PrefManagementFragment"; |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 60 | static final String CURRENT_VALUE = "Current value:: "; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 61 | |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 62 | public AudioManagementFragment() |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 63 | { |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 64 | } |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 65 | |
| 66 | @Override |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 67 | public void onCreate(Bundle savedInstanceState) |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 68 | { |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 69 | super.onCreate(savedInstanceState); |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 70 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 71 | setPreferenceScreen(getAudioPreferenceScreen()); |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 74 | Preference.OnPreferenceChangeListener changePreferenceListener = new Preference.OnPreferenceChangeListener() { |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 75 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 76 | preference.setSummary(CURRENT_VALUE + (CharSequence)newValue); |
| 77 | return true; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | public PreferenceScreen getAudioPreferenceScreen() |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 82 | { |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 83 | Activity currentContext = getActivity(); |
| 84 | |
| 85 | PreferenceScreen root = getPreferenceManager().createPreferenceScreen(currentContext); |
| 86 | |
| 87 | PreferenceCategory audioPrefCat = new PreferenceCategory(currentContext); |
| 88 | audioPrefCat.setTitle(R.string.audio_preferences); |
| 89 | root.addPreference(audioPrefCat); |
| 90 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 91 | // Codec List |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 92 | ListPreference codecListPref = new ListPreference(currentContext); |
| 93 | codecListPref.setEntries(R.array.audio_codec_list); |
| 94 | codecListPref.setEntryValues(R.array.audio_codec_list_value); |
| 95 | codecListPref.setDialogTitle(R.string.dialogtitle_audio_codec_list); |
| 96 | codecListPref.setPersistent(false); |
| 97 | codecListPref.setTitle(R.string.title_audio_codec_list); |
| 98 | codecListPref.setSummary(CURRENT_VALUE + "PCMU"); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 99 | codecListPref.setOnPreferenceChangeListener(changePreferenceListener); |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 100 | audioPrefCat.addPreference(codecListPref); |
| 101 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 102 | // Ringtone |
| 103 | EditTextPreference audioRingtonePref = new EditTextPreference(currentContext); |
| 104 | audioRingtonePref.setDialogTitle(R.string.dialogtitle_audio_ringtone_field); |
| 105 | audioRingtonePref.setPersistent(false); |
| 106 | audioRingtonePref.setTitle(R.string.title_audio_ringtone_field); |
| 107 | audioRingtonePref.setSummary(CURRENT_VALUE + "path/to/ringtone"); |
| 108 | audioRingtonePref.setOnPreferenceChangeListener(changePreferenceListener); |
| 109 | audioPrefCat.addPreference(audioRingtonePref); |
| 110 | |
| 111 | // Speaker volume seekbar |
| 112 | SeekBarPreference speakerSeekBarPref = new SeekBarPreference(currentContext); |
| 113 | speakerSeekBarPref.setPersistent(false); |
| 114 | speakerSeekBarPref.setTitle("Speaker Volume"); |
Alexandre Savard | 74eccf3 | 2012-09-11 19:12:29 -0400 | [diff] [blame] | 115 | speakerSeekBarPref.setProgress(50); |
| 116 | speakerSeekBarPref.setSummary(CURRENT_VALUE + speakerSeekBarPref.getProgress()); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 117 | audioPrefCat.addPreference(speakerSeekBarPref); |
| 118 | |
| 119 | // Capture volume seekbar |
| 120 | SeekBarPreference captureSeekBarPref = new SeekBarPreference(currentContext); |
| 121 | captureSeekBarPref.setPersistent(false); |
| 122 | captureSeekBarPref.setTitle("Capture Volume"); |
Alexandre Savard | 74eccf3 | 2012-09-11 19:12:29 -0400 | [diff] [blame] | 123 | captureSeekBarPref.setProgress(50); |
| 124 | captureSeekBarPref.setSummary(CURRENT_VALUE + captureSeekBarPref.getProgress()); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 125 | audioPrefCat.addPreference(captureSeekBarPref); |
| 126 | |
| 127 | // Ringtone volume seekbar |
| 128 | SeekBarPreference ringtoneSeekBarPref = new SeekBarPreference(currentContext); |
| 129 | ringtoneSeekBarPref.setPersistent(false); |
| 130 | ringtoneSeekBarPref.setTitle("Ringtone Volume"); |
Alexandre Savard | 74eccf3 | 2012-09-11 19:12:29 -0400 | [diff] [blame] | 131 | ringtoneSeekBarPref.setProgress(50); |
| 132 | ringtoneSeekBarPref.setSummary(CURRENT_VALUE + ringtoneSeekBarPref.getProgress()); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 133 | audioPrefCat.addPreference(ringtoneSeekBarPref); |
| 134 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 135 | return root; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 136 | } |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 137 | |
| 138 | public class SeekBarPreference extends Preference implements OnSeekBarChangeListener |
| 139 | { |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 140 | private SeekBar seekbar; |
| 141 | private int progress; |
| 142 | private int max = 100; |
| 143 | private TextView summary; |
| 144 | private boolean discard; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 145 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 146 | public SeekBarPreference (Context context) |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 147 | { |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 148 | super( context ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 151 | public SeekBarPreference (Context context, AttributeSet attrs) |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 152 | { |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 153 | super( context, attrs ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 156 | public SeekBarPreference (Context context, AttributeSet attrs, int defStyle) |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 157 | { |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 158 | super( context, attrs, defStyle ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 159 | } |
| 160 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 161 | protected View onCreateView (ViewGroup p) |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 162 | { |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 163 | final Context ctx = getContext(); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 164 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 165 | LinearLayout layout = new LinearLayout( ctx ); |
| 166 | layout.setId( android.R.id.widget_frame ); |
| 167 | layout.setOrientation( LinearLayout.VERTICAL ); |
Alexandre Savard | 74eccf3 | 2012-09-11 19:12:29 -0400 | [diff] [blame] | 168 | layout.setPadding(65, 10, 15, 10); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 169 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 170 | TextView title = new TextView( ctx ); |
| 171 | int textColor = title.getCurrentTextColor(); |
| 172 | title.setId( android.R.id.title ); |
| 173 | title.setSingleLine(); |
Alexandre Savard | 74eccf3 | 2012-09-11 19:12:29 -0400 | [diff] [blame] | 174 | title.setTextAppearance( ctx, android.R.style.TextAppearance_Medium ); |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 175 | title.setTextColor( textColor ); |
| 176 | layout.addView( title ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 177 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 178 | summary = new TextView( ctx ); |
| 179 | summary.setId( android.R.id.summary ); |
| 180 | summary.setSingleLine(); |
| 181 | summary.setTextAppearance( ctx, android.R.style.TextAppearance_Small ); |
| 182 | summary.setTextColor( textColor ); |
| 183 | layout.addView( summary ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 184 | |
Alexandre Savard | 616c380 | 2012-09-12 09:44:46 -0400 | [diff] [blame] | 185 | seekbar = new SeekBar( ctx ); |
| 186 | seekbar.setId( android.R.id.progress ); |
| 187 | seekbar.setMax( max ); |
| 188 | seekbar.setOnSeekBarChangeListener( this ); |
| 189 | layout.addView( seekbar ); |
| 190 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 191 | return layout; |
| 192 | } |
| 193 | |
| 194 | @Override |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 195 | protected void onBindView (View view) |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 196 | { |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 197 | super.onBindView( view ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 198 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 199 | if (seekbar != null) |
| 200 | seekbar.setProgress( progress ); |
| 201 | } |
| 202 | |
| 203 | public void setProgress (int pcnt) { |
| 204 | if (progress != pcnt) { |
| 205 | persistInt( progress = pcnt ); |
| 206 | |
| 207 | notifyDependencyChange( shouldDisableDependents() ); |
| 208 | notifyChanged(); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 209 | } |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 210 | } |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 211 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 212 | public int getProgress () { |
| 213 | return progress; |
| 214 | } |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 215 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 216 | public void setMax (int max) { |
| 217 | this.max = max; |
| 218 | if (seekbar != null) |
| 219 | seekbar.setMax( max ); |
| 220 | } |
| 221 | |
| 222 | private SeekBar getSeekBar () { |
| 223 | return seekbar; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | @Override |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 227 | protected Object onGetDefaultValue (TypedArray a, int index) { |
| 228 | return a.getInt( index, progress ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Override |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 232 | protected void onSetInitialValue (boolean restoreValue, Object defaultValue) { |
| 233 | setProgress( restoreValue ? getPersistedInt( progress ) : (Integer)defaultValue ); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 236 | @Override |
| 237 | public boolean shouldDisableDependents () { |
| 238 | return progress == 0 || super.shouldDisableDependents(); |
| 239 | } |
| 240 | |
| 241 | public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) { |
| 242 | discard = !callChangeListener( progress ); |
Alexandre Savard | 74eccf3 | 2012-09-11 19:12:29 -0400 | [diff] [blame] | 243 | summary.setText(CURRENT_VALUE + progress); |
Alexandre Savard | e2bb259 | 2012-09-11 18:39:57 -0400 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | public void onStartTrackingTouch (SeekBar seekBar) { |
| 247 | discard = false; |
| 248 | } |
| 249 | |
| 250 | public void onStopTrackingTouch (SeekBar seekBar) { |
| 251 | if (discard) |
| 252 | seekBar.setProgress( progress ); |
| 253 | else { |
| 254 | setProgress( seekBar.getProgress() ); |
| 255 | |
| 256 | OnPreferenceChangeListener listener = getOnPreferenceChangeListener(); |
| 257 | //if (listener instanceof AbstractSeekBarListener) |
| 258 | //// setSummary( ((AbstractSeekBarListener)listener).toSummary( seekBar.getProgress() ) ); |
| 259 | } |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame] | 260 | } |
| 261 | } |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 262 | } |