完成了小地图

This commit is contained in:
董宏宇
2020-12-16 19:25:17 +08:00
parent aed0063417
commit 1c4c7faa81
13 changed files with 72 additions and 150 deletions

View File

@@ -3,6 +3,8 @@ package com.mogo.module.common.view;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PaintFlagsDrawFilter;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
@@ -19,11 +21,10 @@ import com.mogo.skin.support.helper.MogoSkinCompatBackgroundHelperDelegate;
* desc :
* version: 1.0
*/
public class RoundLayout extends RelativeLayout implements IMogoSkinCompatSupportable {
public class RoundLayout extends RelativeLayout {
private float roundLayoutRadius = 14f;
private Path roundPath;
private RectF rectF;
private MogoSkinCompatBackgroundHelperDelegate mBackgroundTintHelper;
public RoundLayout(Context context) {
this(context, null);
@@ -41,9 +42,6 @@ public class RoundLayout extends RelativeLayout implements IMogoSkinCompatSuppor
typedArray.recycle();
init();
mBackgroundTintHelper = new MogoSkinCompatBackgroundHelperDelegate(this);
mBackgroundTintHelper.loadFromAttributes(attrs, defStyleAttr);
}
@@ -75,16 +73,10 @@ public class RoundLayout extends RelativeLayout implements IMogoSkinCompatSuppor
@Override
public void draw(Canvas canvas) {
if (roundLayoutRadius > 0f) {
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
canvas.clipPath(roundPath);
}
super.draw(canvas);
}
@Override
public void applySkin() {
if (mBackgroundTintHelper != null) {
mBackgroundTintHelper.applySkin();
}
}
}

View File

@@ -38,6 +38,9 @@ dependencies {
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.androidxconstraintlayout
implementation rootProject.ext.dependencies.arouter
implementation rootProject.ext.dependencies.amapnavi3dmap
annotationProcessor rootProject.ext.dependencies.aroutercompiler
if (Boolean.valueOf(RELEASE)) {
api rootProject.ext.dependencies.mogomap

View File

@@ -6,6 +6,6 @@
<service
android:name=".SmallMapService"
android:exported="false"
android:process=":smallMap" />
/>
</application>
</manifest>

View File

@@ -8,6 +8,15 @@ import android.widget.ImageView;
import androidx.annotation.Nullable;
import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdate;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.TextureMapView;
import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.BitmapDescriptor;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CustomMapStyleOptions;
import com.amap.api.maps.model.MyLocationStyle;
import com.mogo.module.common.view.RoundLayout;
import com.mogo.module.small.map.animation.DirectionRotateAnimation;
@@ -20,6 +29,12 @@ import com.mogo.module.small.map.animation.DirectionRotateAnimation;
public class SmallMapDirectionView extends RoundLayout {
private ImageView mIvMapBorder;
private TextureMapView mTextureMapView;
private AMap mAMap;
private UiSettings mUiSettings;
private CameraUpdate mCameraUpdate;
private MyLocationStyle myLocationStyle;
private DirectionRotateAnimation mRotateAnimation;
private int lastAngle = 0;
@@ -37,9 +52,43 @@ public class SmallMapDirectionView extends RoundLayout {
}
private void initView(Context context) {
mRotateAnimation = new DirectionRotateAnimation(context, null);
LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
mIvMapBorder = findViewById(R.id.ivMapBorder);
mRotateAnimation = new DirectionRotateAnimation(context, null);
mTextureMapView = findViewById(R.id.textureMapView);
mTextureMapView.onCreate(null);
mAMap = mTextureMapView.getMap();
// mAMap.setMapType(AMap.MAP_TYPE_NIGHT);//夜景地图aMap是地图控制器对象。
mAMap.setCustomMapStyle(new CustomMapStyleOptions()
.setEnable(true)
.setStyleDataPath("file:///android_asset/small_map_style.data")
.setStyleExtraPath("file:///android_asset/small_map_style_extra.data")
);
myLocationStyle = new MyLocationStyle();//初始化定位蓝点样式类myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE);//连续定位、且将视角移动到地图中心点定位点依照设备方向旋转并且会跟随设备移动。1秒1次定位如果不设置myLocationType默认也会执行此种模式。
myLocationStyle.interval(2000); //设置连续定位模式下的定位间隔,只在连续定位模式下生效,单次定位模式下不会生效。单位为毫秒。
BitmapDescriptor location = BitmapDescriptorFactory.fromResource(R.drawable.module_small_map_view_my_location_logo);
myLocationStyle.myLocationIcon(location);
mAMap.setMyLocationStyle(myLocationStyle);//设置定位蓝点的Style
mAMap.setMyLocationEnabled(true);// 设置为true表示启动显示定位蓝点false表示隐藏定位蓝点并不进行定位默认是false。
//设置希望展示的地图缩放级别
mCameraUpdate = CameraUpdateFactory.zoomTo(12);
mAMap.moveCamera(mCameraUpdate);
mUiSettings = mAMap.getUiSettings();
mUiSettings.setZoomControlsEnabled(false);// 地图缩放级别的交换按钮
// mUiSettings.setZoomGesturesEnabled(false);// 缩放手势
// mUiSettings.setScrollGesturesEnabled(false);// 滑动手势
// mUiSettings.setRotateGesturesEnabled(false);// 旋转手势
// mUiSettings.setTiltGesturesEnabled(false);// 倾斜手势
mUiSettings.setAllGesturesEnabled(false);// 所有手势
mUiSettings.setMyLocationButtonEnabled(false); // 显示默认的定位按钮
mUiSettings.setLogoBottomMargin(-150); //设置Logo下边界距离屏幕底部的边距,设置为负值即可
}

View File

@@ -32,7 +32,7 @@ public class SmallMapService extends Service {
public void onCreate() {
super.onCreate();
Logger.d(TAG, "onCreate");
addMachineVisionMapView();
addSmallMapView();
}
@Nullable
@@ -46,7 +46,7 @@ public class SmallMapService extends Service {
@Override
public void onRebind(Intent intent) {
super.onRebind(intent);
addMachineVisionMapView();
addSmallMapView();
Logger.d(TAG, "onRebind");
}
@@ -69,8 +69,8 @@ public class SmallMapService extends Service {
}
}
private void addMachineVisionMapView() {
Logger.d(TAG, "addMachineVisionMapView");
private void addSmallMapView() {
Logger.d(TAG, "addSmallMapView");
mWindowManagerView = new WindowManagerView.Builder(getApplicationContext())
.contentView(R.layout.module_small_map_direction_view)

View File

@@ -1,91 +0,0 @@
package com.mogo.module.small.map;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.mogo.map.MogoBaseMapView;
import com.mogo.utils.logger.Logger;
/**
* @author donghongyu
* @date 12/10/20 1:35 PM
*/
public class SmallMapView extends MogoBaseMapView {
private static final String TAG = "SmallMapView";
public SmallMapView(Context context) {
this(context, null);
}
public SmallMapView(Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}
public SmallMapView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void addMapView(Context context) {
Logger.d(TAG, "addMapView");
mMapView = SmallMapDelegateFactory.getMapView(context);
if (mMapView != null) {
final View mapView = mMapView.getMapView();
if (mapView != null) {
mapView.setOutlineProvider(new TextureVideoViewOutlineProvider(360));
mapView.setClipToOutline(true);
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.");
}
}
@Override
public void onCreate( Bundle bundle ) {
super.onCreate( bundle );
Logger.d( TAG, "onCreate" );
}
@Override
public void onResume() {
super.onResume();
Logger.d( TAG, "onResume" );
}
@Override
public void onPause() {
super.onPause();
Logger.d( TAG, "onPause" );
}
@Override
public void onDestroy() {
super.onDestroy();
Logger.d( TAG, "onDestroy" );
}
@Override
public void onSaveInstanceState( Bundle outState ) {
super.onSaveInstanceState( outState );
}
@Override
public void onLowMemory() {
super.onLowMemory();
}
}

View File

@@ -1,35 +0,0 @@
package com.mogo.module.small.map;
import android.graphics.Outline;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewOutlineProvider;
import androidx.annotation.RequiresApi;
/**
* @author donghongyu
* @date 12/15/20 8:47 PM
*/
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class TextureVideoViewOutlineProvider extends ViewOutlineProvider {
private float mRadius;
public TextureVideoViewOutlineProvider(float radius) {
this.mRadius = radius;
}
@Override
public void getOutline(View view, Outline outline) {
Log.w("OutlineProvider", "======getOutline======");
Rect rect = new Rect();
view.getGlobalVisibleRect(rect);
int leftMargin = 0;
int topMargin = 0;
Rect selfRect = new Rect(leftMargin, topMargin,
rect.right - rect.left - leftMargin, rect.bottom - rect.top - topMargin);
outline.setRoundRect(selfRect, mRadius);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
</selector>

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mogo.module.common.view.RoundLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="@dimen/module_small_map_border_view_width"
android:layout_height="@dimen/module_small_map_border_view_width"
@@ -12,8 +12,8 @@
android:layout_centerInParent="true"
app:roundLayoutRadius="360dp">
<com.mogo.module.small.map.SmallMapView
android:id="@+id/module_mvision_map_view"
<com.amap.api.maps.TextureMapView
android:id="@+id/textureMapView"
android:layout_width="@dimen/module_small_map_view_width"
android:layout_height="@dimen/module_small_map_view_width" />
@@ -26,4 +26,4 @@
android:layout_centerInParent="true"
android:src="@drawable/module_small_map_view_border" />
</com.mogo.module.common.view.RoundLayout>
</RelativeLayout>

View File

@@ -3,8 +3,8 @@
<dimen name="module_small_map_border_view_width">400px</dimen>
<dimen name="module_small_map_border_view_height">400px</dimen>
<dimen name="module_small_map_view_width">300px</dimen>
<dimen name="module_small_map_view_height">300px</dimen>
<dimen name="module_small_map_view_width">260px</dimen>
<dimen name="module_small_map_view_height">260px</dimen>
<dimen name="module_small_map_view_x">1490px</dimen>
<dimen name="module_small_map_view_y">650px</dimen>