package android.view;
+import android.annotation.Nullable;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Paint;
* @param paint The paint used when the layer is drawn into the destination canvas.
* @see View#setLayerPaint(android.graphics.Paint)
*/
- public void setLayerPaint(Paint paint) {
- nSetLayerPaint(mFinalizer.get(), paint.getNativeInstance());
+ public void setLayerPaint(@Nullable Paint paint) {
+ nSetLayerPaint(mFinalizer.get(), paint != null ? paint.getNativeInstance() : 0);
mRenderer.pushLayerUpdate(this);
}
return nSetLayerType(mNativeRenderNode, layerType);
}
- public boolean setLayerPaint(Paint paint) {
+ public boolean setLayerPaint(@Nullable Paint paint) {
return nSetLayerPaint(mNativeRenderNode, paint != null ? paint.getNativeInstance() : 0);
}
package android.view;
+import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
*/
public TextureView(Context context) {
super(context);
- init();
}
/**
*/
public TextureView(Context context, AttributeSet attrs) {
super(context, attrs);
- init();
}
/**
*/
public TextureView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
- init();
}
/**
*/
public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
- init();
- }
-
- private void init() {
- mLayerPaint = new Paint();
}
/**
* method will however be taken into account when rendering the content of
* this TextureView.
*
- * @param layerType The ype of layer to use with this view, must be one of
+ * @param layerType The type of layer to use with this view, must be one of
* {@link #LAYER_TYPE_NONE}, {@link #LAYER_TYPE_SOFTWARE} or
* {@link #LAYER_TYPE_HARDWARE}
* @param paint The paint used to compose the layer. This argument is optional
* {@link #LAYER_TYPE_NONE}
*/
@Override
- public void setLayerType(int layerType, Paint paint) {
- if (paint != mLayerPaint) {
- mLayerPaint = paint == null ? new Paint() : paint;
- invalidate();
- }
+ public void setLayerType(int layerType, @Nullable Paint paint) {
+ setLayerPaint(paint);
}
@Override
- public void setLayerPaint(Paint paint) {
- setLayerType(/* ignored */ 0, paint);
+ public void setLayerPaint(@Nullable Paint paint) {
+ if (paint != mLayerPaint) {
+ mLayerPaint = paint;
+ invalidate();
+ }
}
/**
}
}
- /**
+ /**
* Utility method to retrieve the inverse of the current mMatrix property.
* We cache the matrix to avoid recalculating it when transform properties
* have not changed.
*
* @attr ref android.R.styleable#View_layerType
*/
- public void setLayerType(int layerType, Paint paint) {
+ public void setLayerType(int layerType, @Nullable Paint paint) {
if (layerType < LAYER_TYPE_NONE || layerType > LAYER_TYPE_HARDWARE) {
throw new IllegalArgumentException("Layer type can only be one of: LAYER_TYPE_NONE, "
+ "LAYER_TYPE_SOFTWARE or LAYER_TYPE_HARDWARE");
}
mLayerType = layerType;
- final boolean layerDisabled = (mLayerType == LAYER_TYPE_NONE);
- mLayerPaint = layerDisabled ? null : (paint == null ? new Paint() : paint);
+ mLayerPaint = mLayerType == LAYER_TYPE_NONE ? null : paint;
mRenderNode.setLayerPaint(mLayerPaint);
// draw() behaves differently if we are on a layer, so we need to
*
* @see #setLayerType(int, android.graphics.Paint)
*/
- public void setLayerPaint(Paint paint) {
+ public void setLayerPaint(@Nullable Paint paint) {
int layerType = getLayerType();
if (layerType != LAYER_TYPE_NONE) {
- mLayerPaint = paint == null ? new Paint() : paint;
+ mLayerPaint = paint;
if (layerType == LAYER_TYPE_HARDWARE) {
- if (mRenderNode.setLayerPaint(mLayerPaint)) {
+ if (mRenderNode.setLayerPaint(paint)) {
invalidateViewProperty(false, false);
}
} else {
canvas.drawBitmap(cache, 0.0f, 0.0f, cachePaint);
} else {
// use layer paint to draw the bitmap, merging the two alphas, but also restore
- int layerPaintAlpha = mLayerPaint.getAlpha();
+ int layerPaintAlpha = mLayerPaint != null ? mLayerPaint.getAlpha() : 255;
mLayerPaint.setAlpha((int) (alpha * layerPaintAlpha));
canvas.drawBitmap(cache, 0.0f, 0.0f, mLayerPaint);
mLayerPaint.setAlpha(layerPaintAlpha);