[Mobile] Gestures

Started gesture implementation for
representation panes. Currently added Pan
and Pinch Gesture js, where the PanGesture
tracks single finger movement. PinchGesture
tracks the distance between two fingers. Also
added test spec files that test without error
but are incomplete. Current issue is that
pinch and pan gestures are applied to the entire
right pane, which includes header. Need to target
only representation of the right pane.
This commit is contained in:
Shivam Dave 2015-08-10 11:31:33 -07:00
parent 00aa7ce0c2
commit 3031579a62
6 changed files with 196 additions and 3 deletions

View File

@ -0,0 +1,28 @@
<!--
Open MCT Web, Copyright (c) 2014-2015, United States Government
as represented by the Administrator of the National Aeronautics and Space
Administration. All rights reserved.
Open MCT Web is licensed under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.
Open MCT Web includes source code licensed under additional open source
licenses. See the Open Source Licenses file (LICENSES.md) included with
this source code distribution or the Licensing information page available
at runtime from the About dialog for additional information.
-->
<div class='object-holder abs vscroll'>
<mct-representation ng-controller="BrowseObjectController"
key="representation.selected.key"
mct-object="representation.selected.key && domainObject">
</mct-representation>
</div>

View File

@ -22,7 +22,7 @@
/*global define,Promise*/
/**
* Module defining DragGesture. Created by vwoeltje on 11/17/14.
* Module defining PanGesture. Created by shivamndave on 8/7/15.
*/
define(
['./GestureConstants'],
@ -35,6 +35,7 @@ define(
*
* @constructor
* @param $log Angular's logging service
* @param agentService User Agent service that gets device info
* @param element the jqLite-wrapped element which should become
* draggable
* @param {DomainObject} domainObject the domain object which
@ -44,25 +45,32 @@ define(
// Gets name of current domainobject
var currentObjectName = domainObject.getCapability('type').getName();
// Returns position of touch event
function trackPosition(event) {
return [event.clientX, event.clientY];
}
// On a touch the positon is
// tracked and returned
function panAction(event) {
if (event.changedTouches.length === 1) {
var touchPos = trackPosition(event.changedTouches[0]);
$log.warn("PAN POS: " + touchPos);
// Stops other gestures/button clicks from being active
event.preventDefault();
}
}
// If on a mobile device and the currently represented object is
// not a folder, than read touch start, move, and end events
if (agentService.isMobile(navigator.userAgent) && currentObjectName !== "Folder") {
element.on('touchstart', panAction);
element.on('touchmove', panAction);
element.on('touchend', panAction);
}
return {
/**
* Detach any event handlers associated with this gesture.

View File

@ -22,7 +22,7 @@
/*global define,Promise*/
/**
* Module defining DragGesture. Created by vwoeltje on 11/17/14.
* Module defining PinchGesture. Created by shivamndave on 8/7/15.
*/
define(
['./GestureConstants'],
@ -35,6 +35,7 @@ define(
*
* @constructor
* @param $log Angular's logging service
* @param agentService User Agent service that gets device info
* @param element the jqLite-wrapped element which should become
* draggable
* @param {DomainObject} domainObject the domain object which
@ -44,10 +45,12 @@ define(
// Gets name of current domainobject
var currentObjectName = domainObject.getCapability('type').getName();
// Returns position of touch event
function trackPosition(event) {
return [event.clientX, event.clientY];
}
// Calculates distance between two points
function calculateDistance(coordOne, coordTwo) {
var squareX = Math.pow(coordOne[0] - coordTwo[0], 2),
squareY = Math.pow(coordOne[1] - coordTwo[1], 2);
@ -56,23 +59,29 @@ define(
function pinchAction(event) {
if (event.changedTouches.length === 2) {
// Gets touch positions for separate fingers
// and then calculates the distance between them
var touchPosOne = trackPosition(event.changedTouches[0]),
touchPosTwo = trackPosition(event.changedTouches[1]),
distance = calculateDistance(touchPosOne, touchPosTwo);
$log.warn("PINCH DIST: " + distance);
// Stops other gestures/button clicks from being active
event.preventDefault();
}
}
// If on a mobile device and the currently represented object is
// not a folder, than read touch start, move, and end events
if (agentService.isMobile(navigator.userAgent) && currentObjectName !== "Folder") {
element.on('touchstart', pinchAction);
element.on('touchmove', pinchAction);
element.on('touchend', pinchAction);
}
return {
/**
/**
* Detach any event handlers associated with this gesture.
* @method
* @memberof PinchGesture

View File

@ -0,0 +1,72 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
/**
* PanGesture. Created by shivamndave on 7/7/14.
*/
define(
["../../src/gestures/PanGesture", "../../src/gestures/GestureConstants"],
function (PanGesture, GestureConstants) {
"use strict";
var JQLITE_FUNCTIONS = [ "on", "off", "unbind" ],
LOG_FUNCTIONS = [ "error", "warn", "info", "debug"],
DOMAIN_OBJECT_METHODS = [ "getId", "getModel",
"getCapability", "hasCapability", "useCapability"],
TEST_NAME = "Not Folder";
describe("The pan gesture", function () {
var mockLog,
mockAgentService,
mockElement,
mockDomainObject,
mockObject,
gesture,
fireStartGesture,
fireMoveGesture,
fireEndGesture;
beforeEach(function () {
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockObject = jasmine.createSpyObj("domainObject",
DOMAIN_OBJECT_METHODS);
mockDomainObject = jasmine.createSpyObj("domainObject",
DOMAIN_OBJECT_METHODS);
mockDomainObject.getName.andReturn(TEST_NAME);
mockObject.getCapability.andCallFake(function (c) {
return c === 'type' && mockDomainObject;
});
mockAgentService.isMobile.andReturn(true);
gesture = new PanGesture(mockLog, mockAgentService,
mockElement, mockObject);
fireStartGesture = mockElement.on.calls[0];
fireMoveGesture = mockElement.on.calls[1];
fireEndGesture = mockElement.on.calls[2];
});
});
}
);

View File

@ -0,0 +1,74 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
/**
* PinchGesture. Created by shivamndave on 7/7/14.
*/
define(
["../../src/gestures/PinchGesture", "../../src/gestures/GestureConstants"],
function (PinchGesture, GestureConstants) {
"use strict";
var JQLITE_FUNCTIONS = [ "on", "off", "unbind" ],
LOG_FUNCTIONS = [ "error", "warn", "info", "debug"],
DOMAIN_OBJECT_METHODS = [ "getName", "getModel",
"getCapability", "hasCapability", "useCapability"],
TEST_NAME = "Not Folder";
describe("The pinch gesture", function () {
var mockLog,
mockAgentService,
mockElement,
mockDomainObject,
mockObject,
gesture,
fireStartGesture,
fireMoveGesture,
fireEndGesture;
beforeEach(function () {
mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS);
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockObject = jasmine.createSpyObj("domainObject",
DOMAIN_OBJECT_METHODS);
mockDomainObject = jasmine.createSpyObj("domainObject",
DOMAIN_OBJECT_METHODS);
mockDomainObject.getName.andReturn(TEST_NAME);
mockObject.getCapability.andCallFake(function (c) {
return c === 'type' && mockDomainObject;
});
mockAgentService.isMobile.andReturn(true);
gesture = new PinchGesture(mockLog, mockAgentService,
mockElement, mockObject);
fireStartGesture = mockElement.on.calls[0];
fireMoveGesture = mockElement.on.calls[1];
fireEndGesture = mockElement.on.calls[2];
});
it("pinch", function () {
});
});
}
);

View File

@ -3,6 +3,8 @@
"gestures/ContextMenuGesture",
"gestures/DragGesture",
"gestures/DropGesture",
"gestures/PinchGesture",
"gestures/PanGesture",
"gestures/GestureProvider",
"gestures/GestureRepresenter",
"services/DndService",