Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -4,7 +4,7 @@
|
||||
<asm skipDebug="false" skipFrames="false" skipCode="false" expandFrames="false" />
|
||||
<groovy codeStyle="LEGACY" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -30,7 +30,7 @@ dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
// 上报位置
|
||||
implementation 'com.zhidao.locupload:loc-upload-sdk:1.0.6'
|
||||
implementation 'com.zhidao.locupload:loc-upload-sdk:1.0.8'
|
||||
// 长链
|
||||
implementation 'com.zhidao.socket:built-in-socket:1.0.12'
|
||||
// passport
|
||||
|
||||
1
foudations/mogo-connection/.gitignore
vendored
1
foudations/mogo-connection/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
/build
|
||||
@@ -1,49 +0,0 @@
|
||||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'com.alibaba.arouter'
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.android.compileSdkVersion
|
||||
// buildToolsVersion rootProject.ext.android.buildToolsVersion
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.ext.android.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.android.targetSdkVersion
|
||||
versionCode Integer.valueOf(VERSION_CODE)
|
||||
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles 'consumer-rules.pro'
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
api rootProject.ext.dependencies.socketsdk
|
||||
api rootProject.ext.dependencies.socketsdkconnsvrprotoco
|
||||
api rootProject.ext.dependencies.socketsdkprotobufjava
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
annotationProcessor rootProject.ext.dependencies.aroutercompiler
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation rootProject.ext.dependencies.mogoutils
|
||||
implementation rootProject.ext.dependencies.mogoserviceapi
|
||||
} else {
|
||||
implementation project(":foudations:mogo-utils")
|
||||
implementation project(":services:mogo-service-api")
|
||||
}
|
||||
}
|
||||
|
||||
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()
|
||||
@@ -1,3 +0,0 @@
|
||||
GROUP=com.mogo.connection
|
||||
POM_ARTIFACT_ID=mogo-connection
|
||||
VERSION_CODE=1
|
||||
21
foudations/mogo-connection/proguard-rules.pro
vendored
21
foudations/mogo-connection/proguard-rules.pro
vendored
@@ -1,21 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -1,2 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mogo.connection" />
|
||||
@@ -1,223 +0,0 @@
|
||||
package com.mogo.connection.socket;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.service.connection.IMessageResponse;
|
||||
import com.mogo.service.connection.IMogoMsgAckListener;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.connection.IMogoSocketManager;
|
||||
import com.mogo.service.connection.MsgBody;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.zhidao.ptech.connsvr.commom.protocol.MogoCommon;
|
||||
import com.zhidao.ptech.connsvr.protocol.MogoConnsvr;
|
||||
import com.zhidao.socketsdk.manager.OnSocketAckCallback;
|
||||
import com.zhidao.socketsdk.manager.OnSocketReceiveCallback;
|
||||
import com.zhidao.socketsdk.manager.SocketConnManager;
|
||||
import com.zhidao.socketsdk.manager.SocketConnManagerImpl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
* <p>
|
||||
* 长链实现:基于 netty
|
||||
*/
|
||||
|
||||
public class SocketManager implements IMogoSocketManager, OnSocketReceiveCallback, OnSocketAckCallback {
|
||||
|
||||
private static final String TAG = "SocketManager";
|
||||
|
||||
public static final int MSG_PRODUCT_LINE = MogoCommon.Product.mogoBussiness_VALUE;
|
||||
private static final int MSG_HEADER_TYPE = MogoConnsvr.MsgType.mogoMsgTypeDispatchSvrNoRspReq_VALUE;
|
||||
|
||||
private static volatile SocketManager sInstance;
|
||||
|
||||
private SocketManager( Context context ) {
|
||||
mSocketConnManager = SocketConnManagerImpl.getInstance( context );
|
||||
mSocketConnManager.addSocketMessageCallback( this );
|
||||
mSocketConnManager.addSocketAckCallback( this );
|
||||
}
|
||||
|
||||
public static SocketManager getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( SocketManager.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new SocketManager( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理消息分发
|
||||
* <p>
|
||||
* key - msgType
|
||||
*/
|
||||
private Map< Integer, List< IMogoOnMessageListener > > mListeners = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* 管理消息回执
|
||||
* <p>
|
||||
* key - msgId
|
||||
*/
|
||||
private Map< Long, IMogoMsgAckListener > mAckListeners = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private SocketConnManager mSocketConnManager;
|
||||
public static final int MAX_CAP = 64; //保证充足的容量应对非常延时的推送
|
||||
private ArrayList< Long > mReceivedMsgId = new ArrayList<>( MAX_CAP );
|
||||
private int mCurrentIndex = 0;
|
||||
|
||||
@Override
|
||||
public void init( Context context, String appId ) {
|
||||
if ( mSocketConnManager != null ) {
|
||||
mSocketConnManager.init( appId );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived( byte[] content, long msgId ) {
|
||||
try {
|
||||
MogoConnsvr.Payload payload = MogoConnsvr.Payload.parseFrom( content );
|
||||
int msgType = payload.getMsgType();
|
||||
Logger.d( TAG, "received msg type = %d", msgType );
|
||||
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
|
||||
if ( listeners != null && !listeners.isEmpty() ) {
|
||||
Iterator< IMogoOnMessageListener > iterator = listeners.iterator();
|
||||
if ( msgId != 0 ) { //兼容老版本
|
||||
if ( mReceivedMsgId.contains( msgId ) ) { // 避免消息重发
|
||||
return;
|
||||
}
|
||||
cacheLastReceivedMsgId( msgId );
|
||||
}
|
||||
Object object = null;
|
||||
while ( iterator.hasNext() ) {
|
||||
IMogoOnMessageListener listener = iterator.next();
|
||||
if ( object == null ) {
|
||||
object = GsonUtil.objectFromJson( payload.getPayload().toStringUtf8(), listener.target() );
|
||||
}
|
||||
if ( listener != null ) {
|
||||
Logger.d( TAG, "received msgId = %s, content = %s", msgId, payload.getPayload().toStringUtf8() );
|
||||
listener.onMsgReceived( object );
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch ( InvalidProtocolBufferException e ) {
|
||||
Logger.e( TAG, e, "parse msg error." );
|
||||
}
|
||||
}
|
||||
|
||||
private void cacheLastReceivedMsgId( long msgId ) {
|
||||
if ( msgId == 0 ) {
|
||||
return;
|
||||
}
|
||||
synchronized ( this ){
|
||||
mReceivedMsgId.add( mCurrentIndex % MAX_CAP, msgId );
|
||||
mCurrentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAck( byte[] headerBytes, byte[] payloadBytes ) {
|
||||
try {
|
||||
MogoConnsvr.Header header = MogoConnsvr.Header.parseFrom( headerBytes );
|
||||
int msgType = header.getMsgType();
|
||||
String appId = header.getAppId();
|
||||
int productLine = header.getProductLine();
|
||||
long msgId = header.getMsgId();
|
||||
IMogoMsgAckListener listener = mAckListeners.remove( msgId );
|
||||
if ( listener != null ) {
|
||||
listener.onAck( msgId );
|
||||
}
|
||||
Logger.d( TAG, "send message success: msgType = %d, appId = %s, productLine = %d", msgType, appId, productLine );
|
||||
} catch ( InvalidProtocolBufferException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerOnMessageListener( int msgType, IMogoOnMessageListener listener ) {
|
||||
if ( mListeners.containsKey( msgType ) ) {
|
||||
Logger.w( TAG, "msgType %d is exist.", msgType );
|
||||
}
|
||||
if ( !mListeners.containsKey( msgType ) ) {
|
||||
mListeners.put( msgType, new ArrayList< IMogoOnMessageListener >() );
|
||||
}
|
||||
mListeners.get( msgType ).add( listener );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnMessageListener( int msgType ) {
|
||||
mListeners.remove( msgType );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterOnMessageListener( int msgType, IMogoOnMessageListener listener ) {
|
||||
if ( listener == null ) {
|
||||
return;
|
||||
}
|
||||
if ( !mListeners.containsKey( msgType ) ) {
|
||||
return;
|
||||
}
|
||||
List< IMogoOnMessageListener > listeners = mListeners.get( msgType );
|
||||
if ( listeners != null && listeners.contains( listener ) ) {
|
||||
listeners.remove( listener );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMsg( MsgBody body, IMogoMsgAckListener listener ) {
|
||||
Logger.d( TAG, "sendMsg." );
|
||||
if ( mSocketConnManager != null ) {
|
||||
if ( mSocketConnManager.isConnected() ) {
|
||||
Logger.d( TAG, "isConnected." );
|
||||
final byte[] pb = convertToPBBytes( body.getMsgType(), objectToBytes( body.getContent() ) );
|
||||
mSocketConnManager.sendPayload(
|
||||
MSG_PRODUCT_LINE,
|
||||
pb,
|
||||
MSG_HEADER_TYPE,
|
||||
body.isAck(),
|
||||
body.getMsgId()
|
||||
);
|
||||
mAckListeners.put( body.getMsgId(), listener );
|
||||
} else {
|
||||
Logger.e( TAG, "sendMsg error, connect is lost." );
|
||||
}
|
||||
} else {
|
||||
Logger.e( TAG, "sendMsg error, client is null." );
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] objectToBytes( Object obj ) {
|
||||
String jsonStr = GsonUtil.jsonFromObject( obj );
|
||||
return jsonStr.getBytes();
|
||||
}
|
||||
|
||||
private byte[] convertToPBBytes( int msgType, byte[] payloadBytes ) {
|
||||
MogoConnsvr.Payload payloadData = MogoConnsvr.Payload.newBuilder()
|
||||
.setMsgType( msgType )
|
||||
.setPayload( ByteString.copyFrom( payloadBytes ) ).build();
|
||||
return payloadData.toByteArray();
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
mListeners.clear();
|
||||
mListeners = null;
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void init( Context context ) {
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">mogo-connection</string>
|
||||
</resources>
|
||||
@@ -54,6 +54,7 @@ public class UserDataMarkerInfoWindowAdapter implements IMogoInfoWindowAdapter {
|
||||
|
||||
private View mInfoWindowView = null;
|
||||
|
||||
private View mContentContainer;
|
||||
private MogoImageView mUserHeader;
|
||||
private TextView mContent;
|
||||
private TextView mTag;
|
||||
@@ -92,12 +93,21 @@ public class UserDataMarkerInfoWindowAdapter implements IMogoInfoWindowAdapter {
|
||||
|
||||
if ( mInfoWindowView == null ) {
|
||||
mInfoWindowView = LayoutInflater.from( mContext ).inflate( R.layout.view_map_data_user_info_window, null );
|
||||
mContentContainer = mInfoWindowView.findViewById( R.id.module_service_id_marker_content );
|
||||
mUserHeader = mInfoWindowView.findViewById( R.id.module_service_id_user_header );
|
||||
mContent = mInfoWindowView.findViewById( R.id.module_service_id_content );
|
||||
mTag = mInfoWindowView.findViewById( R.id.module_service_id_tag );
|
||||
mCall = mInfoWindowView.findViewById( R.id.module_service_id_call );
|
||||
}
|
||||
|
||||
mCall.setVisibility( DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_BYD ? View.GONE : View.VISIBLE );
|
||||
if ( DebugConfig.getCarMachineType() == DebugConfig.CAR_MACHINE_TYPE_BYD ) {
|
||||
mContentContainer.setPadding(
|
||||
mContentContainer.getPaddingLeft(),
|
||||
mContentContainer.getPaddingTop(),
|
||||
mContentContainer.getResources().getDimensionPixelSize( R.dimen.module_service_id_marker_content_paddingRight_widthoutCall ),
|
||||
mContentContainer.getPaddingBottom()
|
||||
);
|
||||
mCall.setVisibility( View.GONE );
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
android:id="@+id/module_service_id_marker_content"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/module_services_info_window_height"
|
||||
android:paddingRight="@dimen/module_service_id_marker_content_paddingRight"
|
||||
android:background="@drawable/module_services_driver_blue_info"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
@@ -44,7 +45,7 @@
|
||||
app:layout_constraintStart_toEndOf="@+id/module_service_id_user_header"
|
||||
app:layout_constraintTop_toTopOf="@+id/module_service_id_user_header"
|
||||
app:layout_goneMarginRight="@dimen/dp_30"
|
||||
tools:text="诗" />
|
||||
tools:text="诗一样的远方的远方" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/module_service_id_tag"
|
||||
@@ -64,7 +65,6 @@
|
||||
android:layout_height="@dimen/module_service_user_header_height"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="@dimen/dp_10"
|
||||
android:layout_marginRight="2.5px"
|
||||
android:scaleType="fitXY"
|
||||
android:src="@drawable/module_service_ic_call"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
||||
@@ -21,4 +21,5 @@
|
||||
<dimen name="module_service_content_textSize">24px</dimen>
|
||||
<dimen name="module_service_tag_textSize">20px</dimen>
|
||||
<dimen name="module_service_content_minWidth">120px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight_widthoutCall">20px</dimen>
|
||||
</resources>
|
||||
@@ -20,4 +20,6 @@
|
||||
<dimen name="module_service_content_textSize">14px</dimen>
|
||||
<dimen name="module_service_tag_textSize">12px</dimen>
|
||||
<dimen name="module_service_content_minWidth">64px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight">6.5px</dimen>
|
||||
<dimen name="module_service_id_marker_content_paddingRight_widthoutCall">10px</dimen>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user