Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 31 | |
| 32 | package com.savoirfairelinux.sflphone.client; |
| 33 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 34 | import android.app.Activity; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 35 | import android.content.Context; |
| 36 | import android.graphics.Typeface; |
| 37 | import android.preference.EditTextPreference; |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 38 | import android.preference.ListPreference; |
| 39 | import android.preference.Preference; |
| 40 | import android.preference.PreferenceCategory; |
| 41 | import android.preference.PreferenceFragment; |
| 42 | import android.preference.PreferenceScreen; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 43 | import android.os.Bundle; |
| 44 | import android.util.Log; |
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 | 9a93f06 | 2012-09-11 10:42:43 -0400 | [diff] [blame] | 48 | import android.widget.ArrayAdapter; |
| 49 | import android.widget.ListView; |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 50 | import android.widget.SeekBar; |
| 51 | import android.widget.SeekBar.OnSeekBarChangeListener; |
| 52 | import android.widget.RelativeLayout; |
| 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 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 57 | public class PrefManagementFragment 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 | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 61 | |
| 62 | @Override |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 63 | public void onCreate(Bundle savedInstanceState) |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 64 | { |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 65 | super.onCreate(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 | setPreferenceScreen(getAudioPreferenceScreen()); |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 68 | } |
| 69 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 70 | Preference.OnPreferenceChangeListener changePreferenceListener = new Preference.OnPreferenceChangeListener() { |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 71 | public boolean onPreferenceChange(Preference preference, Object newValue) { |
| 72 | preference.setSummary(CURRENT_VALUE + (CharSequence)newValue); |
| 73 | return true; |
| 74 | } |
| 75 | }; |
| 76 | |
| 77 | public PreferenceScreen getAudioPreferenceScreen() |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 78 | { |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 79 | Activity currentContext = getActivity(); |
| 80 | |
| 81 | PreferenceScreen root = getPreferenceManager().createPreferenceScreen(currentContext); |
| 82 | |
| 83 | PreferenceCategory audioPrefCat = new PreferenceCategory(currentContext); |
| 84 | audioPrefCat.setTitle(R.string.audio_preferences); |
| 85 | root.addPreference(audioPrefCat); |
| 86 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 87 | // Codec List |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 88 | ListPreference codecListPref = new ListPreference(currentContext); |
| 89 | codecListPref.setEntries(R.array.audio_codec_list); |
| 90 | codecListPref.setEntryValues(R.array.audio_codec_list_value); |
| 91 | codecListPref.setDialogTitle(R.string.dialogtitle_audio_codec_list); |
| 92 | codecListPref.setPersistent(false); |
| 93 | codecListPref.setTitle(R.string.title_audio_codec_list); |
| 94 | codecListPref.setSummary(CURRENT_VALUE + "PCMU"); |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 95 | codecListPref.setOnPreferenceChangeListener(changePreferenceListener); |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 96 | audioPrefCat.addPreference(codecListPref); |
| 97 | |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 98 | // Ringtone |
| 99 | EditTextPreference audioRingtonePref = new EditTextPreference(currentContext); |
| 100 | audioRingtonePref.setDialogTitle(R.string.dialogtitle_audio_ringtone_field); |
| 101 | audioRingtonePref.setPersistent(false); |
| 102 | audioRingtonePref.setTitle(R.string.title_audio_ringtone_field); |
| 103 | audioRingtonePref.setSummary(CURRENT_VALUE + "path/to/ringtone"); |
| 104 | audioRingtonePref.setOnPreferenceChangeListener(changePreferenceListener); |
| 105 | audioPrefCat.addPreference(audioRingtonePref); |
| 106 | |
| 107 | // Speaker volume seekbar |
| 108 | SeekBarPreference speakerSeekBarPref = new SeekBarPreference(currentContext); |
| 109 | speakerSeekBarPref.setPersistent(false); |
| 110 | speakerSeekBarPref.setTitle("Speaker Volume"); |
| 111 | speakerSeekBarPref.setSummary("Set the volume for speaker"); |
| 112 | audioPrefCat.addPreference(speakerSeekBarPref); |
| 113 | |
| 114 | // Capture volume seekbar |
| 115 | SeekBarPreference captureSeekBarPref = new SeekBarPreference(currentContext); |
| 116 | captureSeekBarPref.setPersistent(false); |
| 117 | captureSeekBarPref.setTitle("Capture Volume"); |
| 118 | captureSeekBarPref.setSummary("Set the volume for microphone"); |
| 119 | audioPrefCat.addPreference(captureSeekBarPref); |
| 120 | |
| 121 | // Ringtone volume seekbar |
| 122 | SeekBarPreference ringtoneSeekBarPref = new SeekBarPreference(currentContext); |
| 123 | ringtoneSeekBarPref.setPersistent(false); |
| 124 | ringtoneSeekBarPref.setTitle("Ringtone Volume"); |
| 125 | ringtoneSeekBarPref.setSummary("Set the volume for ringtone"); |
| 126 | audioPrefCat.addPreference(ringtoneSeekBarPref); |
| 127 | |
Alexandre Savard | 393ccab | 2012-09-11 15:01:20 -0400 | [diff] [blame] | 128 | return root; |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 129 | } |
Alexandre Savard | 5e0b947 | 2012-09-11 17:56:30 -0400 | [diff] [blame^] | 130 | |
| 131 | public class SeekBarPreference extends Preference implements OnSeekBarChangeListener |
| 132 | { |
| 133 | public int MAXIMUM = 100; |
| 134 | public int INTERVAL = 5; |
| 135 | private float oldValue = 25; |
| 136 | private TextView Indicator; |
| 137 | |
| 138 | public SeekBarPreference(Context context) |
| 139 | { |
| 140 | super(context); |
| 141 | } |
| 142 | |
| 143 | public SeekBarPreference(Context context, AttributeSet attrs) |
| 144 | { |
| 145 | super(context, attrs); |
| 146 | } |
| 147 | |
| 148 | public SeekBarPreference(Context context, AttributeSet attrs, int defStyle) |
| 149 | { |
| 150 | super(context, attrs, defStyle); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | protected View onCreateView(ViewGroup parent) |
| 155 | { |
| 156 | float scale = getContext().getResources().getDisplayMetrics().density; |
| 157 | |
| 158 | RelativeLayout layout = new RelativeLayout(getContext()); |
| 159 | |
| 160 | RelativeLayout.LayoutParams textParams = new RelativeLayout.LayoutParams( |
| 161 | RelativeLayout.LayoutParams.WRAP_CONTENT, |
| 162 | RelativeLayout.LayoutParams.WRAP_CONTENT); |
| 163 | |
| 164 | RelativeLayout.LayoutParams sbarParams = new RelativeLayout.LayoutParams( |
| 165 | Math.round(scale * 160), |
| 166 | RelativeLayout.LayoutParams.WRAP_CONTENT); |
| 167 | |
| 168 | RelativeLayout.LayoutParams indParams = new RelativeLayout.LayoutParams( |
| 169 | RelativeLayout.LayoutParams.WRAP_CONTENT, |
| 170 | RelativeLayout.LayoutParams.WRAP_CONTENT); |
| 171 | |
| 172 | TextView preferenceText = new TextView(getContext()); |
| 173 | preferenceText.setId(0); |
| 174 | preferenceText.setText(getTitle()); |
| 175 | preferenceText.setTextSize(18); |
| 176 | preferenceText.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD); |
| 177 | |
| 178 | SeekBar sbar = new SeekBar(getContext()); |
| 179 | sbar.setId(1); |
| 180 | sbar.setMax(MAXIMUM); |
| 181 | sbar.setProgress((int)this.oldValue); |
| 182 | sbar.setOnSeekBarChangeListener(this); |
| 183 | |
| 184 | this.Indicator = new TextView(getContext()); |
| 185 | this.Indicator.setTextSize(12); |
| 186 | this.Indicator.setTypeface(Typeface.MONOSPACE, Typeface.ITALIC); |
| 187 | this.Indicator.setText("" + sbar.getProgress()); |
| 188 | |
| 189 | textParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); |
| 190 | sbarParams.addRule(RelativeLayout.RIGHT_OF, preferenceText.getId()); |
| 191 | indParams.setMargins(Math.round(20*scale), 0, 0, 0); |
| 192 | indParams.addRule(RelativeLayout.RIGHT_OF, sbar.getId()); |
| 193 | |
| 194 | preferenceText.setLayoutParams(textParams); |
| 195 | sbar.setLayoutParams(sbarParams); |
| 196 | this.Indicator.setLayoutParams(indParams); |
| 197 | layout.addView(preferenceText); |
| 198 | layout.addView(this.Indicator); |
| 199 | layout.addView(sbar); |
| 200 | layout.setId(android.R.id.widget_frame); |
| 201 | |
| 202 | return layout; |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) |
| 207 | { |
| 208 | progress = Math.round(((float) progress)/INTERVAL) * INTERVAL; |
| 209 | |
| 210 | if(!callChangeListener(progress)) { |
| 211 | seekBar.setProgress((int) this.oldValue); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | seekBar.setProgress(progress); |
| 216 | this.oldValue = progress; |
| 217 | this.Indicator.setText("" + progress); |
| 218 | updatePreference(progress); |
| 219 | |
| 220 | notifyChanged(); |
| 221 | } |
| 222 | |
| 223 | @Override |
| 224 | public void onStartTrackingTouch(SeekBar seekBar) |
| 225 | { |
| 226 | } |
| 227 | |
| 228 | @Override |
| 229 | public void onStopTrackingTouch(SeekBar seekBar) |
| 230 | { |
| 231 | } |
| 232 | |
| 233 | private void updatePreference(int newValue) { |
| 234 | // SharedPreference.Editor editor = getEditor(); |
| 235 | // editor.putInt(getKey(), newValue); |
| 236 | // editor.commit(); |
| 237 | } |
| 238 | } |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 239 | } |