Last active
August 29, 2015 14:09
-
-
Save leeuwte/43621d29efb6383751e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package x.y.z; | |
import android.content.Context; | |
import android.graphics.*; | |
import android.util.AttributeSet; | |
import android.widget.ImageView; | |
/** | |
* Created by Benny de Leeuw on 13-11-14. | |
* | |
* A Vertical Metro Line O---O---O---O (but than vertical...) | |
* | |
*/ | |
public class StageView extends ImageView { | |
public StageView(Context context) { | |
super(context); | |
} | |
public StageView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public StageView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
public boolean showTopLine = true; | |
public boolean showBottomLine = true; | |
public boolean isActive = false; | |
public int activeStageColor = Color.GREEN; | |
public int activeStageStrokeColor = Color.BLUE; | |
public int activeStrokeSize = 10; | |
public int inactiveStageColor = Color.LTGRAY; | |
public int inactiveStageStrokeColor = Color.DKGRAY; | |
public int inActiveStrokeSize = 10; | |
public int lineColor = Color.DKGRAY; | |
@Override | |
protected void onDraw(Canvas canvas) { | |
ScaleType scaleType = getScaleType(); | |
float radius = (float) this.getWidth() / 2f; | |
float circleX = this.getWidth() / 2f; | |
float circleY = this.getHeight() / 2f; | |
if (scaleType == ScaleType.FIT_START) { | |
circleY = radius; | |
} else if (scaleType == ScaleType.FIT_END) { | |
circleY = this.getHeight() - radius; | |
} | |
showTopLine &= (scaleType != ScaleType.FIT_START); | |
showBottomLine &= (scaleType != ScaleType.FIT_END); | |
float lineX = this.getWidth() / 2f; | |
float lineStartY = showTopLine ? 0 : circleY; | |
float lineStopY = showBottomLine ? this.getHeight() : circleY; | |
Paint pLine = new Paint(); | |
pLine.setColor(lineColor); | |
pLine.setAntiAlias(true); | |
if (lineStartY != lineStopY) { | |
canvas.drawRect(lineX - 10, lineStartY, lineX + 10, lineStopY, pLine); | |
} | |
int strokeSize = 0; | |
if (!isActive && inActiveStrokeSize > 0) { | |
Paint pStroke = new Paint(); | |
pStroke.setColor(inactiveStageStrokeColor); | |
pStroke.setAntiAlias(true); | |
canvas.drawCircle(circleX, circleY, radius, pStroke); | |
strokeSize = inActiveStrokeSize; | |
} | |
if (isActive && activeStrokeSize > 0) { | |
Paint pStroke = new Paint(); | |
pStroke.setColor(activeStageStrokeColor); | |
pStroke.setAntiAlias(true); | |
canvas.drawCircle(circleX, circleY, radius, pStroke); | |
strokeSize = activeStrokeSize; | |
} | |
int stageColor = isActive ? activeStageColor : inactiveStageColor; | |
Paint p = new Paint(); | |
p.setColor(stageColor); | |
p.setAntiAlias(true); | |
canvas.drawCircle(circleX, circleY, radius - strokeSize, p); | |
super.onDraw(canvas); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment