完成调用接口封装

This commit is contained in:
董宏宇
2021-08-04 18:12:30 +08:00
parent 4a9d18fe5a
commit c2abe34d00
18 changed files with 447 additions and 95 deletions

2
.idea/misc.xml generated
View File

@@ -27,7 +27,7 @@
</map>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="Embedded JDK" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="Embedded JDK" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="VisualizationToolProject">

View File

@@ -2,4 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.warning">
<application>
<receiver android:name=".receiver.TestWarningBroadcastReceiver">
<intent-filter>
<action android:name="com.v2x.control" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
</manifest>

View File

@@ -4,11 +4,13 @@ import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.module.warning.ui.MoGoWarningFragment;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.module.ModuleType;
import com.mogo.service.warning.IMoGoWaringProvider;
import com.mogo.utils.logger.Logger;
@@ -21,16 +23,18 @@ import com.mogo.utils.logger.Logger;
public class MoGoWarningProvider implements IMoGoWaringProvider {
private String TAG = "MoGoWarningProvider";
private MoGoWarningFragment mMoGoWarningFragment;
@Override
public void init(Context context) {
Logger.d(TAG, "初始化蘑菇预警模块 ……");
}
@Override
public Fragment createFragment(Context context, Bundle data) {
Logger.d(TAG, "初始化蘑菇预警模块 Fragment……");
return new MoGoWarningFragment();
mMoGoWarningFragment = new MoGoWarningFragment();
return mMoGoWarningFragment;
}
@NonNull
@@ -41,6 +45,31 @@ public class MoGoWarningProvider implements IMoGoWaringProvider {
@Override
public int getType() {
return 0;
return ModuleType.TYPE_CARD_FRAGMENT;
}
@Override
public void showWarningV2X(int v2xType, @Nullable String alertMessage) {
mMoGoWarningFragment.showWarningV2X(v2xType, alertMessage);
}
@Override
public void showWarningTrafficLight(int checkLightId) {
mMoGoWarningFragment.showWarningTrafficLight(checkLightId);
}
@Override
public void disableWarningTrafficLight() {
mMoGoWarningFragment.disableWarningTrafficLight();
}
@Override
public void showLimitingVelocity(int limitingSpeed) {
mMoGoWarningFragment.showLimitingVelocity(limitingSpeed);
}
@Override
public void disableLimitingVelocity() {
mMoGoWarningFragment.disableLimitingVelocity();
}
}

View File

@@ -7,6 +7,6 @@ package com.mogo.module.warning;
public class WaringConst {
public static String MODULE_NAME = "MODULE_LEFT_PANEL";
public static String BROADCAST_TEST_CONTROL_TYPE_EXTRA_KEY = "waring_type";
public static String BROADCAST_TEST_CONTROL_TYPE_EXTRA_KEY = "warningType";
}

View File

@@ -0,0 +1,76 @@
package com.mogo.module.warning;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-01-1514:47
* desc : 车机启动状态
* version: 1.0
*/
public interface WarningTypeEnum {
/**
* 前向碰撞
*/
int WARING_TYPE_PRIOR_COLLISION = 20001;
/**
* 交叉路口碰撞
*/
int WARING_TYPE_INTERSECTION_COLLISION = 20002;
/**
* 左转辅助
*/
int WARING_TYPE_LEFT_AUXILIARY = 20003;
/**
* 盲区/变道辅助
*/
int WARING_TYPE_BLIND_AREA_COLLISION = 20004;
/**
* 逆向超车
*/
int WARING_TYPE_REVERSE_OVERTAKING = 20005;
/**
* 紧急制动-前车急刹
*/
int WARING_TYPE_VEHICLE_BRAKES = 20006;
/**
* 异常车辆提醒
*/
int WARING_TYPE_ABNORMAL_VEHICLE = 20007;
/**
* 车辆失控预警
*/
int WARING_TYPE_VEHICLE_CONTROL = 20008;
/**
* 道路危险情况预警
*/
int WARING_TYPE_ROAD_HAZARDS = 20009;
/**
* 限速预警
*/
int WARING_TYPE_SPEED_LIMIT = 20010;
/**
* 闯红灯预警
*/
int WARING_TYPE_RED_LIGHT = 20011;
/**
* 弱势交通参与者预警
*/
int WARING_TYPE_VULNERABLE_TRANSPORT_PARTICIPANT = 20012;
/**
* 绿波通行车速引导
*/
int WARING_TYPE_TRAFFIC_SPEED_GUIDE = 20013;
/**
* 车内标牌
*/
int WARING_TYPE_CAR_PLATE = 20014;
/**
* 前方道路拥堵
*/
int WARING_TYPE_TRAFFIC_JAM_AHEAD = 20015;
/**
* 特种车辆通行
*/
int WARING_TYPE_SPECIAL_VEHICLE_ACCESS = 20016;
}

View File

@@ -13,7 +13,7 @@ import com.mogo.module.warning.R;
* @date 2021/8/3 5:50 下午
* 通知管理
*/
public class NotificationManager {
public class WarningNotificationManager {
public static void show(Activity activity) {

View File

@@ -1,46 +0,0 @@
package com.mogo.module.warning.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.mogo.module.warning.WaringConst;
import com.mogo.utils.logger.Logger;
/**
* V2X 测试面板广播接收,目的是可以通过广播调用起来面板
*
* @author donghongyu
*/
public class TestObuBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "TestPanelBroadcastReceiver";
private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
try {
this.mContext = context;
int waringType = intent.getIntExtra(WaringConst.BROADCAST_TEST_CONTROL_TYPE_EXTRA_KEY, 0);
Logger.d(TAG, "waringType:" + waringType);
// 分发场景
dispatchSceneTest(waringType);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 分发处理场景
*
* @param sceneType 场景类型
*/
private void dispatchSceneTest(int sceneType) {
Logger.d(TAG, "sceneType=" + sceneType);
}
}

View File

@@ -0,0 +1,91 @@
package com.mogo.module.warning.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.module.warning.WaringConst;
import com.mogo.module.warning.WarningTypeEnum;
import com.mogo.service.IMogoServiceApis;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.warning.IMoGoWaringProvider;
import com.mogo.utils.logger.Logger;
/**
* V2X 测试面板广播接收,目的是可以通过广播调用起来面板
*
* @author donghongyu
*/
public class TestWarningBroadcastReceiver extends BroadcastReceiver {
private static final String TAG = "TestPanelBroadcastReceiver";
private Context mContext;
private static IMogoServiceApis mMogoServiceApis;
private static IMoGoWaringProvider mIMoGoWaringProvider;
@Override
public void onReceive(Context context, Intent intent) {
try {
mMogoServiceApis = (IMogoServiceApis) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation(context);
mIMoGoWaringProvider = mMogoServiceApis.getWaringProviderApi();
this.mContext = context;
int warningType = intent.getIntExtra(WaringConst.BROADCAST_TEST_CONTROL_TYPE_EXTRA_KEY, 0);
Logger.d(TAG, "warningType:" + warningType);
// 分发场景
dispatchWaring(warningType);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 分发处理场景
*
* @param warningType 场景类型
*/
private void dispatchWaring(int warningType) {
mIMoGoWaringProvider.showWarningV2X(warningType, "预警消息");
switch (warningType) {
case WarningTypeEnum.WARING_TYPE_PRIOR_COLLISION://前向碰撞
break;
case WarningTypeEnum.WARING_TYPE_INTERSECTION_COLLISION://交叉路口碰撞
break;
case WarningTypeEnum.WARING_TYPE_LEFT_AUXILIARY://左转辅助
break;
case WarningTypeEnum.WARING_TYPE_BLIND_AREA_COLLISION://盲区/变道辅助
break;
case WarningTypeEnum.WARING_TYPE_REVERSE_OVERTAKING://逆向超车
break;
case WarningTypeEnum.WARING_TYPE_VEHICLE_BRAKES://紧急制动-前车急刹
break;
case WarningTypeEnum.WARING_TYPE_ABNORMAL_VEHICLE://异常车辆提醒
break;
case WarningTypeEnum.WARING_TYPE_VEHICLE_CONTROL://车辆失控预警
break;
case WarningTypeEnum.WARING_TYPE_ROAD_HAZARDS://道路危险情况提示
break;
case WarningTypeEnum.WARING_TYPE_SPEED_LIMIT://限速预警
break;
case WarningTypeEnum.WARING_TYPE_RED_LIGHT://闯红灯预警
break;
case WarningTypeEnum.WARING_TYPE_VULNERABLE_TRANSPORT_PARTICIPANT://弱势交通参与者
break;
case WarningTypeEnum.WARING_TYPE_TRAFFIC_SPEED_GUIDE://绿波通行车速引导
break;
case WarningTypeEnum.WARING_TYPE_CAR_PLATE://车内标牌
break;
case WarningTypeEnum.WARING_TYPE_TRAFFIC_JAM_AHEAD://前方道路拥堵
break;
case WarningTypeEnum.WARING_TYPE_SPECIAL_VEHICLE_ACCESS://紧急车辆提醒(特种车辆优先通行)
break;
}
}
}

View File

@@ -0,0 +1,54 @@
package com.mogo.module.warning.ui
import com.mogo.commons.mvp.IView
/**
*@author xiaoyuzhou
*@date 2021/8/4 3:38 下午
*/
interface MoGoWarningContract {
/**
*
*/
interface View : IView {
/**
* 展示VR下V2X预警弹窗
*
* @param v2xType V2X类型
* @param alertMessage 提醒文本
*/
fun showWarningV2X(v2xType: Int, alertMessage: String?)
/**
* 关闭VR下V2X预警弹窗
*/
fun disableWarningV2X()
/**
* 展示红绿灯预警
*
* @param checkLightId 0-都是默认1-红2-黄3-绿
*/
fun showWarningTrafficLight(checkLightId: Int)
/**
* 关闭红绿灯预警
*/
fun disableWarningTrafficLight()
/**
* 展示限速预警
*
* @param limitingSpeed 限速速度
*/
fun showLimitingVelocity(limitingSpeed: Int)
/**
* 关闭限速预警
*/
fun disableLimitingVelocity()
}
}

View File

@@ -2,18 +2,47 @@ package com.mogo.module.warning.ui
import com.mogo.commons.mvp.MvpFragment
import com.mogo.module.warning.R
import com.mogo.module.warning.notification.WarningNotificationManager
/**
* @author xiaoyuzhou
* @date 2021/8/3 2:40 下午
* 预警图层
*/
class MoGoWarningFragment : MvpFragment<WaringView?, WaringPresenter?>(), WaringView {
class MoGoWarningFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>(),
MoGoWarningContract.View {
override fun initViews() {}
override fun getLayoutId(): Int {
return R.layout.fragment_warning
}
override fun initViews() {}
override fun createPresenter(): WaringPresenter {
return WaringPresenter(this)
}
override fun showWarningV2X(v2xType: Int, alertMessage: String?) {
WarningNotificationManager.show(activity)
}
override fun disableWarningV2X() {
}
override fun showWarningTrafficLight(checkLightId: Int) {
}
override fun disableWarningTrafficLight() {
}
override fun showLimitingVelocity(limitingSpeed: Int) {
}
override fun disableLimitingVelocity() {
}
}

View File

@@ -0,0 +1,57 @@
package com.mogo.module.warning.ui
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import com.mogo.module.warning.R
import kotlinx.android.synthetic.main.view_traffic_light_vr.view.*
/**
* @author xiaoyuzhou
* @date 2021/8/4 3:16 下午
* 红绿灯控件
*/
class ViewTrafficLight @JvmOverloads constructor(
context: Context?,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {
init {
LayoutInflater.from(context).inflate(R.layout.view_traffic_light_vr, this, true)
}
/**
* 展示红绿灯预警
*
* @param checkLightId 0-都是默认1-红2-黄3-绿
*/
fun showWarningTrafficLight(checkLightId: Int) {
when (checkLightId) {
0 -> {
ctvRedTrafficLight.isChecked = false
ctvYellowTrafficLight.isChecked = false
ctvGreenTrafficLight.isChecked = false
}
1 -> {
ctvRedTrafficLight.isChecked = true
ctvYellowTrafficLight.isChecked = false
ctvGreenTrafficLight.isChecked = false
}
2 -> {
ctvRedTrafficLight.isChecked = false
ctvYellowTrafficLight.isChecked = true
ctvGreenTrafficLight.isChecked = false
}
3 -> {
ctvRedTrafficLight.isChecked = false
ctvYellowTrafficLight.isChecked = false
ctvGreenTrafficLight.isChecked = true
}
}
}
}

View File

@@ -1,13 +1,36 @@
package com.mogo.module.warning.ui;
package com.mogo.module.warning.ui
import com.mogo.commons.mvp.Presenter;
import com.mogo.commons.mvp.Presenter
/**
* @author xiaoyuzhou
* @date 2021/8/3 3:55 下午
*/
public class WaringPresenter extends Presenter< WaringView > {
public WaringPresenter(WaringView view) {
super(view);
class WaringPresenter(view: MoGoWarningContract.View?) :
Presenter<MoGoWarningContract.View?>(view) {
fun showWarningV2X(v2xType: Int, alertMessage: String?) {
mView?.showWarningV2X(v2xType, alertMessage)
}
}
fun disableWarningV2X() {
mView?.disableWarningV2X()
}
fun showWarningTrafficLight(checkLightId: Int) {
mView?.showWarningTrafficLight(checkLightId)
}
fun disableWarningTrafficLight() {
mView?.disableWarningTrafficLight()
}
fun showLimitingVelocity(limitingSpeed: Int) {
mView?.showLimitingVelocity(limitingSpeed)
}
fun disableLimitingVelocity() {
mView?.disableLimitingVelocity()
}
}

View File

@@ -1,10 +0,0 @@
package com.mogo.module.warning.ui;
import com.mogo.commons.mvp.IView;
/**
* @author xiaoyuzhou
* @date 2021/8/3 3:54 下午
*/
public interface WaringView extends IView {
}

View File

@@ -5,9 +5,8 @@
android:layout_height="match_parent">
<include
android:id="@+id/view_traffic_light_vr"
layout="@layout/view_traffic_light_vr"
<com.mogo.module.warning.ui.ViewTrafficLight
android:id="@+id/viewTrafficLightVr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40px"
@@ -16,7 +15,7 @@
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_limiting_velocity"
android:id="@+id/tvLimitingVelocity"
android:layout_width="130px"
android:layout_height="130px"
android:layout_marginTop="30px"
@@ -25,8 +24,8 @@
android:text="60"
android:textColor="#FFFFFF"
android:textSize="74px"
app:layout_constraintEnd_toEndOf="@+id/view_traffic_light_vr"
app:layout_constraintTop_toBottomOf="@+id/view_traffic_light_vr" />
app:layout_constraintEnd_toEndOf="@+id/viewTrafficLightVr"
app:layout_constraintTop_toBottomOf="@+id/viewTrafficLightVr" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -2,7 +2,7 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cl_traffic_light"
android:id="@+id/clTrafficLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_waring_traffic_light_vr"
@@ -12,23 +12,23 @@
android:paddingBottom="30px">
<CheckedTextView
android:id="@+id/tv_red"
android:id="@+id/ctvRedTrafficLight"
android:layout_width="70px"
android:layout_height="70px"
android:background="@drawable/icon_waring_traffic_light_red_vr"
android:checked="true"
android:gravity="center"
android:text="99"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="38px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_yellow"
app:layout_constraintEnd_toStartOf="@+id/ctvYellowTrafficLight"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
tools:checked="true"
tools:text="99" />
<CheckedTextView
android:id="@+id/tv_yellow"
android:id="@+id/ctvYellowTrafficLight"
android:layout_width="70px"
android:layout_height="70px"
android:layout_marginStart="18px"
@@ -39,14 +39,14 @@
android:textColor="#FFFFFF"
android:textSize="38px"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/tv_green"
app:layout_constraintStart_toEndOf="@+id/tv_red"
app:layout_constraintEnd_toStartOf="@+id/ctvGreenTrafficLight"
app:layout_constraintStart_toEndOf="@+id/ctvRedTrafficLight"
app:layout_constraintTop_toTopOf="parent"
tools:checked="true"
tools:text="99" />
<CheckedTextView
android:id="@+id/tv_green"
android:id="@+id/ctvGreenTrafficLight"
android:layout_width="70px"
android:layout_height="70px"
android:background="@drawable/icon_waring_traffic_light_green_vr"

View File

@@ -1,4 +1,10 @@
apply plugin: 'com.android.library'
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.alibaba.arouter'
}
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
@@ -12,9 +18,11 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
javaCompileOptions {
annotationProcessorOptions {
arguments = [AROUTER_MODULE_NAME: project.getName()]
//ARouter apt 参数
kapt {
useBuildCache = false
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
@@ -39,7 +47,7 @@ dependencies {
api rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.arouter
annotationProcessor rootProject.ext.dependencies.aroutercompiler
kapt rootProject.ext.dependencies.aroutercompiler
api rootProject.ext.dependencies.mogoaicloudrealtime
api rootProject.ext.dependencies.fresco

View File

@@ -163,6 +163,8 @@ public class MogoServicePaths {
/**
* 接口集合
*/
@Keep
@Deprecated
public static final String PATH_SERVICE_APIS = "/mogoservice/apis";
/**

View File

@@ -1,11 +1,41 @@
package com.mogo.service.warning;
package com.mogo.service.warning
import com.mogo.service.module.IMogoModuleProvider;
import com.mogo.service.module.IMogoModuleProvider
/**
* @author xiaoyuzhou
* @date 2021/8/2 7:36 下午
*/
public interface IMoGoWaringProvider extends IMogoModuleProvider {
interface IMoGoWaringProvider : IMogoModuleProvider {
/**
* 展示VR下V2X预警
*
* @param v2xType V2X类型
* @param alertMessage 提醒文本
*/
fun showWarningV2X(v2xType: Int, alertMessage: String?)
}
/**
* 展示红绿灯预警
*
* @param checkLightId 0-都是默认1-红2-黄3-绿
*/
fun showWarningTrafficLight(checkLightId: Int)
/**
* 关闭红绿灯预警
*/
fun disableWarningTrafficLight()
/**
* 展示限速预警
*
* @param limitingSpeed 限速速度
*/
fun showLimitingVelocity(limitingSpeed: Int)
/**
* 关闭限速预警
*/
fun disableLimitingVelocity()
}