• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * ConnectBot: simple, powerful, open-source SSH client for Android
3  * Copyright 2007 Kenny Root, Jeffrey Sharkey
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 package org.connectbot.util;
19 
20 import android.content.Context;
21 import android.preference.DialogPreference;
22 import android.util.AttributeSet;
23 import android.view.View;
24 import android.widget.SeekBar;
25 import android.widget.SeekBar.OnSeekBarChangeListener;
26 
27 /**
28  *
29  */
30 public class VolumePreference extends DialogPreference implements OnSeekBarChangeListener {
31 	/**
32 	 * @param context
33 	 * @param attrs
34 	 */
VolumePreference(Context context, AttributeSet attrs)35 	public VolumePreference(Context context, AttributeSet attrs) {
36 		super(context, attrs);
37 
38 		setupLayout(context, attrs);
39 	}
40 
VolumePreference(Context context, AttributeSet attrs, int defStyle)41 	public VolumePreference(Context context, AttributeSet attrs, int defStyle) {
42 		super(context, attrs, defStyle);
43 
44 		setupLayout(context, attrs);
45 	}
46 
setupLayout(Context context, AttributeSet attrs)47 	private void setupLayout(Context context, AttributeSet attrs) {
48 		setPersistent(true);
49 	}
50 
51 	@Override
onCreateDialogView()52 	protected View onCreateDialogView() {
53 		SeekBar sb = new SeekBar(getContext());
54 
55 		sb.setMax(100);
56 		sb.setProgress((int)(getPersistedFloat(
57 				PreferenceConstants.DEFAULT_BELL_VOLUME) * 100));
58 		sb.setPadding(10, 10, 10, 10);
59 		sb.setOnSeekBarChangeListener(this);
60 
61 		return sb;
62 	}
63 
onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)64 	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
65 		persistFloat(progress / 100f);
66 	}
67 
onStartTrackingTouch(SeekBar seekBar)68 	public void onStartTrackingTouch(SeekBar seekBar) { }
69 
onStopTrackingTouch(SeekBar seekBar)70 	public void onStopTrackingTouch(SeekBar seekBar) { }
71 }
72