[Change]
加入usb-camera
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
(cherry picked from commit 3f64bb093a)
Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -1,229 +0,0 @@
|
||||
package com.mogo.map.impl.automap.navi;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Rect;
|
||||
import android.location.Location;
|
||||
|
||||
import com.mogo.eagle.core.data.map.MogoLatLng;
|
||||
import com.mogo.map.navi.IMogoCarLocationChangedListener2;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.navi.MogoCalculatePath;
|
||||
import com.mogo.map.navi.MogoNaviConfig;
|
||||
import com.mogo.map.navi.OnCalculatePathItemClickInteraction;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/2
|
||||
* <p>
|
||||
* 使用高德车机版导航
|
||||
*/
|
||||
public class AutoNaviClient implements IMogoNavi {
|
||||
|
||||
private static final String TAG = "NaviClient";
|
||||
|
||||
public static final String ACTION_AUTO_MAP = "AUTONAVI_STANDARD_BROADCAST_RECV";
|
||||
|
||||
public static final String KEY_TYPE = "KEY_TYPE";
|
||||
public static final String SOURCE_APP = "SOURCE_APP";
|
||||
public static final String LAT = "LAT";
|
||||
public static final String LON = "LON";
|
||||
public static final String ENTRY_LAT = "ENTRY_LAT";
|
||||
public static final String ENTRY_LON = "ENTRY_LON";
|
||||
public static final String DEV = "DEV"; // (int)是否偏移(0:lat 和 lon 是已经加密后的,不需要国测加密; 1:需要国测加密)
|
||||
|
||||
/**
|
||||
* (必填)(int)导航方式
|
||||
* =1(避免收费)
|
||||
* =2(多策略算路)
|
||||
* =3 (不走高速)
|
||||
* =4(躲避拥堵)
|
||||
* =5(不走高速且避免收费)
|
||||
* =6(不走高速且躲避拥堵)
|
||||
* =7(躲避收费且躲避拥堵)
|
||||
* =8(不走高速躲避收费和拥堵)
|
||||
* =20 (高速优先)
|
||||
* =24(高速优先且躲避拥堵)
|
||||
* =-1(地图内部设置默认规则)
|
||||
*/
|
||||
public static final String STYLE = "STYLE";
|
||||
|
||||
private static volatile AutoNaviClient sInstance;
|
||||
private final Context mContext;
|
||||
|
||||
private AutoNaviClient( Context context ) {
|
||||
mContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public static AutoNaviClient getInstance( Context context ) {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( AutoNaviClient.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new AutoNaviClient( context );
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public void naviTo( MogoLatLng endPoint ) {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra( KEY_TYPE, 10038 );
|
||||
intent.putExtra( LAT, endPoint.lat );
|
||||
intent.putExtra( LON, endPoint.lon );
|
||||
// intent.putExtra( ENTRY_LAT, endPoint.lat );
|
||||
// intent.putExtra( ENTRY_LON, endPoint.lon );
|
||||
intent.putExtra( DEV, 0 );
|
||||
intent.putExtra( STYLE, -1 );
|
||||
intent.putExtra( SOURCE_APP, "Third App" );
|
||||
sendByIntent( intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint, MogoNaviConfig config ) {
|
||||
naviTo( endPoint );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint, List< MogoLatLng > wayPoints ) {
|
||||
naviTo( endPoint );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void naviTo( MogoLatLng endPoint, List< MogoLatLng > wayPoints, MogoNaviConfig config ) {
|
||||
naviTo( endPoint );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reCalculateRoute( MogoNaviConfig config ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopNavi() {
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra( "KEY_TYPE", 10010 );
|
||||
sendByIntent( intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startNavi( boolean isRealNavi ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
private void sendByIntent( Intent intent ) {
|
||||
intent.setAction( ACTION_AUTO_MAP );
|
||||
intent.addFlags( Intent.FLAG_INCLUDE_STOPPED_PACKAGES );
|
||||
mContext.sendBroadcast( intent );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNaviing() {
|
||||
return MapState.getInstance().isNaving();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoCalculatePath > getCalculatedStrategies() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoLatLng > getCalculatedPathPos() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLineClickInteraction( OnCalculatePathItemClickInteraction itemClickInteraction ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCalculatePaths() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCalculatePathDisplayBounds( Rect bounds ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoNaviConfig getNaviConfig() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
return MogoMapApi.getApiBuilder().getNavi( mContext ).getNaviConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setBroadcastMode( int mode ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List< MogoLatLng > getNaviPathCoordinates() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCarLocation() {
|
||||
return MogoMapApi.getApiBuilder().getNavi( mContext ).getCarLocation();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getCarLocation2() {
|
||||
return MogoMapApi.getApiBuilder().getNavi( mContext ).getCarLocation2();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCarLocationChangedListener( IMogoCarLocationChangedListener2 listener ) {
|
||||
//do not impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startAimlessMode() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stopAimlessMode() {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAimlessModeStatus( boolean open ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayOverview( Rect bounds ) {
|
||||
Logger.w( TAG, "高德车机导航,不支持此设置" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUseExtraGPSData( boolean use ) {
|
||||
MogoMapApi.getApiBuilder().getNavi( mContext ).setUseExtraGPSData( use );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExtraGPSData( double lon, double lat, float speed, float accuracy, float bearing, long timestamp ) {
|
||||
MogoMapApi.getApiBuilder().getNavi( mContext ).setExtraGPSData( lon, lat, speed, accuracy, bearing, timestamp );
|
||||
}
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
package com.mogo.map.impl.automap.navi;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.mogo.commons.storage.SpStorage;
|
||||
import com.mogo.map.navi.MogoNaviInfo;
|
||||
import com.mogo.map.navi.MogoNaviListenerHandler;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/2
|
||||
* <p>
|
||||
* 高德公版地图透出信息广播接收者
|
||||
*/
|
||||
public class AutoNaviReceiver extends BroadcastReceiver {
|
||||
|
||||
private static final String TAG = "AutoNaviReceiver";
|
||||
|
||||
public static final String ACTION_AUTONAVI_SEND = "AUTONAVI_STANDARD_BROADCAST_SEND";
|
||||
private static AutoNaviReceiver autoNaviReceiver;
|
||||
private static boolean sRegisterFlag = false;
|
||||
|
||||
private static MogoNaviInfo sNaviInfo;
|
||||
private static MogoTraffic sTraffic;
|
||||
|
||||
|
||||
public static void register( Context context ) {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction( ACTION_AUTONAVI_SEND );
|
||||
autoNaviReceiver = new AutoNaviReceiver();
|
||||
context.registerReceiver( autoNaviReceiver, filter );
|
||||
sRegisterFlag = true;
|
||||
}
|
||||
|
||||
public static void unregister( Context context ) {
|
||||
if ( autoNaviReceiver != null && sRegisterFlag ) {
|
||||
try {
|
||||
context.unregisterReceiver( autoNaviReceiver );
|
||||
} catch ( Exception e ) {
|
||||
Logger.e( TAG, e, "error. " );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive( Context context, Intent intent ) {
|
||||
String action = intent.getAction();
|
||||
|
||||
if ( !TextUtils.equals( ACTION_AUTONAVI_SEND, action ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
int keyType = intent.getIntExtra( "KEY_TYPE", 0 );
|
||||
switch ( keyType ) {
|
||||
case 10001:
|
||||
handleAutoNaviInfo( context, intent );
|
||||
break;
|
||||
case 10019:
|
||||
int state = intent.getIntExtra( "EXTRA_STATE", -1 );
|
||||
handleMapStatusChanged( state );
|
||||
break;
|
||||
case 10056:
|
||||
String json = intent.getStringExtra( "EXTRA_ROAD_INFO" );
|
||||
SpStorage.setNavigationTarget( json );
|
||||
Logger.d( TAG, json );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 在导航/巡航/模拟导航中auto主动将变化的引导信息发送给第三方系统
|
||||
*
|
||||
* @param intent
|
||||
*/
|
||||
private void handleAutoNaviInfo( Context context, Intent intent ) {
|
||||
|
||||
int type = intent.getIntExtra( GuideInfoExtraKey.TYPE, -1 );
|
||||
|
||||
int cameraSpeed = intent.getIntExtra( GuideInfoExtraKey.CAMERA_SPEED, 0 );
|
||||
int cameraDisc = intent.getIntExtra( GuideInfoExtraKey.CAMERA_DIST, 0 );
|
||||
int cameraType = intent.getIntExtra( GuideInfoExtraKey.CAMERA_TYPE, 0 );
|
||||
|
||||
if ( type == 0 || type == 1 ) {
|
||||
if ( !MapState.getInstance().isNaving()
|
||||
&& MogoNaviListenerHandler.getInstance().hasDelegateListener() ) {
|
||||
MapState.getInstance().setNaving( true );
|
||||
MogoNaviListenerHandler.getInstance().onStartNavi();
|
||||
}
|
||||
if ( sNaviInfo == null ) {
|
||||
sNaviInfo = new MogoNaviInfo();
|
||||
}
|
||||
sNaviInfo.setCurrentLimitSpeed( cameraSpeed );
|
||||
sNaviInfo.setCurrentRoadName( intent.getStringExtra( GuideInfoExtraKey.CUR_ROAD_NAME ) );
|
||||
sNaviInfo.setCurrentSpeed( intent.getIntExtra( GuideInfoExtraKey.CUR_SPEED, 0 ) );
|
||||
sNaviInfo.setCurStepRetainDistance( intent.getIntExtra( GuideInfoExtraKey.SEG_REMAIN_DIS, 0 ) );
|
||||
sNaviInfo.setCurStepRetainTime( intent.getIntExtra( GuideInfoExtraKey.SEG_REMAIN_TIME, 0 ) );
|
||||
sNaviInfo.setIconResId( MogoMapApi.getApiBuilder().getResIdByIconType( context, intent.getIntExtra( GuideInfoExtraKey.NEW_ICON, 0 ) ) );
|
||||
sNaviInfo.setNextRoadName( intent.getStringExtra( GuideInfoExtraKey.NEXT_ROAD_NAME ) );
|
||||
sNaviInfo.setPathRetainDistance( intent.getIntExtra( GuideInfoExtraKey.ROUTE_REMAIN_DIS, 0 ) );
|
||||
sNaviInfo.setPathRetainTime( intent.getIntExtra( GuideInfoExtraKey.ROUTE_REMAIN_TIME, 0 ) );
|
||||
MogoNaviListenerHandler.getInstance().onNaviInfoUpdate( sNaviInfo );
|
||||
}
|
||||
if ( sTraffic == null ) {
|
||||
sTraffic = new MogoTraffic( MapState.getInstance().isAimless() ? MogoTraffic.TYPE_AIM : MogoTraffic.TYPE_NAVI );
|
||||
}
|
||||
sTraffic.setFromType( MapState.getInstance().isAimless() ? MogoTraffic.TYPE_AIM : MogoTraffic.TYPE_NAVI );
|
||||
sTraffic.setDistance( cameraDisc );
|
||||
sTraffic.setSpeedLimit( cameraSpeed );
|
||||
sTraffic.setTrafficType( cameraType );
|
||||
MogoNaviListenerHandler.getInstance().onUpdateTraffic2( sTraffic );
|
||||
}
|
||||
|
||||
/**
|
||||
* 当导航发生状态变更时,将相应的状态通知给系统。
|
||||
*
|
||||
* @param state
|
||||
*/
|
||||
private void handleMapStatusChanged( int state ) {
|
||||
if ( state == -1 ) {
|
||||
return;
|
||||
}
|
||||
switch ( state ) {
|
||||
case MapStateValue.START_NAVI:
|
||||
case MapStateValue.START_EMULATOR_NAVI:
|
||||
if ( MapState.getInstance().isNaving() ) {
|
||||
Logger.w( TAG, "naving..." );
|
||||
return;
|
||||
}
|
||||
MapState.getInstance().setNaving( true );
|
||||
MogoNaviListenerHandler.getInstance().onStartNavi();
|
||||
break;
|
||||
case MapStateValue.STOP_NAVI:
|
||||
case MapStateValue.STOP_EMULATOR_NAVI:
|
||||
case MapStateValue.APP_START: // 语音退出导航,感觉是杀掉了高德APP了
|
||||
if ( MapState.getInstance().isNaving() ) {
|
||||
MapState.getInstance().setNaving( false );
|
||||
MogoNaviListenerHandler.getInstance().onStopNavi();
|
||||
}
|
||||
break;
|
||||
case MapStateValue.START_AIMLESS_NAVI:
|
||||
MapState.getInstance().setAimless( true );
|
||||
break;
|
||||
case MapStateValue.STOP_AIMLESS_NAVI:
|
||||
MapState.getInstance().setAimless( false );
|
||||
break;
|
||||
case MapStateValue.EXIT_APP:
|
||||
break;
|
||||
case MapStateValue.DESTINATION:
|
||||
MogoNaviListenerHandler.getInstance().onArriveDestination();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
package com.mogo.map.impl.automap.navi;
|
||||
|
||||
//引导信息对应的KEY值机器描述
|
||||
public class GuideInfoExtraKey {
|
||||
/**
|
||||
* 导航类型,对应的值为int类型
|
||||
* 0:GPS导航
|
||||
* 1:模拟导航
|
||||
* 2:巡航
|
||||
*/
|
||||
public static final String TYPE = "TYPE";
|
||||
|
||||
/**
|
||||
* 当前道路名称,对应的值为String类型
|
||||
*/
|
||||
public static final String CUR_ROAD_NAME = "CUR_ROAD_NAME";
|
||||
|
||||
/**
|
||||
* 下一道路名,对应的值为String类型
|
||||
*/
|
||||
public static final String NEXT_ROAD_NAME = "NEXT_ROAD_NAME";
|
||||
|
||||
/**
|
||||
* 电子眼限速度,对应的值为int类型,无限速则为0,单位:公里/小时
|
||||
*/
|
||||
public static final String CAMERA_SPEED = "CAMERA_SPEED";
|
||||
|
||||
/**
|
||||
* 导航转向图标,对应的值为int类型
|
||||
*/
|
||||
public static final String ICON = "ICON";
|
||||
|
||||
/**
|
||||
* 导航最新的转向图标,对应的值为int类型
|
||||
*/
|
||||
public static final String NEW_ICON = "NEW_ICON";
|
||||
|
||||
/**
|
||||
* 路径剩余距离,对应的值为int类型,单位:米
|
||||
*/
|
||||
public static final String ROUTE_REMAIN_DIS = "ROUTE_REMAIN_DIS";
|
||||
/**
|
||||
* 路径剩余时间,对应的值为int类型,单位:秒
|
||||
*/
|
||||
public static final String ROUTE_REMAIN_TIME = "ROUTE_REMAIN_TIME";
|
||||
|
||||
/**
|
||||
* 当前导航段剩余距离,对应的值为int类型,单位:米
|
||||
*/
|
||||
public static final String SEG_REMAIN_DIS = "SEG_REMAIN_DIS";
|
||||
|
||||
/**
|
||||
* 当前导航段剩余时间,对应的值为int类型,单位:秒
|
||||
*/
|
||||
public static final String SEG_REMAIN_TIME = "SEG_REMAIN_TIME";
|
||||
|
||||
/**
|
||||
* 路径总距离,对应的值为int类型,单位:米
|
||||
*/
|
||||
public static final String ROUTE_ALL_DIS = "ROUTE_ALL_DIS";
|
||||
|
||||
/**
|
||||
* 路径总时间,对应的值为int类型,单位:秒
|
||||
*/
|
||||
public static final String ROUTE_ALL_TIME = "ROUTE_ALL_TIME";
|
||||
|
||||
/**
|
||||
* 当前车速,对应的值为int类型,单位:公里/小时
|
||||
*/
|
||||
public static final String CUR_SPEED = "CUR_SPEED";
|
||||
|
||||
/**
|
||||
* 当前道路类型,对应的值为int类型
|
||||
* 0:高速公路
|
||||
* 1:国道
|
||||
* 2:省道
|
||||
* 3:县道
|
||||
* 4:乡公路
|
||||
* 5:县乡村内部道路
|
||||
* 6:主要大街、城市快速道 * 7:主要道路
|
||||
* 8:次要道路
|
||||
* 9:普通道路
|
||||
* 10:非导航道路
|
||||
*/
|
||||
public static final String ROAD_TYPE = "ROAD_TYPE";
|
||||
|
||||
/**
|
||||
* 路径剩余时间,对应的值为String类型,单位:天/小时/分钟 比如:1天2小时, 21小时30分
|
||||
* 钟(只用于长安)
|
||||
*/
|
||||
public static final String ROUTE_REMAIN_TIME_STRING = "ROUTE_REMAIN_TIME_S TRING";
|
||||
|
||||
/**
|
||||
* 下下个路名名称,对应的值为String类型
|
||||
*/
|
||||
public static final String NEXT_NEXT_ROAD_NAME = "NEXT_NEXT_ROAD_NAME";
|
||||
/**
|
||||
* 下下个路口转向图标,对应的值为int类型
|
||||
*/
|
||||
|
||||
public static final String NEXT_NEXT_TURN_ICON = "NEXT_NEXT_TURN_ICON";
|
||||
|
||||
/**
|
||||
* 距离下下个路口剩余距离,对应的值为int类型,单位:米
|
||||
*/
|
||||
public static final String NEXT_SEG_REMAIN_DIS = "NEXT_SEG_REMAIN_DIS";
|
||||
|
||||
/**
|
||||
* 距离下下个路口剩余时间,对应的值为int类型,单位:秒
|
||||
*/
|
||||
public static final String NEXT_SEG_REMAIN_TIME = "NEXT_SEG_REMAIN_TIME";
|
||||
|
||||
/**
|
||||
* 距离最近的电子眼距离,对应的值为int类型,单位:米
|
||||
*/
|
||||
public static final String CAMERA_DIST = "CAMERA_DIST";
|
||||
|
||||
/**
|
||||
* 电子眼类型,对应的值为int类型
|
||||
* 0 测速摄像头
|
||||
* 1为监控摄像头
|
||||
* 2为闯红灯拍照
|
||||
* 3为违章拍照
|
||||
* 4为公交专用道摄像头
|
||||
* 5为应急车道摄像头
|
||||
* 6为非机动车道拍照
|
||||
*/
|
||||
public static final String CAMERA_TYPE = "CAMERA_TYPE";
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
package com.mogo.map.impl.automap.navi;
|
||||
|
||||
public
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/3
|
||||
*
|
||||
* 高德地图状态
|
||||
*/
|
||||
class MapState {
|
||||
|
||||
private static volatile MapState sInstance;
|
||||
|
||||
private MapState() {
|
||||
}
|
||||
|
||||
public static MapState getInstance() {
|
||||
if ( sInstance == null ) {
|
||||
synchronized ( MapState.class ) {
|
||||
if ( sInstance == null ) {
|
||||
sInstance = new MapState();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
private boolean isNaving = false;
|
||||
private boolean isAimless = false;
|
||||
|
||||
public boolean isNaving() {
|
||||
return isNaving;
|
||||
}
|
||||
|
||||
public void setNaving( boolean naving ) {
|
||||
isNaving = naving;
|
||||
}
|
||||
|
||||
public boolean isAimless() {
|
||||
return isAimless;
|
||||
}
|
||||
|
||||
public void setAimless( boolean aimless ) {
|
||||
isAimless = aimless;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.mogo.map.impl.automap.navi;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/6/3
|
||||
* <p>
|
||||
* 高德公版地图状态值
|
||||
*/
|
||||
public interface MapStateValue {
|
||||
|
||||
int START_NAVI = 8;
|
||||
|
||||
int STOP_NAVI = 9;
|
||||
|
||||
int START_EMULATOR_NAVI = 10;
|
||||
|
||||
int STOP_EMULATOR_NAVI = 12;
|
||||
|
||||
int START_AIMLESS_NAVI = 24;
|
||||
|
||||
int STOP_AIMLESS_NAVI = 25;
|
||||
|
||||
int EXIT_APP = 45;
|
||||
|
||||
int DESTINATION = 39;
|
||||
|
||||
int APP_START = 0;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.mogo.map.impl.automap.navi;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.IMogoMapApiBuilder;
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2020/12/10
|
||||
* <p>
|
||||
* 描述
|
||||
*/
|
||||
public class MogoMapApi {
|
||||
|
||||
private static IMogoMapApiBuilder sApiBuilder;
|
||||
|
||||
public static IMogoMapApiBuilder getApiBuilder() {
|
||||
if (sApiBuilder == null) {
|
||||
synchronized (AutoNaviClient.class) {
|
||||
if (sApiBuilder == null) {
|
||||
sApiBuilder = ARouter.getInstance().navigation(IMogoMapApiBuilder.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
return sApiBuilder;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
package com.mogo.usbcamera;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.os.Environment;
|
||||
|
||||
import org.easydarwin.sw.TxtOverlay;
|
||||
import com.serenegiant.usb.DeviceFilter;
|
||||
import com.serenegiant.usb.Size;
|
||||
import com.serenegiant.usb.USBMonitor;
|
||||
import com.serenegiant.usb.UVCCamera;
|
||||
import com.serenegiant.usb.common.AbstractUVCCameraHandler;
|
||||
import com.serenegiant.usb.common.UVCCameraHandler;
|
||||
import com.serenegiant.usb.encoder.RecordParams;
|
||||
import com.serenegiant.usb.widget.CameraViewInterface;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/** UVCCamera Helper class
|
||||
*
|
||||
* Created by jiangdongguo on 2017/9/30.
|
||||
*/
|
||||
|
||||
public class UVCCameraHelper {
|
||||
public static final String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()
|
||||
+ File.separator;
|
||||
public static final String SUFFIX_JPEG = ".jpg";
|
||||
public static final String SUFFIX_MP4 = ".mp4";
|
||||
private static final String TAG = "UVCCameraHelper";
|
||||
private int previewWidth = 640;
|
||||
private int previewHeight = 480;
|
||||
public static final int FRAME_FORMAT_YUYV = UVCCamera.FRAME_FORMAT_YUYV;
|
||||
// Default using MJPEG
|
||||
// if your device is connected,but have no images
|
||||
// please try to change it to FRAME_FORMAT_YUYV
|
||||
public static final int FRAME_FORMAT_MJPEG = UVCCamera.FRAME_FORMAT_MJPEG;
|
||||
public static final int MODE_BRIGHTNESS = UVCCamera.PU_BRIGHTNESS;
|
||||
public static final int MODE_CONTRAST = UVCCamera.PU_CONTRAST;
|
||||
private int mFrameFormat = FRAME_FORMAT_MJPEG;
|
||||
|
||||
private static UVCCameraHelper mCameraHelper;
|
||||
// USB Manager
|
||||
private USBMonitor mUSBMonitor;
|
||||
// Camera Handler
|
||||
private UVCCameraHandler mCameraHandler;
|
||||
private USBMonitor.UsbControlBlock mCtrlBlock;
|
||||
|
||||
private Activity mActivity;
|
||||
private CameraViewInterface mCamView;
|
||||
|
||||
private UVCCameraHelper() {
|
||||
}
|
||||
|
||||
public static UVCCameraHelper getInstance() {
|
||||
if (mCameraHelper == null) {
|
||||
mCameraHelper = new UVCCameraHelper();
|
||||
}
|
||||
return mCameraHelper;
|
||||
}
|
||||
|
||||
public void closeCamera() {
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.close();
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnMyDevConnectListener {
|
||||
void onAttachDev(UsbDevice device);
|
||||
|
||||
void onDettachDev(UsbDevice device);
|
||||
|
||||
void onConnectDev(UsbDevice device, boolean isConnected);
|
||||
|
||||
void onDisConnectDev(UsbDevice device);
|
||||
}
|
||||
|
||||
public void initUSBMonitor(Activity activity, CameraViewInterface cameraView, final OnMyDevConnectListener listener) {
|
||||
this.mActivity = activity;
|
||||
this.mCamView = cameraView;
|
||||
|
||||
mUSBMonitor = new USBMonitor(activity.getApplicationContext(), new USBMonitor.OnDeviceConnectListener() {
|
||||
|
||||
// called by checking usb device
|
||||
// do request device permission
|
||||
@Override
|
||||
public void onAttach(UsbDevice device) {
|
||||
if (listener != null) {
|
||||
listener.onAttachDev(device);
|
||||
}
|
||||
}
|
||||
|
||||
// called by taking out usb device
|
||||
// do close camera
|
||||
@Override
|
||||
public void onDettach(UsbDevice device) {
|
||||
if (listener != null) {
|
||||
listener.onDettachDev(device);
|
||||
}
|
||||
}
|
||||
|
||||
// called by connect to usb camera
|
||||
// do open camera,start previewing
|
||||
@Override
|
||||
public void onConnect(final UsbDevice device, USBMonitor.UsbControlBlock ctrlBlock, boolean createNew) {
|
||||
mCtrlBlock = ctrlBlock;
|
||||
openCamera(ctrlBlock);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// wait for camera created
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// start previewing
|
||||
startPreview(mCamView);
|
||||
}
|
||||
}).start();
|
||||
if(listener != null) {
|
||||
listener.onConnectDev(device,true);
|
||||
}
|
||||
}
|
||||
|
||||
// called by disconnect to usb camera
|
||||
// do nothing
|
||||
@Override
|
||||
public void onDisconnect(UsbDevice device, USBMonitor.UsbControlBlock ctrlBlock) {
|
||||
if (listener != null) {
|
||||
listener.onDisConnectDev(device);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(UsbDevice device) {
|
||||
}
|
||||
});
|
||||
|
||||
createUVCCamera();
|
||||
}
|
||||
|
||||
public void createUVCCamera() {
|
||||
if (mCamView == null) {
|
||||
throw new NullPointerException("CameraViewInterface cannot be null!");
|
||||
}
|
||||
|
||||
// release resources for initializing camera handler
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.release();
|
||||
mCameraHandler = null;
|
||||
}
|
||||
// initialize camera handler
|
||||
mCamView.setAspectRatio(previewWidth / (float)previewHeight);
|
||||
mCameraHandler = UVCCameraHandler.createHandler(mActivity, mCamView, 2,
|
||||
previewWidth, previewHeight, mFrameFormat);
|
||||
}
|
||||
|
||||
public void updateResolution(int width, int height) {
|
||||
if (previewWidth == width && previewHeight == height) {
|
||||
return;
|
||||
}
|
||||
this.previewWidth = width;
|
||||
this.previewHeight = height;
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.release();
|
||||
mCameraHandler = null;
|
||||
}
|
||||
mCamView.setAspectRatio(previewWidth / (float)previewHeight);
|
||||
mCameraHandler = UVCCameraHandler.createHandler(mActivity,mCamView, 2,
|
||||
previewWidth, previewHeight, mFrameFormat);
|
||||
openCamera(mCtrlBlock);
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// wait for camera created
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// start previewing
|
||||
startPreview(mCamView);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void registerUSB() {
|
||||
if (mUSBMonitor != null) {
|
||||
mUSBMonitor.register();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterUSB() {
|
||||
if (mUSBMonitor != null) {
|
||||
mUSBMonitor.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkSupportFlag(final int flag) {
|
||||
return mCameraHandler != null && mCameraHandler.checkSupportFlag(flag);
|
||||
}
|
||||
|
||||
public int getModelValue(final int flag) {
|
||||
return mCameraHandler != null ? mCameraHandler.getValue(flag) : 0;
|
||||
}
|
||||
|
||||
public int setModelValue(final int flag, final int value) {
|
||||
return mCameraHandler != null ? mCameraHandler.setValue(flag, value) : 0;
|
||||
}
|
||||
|
||||
public int resetModelValue(final int flag) {
|
||||
return mCameraHandler != null ? mCameraHandler.resetValue(flag) : 0;
|
||||
}
|
||||
|
||||
public void requestPermission(int index) {
|
||||
List<UsbDevice> devList = getUsbDeviceList();
|
||||
if (devList == null || devList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
int count = devList.size();
|
||||
if (index >= count)
|
||||
new IllegalArgumentException("index illegal,should be < devList.size()");
|
||||
if (mUSBMonitor != null) {
|
||||
mUSBMonitor.requestPermission(getUsbDeviceList().get(index));
|
||||
}
|
||||
}
|
||||
|
||||
public int getUsbDeviceCount() {
|
||||
List<UsbDevice> devList = getUsbDeviceList();
|
||||
if (devList == null || devList.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
return devList.size();
|
||||
}
|
||||
|
||||
public List<UsbDevice> getUsbDeviceList() {
|
||||
List<DeviceFilter> deviceFilters = DeviceFilter
|
||||
.getDeviceFilters(mActivity.getApplicationContext(), R.xml.device_filter);
|
||||
if (mUSBMonitor == null || deviceFilters == null)
|
||||
// throw new NullPointerException("mUSBMonitor ="+mUSBMonitor+"deviceFilters=;"+deviceFilters);
|
||||
return null;
|
||||
// matching all of filter devices
|
||||
return mUSBMonitor.getDeviceList(deviceFilters);
|
||||
}
|
||||
|
||||
public void capturePicture(String savePath,AbstractUVCCameraHandler.OnCaptureListener listener) {
|
||||
if (mCameraHandler != null && mCameraHandler.isOpened()) {
|
||||
|
||||
File file = new File(savePath);
|
||||
if(! Objects.requireNonNull(file.getParentFile()).exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
mCameraHandler.captureStill(savePath,listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void startPusher(AbstractUVCCameraHandler.OnEncodeResultListener listener) {
|
||||
if (mCameraHandler != null && !isPushing()) {
|
||||
mCameraHandler.startRecording(null, listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void startPusher(RecordParams params, AbstractUVCCameraHandler.OnEncodeResultListener listener) {
|
||||
if (mCameraHandler != null && !isPushing()) {
|
||||
if(params.isSupportOverlay()) {
|
||||
TxtOverlay.install(mActivity.getApplicationContext());
|
||||
}
|
||||
mCameraHandler.startRecording(params, listener);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopPusher() {
|
||||
if (mCameraHandler != null && isPushing()) {
|
||||
mCameraHandler.stopRecording();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPushing() {
|
||||
if (mCameraHandler != null) {
|
||||
return mCameraHandler.isRecording();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCameraOpened() {
|
||||
if (mCameraHandler != null) {
|
||||
return mCameraHandler.isOpened();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.release();
|
||||
mCameraHandler = null;
|
||||
}
|
||||
if (mUSBMonitor != null) {
|
||||
mUSBMonitor.destroy();
|
||||
mUSBMonitor = null;
|
||||
}
|
||||
}
|
||||
|
||||
public USBMonitor getUSBMonitor() {
|
||||
return mUSBMonitor;
|
||||
}
|
||||
|
||||
public void setOnPreviewFrameListener(AbstractUVCCameraHandler.OnPreViewResultListener listener) {
|
||||
if(mCameraHandler != null) {
|
||||
mCameraHandler.setOnPreViewResultListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
private void openCamera(USBMonitor.UsbControlBlock ctrlBlock) {
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.open(ctrlBlock);
|
||||
}
|
||||
}
|
||||
|
||||
public void startPreview(CameraViewInterface cameraView) {
|
||||
SurfaceTexture st = cameraView.getSurfaceTexture();
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.startPreview(st);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopPreview() {
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.stopPreview();
|
||||
}
|
||||
}
|
||||
|
||||
public void startCameraFoucs() {
|
||||
if (mCameraHandler != null) {
|
||||
mCameraHandler.startCameraFoucs();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Size> getSupportedPreviewSizes() {
|
||||
if (mCameraHandler == null) {
|
||||
return null;
|
||||
}
|
||||
return mCameraHandler.getSupportedPreviewSizes();
|
||||
}
|
||||
|
||||
public void setDefaultPreviewSize(int defaultWidth,int defaultHeight) {
|
||||
if(mUSBMonitor != null) {
|
||||
throw new IllegalStateException("setDefaultPreviewSize should be call before initMonitor");
|
||||
}
|
||||
this.previewWidth = defaultWidth;
|
||||
this.previewHeight = defaultHeight;
|
||||
}
|
||||
|
||||
public void setDefaultFrameFormat(int format) {
|
||||
if(mUSBMonitor != null) {
|
||||
throw new IllegalStateException("setDefaultFrameFormat should be call before initMonitor");
|
||||
}
|
||||
this.mFrameFormat = format;
|
||||
}
|
||||
|
||||
public int getPreviewWidth() {
|
||||
return previewWidth;
|
||||
}
|
||||
|
||||
public int getPreviewHeight() {
|
||||
return previewHeight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.mogo.usbcamera.utils;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* Created by jiangdongguo on 2017/10/18.
|
||||
*/
|
||||
public class FileUtils {
|
||||
|
||||
private static BufferedOutputStream outputStream;
|
||||
public static String ROOT_PATH = Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator;
|
||||
|
||||
public static void createfile(String path){
|
||||
File file = new File(path);
|
||||
if(file.exists()){
|
||||
file.delete();
|
||||
}
|
||||
try {
|
||||
outputStream = new BufferedOutputStream(new FileOutputStream(file));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void releaseFile(){
|
||||
try {
|
||||
if(outputStream != null) {
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void putFileStream(byte[] data,int offset,int length){
|
||||
if(outputStream != null) {
|
||||
try {
|
||||
outputStream.write(data,offset,length);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void putFileStream(byte[] data){
|
||||
if(outputStream != null) {
|
||||
try {
|
||||
outputStream.write(data);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user