[Change]
增加覆盖全屏幕的View添加&移除方法 添加 OverlayViewUtils.showOverlayView(getContext(),overlayView); 移除 OverlayViewUtils.showOverlayView(getContext(),overlayView); ⚠️注意:调用添加方法后一定要在适当的位置调用移除方法,否则将导致APP无法进入HMI交互视图 Signed-off-by: donghongyu <donghongyu@zhidaoauto.com>
This commit is contained in:
@@ -6,8 +6,8 @@ import com.mogo.commons.mvp.Presenter
|
||||
* @author xiaoyuzhou
|
||||
* @date 2021/8/3 3:55 下午
|
||||
*/
|
||||
class WaringPresenter(view: MoGoWarningContract.View?) :
|
||||
Presenter<MoGoWarningContract.View?>(view) {
|
||||
class HmiPresenter(view: MoGoHmiContract.View?) :
|
||||
Presenter<MoGoHmiContract.View?>(view) {
|
||||
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import com.mogo.eagle.core.function.api.hmi.warning.IMoGoWarningStatusListener
|
||||
*@author xiaoyuzhou
|
||||
*@date 2021/8/4 3:38 下午
|
||||
*/
|
||||
interface MoGoWarningContract {
|
||||
interface MoGoHmiContract {
|
||||
|
||||
interface View : IView {
|
||||
|
||||
@@ -60,10 +60,10 @@ import java.util.*
|
||||
* 预警图层
|
||||
*/
|
||||
@Route(path = MoGoFragmentPaths.PATH_FRAGMENT_HMI)
|
||||
class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>(),
|
||||
class MoGoHmiFragment : MvpFragment<MoGoHmiContract.View?, HmiPresenter?>(),
|
||||
IMoGoWaringProvider,
|
||||
IMoGoHmiViewProxy,
|
||||
MoGoWarningContract.View,
|
||||
MoGoHmiContract.View,
|
||||
IMoGoAutopilotRecordListener {
|
||||
private val TAG = "MoGoHmiFragment"
|
||||
|
||||
@@ -347,8 +347,8 @@ class MoGoHmiFragment : MvpFragment<MoGoWarningContract.View?, WaringPresenter?>
|
||||
return TAG
|
||||
}
|
||||
|
||||
override fun createPresenter(): WaringPresenter {
|
||||
return WaringPresenter(this)
|
||||
override fun createPresenter(): HmiPresenter {
|
||||
return HmiPresenter(this)
|
||||
}
|
||||
|
||||
override fun setSpeedChartViewVisibility(visibility: Int) {
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<!--预警视图 OBU、云端下发、自车感知、自车策略-->
|
||||
<!--HMI 预警视图 OBU、云端下发、自车感知、自车策略-->
|
||||
<FrameLayout
|
||||
android:id="@+id/module_main_id_waring_fragment"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.mogo.eagle.core.utilcode.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
|
||||
/**
|
||||
* 遮罩层工具类
|
||||
*
|
||||
* @author mogoauto
|
||||
*/
|
||||
public class OverlayViewUtils {
|
||||
private static final String TAG = "OverlayViewUtils";
|
||||
|
||||
private static WindowManager windowManager;
|
||||
private static Context applicationContext;
|
||||
private static volatile boolean isShowing = false;
|
||||
|
||||
/**
|
||||
* 记录上一次的View
|
||||
*/
|
||||
private static View lastOverlayView;
|
||||
|
||||
/**
|
||||
* 添加覆盖View在Activity上面
|
||||
*/
|
||||
public static void showOverlayView(Activity context, View overlayView) {
|
||||
if (applicationContext == null) {
|
||||
applicationContext = context.getApplicationContext();
|
||||
}
|
||||
|
||||
if (windowManager == null) {
|
||||
windowManager = context.getWindowManager();
|
||||
}
|
||||
|
||||
// 设置View显示模式,沉浸式的侵入到状态栏,导航栏
|
||||
overlayView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
|
||||
|
||||
LayoutParams params = new LayoutParams();
|
||||
params.width = LayoutParams.MATCH_PARENT;
|
||||
params.height = LayoutParams.MATCH_PARENT;
|
||||
params.alpha = 1.0f;
|
||||
// 设置窗口类型为应用子窗口,和PopupWindow同类型
|
||||
params.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
|
||||
// 没有边界限制,允许窗口扩展到屏幕外
|
||||
params.flags = WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
|
||||
|
||||
|
||||
// 如果正在展示中,并且lastOverlayView不为null,先做移除操作,保证覆盖在最上面的View只有一个,防止叠加导致无法移除
|
||||
if (lastOverlayView != null) {
|
||||
dismissOverlayView(lastOverlayView);
|
||||
}
|
||||
|
||||
try {
|
||||
// 后门逻辑,长时间触摸消失
|
||||
overlayView.setOnLongClickListener(v -> {
|
||||
dismissOverlayView(lastOverlayView);
|
||||
return true;
|
||||
});
|
||||
lastOverlayView = overlayView;
|
||||
windowManager.addView(overlayView, params);
|
||||
isShowing = true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除覆盖View在Activity上面
|
||||
*/
|
||||
public static void dismissOverlayView(View overlayView) {
|
||||
if (!isShowing) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (windowManager != null && overlayView != null) {
|
||||
windowManager.removeView(overlayView);
|
||||
}
|
||||
isShowing = false;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user