1212import android .graphics .drawable .Drawable ;
1313import android .graphics .drawable .GradientDrawable ;
1414import android .graphics .drawable .ShapeDrawable ;
15+ import android .os .Build ;
1516import android .support .annotation .ColorInt ;
1617import android .util .Log ;
1718
@@ -84,6 +85,8 @@ void setPaint(Paint paint) {
8485
8586 private PointF [] mPointFs ;
8687
88+ private RectF mOvalRect [] = new RectF [4 ];
89+
8790 SharpDrawable () {
8891 super ();
8992 init ();
@@ -98,8 +101,14 @@ private void init() {
98101 mPointFs [0 ] = new PointF ();
99102 mPointFs [1 ] = new PointF ();
100103 mPointFs [2 ] = new PointF ();
104+
105+ mOvalRect [0 ] = new RectF ();
106+ mOvalRect [1 ] = new RectF ();
107+ mOvalRect [2 ] = new RectF ();
108+ mOvalRect [3 ] = new RectF ();
101109 }
102110
111+
103112 @ Override
104113 public void draw (Canvas canvas ) {
105114 if (mSharpSize == 0 ) {
@@ -157,6 +166,59 @@ public void draw(Canvas canvas) {
157166 mPath .lineTo (mPointFs [0 ].x , mPointFs [0 ].y );
158167 mPaint .setColor (mBgColor );
159168 canvas .drawPath (mPath , mPaint );
169+
170+
171+
172+ mPaint .setColor (mBorderColor );
173+ mPaint .setStyle (Paint .Style .STROKE );
174+ mPaint .setStrokeWidth (mBorder );
175+ switch (mArrowDirection ) {
176+ case LEFT :
177+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .top ,mRect .right - mCornerRadius ,mRect .top ,mPaint );
178+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .bottom ,mRect .right - mCornerRadius ,mRect .bottom ,mPaint );
179+ canvas .drawLine (mRect .right ,mRect .top + mCornerRadius ,mRect .right ,mRect .bottom - mCornerRadius ,mPaint );
180+ canvas .drawLine (mRect .left ,mRect .top + mCornerRadius ,mRect .left ,mPointFs [1 ].y ,mPaint );
181+ canvas .drawLine (mRect .left ,mPointFs [2 ].y ,mRect .left ,mRect .bottom - mCornerRadius ,mPaint );
182+ break ;
183+ case TOP :
184+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .bottom ,mRect .right - mCornerRadius ,mRect .bottom ,mPaint );
185+ canvas .drawLine (mRect .left ,mRect .top + mCornerRadius ,mRect .left ,mRect .bottom - mCornerRadius ,mPaint );
186+ canvas .drawLine (mRect .right ,mRect .top + mCornerRadius ,mRect .right ,mRect .bottom - mCornerRadius ,mPaint );
187+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .top ,mPointFs [1 ].x ,mRect .top ,mPaint );
188+ canvas .drawLine (mPointFs [2 ].x , mRect .top , mRect .right - mCornerRadius , mRect .top , mPaint );
189+ break ;
190+ case RIGHT :
191+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .top ,mRect .right - mCornerRadius ,mRect .top ,mPaint );
192+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .bottom ,mRect .right - mCornerRadius ,mRect .bottom ,mPaint );
193+ canvas .drawLine (mRect .left ,mRect .top + mCornerRadius ,mRect .left ,mRect .bottom - mCornerRadius ,mPaint );
194+ canvas .drawLine (mRect .right ,mRect .top + mCornerRadius ,mRect .right ,mPointFs [1 ].y ,mPaint );
195+ canvas .drawLine (mRect .right ,mPointFs [2 ].y ,mRect .right ,mRect .bottom - mCornerRadius ,mPaint );
196+ break ;
197+ case BOTTOM :
198+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .top ,mRect .right - mCornerRadius ,mRect .top ,mPaint );
199+ canvas .drawLine (mRect .left ,mRect .top + mCornerRadius ,mRect .left ,mRect .bottom - mCornerRadius ,mPaint );
200+ canvas .drawLine (mRect .right ,mRect .top + mCornerRadius ,mRect .right ,mRect .bottom - mCornerRadius ,mPaint );
201+ canvas .drawLine (mRect .left + mCornerRadius ,mRect .bottom ,mPointFs [1 ].x ,mRect .bottom ,mPaint );
202+ canvas .drawLine (mPointFs [2 ].x , mRect .bottom , mRect .right - mCornerRadius , mRect .bottom , mPaint );
203+ break ;
204+ }
205+
206+ if (mCornerRadius > 0 ) {
207+ float d = 2 * mCornerRadius ;
208+
209+ mOvalRect [0 ].set (mRect .left ,mRect .top ,mRect .left + d ,mRect .top + d );
210+ mOvalRect [1 ].set (mRect .right - d ,mRect .top ,mRect .right ,mRect .top + d );
211+ mOvalRect [2 ].set (mRect .left ,mRect .bottom - d ,mRect .left + d ,mRect .bottom );
212+ mOvalRect [3 ].set (mRect .right - d ,mRect .bottom - d ,mRect .right ,mRect .bottom );
213+ canvas .drawArc (mOvalRect [0 ],180 ,90 ,false ,mPaint );
214+ canvas .drawArc (mOvalRect [1 ],-90 ,90 ,false ,mPaint );
215+ canvas .drawArc (mOvalRect [2 ],90 ,90 ,false ,mPaint );
216+ canvas .drawArc (mOvalRect [3 ],90 ,-90 ,false ,mPaint );
217+ }
218+
219+ canvas .drawLine (mPointFs [0 ].x , mPointFs [0 ].y , mPointFs [1 ].x , mPointFs [1 ].y , mPaint );
220+ canvas .drawLine (mPointFs [0 ].x , mPointFs [0 ].y , mPointFs [2 ].x , mPointFs [2 ].y , mPaint );
221+
160222 }
161223 }
162224
0 commit comments