Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add markerPaddingTop and markerPaddingBottom attributes. #67

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 87 additions & 29 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public class TimelineView extends View {

private Drawable mMarker;
private int mMarkerSize;
private int mMarkerPaddingTop;
private int mMarkerPaddingBottom;
private boolean mMarkerInCenter;
private Paint mLinePaint = new Paint();
private boolean mDrawStartLine = false;
Expand All @@ -74,6 +76,8 @@ private void init(AttributeSet attrs) {
TypedArray typedArray = getContext().obtainStyledAttributes(attrs,R.styleable.TimelineView);
mMarker = typedArray.getDrawable(R.styleable.TimelineView_marker);
mMarkerSize = typedArray.getDimensionPixelSize(R.styleable.TimelineView_markerSize, Utils.dpToPx(20, getContext()));
mMarkerPaddingTop = typedArray.getDimensionPixelSize(R.styleable.TimelineView_markerPaddingTop, 0);
mMarkerPaddingBottom = typedArray.getDimensionPixelSize(R.styleable.TimelineView_markerPaddingBottom, 0);
mMarkerInCenter = typedArray.getBoolean(R.styleable.TimelineView_markerInCenter, true);
mStartLineColor = typedArray.getColor(R.styleable.TimelineView_startLineColor, getResources().getColor(android.R.color.darker_gray));
mEndLineColor = typedArray.getColor(R.styleable.TimelineView_endLineColor, getResources().getColor(android.R.color.darker_gray));
Expand Down Expand Up @@ -139,14 +143,14 @@ private void initTimeline() {
if(mMarkerInCenter) { //Marker in center is true

if(mMarker != null) {
mMarker.setBounds((width/2) - (markSize/2),(height/2) - (markSize/2), (width/2) + (markSize/2),(height/2) + (markSize/2));
mMarker.setBounds((width/2) - (markSize/2),(height/2) - (markSize/2) + mMarkerPaddingTop - mMarkerPaddingBottom, (width/2) + (markSize/2),(height/2) + (markSize/2) + mMarkerPaddingTop - mMarkerPaddingBottom);
mBounds = mMarker.getBounds();
}

} else { //Marker in center is false

if(mMarker != null) {
mMarker.setBounds(pLeft, pTop,pLeft + markSize,pTop + markSize);
mMarker.setBounds(pLeft, pTop + mMarkerPaddingTop - mMarkerPaddingBottom, pLeft + markSize, pTop + markSize + mMarkerPaddingTop - mMarkerPaddingBottom);
mBounds = mMarker.getBounds();
}
}
Expand Down Expand Up @@ -307,6 +311,24 @@ public int getMarkerSize() {
return mMarkerSize;
}

public void setMarkerPaddingTop(int markerPaddingTop) {
mMarkerPaddingTop = markerPaddingTop;
initTimeline();
}

public int getMarkerPaddingTop() {
return mMarkerPaddingTop;
}

public void setMarkerPaddingBottom(int markerPaddingBottom) {
mMarkerPaddingBottom = markerPaddingBottom;
initTimeline();
}

public int getMarkerPaddingBottom() {
return mMarkerPaddingBottom;
}

public boolean isMarkerInCenter() {
return mMarkerInCenter;
}
Expand Down
2 changes: 2 additions & 0 deletions timelineview/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<declare-styleable name="TimelineView" >
<attr name="marker" format="color|reference"/>
<attr name="markerSize" format="dimension"/>
<attr name="markerPaddingTop" format="dimension"/>
<attr name="markerPaddingBottom" format="dimension"/>
<attr name="markerInCenter" format="boolean"/>
<attr name="startLineColor" format="color"/>
<attr name="endLineColor" format="color"/>
Expand Down