[Fix]恢复动态请求悬浮窗权限
原因:Android11弹Toast需要悬浮窗权限
This commit is contained in:
@@ -37,6 +37,7 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
|
||||
private var clickListener: ClickListener? = null
|
||||
private var keyBoardUtil: KeyBoardUtil? = null
|
||||
private var connectStatus = false
|
||||
private var lastTime = 0L
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.view_auto_pilot_check, this, true)
|
||||
@@ -51,10 +52,6 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
|
||||
keyBoardUtil?.setActionListener { inputContent ->
|
||||
inputContent.toIntOrNull()?.let { speed ->
|
||||
when {
|
||||
!connectStatus -> {
|
||||
ToastUtils.showShort("设置车速失败,请启动域控制器")
|
||||
keyBoardUtil?.hideKeyboard()
|
||||
}
|
||||
speed > 60 -> {
|
||||
// 设置失败键盘不消失,让用户直接修改
|
||||
ToastUtils.showShort("超过最大限速值60,设置失败")
|
||||
@@ -90,22 +87,28 @@ class AutoPilotAndCheckView @JvmOverloads constructor(
|
||||
ivDebugFeedback.onClick {
|
||||
clickListener?.showFeedbackView()
|
||||
}
|
||||
etInputSpeed.setOnTouchListener { v, _ ->
|
||||
if (!connectStatus) {
|
||||
ToastUtils.showShort("设置车速失败,请启动域控制器")
|
||||
keyBoardUtil?.hideKeyboard()
|
||||
return@setOnTouchListener true
|
||||
} else {
|
||||
llSpeedPosition.background = resources.getDrawable(R.drawable.pilot_speed_high_light_bg)
|
||||
if (etInputSpeed.hasFocusable()) {
|
||||
etInputSpeed.setOnFocusChangeListener { v, hasFocus ->
|
||||
when {
|
||||
hasFocus -> {
|
||||
llSpeedPosition.background = resources.getDrawable(R.drawable.pilot_speed_high_light_bg)
|
||||
if (keyBoardUtil == null) {
|
||||
keyBoardUtil = KeyBoardUtil(sKeyBoardView, etInputSpeed)
|
||||
}
|
||||
keyBoardUtil?.showKeyboard()
|
||||
}
|
||||
if (!etInputSpeed.hasFocus()) {
|
||||
etInputSpeed.requestFocus()
|
||||
}
|
||||
else -> llSpeedPosition.background = resources.getDrawable(R.drawable.pilot_speed_bg)
|
||||
}
|
||||
}
|
||||
etInputSpeed.setOnTouchListener { v, event ->
|
||||
var curTime = System.currentTimeMillis()
|
||||
if (curTime - lastTime < 1000) {
|
||||
return@setOnTouchListener true
|
||||
}
|
||||
if (!connectStatus) {
|
||||
ToastUtils.showShort("设置车速失败,请启动域控制器")
|
||||
keyBoardUtil?.hideKeyboard()
|
||||
return@setOnTouchListener true
|
||||
} else {
|
||||
return@setOnTouchListener false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
|
||||
<application>
|
||||
<!-- <!–保活用–>
|
||||
|
||||
@@ -107,14 +107,14 @@ public class MainActivity extends MvpActivity<MainView, MainPresenter> implement
|
||||
// if (CallChatApi.getInstance().getApiProvider() != null) {
|
||||
// CallChatApi.getInstance().getApiProvider().initVehicleTeamContainer("init", R.id.module_main_id_message_history_fragment_container, this);
|
||||
// }
|
||||
// //申请悬浮窗权限
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// // 检查是否有悬浮窗权限
|
||||
// if (Settings.canDrawOverlays(this)) {
|
||||
// return;
|
||||
// }
|
||||
// PermissionsDialogUtils.openAppDetails(this, "显示悬浮窗", REQUEST_CODE_DIALOG);
|
||||
// }
|
||||
//申请悬浮窗权限
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
// 检查是否有悬浮窗权限
|
||||
if (Settings.canDrawOverlays(this)) {
|
||||
return;
|
||||
}
|
||||
PermissionsDialogUtils.openAppDetails(this, "显示悬浮窗", REQUEST_CODE_DIALOG);
|
||||
}
|
||||
}
|
||||
|
||||
// 隐藏布局
|
||||
|
||||
@@ -522,9 +522,9 @@ public final class ToastUtils {
|
||||
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_TOAST);
|
||||
} else if (UtilsBridge.isGrantedDrawOverlays()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_APPLICATION_PANEL);
|
||||
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
|
||||
} else {
|
||||
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_TOAST);
|
||||
return new WindowManagerToast(toastUtils, WindowManager.LayoutParams.TYPE_PHONE);
|
||||
}
|
||||
}
|
||||
return new ActivityToast(toastUtils);
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.mogo.module.common.dialog;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -31,12 +32,11 @@ public class BaseFloatDialog extends Dialog {
|
||||
}
|
||||
|
||||
private void addFlag() {
|
||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
// getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
|
||||
// } else {
|
||||
// getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
// }
|
||||
getWindow().setType(WindowManager.LayoutParams.LAST_SUB_WINDOW);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
|
||||
} else {
|
||||
getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
|
||||
}
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
|
||||
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
|
||||
| WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE);
|
||||
|
||||
@@ -8,10 +8,8 @@ import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
|
||||
/**
|
||||
* 采用windowManager实现接口(取消系统级弹窗)
|
||||
* {@link DialogImpl}
|
||||
* 采用windowManager实现接口
|
||||
*/
|
||||
@Deprecated
|
||||
class WindowManagerImpl implements IWindowManagerView {
|
||||
|
||||
private WindowManager mWindowManager;
|
||||
|
||||
@@ -97,7 +97,6 @@ public class WindowManagerView {
|
||||
return new WindowManagerView( mParams, new DialogImpl() );
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public WindowManagerView showInWindowManager() {
|
||||
if ( mParams.mContentView == null ) {
|
||||
throw new NullPointerException( "WMViewParams#mContentView must not be null." );
|
||||
|
||||
Reference in New Issue
Block a user