Skip to content

Commit

Permalink
Merge pull request #67 from tcqq/master
Browse files Browse the repository at this point in the history
Add `markerPaddingTop` and `markerPaddingBottom` attributes to the library
  • Loading branch information
vipulasri authored Sep 28, 2019
2 parents d0314c4 + ceb288c commit 601a518
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 31 deletions.
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

0 comments on commit 601a518

Please sign in to comment.