|
|
@@ -7,17 +7,16 @@ import android.content.Intent
|
|
|
import android.graphics.PixelFormat
|
|
|
import android.os.Build
|
|
|
import android.os.IBinder
|
|
|
-import android.provider.Settings
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import android.view.WindowManager
|
|
|
import android.widget.ImageView
|
|
|
-import androidx.core.net.toUri
|
|
|
import com.atmob.keyboard_android.R
|
|
|
import com.atmob.keyboard_android.ext.click
|
|
|
import com.atmob.keyboard_android.keyboard.InputMethodPickerActivity
|
|
|
+import com.atmob.keyboard_android.util.FloatingWindowUtil
|
|
|
import kotlin.math.abs
|
|
|
|
|
|
/**
|
|
|
@@ -33,15 +32,11 @@ class FloatingButtonService : Service() {
|
|
|
* 启动服务
|
|
|
*/
|
|
|
fun start(context: Context) {
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(context)) {
|
|
|
- val intent = Intent(
|
|
|
- Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
|
|
- "package:${context.packageName}".toUri()
|
|
|
- )
|
|
|
- // 重要:在非 Activity 里启动 Activity 需要添加 FLAG_ACTIVITY_NEW_TASK
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- context.startActivity(intent)
|
|
|
+ // 检查是否有悬浮窗权限,没有则跳转到设置页面
|
|
|
+ if (!FloatingWindowUtil.hasFloatingWindowPermission(context)) {
|
|
|
+ FloatingWindowUtil.jumpFloatingWindowSetting(context)
|
|
|
} else {
|
|
|
+ // 有权限,开启悬浮窗
|
|
|
val serviceIntent = Intent(context, FloatingButtonService::class.java)
|
|
|
context.startService(serviceIntent)
|
|
|
}
|