FileDocCategorySizeDatePackage
RepeatingImageButton.javaAPI DocAndroid 1.5 API4156Wed May 06 22:42:46 BST 2009com.android.music

RepeatingImageButton

public class RepeatingImageButton extends android.widget.ImageButton
A button that will repeatedly call a 'listener' method as long as the button is pressed.

Fields Summary
private long
mStartTime
private int
mRepeatCount
private RepeatListener
mListener
private long
mInterval
private Runnable
mRepeater
Constructors Summary
public RepeatingImageButton(android.content.Context context)

    
       
        this(context, null);
    
public RepeatingImageButton(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, android.R.attr.imageButtonStyle);
    
public RepeatingImageButton(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
        setFocusable(true);
        setLongClickable(true);
    
Methods Summary
private voiddoRepeat(boolean last)


         
        long now = SystemClock.elapsedRealtime();
        if (mListener != null) {
            mListener.onRepeat(this, now - mStartTime, last ? -1 : mRepeatCount++);
        }
    
public booleanonKeyUp(int keyCode, android.view.KeyEvent event)

        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            // remove the repeater, but call the hook one more time
            removeCallbacks(mRepeater);
            if (mStartTime != 0) {
                doRepeat(true);
                mStartTime = 0;
            }
        }
        return super.onKeyUp(keyCode, event);
    
public booleanonTouchEvent(android.view.MotionEvent event)

        if (event.getAction() == MotionEvent.ACTION_UP) {
            // remove the repeater, but call the hook one more time
            removeCallbacks(mRepeater);
            if (mStartTime != 0) {
                doRepeat(true);
                mStartTime = 0;
            }
        }
        return super.onTouchEvent(event);
    
public booleanperformLongClick()

        mStartTime = SystemClock.elapsedRealtime();
        mRepeatCount = 0;
        post(mRepeater);
        return true;
    
public voidsetRepeatListener(com.android.music.RepeatingImageButton$RepeatListener l, long interval)
Sets the listener to be called while the button is pressed and the interval in milliseconds with which it will be called.

param
l The listener that will be called
param
interval The interval in milliseconds for calls

        mListener = l;
        mInterval = interval;