@@ -46,6 +46,7 @@ public class WaveLoadingView extends View {
4646 private static final float DEFAULT_WAVE_SHIFT_RATIO = 0.0f ;
4747 private static final int DEFAULT_WAVE_PROGRESS_VALUE = 50 ;
4848 private static final int DEFAULT_WAVE_COLOR = Color .parseColor ("#212121" );
49+ private static final int DEFAULT_WAVE_BACKGROUND_COLOR = Color .parseColor ("#00000000" );
4950 private static final int DEFAULT_TITLE_COLOR = Color .parseColor ("#212121" );
5051 private static final int DEFAULT_STROKE_COLOR = Color .TRANSPARENT ;
5152 private static final float DEFAULT_BORDER_WIDTH = 0 ;
@@ -77,6 +78,7 @@ public enum TriangleDirection {
7778 private int mCanvasHeight ;
7879 private int mCanvasWidth ;
7980 private float mAmplitudeRatio ;
81+ private int mWaveBgColor ;
8082 private int mWaveColor ;
8183 private int mShapeType ;
8284 private int mTriangleDirection ;
@@ -100,6 +102,8 @@ public enum TriangleDirection {
100102 private Matrix mShaderMatrix ;
101103 // Paint to draw wave.
102104 private Paint mWavePaint ;
105+ //Paint to draw waveBackground.
106+ private Paint mWaveBgPaint ;
103107 // Paint to draw border.
104108 private Paint mBorderPaint ;
105109 // Point to draw title.
@@ -138,7 +142,8 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
138142 // The ANTI_ALIAS_FLAG bit AntiAliasing smooths out the edges of what is being drawn,
139143 // but is has no impact on the interior of the shape.
140144 mWavePaint .setAntiAlias (true );
141-
145+ mWaveBgPaint = new Paint ();
146+ mWaveBgPaint .setAntiAlias (true );
142147 // Init Animation
143148 initAnimation ();
144149
@@ -150,6 +155,9 @@ private void init(Context context, AttributeSet attrs, int defStyleAttr) {
150155
151156 // Init Wave
152157 mWaveColor = attributes .getColor (R .styleable .WaveLoadingView_wlv_waveColor , DEFAULT_WAVE_COLOR );
158+ mWaveBgColor = attributes .getColor (R .styleable .WaveLoadingView_wlv_wave_background_Color , DEFAULT_WAVE_BACKGROUND_COLOR );
159+
160+ mWaveBgPaint .setColor (mWaveBgColor );
153161
154162 // Init AmplitudeRatio
155163 float amplitudeRatioAttr = attributes .getFloat (R .styleable .WaveLoadingView_wlv_waveAmplitude , DEFAULT_AMPLITUDE_VALUE ) / 1000 ;
@@ -259,6 +267,7 @@ public void onDraw(Canvas canvas) {
259267 // Currently does not support the border settings
260268 Point start = new Point (0 , getHeight ());
261269 Path triangle = getEquilateralTriangle (start , getWidth (), getHeight (), mTriangleDirection );
270+ canvas .drawPath (triangle , mWaveBgPaint );
262271 canvas .drawPath (triangle , mWavePaint );
263272 break ;
264273 // Draw circle
@@ -267,7 +276,10 @@ public void onDraw(Canvas canvas) {
267276 canvas .drawCircle (getWidth () / 2f , getHeight () / 2f ,
268277 (getWidth () - borderWidth ) / 2f - 1f , mBorderPaint );
269278 }
279+
270280 float radius = getWidth () / 2f - borderWidth ;
281+ // Draw background
282+ canvas .drawCircle (getWidth () / 2f , getHeight () / 2f , radius , mWaveBgPaint );
271283 canvas .drawCircle (getWidth () / 2f , getHeight () / 2f , radius , mWavePaint );
272284 break ;
273285 // Draw square
@@ -280,6 +292,9 @@ public void onDraw(Canvas canvas) {
280292 getHeight () - borderWidth / 2f - 0.5f ,
281293 mBorderPaint );
282294 }
295+
296+ canvas .drawRect (borderWidth , borderWidth , getWidth () - borderWidth ,
297+ getHeight () - borderWidth , mWaveBgPaint );
283298 canvas .drawRect (borderWidth , borderWidth , getWidth () - borderWidth ,
284299 getHeight () - borderWidth , mWavePaint );
285300 break ;
@@ -288,15 +303,19 @@ public void onDraw(Canvas canvas) {
288303 if (mIsRoundRectangle ) {
289304 if (borderWidth > 0 ) {
290305 RectF rect = new RectF (borderWidth / 2f , borderWidth / 2f , getWidth () - borderWidth / 2f - 0.5f , getHeight () - borderWidth / 2f - 0.5f );
291- canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
306+ canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWaveBgPaint );
307+ canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
292308 } else {
293309 RectF rect = new RectF (0 , 0 , getWidth (), getHeight ());
294- canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
310+ canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWaveBgPaint );
311+ canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
295312 }
296- }else {
313+ } else {
297314 if (borderWidth > 0 ) {
315+ canvas .drawRect (borderWidth / 2f , borderWidth / 2f , getWidth () - borderWidth / 2f - 0.5f , getHeight () - borderWidth / 2f - 0.5f , mWaveBgPaint );
298316 canvas .drawRect (borderWidth / 2f , borderWidth / 2f , getWidth () - borderWidth / 2f - 0.5f , getHeight () - borderWidth / 2f - 0.5f , mWavePaint );
299317 } else {
318+ canvas .drawRect (0 , 0 , canvas .getWidth (), canvas .getHeight (), mWaveBgPaint );
300319 canvas .drawRect (0 , 0 , canvas .getWidth (), canvas .getHeight (), mWavePaint );
301320 }
302321 }
@@ -359,11 +378,11 @@ private void updateWaveShader() {
359378 // IllegalArgumentException: width and height must be > 0 while loading Bitmap from View
360379 // http://stackoverflow.com/questions/17605662/illegalargumentexception-width-and-height-must-be-0-while-loading-bitmap-from
361380 if (bitmapBuffer == null || haveBoundsChanged ()) {
362- if (bitmapBuffer != null )
381+ if (bitmapBuffer != null )
363382 bitmapBuffer .recycle ();
364383 int width = getMeasuredWidth ();
365384 int height = getMeasuredHeight ();
366- if (width > 0 && height > 0 ) {
385+ if (width > 0 && height > 0 ) {
367386 double defaultAngularFrequency = 2.0f * Math .PI / DEFAULT_WAVE_LENGTH_RATIO / width ;
368387 float defaultAmplitude = height * DEFAULT_AMPLITUDE_RATIO ;
369388 mDefaultWaterLevel = height * DEFAULT_WATER_LEVEL_RATIO ;
@@ -459,6 +478,15 @@ private int measureHeight(int measureSpecHeight) {
459478 return (result + 2 );
460479 }
461480
481+
482+ public void setWaveBgColor (int color ) {
483+ this .mWaveBgColor = color ;
484+ }
485+
486+ public int getWaveBgColor () {
487+ return mWaveBgColor ;
488+ }
489+
462490 public void setWaveColor (int color ) {
463491 mWaveColor = color ;
464492 // Need to recreate shader when color changed ?
@@ -726,9 +754,10 @@ private int dp2px(float dp) {
726754
727755 /**
728756 * Draw EquilateralTriangle
729- * @param p1 Start point
730- * @param width The width of triangle
731- * @param height The height of triangle
757+ *
758+ * @param p1 Start point
759+ * @param width The width of triangle
760+ * @param height The height of triangle
732761 * @param direction The direction of triangle
733762 * @return Path
734763 */
0 commit comments