Skip to content

Merged Mousepad controller #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CHANGELOG
=========

# v 0.4.0
- Mousepad in Controller
- Support: Tab, Swipe (depends on your device)

# v 0.3.0
- Install an apk file
- Update app icon

# v 0.2.0
- Add real-time graph for a process
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = function (grunt) {
"src/bower_components/jquery/jquery.min.js",
"src/bower_components/angular/angular.min.js",
"src/bower_components/angular-route/angular-route.min.js",
"src/bower_components/angular-sanitize/angular-sanitize.min.js",
"src/bower_components/jqplot/jquery.jqplot.min.css",
"src/bower_components/jqplot/jquery.jqplot.min.js",
"src/bower_components/jqplot/plugins/jqplot.canvasTextRenderer.min.js",
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Pre-requirements
- ADB included in [Android SDK][1]
- Start ADB daemon
- `$ adb start-server`
- ChromeADB for Android (Optional)
- for Mousepad
- Go to [PlayStore][chromeadb_for_android]



Expand Down Expand Up @@ -78,3 +81,5 @@ BrickSimple Public License 1.0 (Based on the Mozilla Public License Version 2.0)
[2]: https://chrome.google.com/webstore/detail/chrome-adb/fhdoijgfljahinnpbolfdimpcfoicmnm "chrome store"
[3]: https://github.com/android/platform_system_core/blob/master/adb/OVERVIEW.TXT "adb overview"
[4]: https://github.com/android/platform_system_core/blob/master/adb/SERVICES.TXT "adb services"

[chromeadb_for_android]: https://play.google.com/store/apps/details?id=io.github.importre.android.chromeadb
7 changes: 4 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
"importre"
],
"dependencies": {
"angular": "~1.2.2",
"angular-route": "~1.2.4",
"angular": "1.2.10",
"angular-route": "1.2.10",
"angular-sanitize": "1.2.10",
"bootstrap": "~3.0.2",
"jqplot": "*"
},
"description": "Chrome ADB(Android Debug Bridge) Client",
"homepage": "https://github.com/importre/chromeadb",
"license": "BSD",
"name": "ChromeADB",
"version": "0.3.0"
"version": "0.4.0"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"version": "0.3.0"
"version": "0.4.0"
}
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
]
}
],
"version": "0.3.0"
"version": "0.4.0"
}
2 changes: 1 addition & 1 deletion src/scripts/chromeadb.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

var adb = angular.module("chromeADB", ["ngRoute"]);
var adb = angular.module("chromeADB", ["ngRoute", "ngSanitize"]);

adb.config(function ($routeProvider, $locationProvider) {
$routeProvider
Expand Down
216 changes: 200 additions & 16 deletions src/scripts/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

var adb = angular.module("chromeADB");

adb.controller("controller", ["$scope", "$q", "socketService", function ($scope, $q, socketService) {
adb.controller("controller", ["$scope", "$q", "socketService", "$sce", function ($scope, $q, socketService, $sce) {
$scope.host = "127.0.0.1";
$scope.port = 5037;
$scope.numOfXAxis = 15;
Expand Down Expand Up @@ -42,6 +42,7 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,
$scope.memInfo = null;
$scope.diskSpace = null;
$scope.logMessage = null;
$scope.mousepadEnabled = false;
$scope.clearIntervalOfHeapInfo();
}

Expand Down Expand Up @@ -95,7 +96,7 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,
})
.then(function (param) {
// console.log(param);
if (param.data == "OKAY") {
if (param && param.data == "OKAY") {
return socketService.readAll(param.createInfo, arrayBufferToString);
}
})
Expand Down Expand Up @@ -177,7 +178,9 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
$scope.packages = parsePackageList(param.data);
if (param) {
$scope.packages = parsePackageList(param.data);
}
});
}

Expand Down Expand Up @@ -437,12 +440,14 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
var lines = parseProcessList(param.data);
var body = lines.splice(1);
var head = lines[0];
$scope.processList = {
head: head,
processes: body
if (param) {
var lines = parseProcessList(param.data);
var body = lines.splice(1);
var head = lines[0];
$scope.processList = {
head: head,
processes: body
}
}
});
}
Expand All @@ -465,12 +470,14 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
if (!procName) {
var data = parseMemInfo(param.data);
$scope.memInfo = data;
} else {
var data = parsePackageMemInfo(param.data);
drawHeapGraph(data);
if (param) {
if (!procName) {
var data = parseMemInfo(param.data);
$scope.memInfo = data;
} else {
var data = parsePackageMemInfo(param.data);
drawHeapGraph(data);
}
}
});
}
Expand All @@ -488,7 +495,9 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
$scope.diskSpace = parseDiskSpace(param.data);
if (param) {
$scope.diskSpace = parseDiskSpace(param.data);
}
});
}

Expand Down Expand Up @@ -576,5 +585,180 @@ adb.controller("controller", ["$scope", "$q", "socketService", function ($scope,
});
}
}

$scope.scaleOfMousePad = 2;
$scope.mouseDownX = -1;
$scope.mouseDownY = -1;
$scope.swipeDuration = 100;
$scope.packageName = "io.github.importre.android.chromeadb";
$scope.eventFilePath = "/sdcard/chromeadb.event";

