RepeatingImageButtonpublic 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 |
Methods Summary |
---|
private void | doRepeat(boolean last)
long now = SystemClock.elapsedRealtime();
if (mListener != null) {
mListener.onRepeat(this, now - mStartTime, last ? -1 : mRepeatCount++);
}
| public boolean | onKeyUp(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 boolean | onTouchEvent(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 boolean | performLongClick()
mStartTime = SystemClock.elapsedRealtime();
mRepeatCount = 0;
post(mRepeater);
return true;
| public void | setRepeatListener(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.
mListener = l;
mInterval = interval;
|
|