diff --git a/foudations/mogo-commons/src/main/java/com/mogo/commons/utils/MortonCode.java b/foudations/mogo-commons/src/main/java/com/mogo/commons/utils/MortonCode.java new file mode 100644 index 0000000000..14e771b73a --- /dev/null +++ b/foudations/mogo-commons/src/main/java/com/mogo/commons/utils/MortonCode.java @@ -0,0 +1,149 @@ +package com.mogo.commons.utils; + +import java.text.DecimalFormat; + +/** + * 莫顿编码 + * + * @author linyang + * @since 2020.07.09 + */ +public class MortonCode { + + /** + * morton 转 经纬度 时的中间常量 + */ + private static final long NDS_180_DEGREES = 0x7fffffff; + + /** + * morton 转 经纬度 时的中间常量 + */ + private static final long NDS_360_DEGREES = 4294967295L; + + /** + * morton 转 经纬度 时的中间常量 + */ + private static final long NDS_90_DEGREES = 0x3fffffff; + + /** + * 经纬度转 morton 时的中间常量 + */ + private static final double RULE_MORTON = Math.pow( 2, 32 ) / 360; + + /** + * morton 转 经纬度 时的中间常量 + */ + private static final double RULE_MORTON_TO_LONLAT = 360.0 / Math.pow( 2, 32 ); + + /** + * @param lon + * @param lat + * @return + */ + public static long wrapEncodeMorton( Double lon, Double lat ) { + DecimalFormat decimalFormat = new DecimalFormat( "#.######" ); + return encodeMorton( Double.valueOf( decimalFormat.format( lon ) ), + Double.valueOf( decimalFormat.format( lat ) ) ); + } + + /** + * 编码 morton code + * + * @param lon + * @param lat + * @return + */ + public static long encodeMorton( Double lon, Double lat ) { + + Long bit = 1L; + long mortonCode = 0L; + long x = ( long ) ( lon * RULE_MORTON ); + long y = ( long ) ( lat * RULE_MORTON ); + + if ( y < 0 ) { + y += 0x7FFFFFFF; + } + y = y << 1; + for ( int i = 0; i < 32; i++ ) { + // x-part + mortonCode = mortonCode | ( x & bit ); + x = x << 1; + bit = bit << 1; + // y-part + mortonCode = mortonCode | ( y & bit ); + y = y << 1; + bit = bit << 1; + } + + return mortonCode; + } + + /** + * 将莫顿码解码为坐标 + * + * @param mortonCode + * @return + */ + public static double[] decodeMorton( long mortonCode ) { + long[] midPoint = mortonCodeToCoord( mortonCode ); + normalizeCoord( midPoint ); + double[] point = new double[2]; + + // 将经纬度长整数转化为 浮点类型 + point[0] = midPoint[0] * RULE_MORTON_TO_LONLAT; + point[1] = midPoint[1] * RULE_MORTON_TO_LONLAT; + return point; + } + + /** + * 莫顿码分别拆解为 编码后的经纬度长整数 + * + * @param mortonCode + * @return + */ + private static long[] mortonCodeToCoord( long mortonCode ) { + long bit = 1L; + long[] longPoint = new long[2]; + + for ( int i = 0; i < 32; i++ ) { + longPoint[0] |= mortonCode & bit; + mortonCode >>= 1; + longPoint[1] |= mortonCode & bit; + bit <<= 1; + } + return longPoint; + } + + /** + * 对编码后的经纬度长整数进行解码 + * + * @param midPoint + */ + private static void normalizeCoord( long[] midPoint ) { + // if x > 180 degrees, then subtract 360 degrees + if ( midPoint[0] > NDS_180_DEGREES ) { + midPoint[0] -= + NDS_360_DEGREES + 1; // add 1 because 0 must be counted as well + } else if ( midPoint[0] < -NDS_180_DEGREES ) // if x < 180 , x += 360 + { + midPoint[0] += + NDS_360_DEGREES + 1; // add 1 because 0 must be counted as well + } + + // if y > 90 degrees, then subtract 180 degrees + if ( midPoint[1] > NDS_90_DEGREES ) { + midPoint[1] -= + NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well + } else if ( midPoint[1] < -NDS_90_DEGREES ) // if y < 90, y += 180 + { + midPoint[1] += + NDS_180_DEGREES + 1; // add 1 because 0 must be counted as well + } + return; + } + + + public static void main( String[] args ) { + System.out.println( encodeMorton( 116.39584, 39.98152 ) ); + } +} diff --git a/libraries/map-custom/build.gradle b/libraries/map-custom/build.gradle index 38cc3cd161..b8a4271f39 100644 --- a/libraries/map-custom/build.gradle +++ b/libraries/map-custom/build.gradle @@ -55,7 +55,7 @@ dependencies { implementation project(':foudations:mogo-commons') } - implementation 'com.zhidaoauto.machine:map:1.0.0-online-12' + implementation 'com.zhidaoauto.machine:map:1.0.0-online-13' } apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString() diff --git a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java index 6ba0993cdf..c59d308e86 100644 --- a/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java +++ b/libraries/map-custom/src/main/java/com/mogo/map/impl/custom/AMapViewWrapper.java @@ -240,7 +240,7 @@ public class AMapViewWrapper implements IMogoMapView, IMogoMapUIController, Loca @Override public void setTrafficEnabled(boolean visible) { if (checkAMapView()) { - //mMapView.getMapAutoViewHelper().setTraffic(visible); +// mMapView.getMapAutoViewHelper().setTraffic(visible); } } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapDelegateFactory.java b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapDelegateFactory.java index 6d1fffb39f..da5bbc7121 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapDelegateFactory.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapDelegateFactory.java @@ -1,6 +1,7 @@ package com.mogo.map; import android.content.Context; +import android.opengl.Visibility; import com.mogo.commons.debug.DebugConfig; import com.mogo.map.impl.amap.location.ALocationClient; @@ -33,8 +34,14 @@ class MogoMapDelegateFactory { private static final String TAG = "MogoMapDelegateFactory"; + private static boolean useCustom = false; + + public static boolean isUseCustom() { + return useCustom; + } + public static IMogoGeoSearch getGeoSearchDelegate( Context context ) { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoGeoSearch" ); return new com.mogo.map.impl.custom.search.GeocodeSearchClient( context ); } @@ -42,7 +49,7 @@ class MogoMapDelegateFactory { } public static IMogoInputtipsSearch getInputtipsSearchDelegate( Context context, MogoInputtipsQuery query ) { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoInputtipsSearch" ); return new com.mogo.map.impl.custom.search.InputtipsSearch( context, query ); } @@ -50,7 +57,7 @@ class MogoMapDelegateFactory { } public static IMogoLocationClient getLocationClientDelegate( Context context ) { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoLocationClient" ); return new com.mogo.map.impl.custom.location.ALocationClient( context ); } @@ -58,7 +65,7 @@ class MogoMapDelegateFactory { } public static IMogoMapUIController getMapUIControllerDelegate() { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoMapUIController" ); return com.mogo.map.impl.custom.uicontroller.AMapUIController.getInstance(); } @@ -72,16 +79,16 @@ class MogoMapDelegateFactory { } else if ( AppUtils.isAppInstalled( context, "com.autonavi.amapauto" ) ) { return AutoNaviClient.getInstance( context ); } else { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoNavi" ); return com.mogo.map.impl.custom.navi.NaviClient.getInstance( context ); } - return NaviClient.getInstance( context ); } + return NaviClient.getInstance( context ); } public static IMogoPoiSearch getPoiSearchClientDelegate( Context context, MogoPoiSearchQuery query ) { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoPoiSearch" ); return new com.mogo.map.impl.custom.search.PoiSearchClient( context, query ); } @@ -89,7 +96,7 @@ class MogoMapDelegateFactory { } public static IMogoRoadSearch getRoadSearchDelegate() { - if ( DebugConfig.isUseCustomMap() ) { + if ( useCustom ) { Logger.d( TAG, "use custom IMogoRoadSearch" ); return new com.mogo.map.impl.custom.search.RoadSearchClient(); } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapView.java b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapView.java index f27df648db..1695f4010e 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapView.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapView.java @@ -40,32 +40,35 @@ public class MogoMapView extends MogoBaseMapView implements ILifeCycle { @Override protected void addDleMaps() { - mAMapView = new AMapBaseMapView().create( getContext() ); - mCustomMapView = new CustomMapView().create( getContext() ); - if ( mAMapView != null ) { - final View mapView = mAMapView.getMapView(); - if ( mapView != null ) { - addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) ); + if ( !MogoMapDelegateFactory.isUseCustom() ) { + mAMapView = new AMapBaseMapView().create( getContext() ); + if ( mAMapView != null ) { + final View mapView = mAMapView.getMapView(); + if ( mapView != null ) { + addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) ); + } else { + Logger.e( TAG, "create MapView instance failed." ); + } } else { - Logger.e( TAG, "create MapView instance failed." ); + Logger.e( TAG, "create IMogoMapView instance failed." ); } + mMapView = mAMapView; } else { - Logger.e( TAG, "create IMogoMapView instance failed." ); + mCustomMapView = new CustomMapView().create( getContext() ); + if ( mCustomMapView != null ) { + final View mapView = mCustomMapView.getMapView(); + if ( mapView != null ) { + addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) ); + } else { + Logger.e( TAG, "create MapView instance failed." ); + } + } else { + Logger.e( TAG, "create IMogoMapView instance failed." ); + } + mMapView = mCustomMapView; } -// if ( mCustomMapView != null ) { -// final View mapView = mCustomMapView.getMapView(); -// if ( mapView != null ) { -// addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) ); -// } else { -// Logger.e( TAG, "create MapView instance failed." ); -// } -// } else { -// Logger.e( TAG, "create IMogoMapView instance failed." ); -// } - - mMapView = mAMapView; MogoMap.getInstance().init( getContext(), mMapView.getMap() ); } diff --git a/main-extensions/mogo-module-main-independent/src/main/java/com/zhidao/mogo/module/main/independent/MainIndependentActivity.java b/main-extensions/mogo-module-main-independent/src/main/java/com/zhidao/mogo/module/main/independent/MainIndependentActivity.java index 53b3136c4a..7d19201968 100644 --- a/main-extensions/mogo-module-main-independent/src/main/java/com/zhidao/mogo/module/main/independent/MainIndependentActivity.java +++ b/main-extensions/mogo-module-main-independent/src/main/java/com/zhidao/mogo/module/main/independent/MainIndependentActivity.java @@ -37,7 +37,7 @@ public class MainIndependentActivity extends MainActivity { // 事件面板 FrameLayout.LayoutParams eventPanelParams = ( ( FrameLayout.LayoutParams ) mEventPanel.getLayoutParams() ); eventPanelParams.leftMargin = getResources().getDimensionPixelSize( R.dimen.module_main_entrance_fragment_container_marginLeft ); - mEntrance.setLayoutParams( eventPanelParams ); + mEventPanel.setLayoutParams( eventPanelParams ); // 事件面板 FrameLayout.LayoutParams historyMessagePanelParams = ( ( FrameLayout.LayoutParams ) mEventPanel.getLayoutParams() ); diff --git a/main-extensions/mogo-module-main-launcher/src/main/java/com/zhidao/mogo/module/main/launcher/MainLauncherActivity.java b/main-extensions/mogo-module-main-launcher/src/main/java/com/zhidao/mogo/module/main/launcher/MainLauncherActivity.java index 872b5f804f..f952d51835 100644 --- a/main-extensions/mogo-module-main-launcher/src/main/java/com/zhidao/mogo/module/main/launcher/MainLauncherActivity.java +++ b/main-extensions/mogo-module-main-launcher/src/main/java/com/zhidao/mogo/module/main/launcher/MainLauncherActivity.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.os.Process; import android.text.TextUtils; import android.view.View; +import android.widget.FrameLayout; import androidx.annotation.Nullable; @@ -13,6 +14,8 @@ import com.mogo.module.extensions.utils.ExtensionsConfig; import com.mogo.module.main.MainActivity; import com.mogo.module.main.cards.MogoModulesManager; import com.mogo.service.intent.IMogoIntentListener; +import com.mogo.service.statusmanager.IMogoStatusChangedListener; +import com.mogo.service.statusmanager.StatusDescriptor; import com.mogo.utils.logger.Logger; /** @@ -20,13 +23,15 @@ import com.mogo.utils.logger.Logger; * * @author tongchenfei */ -public class MainLauncherActivity extends MainActivity implements IMogoIntentListener { - +public class MainLauncherActivity extends MainActivity implements IMogoIntentListener, IMogoStatusChangedListener { + private static final String TAG = "MainLauncherActivity"; protected boolean mIsHomeKeyDown = false; @Override protected void onCreate( @Nullable Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); ExtensionsConfig.setNeedRequestUserInfo( true ); + mServiceApis.getStatusManagerApi().registerStatusChangedListener(TAG, + StatusDescriptor.VR_MODE, this); } @Override @@ -89,6 +94,8 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis @Override protected void onDestroy() { super.onDestroy(); + mServiceApis.getStatusManagerApi().unregisterStatusChangedListener(TAG, + StatusDescriptor.VR_MODE, this); try { // acc off 之后会出现进程还在,但是页面被杀的情况,这个直接杀掉进程,然后让整个进程重启 Process.killProcess( Process.myPid() ); @@ -110,4 +117,17 @@ public class MainLauncherActivity extends MainActivity implements IMogoIntentLis sendBroadcast( intent ); Logger.d( TAG, "send msg to AI Voice" ); } + + @Override + public void onStatusChanged(StatusDescriptor descriptor, boolean isTrue) { + if (isTrue) { + FrameLayout.LayoutParams entranceParams = ( ( FrameLayout.LayoutParams ) mEntrance.getLayoutParams() ); + entranceParams.leftMargin = getResources().getDimensionPixelSize( R.dimen.module_main_entrance_fragment_container_marginLeft_in_vr_mode ); + mEntrance.setLayoutParams( entranceParams ); + }else{ + FrameLayout.LayoutParams entranceParams = ( ( FrameLayout.LayoutParams ) mEntrance.getLayoutParams() ); + entranceParams.leftMargin = getResources().getDimensionPixelSize( R.dimen.module_main_entrance_fragment_container_marginLeft_out_vr_mode ); + mEntrance.setLayoutParams( entranceParams ); + } + } } diff --git a/main-extensions/mogo-module-main-launcher/src/main/res/values/dimens.xml b/main-extensions/mogo-module-main-launcher/src/main/res/values/dimens.xml new file mode 100644 index 0000000000..79e190ca2d --- /dev/null +++ b/main-extensions/mogo-module-main-launcher/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 204px + 800px + \ No newline at end of file diff --git a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java index 7ec1345d38..0472822c92 100644 --- a/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java +++ b/modules/mogo-module-extensions/src/main/java/com/mogo/module/extensions/entrance/EntranceFragment.java @@ -79,6 +79,7 @@ import java.util.Random; import static com.mogo.module.common.utils.SPConst.getSPGuideRecord; import static com.mogo.module.common.utils.SPConst.getSpGuide; +import static com.mogo.module.extensions.ExtensionsModuleConst.TYPE_ENTRANCE; import static com.mogo.module.share.constant.ShareConstants.KEY_CLICK_SHARE_BUTTON; import static com.mogo.module.share.constant.ShareConstants.KEY_CLICK_SHARE_TIME; import static com.mogo.module.share.constant.ShareConstants.KEY_SERVER_SHOW_DAY_COUNT; @@ -170,6 +171,8 @@ public class EntranceFragment extends MvpFragment{ + // 进入vr模式 + enterVrMode(); + }); + + tvExitVrMode = findViewById(R.id.module_ext_exit_vr_mode); + tvExitVrMode.setOnClickListener((v)->{ + // 退出vr模式 + exitVrMode(); + }); dealWeatherContainer(); @@ -394,6 +408,28 @@ public class EntranceFragment extends MvpFragment