/**
* Sets mouse pad size.
*
* Shows mousepad if parsed window size and chromeadb apk is installed.
*
* @param serial
*/
$scope.initMousePad = function (serial) {
var cmd1 = "host:transport:" + serial;

$scope.mousepadMsg = "Checking...";
$scope.getReadAllPromise(cmd1, "shell:pm list packages")
.then(function (param) {
if (!param) {
// not connected
$scope.mousepadMsg = "";
} else if (param.data.indexOf($scope.packageName) >= 0) {
// connected
var cmd2 = "shell:dumpsys window";
$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
var size = parseResolution(param.data);
if (size != null) {
$scope.mousepadEnabled = true;
$scope.devResolution = {
width: (size.width / $scope.scaleOfMousePad) + "px",
height: (size.height / $scope.scaleOfMousePad) + "px"
};

if ($scope.scaleOfMousePad >= 4) {
$("#mousepad-size-group label:last").click();
} else {
$("#mousepad-size-group label:first").click();
}
} else {
// failed to parse `dumpsys windows`
$scope.mousepadEnabled = false;
var title = "feedback mousepad";

$scope.getReadAllPromise(cmd1, "shell:input")
.then(function(param) {
body += "\n\n\n" + param.data;
$scope.mousepadMsg = "Error: " + $scope.getFeedbackTag(title, body);
});
}
});
} else {
// apk is not installed.
$scope.mousepadEnabled = false;
$scope.mousepadMsg = $scope.packageName;
}
});
}

$scope.mouseDown = function (event) {
$scope.mouseDownX = event.offsetX * $scope.scaleOfMousePad;
$scope.mouseDownY = event.offsetY * $scope.scaleOfMousePad;
}

$scope.mouseUp = function (serial, event) {
var x = event.offsetX * $scope.scaleOfMousePad;
var y = event.offsetY * $scope.scaleOfMousePad;

var cmd1 = "host:transport:" + serial;
var cmd2 = "shell:input touchscreen tap " + x + " " + y;

var x1 = $scope.mouseDownX;
var y1 = $scope.mouseDownY;

if (x1 >= 0 && y1 >= 0) {
var dist = Math.sqrt(Math.pow(x - x1, 2) + Math.pow(y - y1, 2));
// console.log("dist : " + dist);
if (dist > 30) {
cmd2 = "shell:input touchscreen swipe " + [x1, y1, x, y, $scope.swipeDuration].join(" ")
console.log(cmd2);
}
}

$scope.mouseDownX = -1;
$scope.mouseDownY = -1;

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
if (param && param.data) {
$scope.logMessage = {
cmd: "MousePad",
res: param.data.split("\n")[0]
};
}
});
}

$scope.mouseMove = function (serial, event) {
var x = event.offsetX * $scope.scaleOfMousePad;
var y = event.offsetY * $scope.scaleOfMousePad;

$scope.mouseMoveLog = "coord: (" + x + ", " + y + ")";

if ($scope.coords == null) {
$scope.coords = [];
}

$scope.coords.push(x);
$scope.coords.push(y);

if ($scope.coords.length > 2) {
var cmd1 = "host:transport:" + serial;
var cmd2 = "shell: echo move " + $scope.coords.join(",") + " >> " + $scope.eventFilePath;

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
});
$scope.coords = [];
}
}

$scope.mouseEnter = function (serial) {
var cmd1 = "host:transport:" + serial;
var cmd2 = "shell:am startservice --user 0 -n " + $scope.packageName + "/.ChromeAdbService";

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
if (param && param.data) {
if (param.data.indexOf("--user") >= 0) {
cmd2 = cmd2.replace("--user 0 ", "");
$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
});
}
}
});
}

$scope.mouseLeave = function (serial) {
var cmd1 = "host:transport:" + serial;
var cmd2 = "shell:rm -r " + $scope.eventFilePath;

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
cmd2 = "shell:am stopservice -n " + $scope.packageName + "/.ChromeAdbService";

$scope.getReadAllPromise(cmd1, cmd2)
.then(function (param) {
});
});
}

$scope.rotateMousePad = function () {
$scope.devResolution = {
width: $scope.devResolution.height,
height: $scope.devResolution.width
};
}

$scope.setMousePadSize = function (serial, scale) {
$scope.scaleOfMousePad = scale;
$scope.initMousePad(serial);
}

$scope.getFeedbackTag = function (title, body) {
title = "[ChromeADB] " + title;
body = encodeURIComponent(body);

var to = "[email protected]";
var mailto = $sce.trustAsHtml("mailto:" + to + "?subject=" + title + "&body=" + body);
return "<a href='" + mailto + "' target='_blank'>Send feedback</a>";
}
}]);

14 changes: 14 additions & 0 deletions src/scripts/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,17 @@ function parseDiskSpace(data) {
}
return {head: head, body: body};
}

function parseResolution(data) {
var re = /init=(\d+)x(\d+)/g
var res = re.exec(data);
if (res == null) {
re = /mDisplayWidth=(\d+)\s+mDisplayHeight=(\d+)/g
res = re.exec(data);
if (res == null) {
return null;
}
}
return {width: res[1], height: res[2]};
}

15 changes: 15 additions & 0 deletions src/styles/chromeadb.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,18 @@ th {
.navbar {
background-color: #000;
}

#mousepad {
color: white;
background-color: black;
text-align: center;
vertical-align: middle;
display: table-cell;
}

.ng-hide {
display: block !important;
position: absolute;
top: -9999px;
left: -9999px;
}
Loading