Code example for Paint

Methods: getStrokeWidth, setColor, setStyle

0
	private float mRadius = 4;
	private float mRadiusInactive = 4;
	private float mRadiusActive = 4;
	private float spacing = 4;
	private int fadeOutTime = 0;
	private final Paint mPaintInactive = new Paint(Paint.ANTI_ALIAS_FLAG);
	private final Paint mPaintActive = new Paint(Paint.ANTI_ALIAS_FLAG);
	private ViewFlow viewFlow;
	private int currentScroll = 0;
	private int currentPosition = 0;
	private int flowWidth = 0;
	private FadeTimer timer;
	public AnimationListener animationListener = this;
	private Animation animation;
	private boolean mCentered = false;
	private boolean mSnap = false;
 
	/** 
	 * Default constructor 
	 *  
	 * @param context 
	 */ 
	public CircleFlowIndicator(Context context) {
		super(context);
		initColors(0xFFFFFFFF, 0xFFFFFFFF, STYLE_FILL, STYLE_STROKE);
	} 
 
	/** 
	 * The contructor used with an inflater 
	 *  
	 * @param context 
	 * @param attrs 
	 */ 
	public CircleFlowIndicator(Context context, AttributeSet attrs) {
		super(context, attrs);
		// Retrieve styles attributs 
		TypedArray a = context.obtainStyledAttributes(attrs,
				R.styleable.CircleFlowIndicator); 
 
		// Gets the active circle type, defaulting to "fill" 
		int activeType = a.getInt(R.styleable.CircleFlowIndicator_activeType,
				STYLE_FILL);
		 
		int activeDefaultColor = 0xFFFFFFFF;
		 
		// Get a custom active color if there is one 
		int activeColor = a
				.getColor(R.styleable.CircleFlowIndicator_activeColor,
						activeDefaultColor);
 
		// Gets the inactive circle type, defaulting to "stroke" 
		int inactiveType = a.getInt(
				R.styleable.CircleFlowIndicator_inactiveType, STYLE_STROKE);
 
		int inactiveDefaultColor = 0x44FFFFFF;
		// Get a custom inactive color if there is one 
		int inactiveColor = a.getColor(
				R.styleable.CircleFlowIndicator_inactiveColor, 
				inactiveDefaultColor);
 
		// Retrieve the radius 
		mRadius = a.getDimension(R.styleable.CircleFlowIndicator_radius, 4.0f);
		mRadiusActive = mRadius;
		mRadiusInactive = mRadius;
 
		// Retrieve the spacing 
		spacing = a.getDimension(R.styleable.CircleFlowIndicator_spacing, 4.0f);
		// We want the spacing to be center-to-center 
		spacing += 2 * mRadiusActive;
		 
		// Retrieve the fade out time 
		fadeOutTime = a.getInt(R.styleable.CircleFlowIndicator_fadeOut, 0);
		 
		mCentered = a.getBoolean(R.styleable.CircleFlowIndicator_centered, false);
 
		mSnap = a.getBoolean(R.styleable.CircleFlowIndicator_snap, false);
		 
		initColors(activeColor, inactiveColor, activeType, inactiveType);
	} 
 
	private void initColors(int activeColor, int inactiveColor, int activeType,
			int inactiveType) {
		// Select the paint type given the type attr 
		switch (inactiveType) {
		case STYLE_FILL:
			mPaintInactive.setStyle(Style.FILL);
			break; 
		default: 
			mPaintInactive.setStyle(Style.STROKE);
			float strokeWidth = mPaintInactive.getStrokeWidth();
			if (strokeWidth == 0.0f) {
				// It draws in "hairline mode", which is 1 px wide. 
				strokeWidth = 1.0f / getResources().getDisplayMetrics().density;
			} 
			mRadiusInactive -= strokeWidth / 2.0f;
		} 
		mPaintInactive.setColor(inactiveColor);
 
		// Select the paint type given the type attr 
		switch (activeType) {
		case STYLE_STROKE:
			mPaintActive.setStyle(Style.STROKE);
			float strokeWidth = mPaintInactive.getStrokeWidth();
			if (strokeWidth == 0.0f) {
				// It draws in "hairline mode", which is 1 px wide. 
				strokeWidth = 1.0f / getResources().getDisplayMetrics().density;
			} 
			mRadiusActive -= strokeWidth / 2.0f;