Methods Summary |
---|
void | ensureRectVisible()
getRectForRow(mTempRect, mSelectedRow);
requestRectangleOnScreen(mTempRect);
|
public void | getFocusedRect(android.graphics.Rect r)
getRectForRow(r, mSelectedRow);
|
public java.lang.String | getLabel()
return mLabel;
|
public int | getNumRows()
return mNumRows;
|
public void | getRectForRow(android.graphics.Rect rect, int row)
final int rowHeight = getRowHeight();
final int top = mPaddingTop + row * rowHeight;
rect.set(mPaddingLeft,
top,
getWidth() - mPaddingRight,
top + rowHeight);
|
private int | getRowHeight()
return (getHeight() - mPaddingTop - mPaddingBottom) / mNumRows;
|
public int | getSelectedRow()
return mSelectedRow;
|
private void | init()
setFocusable(true);
mTextPaint.setAntiAlias(true);
mTextPaint.setTextSize(10);
mTextPaint.setColor(Color.WHITE);
|
private int | measureHeight(int measureSpec)
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
int desiredHeight = mDesiredHeight != null ?
mDesiredHeight :
mNumRows * mEstimatedPixelHeight + mPaddingTop + mPaddingBottom;
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
return specSize;
} else if (specMode == MeasureSpec.AT_MOST) {
return desiredHeight < specSize ? desiredHeight : specSize;
} else {
return desiredHeight;
}
|
private int | measureWidth(int measureSpec)
int specMode = MeasureSpec.getMode(measureSpec);
int specSize = MeasureSpec.getSize(measureSpec);
int desiredWidth = 300 + mPaddingLeft + mPaddingRight;
if (specMode == MeasureSpec.EXACTLY) {
// We were told how big to be
return specSize;
} else if (specMode == MeasureSpec.AT_MOST) {
return desiredWidth < specSize ? desiredWidth : specSize;
} else {
return desiredWidth;
}
|
protected void | onDraw(android.graphics.Canvas canvas)
int rowHeight = getRowHeight();
int rectTop = mPaddingTop;
int rectLeft = mPaddingLeft;
int rectRight = getWidth() - mPaddingRight;
for (int i = 0; i < mNumRows; i++) {
mPainter.setColor(Color.BLACK);
mPainter.setAlpha(0x20);
// draw background rect
mTempRect.set(rectLeft, rectTop, rectRight, rectTop + rowHeight);
canvas.drawRect(mTempRect, mPainter);
// draw forground rect
if (i == mSelectedRow && hasFocus()) {
mPainter.setColor(Color.RED);
mPainter.setAlpha(0xF0);
mTextPaint.setAlpha(0xFF);
} else {
mPainter.setColor(Color.BLACK);
mPainter.setAlpha(0x40);
mTextPaint.setAlpha(0xF0);
}
mTempRect.set(rectLeft + 2, rectTop + 2,
rectRight - 2, rectTop + rowHeight - 2);
canvas.drawRect(mTempRect, mPainter);
// draw text to help when visually inspecting
canvas.drawText(
Integer.toString(i),
rectLeft + 2,
rectTop + 2 - (int) mTextPaint.ascent(),
mTextPaint);
rectTop += rowHeight;
}
|
protected void | onFocusChanged(boolean focused, int direction, android.graphics.Rect previouslyFocusedRect)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (focused) {
switch (direction) {
case View.FOCUS_DOWN:
mSelectedRow = 0;
break;
case View.FOCUS_UP:
mSelectedRow = mNumRows - 1;
break;
case View.FOCUS_LEFT: // fall through
case View.FOCUS_RIGHT:
// set the row that is closest to the rect
if (previouslyFocusedRect != null) {
int y = previouslyFocusedRect.top
+ (previouslyFocusedRect.height() / 2);
int yPerRow = getHeight() / mNumRows;
mSelectedRow = y / yPerRow;
} else {
mSelectedRow = 0;
}
break;
default:
// can't gleam any useful information about what internal
// selection should be...
return;
}
invalidate();
}
|
public boolean | onKeyDown(int keyCode, android.view.KeyEvent event)
switch(event.getKeyCode()) {
case KeyEvent.KEYCODE_DPAD_UP:
if (mSelectedRow > 0) {
mSelectedRow--;
invalidate();
ensureRectVisible();
return true;
}
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
if (mSelectedRow < (mNumRows - 1)) {
mSelectedRow++;
invalidate();
ensureRectVisible();
return true;
}
break;
}
return false;
|
protected void | onMeasure(int widthMeasureSpec, int heightMeasureSpec)
setMeasuredDimension(
measureWidth(widthMeasureSpec),
measureHeight(heightMeasureSpec));
|
public void | setDesiredHeight(int desiredHeight)
mDesiredHeight = desiredHeight;
|
public java.lang.String | toString()
if (mLabel != null) {
return mLabel;
}
return super.toString();
|