完成了小地图单进程的使用,原理是 LayoutInflater.from(this).cloneInContext(this);复制出一个原始的填充器

This commit is contained in:
董宏宇
2020-12-23 14:24:31 +08:00
parent e4b574c0e1
commit f8ecca6cf1
7 changed files with 54 additions and 167 deletions

View File

@@ -10,10 +10,6 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;
import com.elegant.analytics.Analytics;
import com.elegant.analytics.AnalyticsConfig;
import com.elegant.analytics.IAnalyticsParamsProvider;
import com.elegant.analytics.UploadMode;
import com.mogo.commons.analytics.AnalyticsUtils;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.device.Devices;
@@ -28,10 +24,8 @@ import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.TipDrawable;
import com.mogo.utils.TipToast;
import com.mogo.utils.network.NetConfig;
import com.mogo.utils.storage.SharedPrefsMgr;
import java.security.SecureRandom;
import java.util.Map;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -48,6 +42,13 @@ public abstract class AbsMogoApplication extends Application {
private static final String TAG = "AbsMogoApplication";
// 没有换肤功能的LayoutInflater
private static LayoutInflater mLayoutInflaterNoSkin;
public static LayoutInflater getLayoutInflaterNoSkin() {
return mLayoutInflaterNoSkin;
}
private static Application sApp;
public static Application getApp() {
@@ -57,6 +58,8 @@ public abstract class AbsMogoApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// 在设置皮肤布局填充器之前进行克隆一个出来
mLayoutInflaterNoSkin = LayoutInflater.from(this).cloneInContext(this);
sApp = this;
initARouter();
if ( shouldInit() ) {

View File

@@ -83,7 +83,7 @@ public class MainActivity extends MvpActivity< MainView, MainPresenter > impleme
@Override
protected void beforeSetContentView( Bundle savedInstanceState ) {
init();
installSkinManager( savedInstanceState );
//installSkinManager( savedInstanceState );
}
/**

View File

@@ -1,11 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.small.map">
<application>
<service
android:name=".SmallMapService"
android:exported="false"
android:process=":smallMap"/>
</application>
</manifest>

View File

@@ -4,7 +4,6 @@ import android.content.Context;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.RelativeLayout;
@@ -18,6 +17,7 @@ import com.amap.api.maps.UiSettings;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.navi.AMapNaviView;
import com.amap.api.navi.AMapNaviViewOptions;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.small.map.animation.DirectionRotateAnimation;
import com.mogo.utils.FileUtils;
@@ -58,7 +58,7 @@ public class SmallMapDirectionView extends RelativeLayout {
private void initView(Context context) {
mRotateAnimation = new DirectionRotateAnimation(context, null);
LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
AbsMogoApplication.getLayoutInflaterNoSkin().inflate(R.layout.module_small_map_view, this);
mIvMapBorder = findViewById(R.id.ivMapBorder);
mAMapNaviView = findViewById(R.id.aMapNaviView);
mAMapNaviView.onCreate(null);

View File

@@ -1,134 +0,0 @@
package com.mogo.module.small.map;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.Gravity;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.mogo.module.common.entity.MogoSnapshotSetData;
import com.mogo.module.common.machinevision.IMachineVisionInterface;
import com.mogo.module.common.wm.WindowManagerView;
import com.mogo.utils.logger.Logger;
/**
* @author donghongyu
* @date 12/10/20 1:35 PM
*/
public class SmallMapService extends Service {
private static final String TAG = "MachineVisionMapService";
private IBinder mBinder;
private WindowManagerView mWindowManagerView;
private SmallMapDirectionView mSmallMapDirectionView;
@Override
public void onCreate() {
super.onCreate();
Logger.d(TAG, "onCreate");
addSmallMapView();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
Logger.d(TAG, "onBind");
mBinder = new SmallMapServiceBinder();
return mBinder;
}
@Override
public void onRebind(Intent intent) {
super.onRebind(intent);
addSmallMapView();
Logger.d(TAG, "onRebind");
}
@Override
public boolean onUnbind(Intent intent) {
Logger.d(TAG, "onUnbind");
if (mWindowManagerView != null && mWindowManagerView.isShowing()) {
mWindowManagerView.dismiss();
}
mWindowManagerView = null;
return true;
}
@Override
public void onDestroy() {
super.onDestroy();
Logger.d(TAG, "onDestroy");
if (mWindowManagerView != null) {
mWindowManagerView.dismiss();
}
}
/**
* 添加小地图View
*/
private void addSmallMapView() {
Logger.d(TAG, "addSmallMapView");
// 初始化小地图控件
mSmallMapDirectionView = new SmallMapDirectionView(getApplicationContext());
mWindowManagerView = new WindowManagerView.Builder(getApplicationContext())
.contentView(mSmallMapDirectionView)
.size(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
.position(
getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_x),
getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_y)
)
.gravity(Gravity.TOP | Gravity.LEFT)
.showInWindowManager();
mWindowManagerView.show();
}
/**
* 小地图与大地图之间进程通讯
*/
public class SmallMapServiceBinder extends IMachineVisionInterface.Stub {
@Override
public void linkToDeath(@NonNull DeathRecipient recipient, int flags) {
super.linkToDeath(recipient, flags);
Logger.d(TAG, "linkToDeath");
}
@Override
public boolean unlinkToDeath(@NonNull DeathRecipient recipient, int flags) {
Logger.d(TAG, "unlinkToDeath");
return super.unlinkToDeath(recipient, flags);
}
@Override
public void postData(MogoSnapshotSetData data) throws RemoteException {
Logger.d(TAG, "postData");
}
@Override
public void hideViewIfExist() throws RemoteException {
Logger.d(TAG, "hideViewIfExist");
}
@Override
public void showViewIfExist() throws RemoteException {
Logger.d(TAG, "showViewIfExist");
}
}
}

View File

@@ -1,8 +0,0 @@
package com.mogo.module.small.map;
/**
* @author donghongyu
* @date 12/10/20 1:35 PM
*/
public class SmallMapViewHandler {
}

View File

@@ -1,22 +1,24 @@
package com.mogo.module.small.map;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.wm.WindowManagerView;
import com.mogo.service.MogoServicePaths;
import com.mogo.service.map.IMogoSmallMapProvider;
import com.mogo.service.module.ModuleType;
import com.mogo.service.statusmanager.IMogoStatusChangedListener;
import com.mogo.service.statusmanager.StatusDescriptor;
import com.mogo.utils.logger.Logger;
/**
* @author donghongyu
@@ -26,9 +28,11 @@ import com.mogo.service.statusmanager.StatusDescriptor;
public class SmallVisionProvider implements IMogoSmallMapProvider, IMogoStatusChangedListener {
private final String TAG = "SmallVisionProvider";
private Intent mSmallMapServiceIntent;
private Context mContext;
private WindowManagerView mWindowManagerView;
private SmallMapDirectionView mSmallMapDirectionView;
@Override
public Fragment createFragment(Context context, Bundle data) {
return null;
@@ -76,22 +80,22 @@ public class SmallVisionProvider implements IMogoSmallMapProvider, IMogoStatusCh
public void onDestroy() {
Log.d(TAG, "小地图模块销毁……");
hidePanel();
// 释放组件内存
mSmallMapDirectionView = null;
mWindowManagerView = null;
}
@Override
public void showPanel() {
Log.d(TAG, "小地图模块触发展示……");
if (MogoApisHandler.getInstance().getApis().getStatusManagerApi().isVrMode()) {
mSmallMapServiceIntent = new Intent(mContext, SmallMapService.class);
mContext.startService(mSmallMapServiceIntent);
}
addSmallMapView();
}
@Override
public void hidePanel() {
Log.d(TAG, "小地图模块触发隐藏……");
if (mSmallMapServiceIntent != null) {
AbsMogoApplication.getApp().stopService(mSmallMapServiceIntent);
if (mWindowManagerView != null && mWindowManagerView.isShowing()) {
mWindowManagerView.dismiss();
}
}
@@ -119,4 +123,33 @@ public class SmallVisionProvider implements IMogoSmallMapProvider, IMogoStatusCh
}
}
}
/**
* 添加小地图View
*/
private void addSmallMapView() {
Logger.d(TAG, "addSmallMapView");
// 初始化小地图控件
if (mSmallMapDirectionView == null) {
mSmallMapDirectionView = new SmallMapDirectionView(mContext);
}
if (mWindowManagerView == null) {
mWindowManagerView = new WindowManagerView.Builder(mContext)
.contentView(mSmallMapDirectionView)
.size(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT
)
.position(
mContext.getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_x),
mContext.getResources().getDimensionPixelOffset(R.dimen.module_small_map_view_y)
)
.gravity(Gravity.TOP | Gravity.LEFT)
.showInWindowManager();
}
mWindowManagerView.show();
}
}