@@ -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 ;
@@ -267,7 +275,10 @@ public void onDraw(Canvas canvas) {
267275 canvas .drawCircle (getWidth () / 2f , getHeight () / 2f ,
268276 (getWidth () - borderWidth ) / 2f - 1f , mBorderPaint );
269277 }
278+
270279 float radius = getWidth () / 2f - borderWidth ;
280+ // Draw background
281+ canvas .drawCircle (getWidth () / 2f , getHeight () / 2f , radius , mWaveBgPaint );
271282 canvas .drawCircle (getWidth () / 2f , getHeight () / 2f , radius , mWavePaint );
272283 break ;
273284 // Draw square
@@ -288,12 +299,12 @@ public void onDraw(Canvas canvas) {
288299 if (mIsRoundRectangle ) {
289300 if (borderWidth > 0 ) {
290301 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 );
302+ canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
292303 } else {
293304 RectF rect = new RectF (0 , 0 , getWidth (), getHeight ());
294- canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
305+ canvas .drawRoundRect (rect , mRoundRectangleXY , mRoundRectangleXY , mWavePaint );
295306 }
296- }else {
307+ } else {
297308 if (borderWidth > 0 ) {
298309 canvas .drawRect (borderWidth / 2f , borderWidth / 2f , getWidth () - borderWidth / 2f - 0.5f , getHeight () - borderWidth / 2f - 0.5f , mWavePaint );
299310 } else {
@@ -359,11 +370,11 @@ private void updateWaveShader() {
359370 // IllegalArgumentException: width and height must be > 0 while loading Bitmap from View
360371 // http://stackoverflow.com/questions/17605662/illegalargumentexception-width-and-height-must-be-0-while-loading-bitmap-from
361372 if (bitmapBuffer == null || haveBoundsChanged ()) {
362- if (bitmapBuffer != null )
373+ if (bitmapBuffer != null )
363374 bitmapBuffer .recycle ();
364375 int width = getMeasuredWidth ();
365376 int height = getMeasuredHeight ();
366- if (width > 0 && height > 0 ) {
377+ if (width > 0 && height > 0 ) {
367378 double defaultAngularFrequency = 2.0f * Math .PI / DEFAULT_WAVE_LENGTH_RATIO / width ;
368379 float defaultAmplitude = height * DEFAULT_AMPLITUDE_RATIO ;
369380 mDefaultWaterLevel = height * DEFAULT_WATER_LEVEL_RATIO ;
@@ -459,6 +470,15 @@ private int measureHeight(int measureSpecHeight) {
459470 return (result + 2 );
460471 }
461472
473+
474+ public void setWaveBgColor (int color ) {
475+ this .mWaveBgColor = color ;
476+ }
477+
478+ public int getWaveBgColor () {
479+ return mWaveBgColor ;
480+ }
481+
462482 public void setWaveColor (int color ) {
463483 mWaveColor = color ;
464484 // Need to recreate shader when color changed ?
@@ -726,9 +746,10 @@ private int dp2px(float dp) {
726746
727747 /**
728748 * Draw EquilateralTriangle
729- * @param p1 Start point
730- * @param width The width of triangle
731- * @param height The height of triangle
749+ *
750+ * @param p1 Start point
751+ * @param width The width of triangle
752+ * @param height The height of triangle
732753 * @param direction The direction of triangle
733754 * @return Path
734755 */
0 commit comments