If you think the Android project cube-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package in.srain.cube.views;
//fromwww.java2s.comimport android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
import in.srain.cube.R;
publicclass MoreActionView extends View {
privateint mColor = 0xFFFFFFFF;
private Paint mPaint;
privatefloat mDotRadius = 3;
privatefloat mDotSpan = 5;
public MoreActionView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.MoreActionView, 0, 0);
if (arr != null) {
if (arr.hasValue(R.styleable.MoreActionView_more_action_dot_radius)) {
mDotRadius = arr.getDimension(R.styleable.MoreActionView_more_action_dot_radius, mDotRadius);
}
if (arr.hasValue(R.styleable.MoreActionView_more_action_dot_span)) {
mDotSpan = (int) arr.getDimension(R.styleable.MoreActionView_more_action_dot_span, mDotSpan);
}
mColor = arr.getColor(R.styleable.MoreActionView_more_action_dot_color, mColor);
arr.recycle();
}
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(mColor);
}
@Override
protectedvoid onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int desiredHeight = (int) (mDotRadius * 2);
int desiredWidth = (int) (mDotRadius * 6 + mDotSpan * 2);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int heightMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSize = MeasureSpec.getSize(heightMeasureSpec);
int width;
int height;
// Measure Width
if (widthMode == MeasureSpec.EXACTLY) {
// Must be this size
width = widthSize;
} elseif (widthMode == MeasureSpec.AT_MOST) {
// Can't be bigger than...
width = Math.min(desiredWidth, widthSize);
} else {
// Be whatever you want
width = desiredWidth;
}
// Measure Height
if (heightMode == MeasureSpec.EXACTLY) {
// Must be this size
height = heightSize;
} elseif (heightMode == MeasureSpec.AT_MOST) {
// Can't be bigger than...
height = Math.min(desiredHeight, heightSize);
} else {
// Be whatever you want
height = desiredHeight;
}
// MUST CALL THIS
setMeasuredDimension(width, height);
}
@Override
protectedvoid onDraw(Canvas canvas) {
super.onDraw(canvas);
for (int i = 0; i < 3; i++) {
float x = i * (mDotRadius * 2 + mDotSpan) + mDotRadius;
canvas.drawCircle(x, mDotRadius, mDotRadius, mPaint);
}
}
}