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