Methods Summary |
---|
public void | draw(android.graphics.Canvas canvas)
final boolean needsFadingLow = needsFadingLowEdge();
final boolean needsFadingHigh = needsFadingHighEdge();
if (!needsFadingLow) {
mTempBitmapLow = null;
}
if (!needsFadingHigh) {
mTempBitmapHigh = null;
}
if (!needsFadingLow && !needsFadingHigh) {
super.draw(canvas);
return;
}
int lowEdge = mFadingLowEdge? getPaddingLeft() - mLowFadeShaderOffset - mLowFadeShaderLength : 0;
int highEdge = mFadingHighEdge ? getWidth() - getPaddingRight()
+ mHighFadeShaderOffset + mHighFadeShaderLength : getWidth();
// draw not-fade content
int save = canvas.save();
canvas.clipRect(lowEdge + (mFadingLowEdge ? mLowFadeShaderLength : 0), 0,
highEdge - (mFadingHighEdge ? mHighFadeShaderLength : 0), getHeight());
super.draw(canvas);
canvas.restoreToCount(save);
Canvas tmpCanvas = new Canvas();
mTempRect.top = 0;
mTempRect.bottom = getHeight();
if (needsFadingLow && mLowFadeShaderLength > 0) {
Bitmap tempBitmap = getTempBitmapLow();
tempBitmap.eraseColor(Color.TRANSPARENT);
tmpCanvas.setBitmap(tempBitmap);
// draw original content
int tmpSave = tmpCanvas.save();
tmpCanvas.clipRect(0, 0, mLowFadeShaderLength, getHeight());
tmpCanvas.translate(-lowEdge, 0);
super.draw(tmpCanvas);
tmpCanvas.restoreToCount(tmpSave);
// draw fading out
mTempPaint.setShader(mLowFadeShader);
tmpCanvas.drawRect(0, 0, mLowFadeShaderLength, getHeight(), mTempPaint);
// copy back to canvas
mTempRect.left = 0;
mTempRect.right = mLowFadeShaderLength;
canvas.translate(lowEdge, 0);
canvas.drawBitmap(tempBitmap, mTempRect, mTempRect, null);
canvas.translate(-lowEdge, 0);
}
if (needsFadingHigh && mHighFadeShaderLength > 0) {
Bitmap tempBitmap = getTempBitmapHigh();
tempBitmap.eraseColor(Color.TRANSPARENT);
tmpCanvas.setBitmap(tempBitmap);
// draw original content
int tmpSave = tmpCanvas.save();
tmpCanvas.clipRect(0, 0, mHighFadeShaderLength, getHeight());
tmpCanvas.translate(-(highEdge - mHighFadeShaderLength), 0);
super.draw(tmpCanvas);
tmpCanvas.restoreToCount(tmpSave);
// draw fading out
mTempPaint.setShader(mHighFadeShader);
tmpCanvas.drawRect(0, 0, mHighFadeShaderLength, getHeight(), mTempPaint);
// copy back to canvas
mTempRect.left = 0;
mTempRect.right = mHighFadeShaderLength;
canvas.translate(highEdge - mHighFadeShaderLength, 0);
canvas.drawBitmap(tempBitmap, mTempRect, mTempRect, null);
canvas.translate(-(highEdge - mHighFadeShaderLength), 0);
}
|
public final boolean | getFadingLeftEdge()Return true if fading left edge.
return mFadingLowEdge;
|
public final int | getFadingLeftEdgeLength()Get left edge fading length in pixels.
return mLowFadeShaderLength;
|
public final int | getFadingLeftEdgeOffset()Get distance in pixels between fading start position and left padding edge.
The fading start position is positive when start position is inside left padding
area. Default value is 0, means that the fading starts from left padding edge.
return mLowFadeShaderOffset;
|
public final boolean | getFadingRightEdge()Return true if fading right edge.
return mFadingHighEdge;
|
public final int | getFadingRightEdgeLength()Get right edge fading length in pixels.
return mHighFadeShaderLength;
|
public final int | getFadingRightEdgeOffset()Set distance in pixels between fading start position and right padding edge.
The fading start position is positive when start position is inside right padding
area. Default value is 0, means that the fading starts from right padding edge.
return mHighFadeShaderOffset;
|
private android.graphics.Bitmap | getTempBitmapHigh()
if (mTempBitmapHigh == null
|| mTempBitmapHigh.getWidth() != mHighFadeShaderLength
|| mTempBitmapHigh.getHeight() != getHeight()) {
// TODO: fix logic for sharing mTempBitmapLow
if (false && mTempBitmapLow != null
&& mTempBitmapLow.getWidth() == mHighFadeShaderLength
&& mTempBitmapLow.getHeight() == getHeight()) {
// share same bitmap for low edge fading and high edge fading.
mTempBitmapHigh = mTempBitmapLow;
} else {
mTempBitmapHigh = Bitmap.createBitmap(mHighFadeShaderLength, getHeight(),
Bitmap.Config.ARGB_8888);
}
}
return mTempBitmapHigh;
|
private android.graphics.Bitmap | getTempBitmapLow()
if (mTempBitmapLow == null
|| mTempBitmapLow.getWidth() != mLowFadeShaderLength
|| mTempBitmapLow.getHeight() != getHeight()) {
mTempBitmapLow = Bitmap.createBitmap(mLowFadeShaderLength, getHeight(),
Bitmap.Config.ARGB_8888);
}
return mTempBitmapLow;
|
protected void | initAttributes(android.content.Context context, android.util.AttributeSet attrs)
initBaseGridViewAttributes(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.lbHorizontalGridView);
setRowHeight(a);
setNumRows(a.getInt(R.styleable.lbHorizontalGridView_numberOfRows, 1));
a.recycle();
updateLayerType();
mTempPaint = new Paint();
mTempPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
|
private boolean | needsFadingHighEdge()
if (!mFadingHighEdge) {
return false;
}
final int c = getChildCount();
for (int i = c - 1; i >= 0; i--) {
View view = getChildAt(i);
if (mLayoutManager.getOpticalRight(view) > getWidth()
- getPaddingRight() + mHighFadeShaderOffset) {
return true;
}
}
return false;
|
private boolean | needsFadingLowEdge()
if (!mFadingLowEdge) {
return false;
}
final int c = getChildCount();
for (int i = 0; i < c; i++) {
View view = getChildAt(i);
if (mLayoutManager.getOpticalLeft(view) <
getPaddingLeft() - mLowFadeShaderOffset) {
return true;
}
}
return false;
|
public final void | setFadingLeftEdge(boolean fading)Set fade out left edge to transparent. Note turn on fading edge is very expensive
that you should turn off when HorizontalGridView is scrolling.
if (mFadingLowEdge != fading) {
mFadingLowEdge = fading;
if (!mFadingLowEdge) {
mTempBitmapLow = null;
}
invalidate();
updateLayerType();
}
|
public final void | setFadingLeftEdgeLength(int fadeLength)Set left edge fading length in pixels.
if (mLowFadeShaderLength != fadeLength) {
mLowFadeShaderLength = fadeLength;
if (mLowFadeShaderLength != 0) {
mLowFadeShader = new LinearGradient(0, 0, mLowFadeShaderLength, 0,
Color.TRANSPARENT, Color.BLACK, Shader.TileMode.CLAMP);
} else {
mLowFadeShader = null;
}
invalidate();
}
|
public final void | setFadingLeftEdgeOffset(int fadeOffset)Set distance in pixels between fading start position and left padding edge.
The fading start position is positive when start position is inside left padding
area. Default value is 0, means that the fading starts from left padding edge.
if (mLowFadeShaderOffset != fadeOffset) {
mLowFadeShaderOffset = fadeOffset;
invalidate();
}
|
public final void | setFadingRightEdge(boolean fading)Set fade out right edge to transparent. Note turn on fading edge is very expensive
that you should turn off when HorizontalGridView is scrolling.
if (mFadingHighEdge != fading) {
mFadingHighEdge = fading;
if (!mFadingHighEdge) {
mTempBitmapHigh = null;
}
invalidate();
updateLayerType();
}
|
public final void | setFadingRightEdgeLength(int fadeLength)Set right edge fading length in pixels.
if (mHighFadeShaderLength != fadeLength) {
mHighFadeShaderLength = fadeLength;
if (mHighFadeShaderLength != 0) {
mHighFadeShader = new LinearGradient(0, 0, mHighFadeShaderLength, 0,
Color.BLACK, Color.TRANSPARENT, Shader.TileMode.CLAMP);
} else {
mHighFadeShader = null;
}
invalidate();
}
|
public final void | setFadingRightEdgeOffset(int fadeOffset)Get distance in pixels between fading start position and right padding edge.
The fading start position is positive when start position is inside right padding
area. Default value is 0, means that the fading starts from right padding edge.
if (mHighFadeShaderOffset != fadeOffset) {
mHighFadeShaderOffset = fadeOffset;
invalidate();
}
|
public void | setNumRows(int numRows)Set the number of rows. Defaults to one.
mLayoutManager.setNumRows(numRows);
requestLayout();
|
void | setRowHeight(android.content.res.TypedArray array)
TypedValue typedValue = array.peekValue(R.styleable.lbHorizontalGridView_rowHeight);
int size;
if (typedValue != null && typedValue.type == TypedValue.TYPE_DIMENSION) {
size = array.getDimensionPixelSize(R.styleable.lbHorizontalGridView_rowHeight, 0);
} else {
size = array.getInt(R.styleable.lbHorizontalGridView_rowHeight, 0);
}
setRowHeight(size);
|
public void | setRowHeight(int height)Set the row height.
mLayoutManager.setRowHeight(height);
requestLayout();
|
private void | updateLayerType()Updates the layer type for this view.
If fading edges are needed, use a hardware layer. This works around the problem
that when a child invalidates itself (for example has an animated background),
the parent view must also be invalidated to refresh the display list which
updates the the caching bitmaps used to draw the fading edges.
if (mFadingLowEdge || mFadingHighEdge) {
setLayerType(View.LAYER_TYPE_HARDWARE, null);
setWillNotDraw(false);
} else {
setLayerType(View.LAYER_TYPE_NONE, null);
setWillNotDraw(true);
}
|