函数执行缓慢-DataOutPutStream

时间:2018-09-05 17:13:31

标签: java android dataoutputstream

List<Widget> widgetList = new List<Widget>();
List<String> _names = [ /*This contains the text of each Card in a string*/ ];
Color backgroundCol = new Color.fromRGBO(230, 230, 230, 1.0);

void _makeCards() {

  widgetList = [];

  for (int i = 0; i < _names.length; i++) {
    Column myWidget = new Column(
      children: <Widget>[
        new Flexible(
          fit: FlexFit.loose,
          child: new Card(
            color: Colors.white,
            child: new Container(
              padding: EdgeInsets.all(8.0),
              child: new Text(_names[i], style: new TextStyle(fontFamily: 'RobotoSlab')),
            )
          )
        )
      ],
    );

    widgetList.add(myWidget);
  }
}

@override
Widget build(BuildContext context) {

  _makeCards();

  return new Scaffold(
    appBar: new AppBar(
      title: new Text('Notes', style: new TextStyle(fontFamily: 'RobotoSlab')),
      backgroundColor: Colors.amber,
      actions: <Widget>[new IconButton(icon: new Icon(Icons.add), onPressed: _onAdd)],
      ),
    drawer: new Drawer(),
    body: new Container(
      color: backgroundCol,
      child: new GridView.count(
        crossAxisCount: 2,
        children: widgetList,
      ),
    ),
  );
}

09-06 01:09: 43.878 13600-13600 / com.example.na D / Tap:首先

09-06 01:09: 46.178 13600-13600 / com.example.na D / Tap:秒

这真的非常慢,我想模拟两次双击,两次点击之间可能会有200MS的延迟。但最快可以做到3秒...请指教。

更新-尝试过此操作,每次敲击之间仍然存在延迟,但速度更快。

private void sendCommand(String cmd) {
        Process process = null;
        try {
            process = Runtime.getRuntime().exec("su");
            DataOutputStream os = new DataOutputStream(process.getOutputStream());
            os.writeBytes(cmd);
            os.writeBytes("exit\n");
            os.flush();
            os.close();
            process.waitFor();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }


String cmd = "/system/bin/input tap 244 580\n";
sendCommand(cmd);
Log.d("Tap","first");
sendCommand(cmd);
Log.d("Tap","second");

0 个答案:

没有答案