Skip to content

Commit

Permalink
增加遥控器方向按键
Browse files Browse the repository at this point in the history
  • Loading branch information
EaniaHuui committed Jun 17, 2022
1 parent 38f531b commit ad3ce8a
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 0 deletions.
Binary file modified fonts/iconfont.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions lib/page/common/icon_font.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ class IconFont {
static const IconData swipeLeft = IconData(0xe603, fontFamily: "IconFont");
static const IconData swipeRight = IconData(0xe60a, fontFamily: "IconFont");
static const IconData click = IconData(0xe6ca, fontFamily: "IconFont");
static const IconData remoteControl = IconData(0xe697, fontFamily: "IconFont");
}
13 changes: 13 additions & 0 deletions lib/page/feature_page/feature_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ class _FeaturePageState extends BasePage<FeaturePage, FeatureViewModel> {
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
buttonView(
IconFont.remoteControl,
"遥控器",
() {
viewModel.showRemoteControlDialog(context);
},
),
Expanded(flex: 3, child: Container()),
],
),
],
),
),
Expand Down
76 changes: 76 additions & 0 deletions lib/page/feature_page/feature_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:android_tool/page/common/base_view_model.dart';
import 'package:android_tool/page/common/package_help_mixin.dart';
import 'package:android_tool/widget/input_dialog.dart';
import 'package:android_tool/widget/list_filter_dialog.dart';
import 'package:android_tool/widget/remote_control_dialog.dart';
import 'package:desktop_drop/desktop_drop.dart';
import 'package:file_selector/file_selector.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -707,7 +708,82 @@ class FeatureViewModel extends BaseViewModel with PackageHelpMixin {
]);
}

/// 遥控器按键上
void pressRemoteUp() async {
await execAdb([
'-s',
deviceId,
'shell',
'input',
'keyevent',
'19',
]);
}

/// 遥控器按键下
void pressRemoteDown() async {
await execAdb([
'-s',
deviceId,
'shell',
'input',
'keyevent',
'20',
]);
}

/// 遥控器按键左
void pressRemoteLeft() async {
await execAdb([
'-s',
deviceId,
'shell',
'input',
'keyevent',
'21',
]);
}

/// 遥控器按键右
void pressRemoteRight() async {
await execAdb([
'-s',
deviceId,
'shell',
'input',
'keyevent',
'22',
]);
}

/// 遥控器按键OK
void pressRemoteOk() async {
await execAdb([
'-s',
deviceId,
'shell',
'input',
'keyevent',
'23',
]);
}

Color getColor(String name) {
return colors[name.hashCode % colors.length];
}

void showRemoteControlDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) {
return RemoteControlDialog(
onTapLeft: pressRemoteLeft,
onTapRight: pressRemoteRight,
onTapUp: pressRemoteUp,
onTapDown: pressRemoteDown,
onTapOk: pressRemoteOk,
);
},
);
}
}
143 changes: 143 additions & 0 deletions lib/widget/remote_control_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import 'package:android_tool/widget/text_view.dart';
import 'package:flutter/material.dart';

class RemoteControlDialog extends StatelessWidget {
final GestureTapCallback? onTapUp;
final GestureTapCallback? onTapDown;
final GestureTapCallback? onTapLeft;
final GestureTapCallback? onTapRight;
final GestureTapCallback? onTapOk;

const RemoteControlDialog({
Key? key,
this.onTapUp,
this.onTapDown,
this.onTapLeft,
this.onTapRight,
this.onTapOk,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return AlertDialog(
content: Stack(
children: [
buildCloseView(context),
Padding(
padding: const EdgeInsets.all(50),
child: Container(
height: 300,
width: 300,
decoration: BoxDecoration(
color: Colors.blue.shade100,
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(150),
),
child: Column(
children: [
buildDirectionView(
width: 150,
height: 60,
icon: Icons.keyboard_arrow_up,
onTap: onTapUp,
),
Expanded(
child: Row(
children: [
buildDirectionView(
width: 60,
height: 150,
icon: Icons.keyboard_arrow_left,
onTap: onTapLeft,
),
buildOKButton(),
buildDirectionView(
width: 60,
height: 150,
icon: Icons.keyboard_arrow_right,
onTap: onTapRight,
),
],
),
),
buildDirectionView(
width: 150,
height: 60,
icon: Icons.keyboard_arrow_down,
onTap: onTapDown,
),
],
),
),
),
],
),
);
}

Widget buildCloseView(BuildContext context) {
return Positioned(
right: 0,
child: InkWell(
onTap: () {
Navigator.of(context).pop();
},
child: const Padding(
padding: EdgeInsets.all(8.0),
child: Icon(
Icons.close,
color: Colors.grey,
),
),
),
);
}

Widget buildOKButton() {
return Expanded(
child: Container(
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(100),
),
child: InkWell(
onTap: onTapOk,
child: Container(
height: double.infinity,
width: double.infinity,
alignment: Alignment.center,
child: const TextView(
"OK",
color: Colors.black45,
),
),
),
),
);
}

Widget buildDirectionView({
required double width,
required double height,
required IconData icon,
GestureTapCallback? onTap,
}) {
return InkWell(
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onTap: onTap,
child: SizedBox(
height: height,
width: width,
child: Icon(
icon,
color: Colors.black45,
),
),
);
}
}

0 comments on commit ad3ce8a

Please sign in to comment.