diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-03-03 19:31:44 -0800 |
commit | 9066cfe9886ac131c34d59ed0e2d287b0e3c0087 (patch) | |
tree | d88beb88001f2482911e3d28e43833b50e4b4e97 /core/java/android/widget/SeekBar.java | |
parent | d83a98f4ce9cfa908f5c54bbd70f03eec07e7553 (diff) | |
download | frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.zip frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.gz frameworks_base-9066cfe9886ac131c34d59ed0e2d287b0e3c0087.tar.bz2 |
auto import from //depot/cupcake/@135843
Diffstat (limited to 'core/java/android/widget/SeekBar.java')
-rw-r--r-- | core/java/android/widget/SeekBar.java | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/core/java/android/widget/SeekBar.java b/core/java/android/widget/SeekBar.java new file mode 100644 index 0000000..dfee29b --- /dev/null +++ b/core/java/android/widget/SeekBar.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2006 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.widget; + +import android.content.Context; +import android.util.AttributeSet; + + + +/** + * A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch + * the thumb and drag left or right to set the current progress level or use the arrow keys. + * Placing focusable widgets to the left or right of a SeekBar is discouraged. + * <p> + * Clients of the SeekBar can attach a {@link SeekBar.OnSeekBarChangeListener} to + * be notified of the user's actions. + * + * @attr ref android.R.styleable#SeekBar_thumb + */ +public class SeekBar extends AbsSeekBar { + + /** + * A callback that notifies clients when the progress level has been + * changed. This includes changes that were initiated by the user through a + * touch gesture or arrow key/trackball as well as changes that were initiated + * programmatically. + */ + public interface OnSeekBarChangeListener { + + /** + * Notification that the progress level has changed. Clients can use the fromUser parameter + * to distinguish user-initiated changes from those that occurred programmatically. + * + * @param seekBar The SeekBar whose progress has changed + * @param progress The current progress level. This will be in the range 0..max where max + * was set by {@link ProgressBar#setMax(int)}. (The default value for max is 100.) + * @param fromUser True if the progress change was initiated by the user. + */ + void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser); + + /** + * Notification that the user has started a touch gesture. Clients may want to use this + * to disable advancing the seekbar. + * @param seekBar The SeekBar in which the touch gesture began + */ + void onStartTrackingTouch(SeekBar seekBar); + + /** + * Notification that the user has finished a touch gesture. Clients may want to use this + * to re-enable advancing the seekbar. + * @param seekBar The SeekBar in which the touch gesture began + */ + void onStopTrackingTouch(SeekBar seekBar); + } + + private OnSeekBarChangeListener mOnSeekBarChangeListener; + + public SeekBar(Context context) { + this(context, null); + } + + public SeekBar(Context context, AttributeSet attrs) { + this(context, attrs, com.android.internal.R.attr.seekBarStyle); + } + + public SeekBar(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + void onProgressRefresh(float scale, boolean fromUser) { + super.onProgressRefresh(scale, fromUser); + + if (mOnSeekBarChangeListener != null) { + mOnSeekBarChangeListener.onProgressChanged(this, getProgress(), fromUser); + } + } + + /** + * Sets a listener to receive notifications of changes to the SeekBar's progress level. Also + * provides notifications of when the user starts and stops a touch gesture within the SeekBar. + * + * @param l The seek bar notification listener + * + * @see SeekBar.OnSeekBarChangeListener + */ + public void setOnSeekBarChangeListener(OnSeekBarChangeListener l) { + mOnSeekBarChangeListener = l; + } + + @Override + void onStartTrackingTouch() { + if (mOnSeekBarChangeListener != null) { + mOnSeekBarChangeListener.onStartTrackingTouch(this); + } + } + + @Override + void onStopTrackingTouch() { + if (mOnSeekBarChangeListener != null) { + mOnSeekBarChangeListener.onStopTrackingTouch(this); + } + } + +} |