fix:reconnect time,enter password focus,wrong gesture tap-up;ctrl soft keyboard

This commit is contained in:
csf 2022-04-26 21:21:08 +08:00
parent b30299cc12
commit c188a6f93f
6 changed files with 106 additions and 63 deletions

View File

@ -10,6 +10,7 @@ import android.os.Build
import android.os.IBinder
import android.provider.Settings
import android.util.Log
import android.view.WindowManager
import androidx.annotation.RequiresApi
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
@ -125,6 +126,18 @@ class MainActivity : FlutterActivity() {
result.success(true)
}
}
"enable_soft_keyboard" -> {
// https://blog.csdn.net/hanye2020/article/details/105553780
try {
if (call.arguments as Boolean) {
window.clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
} else {
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM)
}
} finally {
result.success(true)
}
}
else -> {
result.error("-1", "No such method", null)
}

View File

@ -249,6 +249,7 @@ class FfiModel with ChangeNotifier {
if (displays.length > 0) {
showLoading(translate('Connected, waiting for image...'));
_waitForImage = true;
_reconnects = 1;
}
}
notifyListeners();

View File

@ -148,6 +148,7 @@ hideChatWindowOverlay() {
toggleChatOverlay() {
if (iconOverlayEntry == null || windowOverlayEntry == null) {
FFI.invokeMethod("enable_soft_keyboard", true);
showChatIconOverlay();
showChatWindowOverlay();
} else {

View File

@ -60,6 +60,7 @@ class _RemotePageState extends State<RemotePage> {
@override
void dispose() {
FFI.listenToMouse(false);
FFI.invokeMethod("enable_soft_keyboard", true);
_mobileFocusNode.dispose();
_physicalFocusNode.dispose();
FFI.close();
@ -90,6 +91,7 @@ class _RemotePageState extends State<RemotePage> {
if (v < 100) {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: []);
FFI.invokeMethod("enable_soft_keyboard", false);
}
});
}
@ -181,6 +183,7 @@ class _RemotePageState extends State<RemotePage> {
}
void openKeyboard() {
FFI.invokeMethod("enable_soft_keyboard", true);
// destroy first, so that our _value trick can work
_value = initText;
setState(() => _showEdit = false);
@ -193,7 +196,6 @@ class _RemotePageState extends State<RemotePage> {
_timer = Timer(Duration(milliseconds: 30), () {
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
SystemChannels.textInput.invokeMethod('TextInput.show');
_mobileFocusNode.requestFocus();
});
});
@ -211,12 +213,16 @@ class _RemotePageState extends State<RemotePage> {
final pi = Provider.of<FfiModel>(context).pi;
final hideKeyboard = isKeyboardShown() && _showEdit;
final showActionButton = !_showBar || hideKeyboard;
final keyboard = FFI.ffiModel.permissions['keyboard'] != false;
return WillPopScope(
onWillPop: () async {
clientClose();
return false;
},
child: Scaffold(
child: getRawPointerAndKeyBody(
keyboard,
Scaffold(
// resizeToAvoidBottomInset: true,
floatingActionButton: !showActionButton
? null
@ -229,8 +235,8 @@ class _RemotePageState extends State<RemotePage> {
setState(() {
if (hideKeyboard) {
_showEdit = false;
FFI.invokeMethod("enable_soft_keyboard", false);
_mobileFocusNode.unfocus();
SystemChannels.textInput.invokeMethod('TextInput.hide');
_physicalFocusNode.requestFocus();
} else {
_showBar = !_showBar;
@ -242,17 +248,24 @@ class _RemotePageState extends State<RemotePage> {
body: Overlay(
initialEntries: [
OverlayEntry(builder: (context) {
final keyboard = FFI.ffiModel.permissions['keyboard'] != false;
return Container(
color: Colors.black,
child: getRawPointerAndKeyBody(keyboard));
// child: getRawPointerAndKeyBody(keyboard));
child: isDesktop
? getBodyForDesktopWithListener(keyboard)
: SafeArea(
child: Container(
color: MyTheme.canvasColor,
child: _isPhysicalKeyboard
? getBodyForMobile()
: getBodyForMobileWithGesture())));
})
],
)),
))),
);
}
Widget getRawPointerAndKeyBody(bool keyboard) {
Widget getRawPointerAndKeyBody(bool keyboard, Widget child) {
return Listener(
onPointerHover: (e) {
if (e.kind != ui.PointerDeviceKind.mouse) return;
@ -351,14 +364,7 @@ class _RemotePageState extends State<RemotePage> {
}
return KeyEventResult.handled;
},
child: isDesktop
? getBodyForDesktopWithListener(keyboard)
: SafeArea(
child: Container(
color: MyTheme.canvasColor,
child: _isPhysicalKeyboard
? getBodyForMobile()
: getBodyForMobileWithGesture()))))));
child: child))));
}
Widget getBottomAppBar() {
@ -490,7 +496,7 @@ class _RemotePageState extends State<RemotePage> {
FFI.cursorModel.updatePan(d.delta.dx, d.delta.dy, _touchMode);
}
},
onHoldDragCancel: () {
onHoldDragEnd: (_) {
if (!_touchMode) {
FFI.sendMouse('up', MouseButtons.left);
}
@ -499,8 +505,6 @@ class _RemotePageState extends State<RemotePage> {
if (_touchMode) {
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
FFI.sendMouse('down', MouseButtons.left);
} else {
FFI.sendMouse('up', MouseButtons.left);
}
},
onOneFingerPanUpdate: (d) {
@ -543,6 +547,7 @@ class _RemotePageState extends State<RemotePage> {
textInputAction: TextInputAction.newline,
autocorrect: false,
enableSuggestions: false,
autofocus: true,
focusNode: _mobileFocusNode,
maxLines: null,
initialValue: _value,

View File

@ -1,3 +1,5 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import '../common.dart';
@ -115,7 +117,6 @@ void enterPasswordDialog(String id) {
),
value: remember,
onChanged: (v) {
debugPrint("onChanged");
if (v != null) {
setState(() => remember = v);
}
@ -181,11 +182,25 @@ class PasswordWidget extends StatefulWidget {
class _PasswordWidgetState extends State<PasswordWidget> {
bool _passwordVisible = false;
final _focusNode = FocusNode();
@override
void initState() {
super.initState();
Timer(Duration(milliseconds: 50), () => _focusNode.requestFocus());
}
@override
void dispose() {
_focusNode.unfocus();
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return TextField(
autofocus: true,
focusNode: _focusNode,
controller: widget.controller,
obscureText: !_passwordVisible,
//This will obscure text dynamically

View File

@ -236,6 +236,7 @@ class HoldTapMoveGestureRecognizer extends GestureRecognizer {
GestureDragUpdateCallback? onHoldDragUpdate;
GestureDragDownCallback? onHoldDragDown;
GestureDragCancelCallback? onHoldDragCancel;
GestureDragEndCallback? onHoldDragEnd;
bool _isStart = false;
@ -253,7 +254,8 @@ class HoldTapMoveGestureRecognizer extends GestureRecognizer {
case kPrimaryButton:
if (onHoldDragStart == null &&
onHoldDragUpdate == null &&
onHoldDragCancel == null) {
onHoldDragCancel == null &&
onHoldDragEnd == null) {
return false;
}
break;
@ -305,6 +307,10 @@ class HoldTapMoveGestureRecognizer extends GestureRecognizer {
if (event is PointerUpEvent) {
if (_firstTap == null && _secondTap == null) {
_registerFirstTap(tracker);
} else if (_secondTap != null) {
if (event.pointer == _secondTap!.pointer) {
if (onHoldDragEnd != null) onHoldDragEnd!(DragEndDetails());
}
} else {
_reject(tracker);
}
@ -739,6 +745,7 @@ RawGestureDetector getMixinGestureDetector({
GestureDragStartCallback? onHoldDragStart,
GestureDragUpdateCallback? onHoldDragUpdate,
GestureDragCancelCallback? onHoldDragCancel,
GestureDragEndCallback? onHoldDragEnd,
GestureTapDownCallback? onDoubleFinerTap,
GestureDragStartCallback? onOneFingerPanStart,
GestureDragUpdateCallback? onOneFingerPanUpdate,
@ -782,6 +789,7 @@ RawGestureDetector getMixinGestureDetector({
..onHoldDragStart = onHoldDragStart
..onHoldDragUpdate = onHoldDragUpdate
..onHoldDragCancel = onHoldDragCancel
..onHoldDragEnd = onHoldDragEnd
}),
DoubleFinerTapGestureRecognizer: GestureRecognizerFactoryWithHandlers<
DoubleFinerTapGestureRecognizer>(