[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

@@ -7,7 +7,6 @@ import static com.mogo.och.bus.constant.BusConst.STATION_STATUS_STOPPED;
import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import androidx.annotation.NonNull;
@@ -81,7 +80,6 @@ import java.util.ArrayList;
import java.util.List;
import io.reactivex.exceptions.UndeliverableException;
import io.reactivex.functions.Consumer;
import io.reactivex.plugins.RxJavaPlugins;
import mogo.telematics.pad.MessagePad;
@@ -98,6 +96,7 @@ public class OrderModel {
private int backgroundCurrentStationIndex = 0;//A->B 此处值是A站点索引
private static volatile OrderModel sInstance;
private static final byte[] obj = new byte[0];
private Context mContext;
private final List<BusStationBean> stationList = new ArrayList<>();
private BusRoutesResult busRoutesResult = null;
@@ -125,20 +124,20 @@ public class OrderModel {
private LoginService loginService;
private final Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
if (msg.what == MSG_QUERY_BUS_STATION) {
queryBusRoutes();
return true;
}
return false;
private final Handler handler = new Handler(msg -> {
if (msg.what == MSG_QUERY_BUS_STATION) {
queryBusRoutes();
return true;
}
return false;
});
private OrderModel() {
}
public static OrderModel getInstance() {
if (sInstance == null) {
synchronized (OrderModel.class) {
synchronized (obj) {
if (sInstance == null) {
sInstance = new OrderModel();
}
@@ -147,10 +146,6 @@ public class OrderModel {
return sInstance;
}
private OrderModel() {
}
public void init() {
mContext = AbsMogoApplication.getApp();
loginService = (LoginService) ARouter.getInstance().build(OchCommonConst.LOGINSERVICE).navigation();
@@ -171,7 +166,7 @@ public class OrderModel {
OCHSocketMessageManager.INSTANCE.registerSocketMessageListener(//监听核销乘客
OCHSocketMessageManager.msgWriteOffPassengerType,
mWriteOffPassengeOnMessageListener);
mWriteOffPassengerOnMessageListener);
AbnormalFactorsLoopManager.INSTANCE.startLoopAbnormalFactors(mContext);
@@ -180,38 +175,35 @@ public class OrderModel {
//2022.1.28
// 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃
// The exception could not be delivered to the consumer because it has already canceled/disposed
// the flow or the excTeption has nowhere to go to begin with
RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
if (e instanceof UndeliverableException) {
e = e.getCause();
CallerLogger.d(M_BUS + TAG, "UndeliverableException");
}
if ((e instanceof IOException)) {//
// fine, irrelevant network problem or API that throws on cancellation
CallerLogger.d(M_BUS + TAG, "IOException");
return;
}
if (e instanceof InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
CallerLogger.d(M_BUS + TAG, "InterruptedException");
return;
}
if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {
// that's likely a bug in the application
CallerLogger.d(M_BUS + TAG, "NullPointerException or IllegalArgumentException");
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
return;
}
if (e instanceof IllegalStateException) {
// that's a bug in RxJava or in a custom operator
CallerLogger.d(M_BUS + TAG, "IllegalStateException");
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
return;
}
CallerLogger.d(M_BUS + TAG, "Undeliverable exception");
// the flow or the exception has nowhere to go to begin with
RxJavaPlugins.setErrorHandler(e -> {
if (e instanceof UndeliverableException) {
e = e.getCause();
CallerLogger.d(M_BUS + TAG, "UndeliverableException");
}
if ((e instanceof IOException)) {
// fine, irrelevant network problem or API that throws on cancellation
CallerLogger.d(M_BUS + TAG, "IOException");
return;
}
if (e instanceof InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
CallerLogger.d(M_BUS + TAG, "InterruptedException");
return;
}
if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {
// that's likely a bug in the application
CallerLogger.d(M_BUS + TAG, "NullPointerException or IllegalArgumentException");
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
return;
}
if (e instanceof IllegalStateException) {
// that's a bug in RxJava or in a custom operator
CallerLogger.d(M_BUS + TAG, "IllegalStateException");
Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), e);
return;
}
CallerLogger.d(M_BUS + TAG, "Undeliverable exception");
});
}
@@ -234,7 +226,7 @@ public class OrderModel {
}
};
private final IMogoOnMessageListener<WriteOffPassenger> mWriteOffPassengeOnMessageListener =
private final IMogoOnMessageListener<WriteOffPassenger> mWriteOffPassengerOnMessageListener =
new IMogoOnMessageListener<WriteOffPassenger>() {
@Override
public Class<WriteOffPassenger> target() {
@@ -272,11 +264,8 @@ public class OrderModel {
this.mControllerStatusCallback = callback;
}
private final ITrajectoryListener trajectoryListener = new ITrajectoryListener() {
@Override
public void trajectoryCallback(@NonNull List<MogoLocation> routeArrivied, @NonNull List<MogoLocation> routeArriving, @NonNull MogoLocation location) {
private final ITrajectoryListener trajectoryListener = (routeArrivied, routeArriving, location) -> {
}
};
private final IMoGoPlanningRottingListener moGoAutopilotPlanningListener = new IMoGoPlanningRottingListener() {
@@ -361,11 +350,6 @@ public class OrderModel {
TrajectoryAndDistanceManager.INSTANCE.removeListener(TAG);
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
private final IMogoStatusChangedListener mMogoStatusChangedListener = new IMogoStatusChangedListener() {
// VR mode变更回调
@Override
@@ -444,8 +428,6 @@ public class OrderModel {
CallerLogger.d(M_BUS + TAG, "judgeArrivedStation() = 刚过站且在15m内");
onArriveAt(null); //无自动驾驶到站信息传null
}
return;
}
}
@@ -621,10 +603,7 @@ public class OrderModel {
leaveTTSTips(nextStation,nextStationKr);
if (busRoutesResult != null) {
boolean isLastStop = false;
if (leaveIndex + 1 == stationList.size() - 1) {
isLastStop = true;
}
boolean isLastStop = leaveIndex + 1 == stationList.size() - 1;
//给bus外屏发送
BusSendTripInfoManager.INSTANCE.sendBusTripInfo(BusSendTripInfoManager.LEAVE_STATION
, busRoutesResult.getName()
@@ -768,10 +747,7 @@ public class OrderModel {
private void arriveStationSuccess(int arrivedStationIndex, String departureStopName,
String arriveStation, String arriveStationKr) {
if (busRoutesResult != null) {
boolean isLastStop = false;
if (arrivedStationIndex == busRoutesResult.getSites().size() - 1) {
isLastStop = true;
}
boolean isLastStop = arrivedStationIndex == busRoutesResult.getSites().size() - 1;
//给bus外屏发送
BusSendTripInfoManager.INSTANCE.sendBusTripInfo(BusSendTripInfoManager.ARRIVE_STATION
, busRoutesResult.getName()
@@ -845,12 +821,7 @@ public class OrderModel {
//车站10s后播报
private void leaveTTSTips(String nextStation,String nextStationKr) {
UiThreadHandler.postDelayed(new Runnable() {
@Override
public void run() {
VoiceManager.INSTANCE.leaveStationBus(nextStation,nextStationKr);
}
},DELAY_10S);
UiThreadHandler.postDelayed(() -> VoiceManager.INSTANCE.leaveStationBus(nextStation,nextStationKr),DELAY_10S);
}
/**
@@ -981,16 +952,12 @@ public class OrderModel {
}
}
Runnable tip3Runnable = new Runnable() {
@Override
public void run() {
if (backgroundCurrentStationIndex == 0 && stationList.get(0).getDrivingStatus() == STATION_STATUS_STOPPED
&& !stationList.get(0).isLeaving()){
tipStartTask("3");
}else {
removeTipRunnables();
}
Runnable tip3Runnable = () -> {
if (backgroundCurrentStationIndex == 0 && stationList.get(0).getDrivingStatus() == STATION_STATUS_STOPPED
&& !stationList.get(0).isLeaving()){
tipStartTask("3");
}else {
removeTipRunnables();
}
};
@@ -1005,16 +972,11 @@ public class OrderModel {
VoiceNotice.showNotice(tips);
}
Runnable tip1Runnable = new Runnable() {
@Override
public void run() {
if (backgroundCurrentStationIndex == 0 && stationList != null &&
stationList.get(0).getDrivingStatus() == STATION_STATUS_STOPPED
&& !stationList.get(0).isLeaving()){
tipStartTask("1");
}else {
removeTipRunnables();
}
Runnable tip1Runnable = () -> {
if (backgroundCurrentStationIndex == 0 && stationList.get(0).getDrivingStatus() == STATION_STATUS_STOPPED && !stationList.get(0).isLeaving()){
tipStartTask("1");
}else {
removeTipRunnables();
}
};
@@ -1205,7 +1167,7 @@ public class OrderModel {
}
public void triggerStartServiceEvent(boolean isRestart, boolean send) {
if (stationList == null || backgroundCurrentStationIndex >= stationList.size() - 1) {
if (backgroundCurrentStationIndex >= stationList.size() - 1) {
return;
}
BusStationBean currentStation = stationList.get(backgroundCurrentStationIndex);
@@ -1215,7 +1177,7 @@ public class OrderModel {
}
public void triggerUnableStartAPReasonEvent() {
if (stationList == null || backgroundCurrentStationIndex >= stationList.size() - 1) {
if (backgroundCurrentStationIndex >= stationList.size() - 1) {
return;
}
BusStationBean currentStation = stationList.get(backgroundCurrentStationIndex);
@@ -1253,8 +1215,8 @@ public class OrderModel {
}
private AutopilotControlParameters initAutopilotControlParameters(int leaveIndex) {
BusStationBean currentStation = null;
BusStationBean nextStation = null;
BusStationBean currentStation;
BusStationBean nextStation;
if (leaveIndex < 0) {
if (backgroundCurrentStationIndex + 1 > stationList.size() - 1 || !isGoingToNextStation) {

View File

@@ -1,7 +1,6 @@
package com.mogo.och.bus.model;
import android.content.Context;
import android.util.Log;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.utilcode.util.NetworkUtils;
@@ -24,9 +23,13 @@ public class BusLineModel {
private static volatile BusLineModel sInstance;
private Context mContext;
private IBusLinesCallback mBusLinesCallback;
private static final byte[] obj = new byte[0];
private BusLineModel() {
}
public static BusLineModel getInstance() {
if ( sInstance == null ) {
synchronized ( BusLineModel.class ) {
synchronized ( obj ) {
if ( sInstance == null ) {
sInstance = new BusLineModel();
}
@@ -34,9 +37,7 @@ public class BusLineModel {
}
return sInstance;
}
private BusLineModel() {
}
public void init() {
mContext = AbsMogoApplication.getApp();
}
@@ -79,7 +80,7 @@ public class BusLineModel {
/**
* 通过线路id 查询线路排班表
* @param lineId
* @param lineId 线路id
* @param position 位置
*/
public void queryBusLineTasksById(int lineId, int position,boolean autoRefresh){

View File

@@ -32,14 +32,14 @@ public class OpenItemAnimator extends DefaultItemAnimator {
private final ArrayList<MoveInfo> mPendingMoves = new ArrayList<>();
private final ArrayList<ChangeInfo> mPendingChanges = new ArrayList<>();
private ArrayList<ArrayList<RecyclerView.ViewHolder>> mAdditionsList = new ArrayList<>();
private ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
private ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
private final ArrayList<ArrayList<RecyclerView.ViewHolder>> mAdditionsList = new ArrayList<>();
private final ArrayList<ArrayList<MoveInfo>> mMovesList = new ArrayList<>();
private final ArrayList<ArrayList<ChangeInfo>> mChangesList = new ArrayList<>();
private ArrayList<RecyclerView.ViewHolder> mAddAnimations = new ArrayList<>();
private ArrayList<RecyclerView.ViewHolder> mMoveAnimations = new ArrayList<>();
private ArrayList<RecyclerView.ViewHolder> mRemoveAnimations = new ArrayList<>();
private ArrayList<RecyclerView.ViewHolder> mChangeAnimations = new ArrayList<>();
private final ArrayList<RecyclerView.ViewHolder> mAddAnimations = new ArrayList<>();
private final ArrayList<RecyclerView.ViewHolder> mMoveAnimations = new ArrayList<>();
private final ArrayList<RecyclerView.ViewHolder> mRemoveAnimations = new ArrayList<>();
private final ArrayList<RecyclerView.ViewHolder> mChangeAnimations = new ArrayList<>();
private static class MoveInfo {
public RecyclerView.ViewHolder holder;
@@ -328,8 +328,8 @@ public class OpenItemAnimator extends DefaultItemAnimator {
final ViewPropertyAnimator oldViewAnim = view.animate().setDuration(
getChangeDuration());
mChangeAnimations.add(changeInfo.oldHolder);
oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
oldViewAnim.translationX((float) (changeInfo.toX - changeInfo.fromX));
oldViewAnim.translationY((float) (changeInfo.toY - changeInfo.fromY));
oldViewAnim.alpha(0).setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationStart(Animator animator) {

View File

@@ -24,13 +24,13 @@ import com.mogo.och.bus.R;
public class BusArcView extends View {
//中心的文字描述
private String mDes = "KM/H";
private final String mDes = "KM/H";
//根据数据显示的圆弧Paint
private Paint mArcPaint;
//圆弧颜色
private int mArcColor;
//圆弧的画笔的宽度
private float mStrokeWith = getResources().getDimension(R.dimen.bus_ext_arcView_stroke_with);
private final float mStrokeWith = getResources().getDimension(R.dimen.bus_ext_arcView_stroke_with);
//文字描述的paint
private Paint mTextPaint;
@@ -39,9 +39,9 @@ public class BusArcView extends View {
//当前数据
private int currentValue;
//最大数据
private int maxValue = 240;
private final int maxValue = 240;
//圆弧背景的开始和结束间的夹角大小
private float mAngle = 270;
private final float mAngle = 270;
//上次绘制圆弧夹角
private float lastAngle = 0;
@@ -75,13 +75,13 @@ public class BusArcView extends View {
mTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
//绘制中心的数值
mTextPaint.getTextBounds(mValue, 0, mValue.length(), mRect);
canvas.drawText(mValue, getWidth() / 2, getHeight() / 2 + mRect.height() / 2 - 10, mTextPaint);
canvas.drawText(mValue, getWidth() / 2.0f, getHeight() / 2.0f + mRect.height() / 2.0f - 10, mTextPaint);
mTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
//绘制中心文字描述
mTextPaint.setTextSize(getResources().getDimension(R.dimen.bus_ext_arcView_des_text_size));
mTextPaint.getTextBounds(mDes, 0, mDes.length(), mRect);
canvas.drawText(mDes, getWidth() / 2, getHeight() * 17 / 20 + mRect.height() / 2, mTextPaint);
canvas.drawText(mDes, getWidth() / 2.0f, getHeight() * 17.0f / 20.0f + mRect.height() / 2.0f, mTextPaint);
}
private void drawArc(Canvas canvas) {
@@ -135,13 +135,10 @@ public class BusArcView extends View {
ValueAnimator progressAnimator = ValueAnimator.ofFloat(startAngle, currentAngle);
progressAnimator.setDuration(time);
progressAnimator.setTarget(mIncludedAngle);
progressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mIncludedAngle = (float) animation.getAnimatedValue();
//重新绘制,不然不会出现效果
postInvalidate();
}
progressAnimator.addUpdateListener(animation -> {
mIncludedAngle = (float) animation.getAnimatedValue();
//重新绘制,不然不会出现效果
postInvalidate();
});
//开始执行动画
progressAnimator.start();

View File

@@ -22,7 +22,6 @@ import android.view.animation.DecelerateInterpolator;
import androidx.annotation.Nullable;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.eagle.core.utilcode.util.BitmapHelper;
import com.mogo.och.bus.R;
import me.jessyan.autosize.AutoSizeConfig;
@@ -93,7 +92,7 @@ public class SlidePanelView extends View {
private ObjectAnimator matrixAnim;
private String blockText = STRING_SLIDE_TO_RIGHT;
private Paint.FontMetrics blockTextMetrics = new Paint.FontMetrics();
private final Paint.FontMetrics blockTextMetrics = new Paint.FontMetrics();
private static final int GRADIENT_OFFSET = 200;
@@ -250,7 +249,7 @@ public class SlidePanelView extends View {
private void startBlockBackAnim() {
ObjectAnimator blockBackanimator = ObjectAnimator.ofInt(this, "blockOffset", blockOffset, 0);
blockBackanimator.setInterpolator(new DecelerateInterpolator());
blockBackanimator.setDuration(1000 * blockOffset / getWidth());
blockBackanimator.setDuration(1000L * blockOffset / getWidth());
blockBackanimator.start();
lastX = 0;
}
@@ -259,15 +258,15 @@ public class SlidePanelView extends View {
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 画背景
canvas.drawRoundRect(bgRectF, (float) getHeight() / 2, (float) getHeight() / 2, bgPaint);
canvas.drawRoundRect(bgRectF, (float) getHeight() / 2.0f, (float) getHeight() / 2.0f, bgPaint);
// 画文字
gradientMatrix.setTranslate(matrixTranslate, 0);
textGradient.setLocalMatrix(gradientMatrix);
canvas.save();
canvas.drawText(blockText, blockWidth + BLOCK_START_X + textMarginLeft, textOffset, textPaint);
canvas.drawText(blockText, (float) (blockWidth + BLOCK_START_X + textMarginLeft), textOffset, textPaint);
canvas.restore();
// 画滑块
canvas.drawBitmap(bmBlock, BLOCK_START_X + blockOffset, BLOCK_START_Y, blockPaint);
canvas.drawBitmap(bmBlock, (float) (BLOCK_START_X + blockOffset), (float) BLOCK_START_Y, blockPaint);
}
public interface OnSlidePanelMoveToEndListener {