@@ -344,44 +344,29 @@ private void drawBgShape(Canvas canvas) {
344344 angle = 360 + angle ;
345345 }
346346 float x0 , y0 , x1 , y1 ;
347- if (angle >= 0 && angle <= 45 ) {
348- float percent = angle / 45 ;
349- x0 = width / 2 + width / 2 * percent ;
350- y0 = 0 ;
351- } else if (angle <= 90 ) {
352- float percent = (angle - 45 ) / 45 ;
353- x0 = width ;
354- y0 = height / 2 * percent ;
355- } else if (angle <= 135 ) {
356- float percent = (angle - 90 ) / 45 ;
357- x0 = width ;
358- y0 = height / 2 * percent + height / 2 ;
359- } else if (angle <= 180 ) {
360- float percent = (angle - 135 ) / 45 ;
361- x0 = width / 2 + width / 2 * (1 -percent );
362- y0 = height ;
363- } else if (angle <= 225 ) {
364- float percent = (angle - 180 ) / 45 ;
365- x0 = width / 2 - width / 2 * percent ;
366- y0 = height ;
367- } else if (angle <= 270 ) {
368- float percent = (angle - 225 ) / 45 ;
369- x0 = 0 ;
370- y0 = height - height / 2 * percent ;
371- } else if (angle <= 315 ) {
372- float percent = (angle - 270 ) / 45 ;
373- x0 = 0 ;
374- y0 = height / 2 - height / 2 * percent ;
375- } else {
376- float percent = (angle - 315 ) / 45 ;
377- x0 = width / 2 * percent ;
378- y0 = 0 ;
347+ if ((angle >= 0 && angle < 90 ) || (angle >=180 && angle < 270 )){
348+ x0 = (float ) (width /2 + Math .signum (90 - angle ) * height /2f * Math .tan (Math .toRadians (angle - (angle >= 180 ?180 :0 ))));
349+ if (x0 >= width || x0 <= 0 ){
350+ x0 = angle < 90 ?width :0 ;
351+ y0 = (float ) (height /2 - Math .signum (90 - angle ) * width /2f * Math .tan (Math .toRadians ((angle >= 180 ?270 :90 ) - angle )));
352+ }else {
353+ y0 = angle < 90 ?0 :height ;
354+ }
355+ }else {
356+ y0 = (float ) (height /2f + Math .signum (180 - angle ) * width /2f * Math .tan (Math .toRadians (angle - (angle < 180 ?90 :270 ))));
357+ if (y0 >= height || y0 <= 0 ){
358+ y0 = angle < 180 ?height :0 ;
359+ x0 = (float ) (width /2 + Math .signum (180 - angle ) * height /2f * Math .tan (Math .toRadians ((angle < 180 ?180 :360 ) - angle )));
360+ }else {
361+ x0 = angle < 180 ?width :0 ;
362+ }
379363 }
380364 x1 = width - x0 ;
381365 y1 = height - y0 ;
382366 LinearGradient linearGradient = new LinearGradient (x0 , y0 , x1 , y1 , gradientColors , gradientPositions , Shader .TileMode .CLAMP );
383367 mBgPaint .setShader (linearGradient );
384368 }
369+ mDrawBgPath .reset ();
385370 if (bgShapeType == ShapeType .OVAL ) {
386371 mDrawBgPath .addOval (mBgRectF , Path .Direction .CCW );
387372 } else {
0 commit comments