mirror of
https://github.com/weyne85/rustdesk.git
synced 2025-10-29 17:00:05 +00:00
update android
This commit is contained in:
@@ -11,9 +11,7 @@ import androidx.annotation.RequiresApi
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
class InputService : AccessibilityService() {
|
||||
// companion object {
|
||||
// var inputService:InputService? = null
|
||||
// }
|
||||
|
||||
private val logTag = "input service"
|
||||
private var leftIsDown = false
|
||||
private var mPath = Path()
|
||||
@@ -22,14 +20,14 @@ class InputService : AccessibilityService() {
|
||||
private var mouseY = 0
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
fun mouseInput(mask: Int, _x: Int, _y: Int) {
|
||||
fun rustMouseInput(mask: Int, _x: Int, _y: Int) {
|
||||
Log.w(logTag, "got mouse input:x:$_x ,y:$_y ,mask:$mask ")
|
||||
|
||||
// TODO 临时倍数
|
||||
// TODO 按键抬起按下时候 x y 都是0
|
||||
if ( !(mask == 9 || mask == 10) ) {
|
||||
mouseX = _x * 2
|
||||
mouseY = _y * 2
|
||||
mouseX = _x * SCALE
|
||||
mouseY = _y * SCALE
|
||||
}
|
||||
|
||||
// left button down ,was up
|
||||
|
||||
@@ -2,36 +2,34 @@ package com.carriez.flutter_hbb
|
||||
|
||||
import android.app.Activity
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.media.projection.MediaProjectionManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.provider.Settings
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import androidx.annotation.RequiresApi
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import java.nio.ByteBuffer
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
const val MAX_SIZE = 1400
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
private val channelTag = "mChannel"
|
||||
private val logTag = "mMainActivity"
|
||||
private var mediaProjectionResultIntent: Intent? = null
|
||||
private val requestCode = 1
|
||||
private val buf = ByteBuffer.allocate(16)
|
||||
|
||||
init {
|
||||
System.loadLibrary("rustdesk")
|
||||
}
|
||||
|
||||
external fun rustSetInfo(username: String, hostname: String, width: Int, height: Int)
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine) // 必要 否则无法正确初始化flutter
|
||||
|
||||
updateMachineInfo()
|
||||
MethodChannel(
|
||||
flutterEngine.dartExecutor.binaryMessenger,
|
||||
channelTag
|
||||
@@ -52,7 +50,7 @@ class MainActivity : FlutterActivity() {
|
||||
mStopService()
|
||||
result.success(true)
|
||||
}
|
||||
"checkInput" ->{
|
||||
"checkInput" -> {
|
||||
checkInput()
|
||||
result.success(true)
|
||||
}
|
||||
@@ -128,4 +126,40 @@ class MainActivity : FlutterActivity() {
|
||||
mediaProjectionResultIntent = data
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateMachineInfo() {
|
||||
// 屏幕尺寸 控制最长边不超过1400 超过则减半直到1400 并储存缩放比例 实际发送给手机端的尺寸为缩小后的尺寸
|
||||
// input控制时再通过缩放比例恢复原始尺寸进行path入参
|
||||
val dm = DisplayMetrics()
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
display?.getRealMetrics(dm)
|
||||
} else {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
@Suppress("DEPRECATION")
|
||||
windowManager.defaultDisplay.getRealMetrics(dm)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
windowManager.defaultDisplay.getMetrics(dm)
|
||||
}
|
||||
}
|
||||
var w = dm.widthPixels
|
||||
var h = dm.heightPixels
|
||||
var scale = 1
|
||||
if (w != 0 && h != 0) {
|
||||
if (w > MAX_SIZE || h > MAX_SIZE) {
|
||||
scale = 2
|
||||
w /= scale
|
||||
h /= scale
|
||||
}
|
||||
Log.d(logTag, "Real size - width:$w,height:$h")
|
||||
|
||||
FIXED_WIDTH = 540
|
||||
FIXED_HEIGHT = 1140
|
||||
SCALE = scale
|
||||
// TODO username hostname
|
||||
rustSetInfo("csf", "Android", FIXED_WIDTH, FIXED_HEIGHT)
|
||||
} else {
|
||||
Log.e(logTag, "Got Screen Size Fail!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,10 @@ import android.media.projection.MediaProjection
|
||||
import android.media.projection.MediaProjectionManager
|
||||
import android.os.Build
|
||||
import android.os.IBinder
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.view.Surface
|
||||
import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.core.app.NotificationCompat
|
||||
@@ -26,9 +28,9 @@ const val START_SERVICE = "start_service"
|
||||
const val STOP_SERVICE = "stop_service"
|
||||
const val MIME_TYPE = MediaFormat.MIMETYPE_VIDEO_VP9
|
||||
|
||||
// 获取手机尺寸 建立连接时发送尺寸和基础信息
|
||||
const val FIXED_WIDTH = 500 // 编码器有上限
|
||||
const val FIXED_HEIGHT = 1000
|
||||
var FIXED_WIDTH = 0 // 编码器有上限
|
||||
var FIXED_HEIGHT = 0
|
||||
var SCALE = 1 // RealScreenWidth = screenWidth * scale
|
||||
const val M_KEY_BIT_RATE = 1024_000
|
||||
const val M_KEY_FRAME_RATE = 30
|
||||
|
||||
|
||||
Reference in New Issue
Block a user