[sonar] fix sonar plm

This commit is contained in:
zhongchao
2023-10-23 17:01:37 +08:00
parent 0672cbb39c
commit 5b910c2082
41 changed files with 1117 additions and 1279 deletions

View File

@@ -60,7 +60,7 @@ public class S2FractalBuilder {
*/
private double offsetFraction = 0;
private Random rand;
private final Random rand;
/** You must call setMaxLevel() or setLevelForApproxMaxMedges() before calling makeLoop(). */
public S2FractalBuilder(Random rand) {
@@ -124,7 +124,7 @@ public class S2FractalBuilder {
/** Returns level from values in the range [1.5 * (4 ^ n), 6 * (4 ^ n)]. */
private static int levelFromEdges(int edges) {
return (int) Math.ceil(0.5 * Math.log(edges / 3) / Math.log(2));
return (int) Math.ceil(0.5 * Math.log(edges / 3.0f) / Math.log(2));
}
/**

View File

@@ -49,12 +49,12 @@ public class GlideCircleBitmapTransform extends BitmapTransformation {
borderPaint.setStrokeWidth( mBorderWidth );
borderPaint.setColor( mBorderColor );
borderPaint.setAntiAlias( true );
canvas.drawCircle( radius, radius, radius - mBorderWidth / 2, borderPaint );
canvas.drawCircle( radius, radius, radius - mBorderWidth / 2.0f, borderPaint );
}
Paint paint = new Paint();
paint.setShader( new BitmapShader( bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP ) );
paint.setAntiAlias( true );
canvas.drawCircle( radius, radius, radius - mBorderWidth, paint );
canvas.drawCircle( radius, radius, (float) (radius - mBorderWidth), paint );
DiskLruCacheManager.getInstance( mContext ).put( mKey, result );

View File

@@ -39,7 +39,7 @@ public class GlideRoundBitmapTransform extends BitmapTransformation {
}
int width = toTransform.getWidth();
int height = toTransform.getHeight();
RectF rectF = new RectF( mBorderWidth, mBorderWidth, width - mBorderWidth, height - mBorderWidth );
RectF rectF = new RectF( mBorderWidth, mBorderWidth, (float) (width - mBorderWidth), (float) (height - mBorderWidth) );
Bitmap result = pool.get( width, height, toTransform.getConfig() );
// if ( result == null ) { //get() func always return not null
// result = toTransform.copy( toTransform.getConfig(), true );

View File

@@ -307,12 +307,12 @@ public final class ColorUtils {
int[] cColor = hexToArgb(centerColor);
int[] eColor = hexToArgb(endColor);
if (step >= 3) {
int colorStep = (int) Math.floor(step/2);
int colorStep = (int) Math.floor(step/2.0f);
// 计算每一步的差值
float aStep = (cColor[0] - sColor[0]) / colorStep;
float rStep = (cColor[1] - sColor[1]) / colorStep;
float gStep = (cColor[2] - sColor[2]) / colorStep;
float bStep = (cColor[3] - sColor[3]) / colorStep;
float aStep = (float) (cColor[0] - sColor[0]) / colorStep;
float rStep = (float) (cColor[1] - sColor[1]) / colorStep;
float gStep = (float) (cColor[2] - sColor[2]) / colorStep;
float bStep = (float) (cColor[3] - sColor[3]) / colorStep;
for (int i = 0; i < colorStep; i++) {
@@ -322,10 +322,10 @@ public final class ColorUtils {
(int)(gStep * i + sColor[2]),
(int)(bStep * i + sColor[3])));
}
float aStep_ = (eColor[0] - cColor[0]) / colorStep;
float rStep_ = (eColor[1] - cColor[1]) / colorStep;
float gStep_ = (eColor[2] - cColor[2]) / colorStep;
float bStep_ = (eColor[3] - cColor[3]) / colorStep;
float aStep_ = (float) (eColor[0] - cColor[0]) / colorStep;
float rStep_ = (float) (eColor[1] - cColor[1]) / colorStep;
float gStep_ = (float) (eColor[2] - cColor[2]) / colorStep;
float bStep_ = (float) (eColor[3] - cColor[3]) / colorStep;
for (int i = 0; i < colorStep; i++) {
gradientColorArr.add(

View File

@@ -777,14 +777,14 @@ public final class ConvertUtils {
SpannableStringBuilder spannable = new SpannableStringBuilder();
int length = value.length();
if (length > 1) {
/**
/*
* 对于长度大于1的数对首位进行赋值
* 对于两位数: 如果首位为“1”则拼接的字符串为“”
*/
spannable.append(getChinese(number / (int) Math.pow(10, length - 1), length))
spannable.append(getChinese(number / (int) Math.pow(10.0f, length - 1.0f), length))
.append(getUnitChinese(length));
// 如果该数值取余数为0则直接返回已有字符例如100直接返回一百
if (number % (int) Math.pow(10, length - 1) == 0) {
if (number % (int) Math.pow(10.0f, length - 1.0f) == 0) {
return spannable.toString();
}
}

View File

@@ -182,10 +182,10 @@ public class ShadowUtils {
private float mShadowHorizScale = 1f;
private float mShadowBottomScale = 1f;
private Paint mCornerShadowPaint;
private Paint mEdgeShadowPaint;
private final Paint mCornerShadowPaint;
private final Paint mEdgeShadowPaint;
private RectF mContentBounds;
private final RectF mContentBounds;
private float mCornerRadius;
@@ -210,7 +210,7 @@ public class ShadowUtils {
private float mRotation;
private boolean isCircle;
private final boolean isCircle;
public ShadowDrawable(Drawable content, float radius,
float shadowSize, float maxShadowSize, int shadowColor, boolean isCircle) {
@@ -494,7 +494,7 @@ public class ShadowUtils {
// We could have different top-bottom offsets to avoid extra gap above but in that case
// center aligning Views inside the CardView would be problematic.
if (isCircle) {
mCornerRadius = bounds.width() / 2;
mCornerRadius = bounds.width() / 2.0f;
}
final float verticalOffset = mRawMaxShadowSize * mShadowMultiplier;
mContentBounds.set(bounds.left + mRawMaxShadowSize, bounds.top + verticalOffset,
@@ -679,7 +679,7 @@ public class ShadowUtils {
public void setWrappedDrawable(Drawable drawable) {
if (this.mDrawable != null) {
this.mDrawable.setCallback((Callback) null);
this.mDrawable.setCallback(null);
}
this.mDrawable = drawable;

View File

@@ -1,5 +1,6 @@
package com.mogo.eagle.core.utilcode.util;
import android.annotation.SuppressLint;
import android.media.*;
import android.content.*;
import android.os.*;
@@ -21,20 +22,15 @@ public class SoundPoolUtils {
private int resId;
private Context mContext;
private volatile static SoundPoolUtils INSTANCE;
private SoundPoolUtils(){}
public static SoundPoolUtils getSoundPool(){
if (INSTANCE == null){
synchronized (SoundPoolUtils.class){
if (INSTANCE == null){
INSTANCE = new SoundPoolUtils();
}
}
}
return INSTANCE;
return Holder.INSTANCE;
}
private static final class Holder{
@SuppressLint("StaticFieldLeak")
private static final SoundPoolUtils INSTANCE = new SoundPoolUtils();
}
public SoundPoolUtils(){}
//播放资源文件
public void playSoundWithRedId(Context context,int resId){
@@ -63,30 +59,20 @@ public class SoundPoolUtils {
if (mSoundPool == null){
// For Android SDK >= 21
if (Build.VERSION.SDK_INT >= 21 ) {
AudioAttributes audioAttrib = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_GAME)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
AudioAttributes audioAttrib = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_GAME)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build();
SoundPool.Builder builder= new SoundPool.Builder();
builder.setAudioAttributes(audioAttrib).setMaxStreams(MAX_STREAMS);
SoundPool.Builder builder= new SoundPool.Builder();
builder.setAudioAttributes(audioAttrib).setMaxStreams(MAX_STREAMS);
this.mSoundPool = builder.build();
} else {// for Android SDK < 21
// SoundPool(int maxStreams, int streamType, int srcQuality)
this.mSoundPool = new SoundPool(MAX_STREAMS, AudioManager.STREAM_MUSIC, 0);
}
this.mSoundPool = builder.build();
}
// When Sound Pool load complete.
this.mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
playSound();
}
});
this.mSoundPool.setOnLoadCompleteListener((soundPool, sampleId, status) -> playSound());
//load res
this.mSoundId =this.mSoundPool.load(this.mContext,this.resId,1);
@@ -108,10 +94,10 @@ public class SoundPoolUtils {
//play the sound res
private void playSound(){
float leftVolumn = volume;
float rightVolumn = volume;
float leftVolume = volume;
float rightVolume = volume;
// Play sound of gunfire. Returns the ID of the new stream.
int streamId = this.mSoundPool.play(this.mSoundId,leftVolumn, rightVolumn, 1, 0, 1f);
int streamId = this.mSoundPool.play(this.mSoundId,leftVolume, rightVolume, 1, 0, 1f);
}
}

View File

@@ -1031,7 +1031,7 @@ public final class SpanUtils {
// }
// }
canvas.drawText(text.toString(), x, y - ((y + fm.descent + y + fm.ascent) / 2 - (bottom + top) / 2), paint);
canvas.drawText(text.toString(), x, y - ((y + fm.descent + y + fm.ascent) / 2.0f - (bottom + top) / 2.0f), paint);
}
}
@@ -1200,11 +1200,11 @@ public final class SpanUtils {
sBulletPath.addCircle(0.0f, 0.0f, radius, Path.Direction.CW);
}
c.save();
c.translate(x + dir * radius, (top + bottom) / 2.0f);
c.translate((float)(x + dir * radius), (top + bottom) / 2.0f);
c.drawPath(sBulletPath, p);
c.restore();
} else {
c.drawCircle(x + dir * radius, (top + bottom) / 2.0f, radius, p);
c.drawCircle((float)(x + dir * radius), (top + bottom) / 2.0f, radius, p);
}
p.setColor(oldColor);
p.setStyle(style);
@@ -1386,7 +1386,7 @@ public final class SpanUtils {
if (mVerticalAlignment == ALIGN_TOP) {
transY = top;
} else if (mVerticalAlignment == ALIGN_CENTER) {
transY = (bottom + top - rect.height()) / 2;
transY = (bottom + top - rect.height()) / 2.0f;
} else if (mVerticalAlignment == ALIGN_BASELINE) {
transY = y - rect.height();
} else {
@@ -1417,7 +1417,7 @@ public final class SpanUtils {
}
static class ShaderSpan extends CharacterStyle implements UpdateAppearance {
private Shader mShader;
private final Shader mShader;
private ShaderSpan(final Shader shader) {
this.mShader = shader;