├── .gitignore ├── .travis.yml ├── AUTHORS.TXT ├── demo ├── JavaFxTest │ ├── .gitignore │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── build.gradle │ ├── javafx.plugin │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── com │ │ │ │ └── orange │ │ │ │ └── dgil │ │ │ │ └── trail │ │ │ │ └── app │ │ │ │ └── fxdrawertest │ │ │ │ └── fxml │ │ │ │ └── FxDrawer.fxml │ │ │ └── java │ │ │ └── com │ │ │ └── orange │ │ │ └── dgil │ │ │ └── trail │ │ │ └── app │ │ │ └── fxdrawertest │ │ │ ├── FxDrawer.java │ │ │ ├── drawer │ │ │ └── GraphicContextDrawer.java │ │ │ ├── curves │ │ │ └── Curves.java │ │ │ └── fxcontroller │ │ │ └── MouseController.java │ ├── gradlew.bat │ └── gradlew ├── example.png ├── DroidDrawingTest.apk └── DroidTest │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── src │ └── main │ │ ├── res │ │ ├── drawable-xxhdpi │ │ │ └── ic_launcher.png │ │ ├── values-fr │ │ │ └── strings.xml │ │ ├── values │ │ │ └── strings.xml │ │ └── layout │ │ │ └── main.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── orange │ │ └── dgil │ │ └── trail │ │ └── app │ │ └── android │ │ └── drawingtest │ │ ├── DrawingTestActivity.java │ │ └── view │ │ └── DrawingArea.java │ ├── gradle.properties │ ├── build.gradle │ ├── gradlew.bat │ └── gradlew ├── lombok.config ├── sonar-project.properties ├── src ├── main │ └── java │ │ └── com │ │ └── orange │ │ └── dgil │ │ └── trail │ │ ├── android │ │ ├── animation │ │ │ ├── IAnimListener.java │ │ │ ├── IAnimDrawer.java │ │ │ ├── AnimParameters.java │ │ │ ├── AnimManager.java │ │ │ └── AnimRunnable.java │ │ ├── drawingtool │ │ │ ├── quillpen │ │ │ │ ├── QuillTrailBitmapListener.java │ │ │ │ ├── QuillParameters.java │ │ │ │ ├── BitmapDrawer.java │ │ │ │ ├── TrailBounds.java │ │ │ │ ├── QuadCurveTrail.java │ │ │ │ ├── QuillBitmap.java │ │ │ │ ├── QuillTrailBitmapEnd.java │ │ │ │ └── QuillTrailBitmap.java │ │ │ ├── IDrawingTool.java │ │ │ ├── DrawingToolsContext.java │ │ │ ├── InvalidateArea.java │ │ │ ├── DrawingTools.java │ │ │ ├── TrailOptions.java │ │ │ └── markerpen │ │ │ │ ├── MarkerPaths.java │ │ │ │ └── Painters.java │ │ ├── DefaultDrawerConf.java │ │ ├── ITrailDrawer.java │ │ └── AndroidMetrics.java │ │ └── core │ │ ├── vecto │ │ ├── vecto │ │ │ ├── OnWindowSizeListener.java │ │ │ ├── VectoFilterListener.java │ │ │ ├── VectoSettings.java │ │ │ ├── VectoFilter.java │ │ │ ├── WindowAnalysis.java │ │ │ └── RawVectoFilter.java │ │ ├── linearwindowfilter │ │ │ ├── LinearWindowFilterListener.java │ │ │ └── LinearWindowFilter.java │ │ ├── SlidingWindowIndexException.java │ │ └── SlidingWindow.java │ │ ├── quad │ │ ├── QuadCurveException.java │ │ ├── QuadCurveArrayException.java │ │ ├── QuadDat.java │ │ ├── QuadCurveArray.java │ │ ├── QuadCurve.java │ │ └── QuadInterpolator.java │ │ └── common │ │ ├── TrailException.java │ │ ├── TrailRect.java │ │ ├── TrailPoint.java │ │ └── Vector.java └── test │ └── java │ └── com │ └── orange │ └── dgil │ └── trail │ ├── core │ ├── vecto │ │ ├── linearwindowfilter │ │ │ ├── LinearWindowFilterCtorTest.java │ │ │ ├── LinearWindowFilterGetWeightsSumTest.java │ │ │ ├── LinearWindowFilterResetTest.java │ │ │ ├── LinearWindowFilterInitPropertiesTest.java │ │ │ ├── LinearWindowFilterGetLastPointTest.java │ │ │ ├── LinearWindowFilterAddPointTest.java │ │ │ ├── LinearWindowFilterDoAddPointTest.java │ │ │ ├── LinearWindowFilterFunctionalTest.java │ │ │ ├── LinearWindowFilterGetMeanXYTest.java │ │ │ ├── LinearWindowFilterComputeNewPointTest.java │ │ │ └── LinearWindowFilterIsNewPointAvailableTest.java │ │ ├── SlidingWindowCtorAllocatePointsTest.java │ │ ├── SlidingWindowResetTest.java │ │ ├── SlidingWindowGetAddedElementNumberTest.java │ │ ├── SlidingWindowGetLastElementTest.java │ │ ├── SlidingWindowSlidePointsToTheLeftTest.java │ │ ├── SlidingWindowDoAddTest.java │ │ ├── SlidingWindowGetElementAtTest.java │ │ ├── SlidingWindowIsFullTest.java │ │ ├── SlidingWindowAddTest.java │ │ ├── SlidingWindowGetMaxIndexTest.java │ │ ├── SlidingWindowGetInsertIndexTest.java │ │ ├── SlidingWindowGetLastElementIndexTest.java │ │ ├── SlidingWindowIsIndexValidTest.java │ │ ├── SlidingWindowIsSameAsLastTest.java │ │ └── vecto │ │ │ └── RawVectoFilterFunctionalTest.java │ ├── common │ │ ├── TrailPointTest.java │ │ └── VectorGetHeightToTest.java │ └── quad │ │ └── QuadInterpolatorRawInterpolateFunctionalTest.java │ ├── TestTools.java │ └── android │ └── AndroidMetricsTest.java └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | .idea 3 | *.iml 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk8 4 | -------------------------------------------------------------------------------- /AUTHORS.TXT: -------------------------------------------------------------------------------- 1 | christophe.maldivi@orange.com 2 | eric.petit@orange.com 3 | -------------------------------------------------------------------------------- /demo/JavaFxTest/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | out 3 | *.iml 4 | *.ipr 5 | *.iws 6 | .idea 7 | .gradle -------------------------------------------------------------------------------- /demo/JavaFxTest/gradle.properties: -------------------------------------------------------------------------------- 1 | trailCoreLibVersion = 1.1.2 2 | 3 | gradleWrapperVersion = 2.4 4 | -------------------------------------------------------------------------------- /demo/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Orange-OpenSource/android-trail-drawing/HEAD/demo/example.png -------------------------------------------------------------------------------- /lombok.config: -------------------------------------------------------------------------------- 1 | lombok.anyConstructor.suppressConstructorProperties = true 2 | lombok.addGeneratedAnnotation = false 3 | -------------------------------------------------------------------------------- /demo/DroidDrawingTest.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Orange-OpenSource/android-trail-drawing/HEAD/demo/DroidDrawingTest.apk -------------------------------------------------------------------------------- /demo/DroidTest/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Orange-OpenSource/android-trail-drawing/HEAD/demo/DroidTest/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/JavaFxTest/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Orange-OpenSource/android-trail-drawing/HEAD/demo/JavaFxTest/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/DroidTest/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Orange-OpenSource/android-trail-drawing/HEAD/demo/DroidTest/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/DroidTest/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri May 29 14:17:38 CEST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip 7 | -------------------------------------------------------------------------------- /demo/DroidTest/src/main/res/values-fr/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | DrawingTest 4 | Effacer 5 | Marqueur 6 | Plume 7 | -------------------------------------------------------------------------------- /demo/JavaFxTest/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jul 17 15:42:39 CEST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip 7 | -------------------------------------------------------------------------------- /demo/DroidTest/gradle.properties: -------------------------------------------------------------------------------- 1 | appVersion = 0.1 2 | appVersionCode = 1 3 | 4 | trailCoreLibVersion = 1.2.4-SNAPSHOT 5 | 6 | appCompileSdkVersion = 23 7 | appBuildToolsVersion = 23.0.2 8 | appMinSdkVersion = 14 9 | appTargetSdkVersion = 23 10 | 11 | gradleAndroidPluginVersion = 1.3.1 12 | gradleWrapperVersion = 2.9 13 | -------------------------------------------------------------------------------- /demo/DroidTest/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | DrawingTest 4 | Quill 5 | Marker 6 | Clear 7 | multistroke 8 | 9 | -------------------------------------------------------------------------------- /demo/JavaFxTest/build.gradle: -------------------------------------------------------------------------------- 1 | apply from: 'javafx.plugin' 2 | 3 | javafx { 4 | appID 'FxDrawer' 5 | mainClass 'com.orange.dgil.trail.app.fxdrawertest.FxDrawer' 6 | } 7 | 8 | dependencies { 9 | compile "com.orange.dgil.trail:trail-core-lib:${project.ext.trailCoreLibVersion}" 10 | } 11 | 12 | repositories { 13 | mavenLocal() 14 | mavenCentral() 15 | } 16 | 17 | task wrapper(type: Wrapper) { 18 | gradleVersion = gradleWrapperVersion 19 | } 20 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | # Required metadata 2 | sonar.projectKey=com.orange.dgil.trail 3 | sonar.projectName=trail-core-lib 4 | sonar.projectVersion=1.0 5 | 6 | # Paths to source directories. 7 | sonar.sources=src/main/java 8 | 9 | # Paths to binaries directories. 10 | sonar.binaries=build/classes/main 11 | 12 | # The value of the property must be the key of the language. 13 | sonar.language=java 14 | 15 | # Encoding of the source code 16 | sonar.sourceEncoding=UTF-8 17 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/animation/IAnimListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.animation; 11 | 12 | public interface IAnimListener { 13 | void animationFinished(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/vecto/vecto/OnWindowSizeListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.vecto; 11 | 12 | interface OnWindowSizeListener { 13 | void onWindowSizeChanged(int size); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/quillpen/QuillTrailBitmapListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool.quillpen; 11 | 12 | interface QuillTrailBitmapListener { 13 | void onLastDrawnPointChange(int x, int y ); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/quad/QuadCurveException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.quad; 11 | 12 | public class QuadCurveException extends RuntimeException { 13 | public QuadCurveException(String message) { 14 | super(message); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/vecto/linearwindowfilter/LinearWindowFilterListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.linearwindowfilter; 11 | 12 | public interface LinearWindowFilterListener { 13 | void onNewFilteredPointAvailable(int x, int y); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/vecto/vecto/VectoFilterListener.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.vecto; 11 | 12 | public interface VectoFilterListener { 13 | void onNewVectoPointAvailable(int x, int y); 14 | void onLastVectoPointAvailable(int x, int y); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/animation/IAnimDrawer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.animation; 11 | 12 | import android.view.View; 13 | 14 | public interface IAnimDrawer { 15 | void invalidatePath(); 16 | void animationFinished(); 17 | View getView(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/quad/QuadCurveArrayException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.quad; 11 | 12 | import com.orange.dgil.trail.core.common.TrailException; 13 | 14 | public class QuadCurveArrayException extends TrailException { 15 | public QuadCurveArrayException(String message) { 16 | super(message); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/vecto/SlidingWindowIndexException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.core.common.TrailException; 13 | 14 | public class SlidingWindowIndexException extends TrailException { 15 | public SlidingWindowIndexException(String msg) { 16 | super(msg); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/common/TrailException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.common; 11 | 12 | public abstract class TrailException extends RuntimeException { 13 | 14 | public TrailException(String message) { 15 | super(message); 16 | trace(message); 17 | } 18 | 19 | private void trace(String message) { 20 | System.out.println(String.format("Trail exception: '%s'", message)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/IDrawingTool.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool; 11 | 12 | import android.graphics.Canvas; 13 | 14 | public interface IDrawingTool { 15 | void reset(); 16 | 17 | void touchDown(int x, int y); 18 | void touchMove(int x, int y); 19 | void touchUp(); 20 | 21 | void draw(Canvas c); 22 | 23 | void invalidateAreaOnMove(); 24 | void invalidatePath(); 25 | 26 | void forceRedrawForAnimation(boolean eraseBitmap); 27 | 28 | void trimMemory(); 29 | } 30 | -------------------------------------------------------------------------------- /demo/DroidTest/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/linearwindowfilter/LinearWindowFilterCtorTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.linearwindowfilter; 11 | 12 | import org.junit.Test; 13 | 14 | public class LinearWindowFilterCtorTest implements LinearWindowFilterListener { 15 | 16 | @Test 17 | public void shouldInstantiateWithoutCrash() { 18 | // given 19 | // do 20 | LinearWindowFilter f = new LinearWindowFilter(this); 21 | // then 22 | // no crash 23 | } 24 | 25 | @Override 26 | public void onNewFilteredPointAvailable(int x, int y) { 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/common/TrailRect.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.common; 11 | 12 | import lombok.Getter; 13 | 14 | @Getter 15 | public class TrailRect { 16 | private int left; 17 | private int top; 18 | private int right; 19 | private int bottom; 20 | 21 | public void initAtPoint(int x, int y) { 22 | left = x; 23 | top = y; 24 | right = x; 25 | bottom = y; 26 | } 27 | 28 | public void union(int x, int y) { 29 | left = Math.min(left, x); 30 | right = Math.max(right, x); 31 | top = Math.min(top, y); 32 | bottom = Math.max(bottom, y); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/TestTools.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail; 11 | 12 | import org.powermock.api.mockito.PowerMockito; 13 | 14 | public class TestTools { 15 | 16 | public static Object getObj(String fieldName, Class clazz, Object instance) throws IllegalArgumentException, IllegalAccessException { 17 | return PowerMockito.field(clazz, fieldName).get(instance); 18 | } 19 | 20 | public static void setObj(String fieldName, Class clazz, Object instance, Object value) throws IllegalArgumentException, IllegalAccessException { 21 | PowerMockito.field(clazz, fieldName).set(instance, value); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/DrawingToolsContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool; 11 | 12 | import android.view.View; 13 | 14 | import com.orange.dgil.trail.android.AndroidMetrics; 15 | import com.orange.dgil.trail.android.animation.AnimManager; 16 | 17 | import lombok.Getter; 18 | import lombok.RequiredArgsConstructor; 19 | 20 | @RequiredArgsConstructor 21 | @Getter 22 | public class DrawingToolsContext { 23 | private final View view; 24 | private final AnimManager animManager; 25 | private final AndroidMetrics androidMetrics; 26 | private final TrailOptions trailOptions; 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/vecto/vecto/VectoSettings.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.vecto; 11 | 12 | import lombok.Getter; 13 | import lombok.RequiredArgsConstructor; 14 | import lombok.Setter; 15 | 16 | @RequiredArgsConstructor 17 | public class VectoSettings { 18 | private static final int DEFAULT_VECTO_ERROR_HEIGHT_PIXELS = 1; 19 | 20 | private final WindowAnalysis windowAnalysis; 21 | 22 | @Getter 23 | @Setter 24 | private int vectorsHeightThreshold = DEFAULT_VECTO_ERROR_HEIGHT_PIXELS; 25 | 26 | public void setWindowSize(int windowSize) { 27 | windowAnalysis.setWindowSize(windowSize); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /demo/DroidTest/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion Integer.parseInt(appCompileSdkVersion) 5 | buildToolsVersion appBuildToolsVersion 6 | 7 | defaultConfig { 8 | minSdkVersion Integer.parseInt(appMinSdkVersion) 9 | targetSdkVersion Integer.parseInt(appTargetSdkVersion) 10 | versionCode Integer.parseInt(appVersionCode) 11 | versionName appVersion 12 | } 13 | 14 | compileOptions { 15 | sourceCompatibility JavaVersion.VERSION_1_7 16 | targetCompatibility JavaVersion.VERSION_1_7 17 | } 18 | } 19 | 20 | dependencies { 21 | compile "com.orange.dgil.trail:trail-core-lib:${project.ext.trailCoreLibVersion}" 22 | } 23 | 24 | buildscript { 25 | repositories { 26 | mavenCentral() 27 | } 28 | dependencies { 29 | classpath "com.android.tools.build:gradle:${project.ext.gradleAndroidPluginVersion}" 30 | } 31 | } 32 | 33 | repositories { 34 | mavenLocal() 35 | mavenCentral() 36 | } 37 | 38 | task wrapper(type: Wrapper) { 39 | gradleVersion = gradleWrapperVersion 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/DefaultDrawerConf.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android; 11 | 12 | import android.graphics.Color; 13 | 14 | public class DefaultDrawerConf { 15 | public static final int TRAIL_COLOR = Color.rgb(0xFF, 0x99, 0); 16 | public static final int TRAIL_WIDTH_UM = 2500; 17 | 18 | public static final float SHADOW_RADIUS_FACTOR = 0.5f; 19 | public static final float SHADOW_OFFSET_FACTOR = 0.33f; 20 | public static final int SHADOW_COLOR = Color.BLACK; 21 | 22 | public static final int ANIM_PRE_ANIM_DELAY_MS = 100; 23 | public static final int ANIM_DURATION_MS = 400; 24 | 25 | public static final int QUILL_WIDTH_UM = 3000; 26 | public static final int QUILL_HEIGHT_UM = 1000; 27 | public static final int QUILL_ANGLE_DEG = 45; 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/InvalidateArea.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool; 11 | 12 | import android.graphics.Point; 13 | import android.graphics.Rect; 14 | 15 | import lombok.Getter; 16 | import lombok.Setter; 17 | 18 | @Getter 19 | @Setter 20 | public class InvalidateArea { 21 | private final Rect rect = new Rect(); 22 | private int radius; 23 | 24 | public void setOrigin(int x, int y) { 25 | rect.set(x - radius, y - radius, x + radius, y + radius); 26 | } 27 | public void setOrigin(Point p) { 28 | setOrigin(p.x, p.y); 29 | } 30 | 31 | public void add(int x, int y) { 32 | rect.union(x - radius, y - radius, x + radius, y + radius); 33 | } 34 | public void add(Point p) { 35 | add(p.x, p.y); 36 | } 37 | 38 | public void setEmpty() { 39 | rect.setEmpty(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/common/TrailPoint.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.common; 11 | 12 | import lombok.Getter; 13 | import lombok.NoArgsConstructor; 14 | 15 | @Getter 16 | @NoArgsConstructor 17 | public class TrailPoint { 18 | private int x = -1; 19 | private int y = -1; 20 | 21 | public TrailPoint(int x, int y) { 22 | set(x, y); 23 | } 24 | 25 | public void set(int x, int y) { 26 | this.x = x; 27 | this.y = y; 28 | } 29 | 30 | public boolean isSameAs(TrailPoint point) { 31 | return x == point.x && y == point.y; 32 | } 33 | 34 | public double getDistanceTo(TrailPoint point) { 35 | int dx = x - point.getX(); 36 | int dy = y - point.getY(); 37 | return Math.sqrt(dx * dx + dy * dy); 38 | } 39 | 40 | public void deepCopy(TrailPoint point) { 41 | x = point.x; 42 | y = point.y; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowCtorAllocatePointsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.common.TrailPoint; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | public class SlidingWindowCtorAllocatePointsTest { 21 | 22 | private SlidingWindow slidingWindow; 23 | 24 | @Before 25 | public void setUp() { 26 | slidingWindow = Mockito.mock(SlidingWindow.class); 27 | } 28 | 29 | @Test 30 | public void shouldInstantiate() throws IllegalAccessException { 31 | // given 32 | int windowSize = 5; 33 | // do 34 | slidingWindow = new SlidingWindow(windowSize); 35 | // then 36 | TrailPoint[] points = (TrailPoint[]) TestTools.getObj("points", SlidingWindow.class, slidingWindow); 37 | Assert.assertEquals(windowSize, points.length); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowResetTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.mockito.Mockito; 18 | 19 | public class SlidingWindowResetTest { 20 | 21 | private SlidingWindow slidingWindow; 22 | 23 | @Before 24 | public void setUp() { 25 | slidingWindow = Mockito.mock(SlidingWindow.class); 26 | } 27 | 28 | @Test 29 | public void shouldReset() throws IllegalAccessException { 30 | // given 31 | int addedElementsNumber = 10; 32 | TestTools.setObj("addedElementsNumber", SlidingWindow.class, slidingWindow, addedElementsNumber); 33 | Mockito.doCallRealMethod().when(slidingWindow).reset(); 34 | // do 35 | slidingWindow.reset(); 36 | // then 37 | Assert.assertEquals(0, TestTools.getObj("addedElementsNumber", SlidingWindow.class, slidingWindow)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/linearwindowfilter/LinearWindowFilterGetWeightsSumTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.linearwindowfilter; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.mockito.Mockito; 18 | 19 | public class LinearWindowFilterGetWeightsSumTest { 20 | 21 | private LinearWindowFilter filter; 22 | 23 | @Before 24 | public void setUp() { 25 | filter = Mockito.mock(LinearWindowFilter.class); 26 | } 27 | 28 | @Test 29 | public void shouldGetWeightsSum() throws IllegalAccessException { 30 | // given 31 | int[] windowWeights = {1, 2, 1}; 32 | TestTools.setObj("windowWeights", LinearWindowFilter.class, filter, windowWeights); 33 | Mockito.doCallRealMethod().when(filter).getWeightsSum(); 34 | // do 35 | int sum = filter.getWeightsSum(); 36 | // then 37 | Assert.assertEquals(4, sum); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/quad/QuadDat.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.quad; 11 | 12 | import com.orange.dgil.trail.core.common.TrailPoint; 13 | 14 | import lombok.AccessLevel; 15 | import lombok.Getter; 16 | import lombok.Setter; 17 | 18 | @Getter(AccessLevel.PACKAGE) 19 | @Setter(AccessLevel.PACKAGE) 20 | class QuadDat { 21 | private final TrailPoint interpStartPoint = new TrailPoint(); 22 | private final TrailPoint interpEndPoint = new TrailPoint(); 23 | private final TrailPoint middlePoint = new TrailPoint(); 24 | 25 | private long coefA; 26 | private long coefB; 27 | private long coefC; 28 | private long coefD; 29 | private long coefE; 30 | private long coefF; 31 | 32 | private int interpNbPoints; 33 | 34 | private boolean curveStart; 35 | private boolean curveEnd; 36 | 37 | private TrailPoint point0; 38 | private TrailPoint point1; 39 | private TrailPoint point2; 40 | 41 | 42 | void reset() { 43 | curveStart = true; 44 | curveEnd = false; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowGetAddedElementNumberTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.mockito.Mockito; 18 | 19 | public class SlidingWindowGetAddedElementNumberTest { 20 | 21 | private SlidingWindow slidingWindow; 22 | 23 | @Before 24 | public void setUp() { 25 | slidingWindow = Mockito.mock(SlidingWindow.class); 26 | } 27 | 28 | @Test 29 | public void shouldGetAddedElementsNumber() throws IllegalAccessException { 30 | // given 31 | int addedElementsNumber = 123; 32 | TestTools.setObj("addedElementsNumber", SlidingWindow.class, slidingWindow, addedElementsNumber); 33 | Mockito.doCallRealMethod().when(slidingWindow).getAddedElementsNumber(); 34 | // do 35 | int ret = slidingWindow.getAddedElementsNumber(); 36 | // then 37 | Assert.assertEquals(addedElementsNumber, ret); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/linearwindowfilter/LinearWindowFilterResetTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.linearwindowfilter; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.vecto.SlidingWindow; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | public class LinearWindowFilterResetTest { 21 | 22 | private LinearWindowFilter filter; 23 | 24 | @Before 25 | public void setUp() { 26 | filter = Mockito.mock(LinearWindowFilter.class); 27 | } 28 | 29 | @Test 30 | public void shouldReset() throws IllegalAccessException { 31 | // given 32 | SlidingWindow slidingWindow = Mockito.mock(SlidingWindow.class); 33 | TestTools.setObj("slidingWindow", LinearWindowFilter.class, filter, slidingWindow); 34 | Mockito.doCallRealMethod().when(filter).reset(); 35 | // do 36 | filter.reset(); 37 | // then 38 | Mockito.verify(slidingWindow, Mockito.times(1)).reset(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowGetLastElementTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.core.common.TrailPoint; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.mockito.Mockito; 18 | 19 | public class SlidingWindowGetLastElementTest { 20 | 21 | private SlidingWindow slidingWindow; 22 | 23 | @Before 24 | public void setUp() { 25 | slidingWindow = Mockito.mock(SlidingWindow.class); 26 | } 27 | 28 | @Test 29 | public void shouldGetLastElement() throws IllegalAccessException { 30 | // given 31 | int lastIndex = 3; 32 | Mockito.when(slidingWindow.getLastElementIndex()).thenReturn(lastIndex); 33 | TrailPoint lastPoint = new TrailPoint(); 34 | Mockito.when(slidingWindow.getElementAt(lastIndex)).thenReturn(lastPoint); 35 | Mockito.doCallRealMethod().when(slidingWindow).getLastElement(); 36 | // do 37 | TrailPoint ret = slidingWindow.getLastElement(); 38 | // then 39 | Assert.assertEquals(lastPoint, ret); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /demo/JavaFxTest/javafx.plugin: -------------------------------------------------------------------------------- 1 | /* 2 | * Bootstrap script for the Gradle JavaFX Plugin. 3 | * (based on http://plugins.jasoft.fi/vaadin.plugin) 4 | * 5 | * The script will add the latest version of the plugin to the build script 6 | * dependencies and apply the plugin to the project. If you do not want 7 | * this behavior you can copy and paste the below configuration into your 8 | * own build script and define your own repository and version for the plugin. 9 | */ 10 | 11 | buildscript { 12 | repositories { 13 | mavenLocal() 14 | maven { 15 | name = 'BinTray' 16 | url = 'http://dl.bintray.com/content/shemnon/javafx-gradle/' 17 | } 18 | maven { 19 | name = 'CloudBees Snapshot' 20 | url = 'http://repository-javafx-gradle-plugin.forge.cloudbees.com/snapshot' 21 | } 22 | ivy { 23 | url = 'http://repository-javafx-gradle-plugin.forge.cloudbees.com/snapshot' 24 | } 25 | mavenCentral() 26 | } 27 | dependencies { 28 | classpath 'org.bitbucket.shemnon.javafxplugin:gradle-javafx-plugin:0.4.0' 29 | classpath project.files("${System.properties['java.home']}/../lib/ant-javafx.jar") 30 | classpath project.files("${System.properties['java.home']}/lib/jfxrt.jar") 31 | } 32 | } 33 | 34 | if (!project.plugins.findPlugin(org.bitbucket.shemnon.javafxplugin.JavaFXPlugin)) { 35 | project.apply(plugin: org.bitbucket.shemnon.javafxplugin.JavaFXPlugin) 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/linearwindowfilter/LinearWindowFilterInitPropertiesTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.linearwindowfilter; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | 14 | import org.junit.Assert; 15 | import org.junit.Before; 16 | import org.junit.Test; 17 | import org.mockito.Mockito; 18 | 19 | public class LinearWindowFilterInitPropertiesTest { 20 | 21 | private LinearWindowFilter filter; 22 | 23 | @Before 24 | public void setUp() { 25 | filter = Mockito.mock(LinearWindowFilter.class); 26 | } 27 | 28 | @Test 29 | public void shouldInitProperties() throws IllegalAccessException { 30 | // given 31 | int[] windowWeights = {1, 2, 1}; 32 | int weightsSum = 4; 33 | TestTools.setObj("windowWeights", LinearWindowFilter.class, filter, windowWeights); 34 | Mockito.when(filter.getWeightsSum()).thenReturn(weightsSum); 35 | Mockito.doCallRealMethod().when(filter).initProperties(); 36 | // do 37 | filter.initProperties(); 38 | // then 39 | Assert.assertEquals(weightsSum, TestTools.getObj("weightsSum", LinearWindowFilter.class, filter)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/linearwindowfilter/LinearWindowFilterGetLastPointTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.linearwindowfilter; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.common.TrailPoint; 14 | import com.orange.dgil.trail.core.vecto.SlidingWindow; 15 | 16 | import org.junit.Assert; 17 | import org.junit.Before; 18 | import org.junit.Test; 19 | import org.mockito.Mockito; 20 | 21 | public class LinearWindowFilterGetLastPointTest { 22 | 23 | private LinearWindowFilter filter; 24 | 25 | @Before 26 | public void setUp() { 27 | filter = Mockito.mock(LinearWindowFilter.class); 28 | } 29 | 30 | @Test 31 | public void shouldGetNewPointWhenAvailable() throws IllegalAccessException { 32 | // given 33 | SlidingWindow slidingWindow = Mockito.mock(SlidingWindow.class); 34 | TestTools.setObj("slidingWindow", LinearWindowFilter.class, filter, slidingWindow); 35 | TrailPoint point = new TrailPoint(); 36 | Mockito.when(slidingWindow.getLastElement()).thenReturn(point); 37 | Mockito.doCallRealMethod().when(filter).getLastPoint(); 38 | // do 39 | TrailPoint ret = filter.getLastPoint(); 40 | // then 41 | Assert.assertEquals(point, ret); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/quillpen/QuillParameters.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool.quillpen; 11 | 12 | import com.orange.dgil.trail.android.AndroidMetrics; 13 | import com.orange.dgil.trail.android.DefaultDrawerConf; 14 | 15 | import lombok.AccessLevel; 16 | import lombok.Getter; 17 | 18 | @Getter 19 | public class QuillParameters { 20 | 21 | @Getter(AccessLevel.NONE) 22 | private final AndroidMetrics metrics; 23 | 24 | private int quillWidthPixels; 25 | private int quillHeightPixels; 26 | private int quillAngleDeg; 27 | private int quillAngleXOffset; 28 | private int radius; 29 | 30 | public QuillParameters(AndroidMetrics metrics) { 31 | this.metrics = metrics; 32 | init(); 33 | } 34 | 35 | private void init() { 36 | setQuillWidthHeightMicrometers(DefaultDrawerConf.QUILL_WIDTH_UM, DefaultDrawerConf.QUILL_HEIGHT_UM); 37 | setQuillAngleDeg(DefaultDrawerConf.QUILL_ANGLE_DEG); 38 | } 39 | 40 | public void setQuillWidthHeightMicrometers(int widthMicrometers, int heightMicrometers) { 41 | quillWidthPixels = metrics.micrometersToPixels(widthMicrometers); 42 | quillHeightPixels = metrics.micrometersToPixels(heightMicrometers); 43 | radius = 2 * quillWidthPixels; 44 | setQuillAngleDeg(quillAngleDeg); 45 | } 46 | 47 | public void setQuillAngleDeg(int angleDeg) { 48 | // FIXME - TODO 49 | quillAngleDeg = angleDeg; 50 | quillAngleXOffset = quillHeightPixels; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/DrawingTools.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool; 11 | 12 | import android.view.View; 13 | 14 | import com.orange.dgil.trail.android.AndroidMetrics; 15 | import com.orange.dgil.trail.android.animation.AnimManager; 16 | import com.orange.dgil.trail.android.drawingtool.markerpen.MarkerPaths; 17 | import com.orange.dgil.trail.android.drawingtool.quillpen.QuillPen; 18 | 19 | import lombok.Getter; 20 | 21 | public class DrawingTools { 22 | 23 | @Getter 24 | private IDrawingTool drawingTool; 25 | @Getter 26 | private TrailOptions trailOptions; 27 | 28 | private MarkerPaths markerPaths; 29 | private QuillPen quillPen; 30 | 31 | public DrawingTools(View view, AnimManager animManager) { 32 | initDrawingTools(view, animManager); 33 | } 34 | 35 | private void initDrawingTools(View view, AnimManager animManager) { 36 | AndroidMetrics androidMetrics = AndroidMetrics.get(view.getContext()); 37 | trailOptions = new TrailOptions(androidMetrics, this); 38 | DrawingToolsContext drawingToolsContext = new DrawingToolsContext(view, animManager, androidMetrics, trailOptions); 39 | markerPaths = new MarkerPaths(drawingToolsContext); 40 | quillPen = new QuillPen(drawingToolsContext); 41 | selectQuillPen(); 42 | } 43 | 44 | public void selectMarkerPen() { 45 | drawingTool = markerPaths; 46 | } 47 | 48 | public void selectQuillPen() { 49 | drawingTool = quillPen; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/quillpen/BitmapDrawer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool.quillpen; 11 | 12 | import android.graphics.Canvas; 13 | import android.graphics.Color; 14 | import android.graphics.Paint; 15 | import android.graphics.RectF; 16 | 17 | import com.orange.dgil.trail.android.drawingtool.TrailOptions; 18 | 19 | import lombok.RequiredArgsConstructor; 20 | 21 | @RequiredArgsConstructor 22 | class BitmapDrawer { 23 | 24 | private final Paint paint = new Paint(); 25 | private final RectF rectF = new RectF(); 26 | 27 | private final TrailOptions trailOptions; 28 | 29 | private int wRadius; 30 | private int hRadius; 31 | 32 | void updateDrawParameters() { 33 | paint.setColor(trailOptions.getColor()); 34 | updateRadius(); 35 | } 36 | 37 | private void updateRadius() { 38 | QuillParameters quillParameters = trailOptions.getQuillParameters(); 39 | wRadius = quillParameters.getQuillWidthPixels()/2; 40 | hRadius = quillParameters.getQuillHeightPixels()/2; 41 | } 42 | 43 | void forceColor(int color) { 44 | paint.setColor(color); 45 | } 46 | 47 | void drawPoint(Canvas canvas, int x, int y) { 48 | rectF.set(x - wRadius, y - hRadius, x + wRadius, y + hRadius); 49 | canvas.drawOval(rectF, paint); 50 | } 51 | 52 | void drawCirclePoint(Canvas canvas, int x, int y) { 53 | rectF.set(x - wRadius, y - wRadius, x + wRadius, y + wRadius); 54 | canvas.drawOval(rectF, paint); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowSlidePointsToTheLeftTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.common.TrailPoint; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | public class SlidingWindowSlidePointsToTheLeftTest { 21 | 22 | private SlidingWindow slidingWindow; 23 | 24 | @Before 25 | public void setUp() { 26 | slidingWindow = Mockito.mock(SlidingWindow.class); 27 | } 28 | 29 | @Test 30 | public void shouldSlidePointsToTheLeft() throws IllegalAccessException { 31 | // given 32 | TrailPoint[] points = new TrailPoint[3]; 33 | TrailPoint p0 = new TrailPoint(); 34 | TrailPoint p1 = new TrailPoint(); 35 | TrailPoint p2 = new TrailPoint(); 36 | p0.set(1, 10); 37 | p1.set(2, 20); 38 | p2.set(3, 30); 39 | points[0] = p0; 40 | points[1] = p1; 41 | points[2] = p2; 42 | TestTools.setObj("points", SlidingWindow.class, slidingWindow, points); 43 | Mockito.doCallRealMethod().when(slidingWindow).slidePointsToTheLeft(); 44 | // do 45 | slidingWindow.slidePointsToTheLeft(); 46 | // then 47 | Assert.assertEquals(2, points[0].getX()); 48 | Assert.assertEquals(3, points[1].getX()); 49 | Assert.assertEquals(20, points[0].getY()); 50 | Assert.assertEquals(30, points[1].getY()); 51 | Assert.assertEquals(p0, points[2]); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/android/AndroidMetricsTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android; 11 | 12 | import org.junit.Assert; 13 | import org.junit.Before; 14 | import org.junit.Test; 15 | 16 | /** Tests the methods of {@link AndroidMetrics}. */ 17 | public final class AndroidMetricsTest { 18 | 19 | private static final float YDPI = 254f; 20 | private static final float DENSITY = 1f; 21 | private static final int W = 480; 22 | private static final int H = 800; 23 | 24 | private AndroidMetrics metrics; 25 | 26 | @Before 27 | public void setUp() { 28 | metrics = new AndroidMetrics(YDPI, DENSITY, W, H); 29 | } 30 | 31 | @Test 32 | public void shouldGetDensity() { 33 | Assert.assertEquals(DENSITY, metrics.getDensity(), 0); 34 | } 35 | 36 | @Test 37 | public void shouldGetWidth() { 38 | Assert.assertEquals(W, metrics.getWidthPixels()); 39 | } 40 | 41 | @Test 42 | public void shouldGetHeight() { 43 | Assert.assertEquals(H, metrics.getHeightPixels()); 44 | } 45 | 46 | @Test 47 | public void shouldGetMicrometersPerPixel() { 48 | Assert.assertEquals(100, metrics.getMicrometersPerPixel()); 49 | } 50 | 51 | @Test 52 | public void shouldConvertPixelsToMicrometers() { 53 | Assert.assertEquals(100, metrics.pixelsToMicrometers(1)); 54 | } 55 | 56 | @Test 57 | public void shouldConvertPixelsToMillimeters() { 58 | Assert.assertEquals(1, metrics.pixelsToMillimeters(10)); 59 | } 60 | 61 | @Test 62 | public void shouldConvertMicrometersToPixels() { 63 | Assert.assertEquals(1, metrics.micrometersToPixels(100)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowDoAddTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.common.TrailPoint; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | public class SlidingWindowDoAddTest { 21 | 22 | private SlidingWindow slidingWindow; 23 | 24 | @Before 25 | public void setUp() { 26 | slidingWindow = Mockito.mock(SlidingWindow.class); 27 | } 28 | 29 | @Test 30 | public void shouldDoAdd() throws IllegalAccessException { 31 | // given 32 | TrailPoint point = new TrailPoint(); 33 | point.set(1, 10); 34 | TrailPoint[] points = new TrailPoint[3]; 35 | points[0] = new TrailPoint(); 36 | points[1] = new TrailPoint(); 37 | points[2] = new TrailPoint(); 38 | TestTools.setObj("points", SlidingWindow.class, slidingWindow, points); 39 | int insertedIndex = 2; 40 | Mockito.when(slidingWindow.getInsertIndex()).thenReturn(insertedIndex); 41 | int addedElementsNumber = 100; 42 | TestTools.setObj("addedElementsNumber", SlidingWindow.class, slidingWindow, addedElementsNumber); 43 | Mockito.doCallRealMethod().when(slidingWindow).doAdd(point.getX(), point.getY()); 44 | // do 45 | slidingWindow.doAdd(point.getX(), point.getY()); 46 | // then 47 | Assert.assertEquals(1, points[2].getX()); 48 | Assert.assertEquals(10, points[2].getY()); 49 | Assert.assertEquals(addedElementsNumber+1, TestTools.getObj("addedElementsNumber", SlidingWindow.class, slidingWindow)); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/android/drawingtool/quillpen/TrailBounds.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.android.drawingtool.quillpen; 11 | 12 | import android.view.View; 13 | 14 | import com.orange.dgil.trail.android.drawingtool.InvalidateArea; 15 | import com.orange.dgil.trail.core.common.TrailPoint; 16 | import com.orange.dgil.trail.core.common.TrailRect; 17 | 18 | import lombok.RequiredArgsConstructor; 19 | 20 | @RequiredArgsConstructor 21 | class TrailBounds { 22 | 23 | private final QuillParameters quillParameters; 24 | private final TrailRect trailRect; 25 | private final InvalidateArea trailBounds = new InvalidateArea(); 26 | private final InvalidateArea lastMoveBounds = new InvalidateArea(); 27 | private final TrailPoint lastPoint = new TrailPoint(); 28 | 29 | void updateTrailBoundsOnTouchDown(int x, int y) { 30 | updateRadius(); 31 | lastMoveBounds.setEmpty(); 32 | lastPoint.set(x, y); 33 | } 34 | 35 | void updateRadius() { 36 | trailBounds.setRadius(quillParameters.getRadius()); 37 | lastMoveBounds.setRadius(quillParameters.getRadius()); 38 | } 39 | 40 | void updateTrailBounds(int x, int y) { 41 | lastMoveBounds.setOrigin(lastPoint.getX(), lastPoint.getY()); 42 | lastMoveBounds.add(x, y); 43 | lastPoint.set(x, y); 44 | } 45 | 46 | void invalidateAreaOnMove(View view) { 47 | view.invalidate(lastMoveBounds.getRect()); 48 | } 49 | 50 | void invalidatePath(View view) { 51 | trailBounds.setOrigin(trailRect.getLeft(), trailRect.getTop()); 52 | trailBounds.add(trailRect.getRight(), trailRect.getBottom()); 53 | view.invalidate(trailBounds.getRect()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowGetElementAtTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.common.TrailPoint; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | public class SlidingWindowGetElementAtTest { 21 | 22 | private SlidingWindow slidingWindow; 23 | 24 | @Before 25 | public void setUp() { 26 | slidingWindow = Mockito.mock(SlidingWindow.class); 27 | } 28 | 29 | @Test 30 | public void shouldGetElementAt() throws IllegalAccessException { 31 | // given 32 | TrailPoint[] points = new TrailPoint[3]; 33 | points[0] = new TrailPoint(); 34 | TestTools.setObj("points", SlidingWindow.class, slidingWindow, points); 35 | int index = 0; 36 | Mockito.when(slidingWindow.isIndexValid(index)).thenReturn(true); 37 | Mockito.doCallRealMethod().when(slidingWindow).getElementAt(index); 38 | // do 39 | TrailPoint ret = slidingWindow.getElementAt(index); 40 | // then 41 | Assert.assertEquals(points[0], ret); 42 | } 43 | 44 | @Test 45 | public void shouldGetElementAtWithException() throws IllegalAccessException { 46 | // given 47 | int index = 0; 48 | Mockito.when(slidingWindow.isIndexValid(index)).thenReturn(false); 49 | Mockito.doCallRealMethod().when(slidingWindow).getElementAt(index); 50 | // do 51 | boolean getException = false; 52 | try { 53 | slidingWindow.getElementAt(index); 54 | } catch (SlidingWindowIndexException e) { 55 | getException = true; 56 | } 57 | // then 58 | Assert.assertTrue(getException); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowIsFullTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.TestTools; 13 | import com.orange.dgil.trail.core.common.TrailPoint; 14 | 15 | import org.junit.Assert; 16 | import org.junit.Before; 17 | import org.junit.Test; 18 | import org.mockito.Mockito; 19 | 20 | public class SlidingWindowIsFullTest { 21 | 22 | private SlidingWindow slidingWindow; 23 | 24 | @Before 25 | public void setUp() { 26 | slidingWindow = Mockito.mock(SlidingWindow.class); 27 | } 28 | 29 | @Test 30 | public void shouldReturnTrueWhenIsFull() throws IllegalAccessException { 31 | // given 32 | int addedElementsNumber = 3; 33 | int windowSize = 3; 34 | TrailPoint[] points = new TrailPoint[windowSize]; 35 | TestTools.setObj("addedElementsNumber", SlidingWindow.class, slidingWindow, addedElementsNumber); 36 | TestTools.setObj("points", SlidingWindow.class, slidingWindow, points); 37 | Mockito.doCallRealMethod().when(slidingWindow).isFull(); 38 | // do 39 | boolean ret = slidingWindow.isFull(); 40 | // then 41 | Assert.assertTrue(ret); 42 | } 43 | 44 | @Test 45 | public void shouldReturnTrueWhenIsNotFull() throws IllegalAccessException { 46 | // given 47 | int addedElementsNumber = 2; 48 | int windowSize = 3; 49 | TrailPoint[] points = new TrailPoint[windowSize]; 50 | TestTools.setObj("addedElementsNumber", SlidingWindow.class, slidingWindow, addedElementsNumber); 51 | TestTools.setObj("points", SlidingWindow.class, slidingWindow, points); 52 | Mockito.doCallRealMethod().when(slidingWindow).isFull(); 53 | // do 54 | boolean ret = slidingWindow.isFull(); 55 | // then 56 | Assert.assertFalse(ret); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /demo/JavaFxTest/src/main/resources/com/orange/dgil/trail/app/fxdrawertest/fxml/FxDrawer.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /demo/DroidTest/src/main/java/com/orange/dgil/trail/app/android/drawingtest/DrawingTestActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.app.android.drawingtest; 11 | 12 | import android.app.Activity; 13 | import android.os.Bundle; 14 | import android.view.View; 15 | import android.widget.Switch; 16 | 17 | import com.orange.dgil.trail.app.android.drawing.R; 18 | import com.orange.dgil.trail.app.android.drawingtest.view.DrawingArea; 19 | 20 | public class DrawingTestActivity extends Activity { 21 | 22 | private DrawingArea drawingArea; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.main); 28 | } 29 | 30 | @Override 31 | public void onPause() { 32 | super.onPause(); 33 | drawingArea.trimMemory(); 34 | } 35 | 36 | @Override 37 | public void onResume() { 38 | super.onResume(); 39 | initDrawingArea(); 40 | } 41 | 42 | private void initDrawingArea() { 43 | if (drawingArea == null) { 44 | drawingArea = (DrawingArea) findViewById(R.id.drawing_area); 45 | drawingArea.initTrailDrawer(); 46 | } 47 | } 48 | 49 | /** on click, see layout.xml */ 50 | public void onQuillSelected(View view) { 51 | drawingArea.onQuillSelected(); 52 | } 53 | 54 | /** on click, see layout.xml */ 55 | public void onMarkerSelected(View view) { 56 | drawingArea.onMarkerSelected(); 57 | } 58 | 59 | /** on click, see layout.xml */ 60 | public void onClearSelected(View view) { 61 | drawingArea.onClearSelected(); 62 | } 63 | 64 | /** on click, see layout.xml */ 65 | public void onMultistrokeSwitchToggled(View view) { 66 | Switch toggle = (Switch) view; 67 | drawingArea.onMultistrokeSwitchToggled(toggle.isChecked()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/orange/dgil/trail/core/vecto/SlidingWindowAddTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto; 11 | 12 | import com.orange.dgil.trail.core.common.TrailPoint; 13 | 14 | import org.junit.Before; 15 | import org.junit.Test; 16 | import org.mockito.Mockito; 17 | 18 | public class SlidingWindowAddTest { 19 | 20 | private SlidingWindow slidingWindow; 21 | 22 | @Before 23 | public void setUp() { 24 | slidingWindow = Mockito.mock(SlidingWindow.class); 25 | } 26 | 27 | @Test 28 | public void shouldAddWhenWindowFull() throws IllegalAccessException { 29 | // given 30 | boolean full = true; 31 | TrailPoint point = new TrailPoint(12, 34); 32 | Mockito.when(slidingWindow.isFull()).thenReturn(full); 33 | Mockito.doCallRealMethod().when(slidingWindow).add(point); 34 | Mockito.doCallRealMethod().when(slidingWindow).add(point.getX(), point.getY()); 35 | // do 36 | slidingWindow.add(point); 37 | // then 38 | Mockito.verify(slidingWindow, Mockito.times(1)).slidePointsToTheLeft(); 39 | Mockito.verify(slidingWindow, Mockito.times(1)).doAdd(point.getX(), point.getY()); 40 | } 41 | 42 | @Test 43 | public void shouldAddWhenWindowNotFull() throws IllegalAccessException { 44 | // given 45 | boolean full = false; 46 | TrailPoint point = new TrailPoint(12, 34); 47 | Mockito.when(slidingWindow.isFull()).thenReturn(full); 48 | Mockito.doCallRealMethod().when(slidingWindow).add(point); 49 | Mockito.doCallRealMethod().when(slidingWindow).add(point.getX(), point.getY()); 50 | // do 51 | slidingWindow.add(point); 52 | // then 53 | Mockito.verify(slidingWindow, Mockito.times(0)).slidePointsToTheLeft(); 54 | Mockito.verify(slidingWindow, Mockito.times(1)).add(point.getX(), point.getY()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/orange/dgil/trail/core/vecto/vecto/VectoFilter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Trail drawing library 3 | * Copyright (C) 2014 Orange 4 | * Authors: christophe.maldivi@orange.com, eric.petit@orange.com 5 | * 6 | * This Source Code Form is subject to the terms of the Mozilla Public 7 | * License, v. 2.0. If a copy of the MPL was not distributed with this 8 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9 | */ 10 | package com.orange.dgil.trail.core.vecto.vecto; 11 | 12 | import com.orange.dgil.trail.core.common.TrailPoint; 13 | import com.orange.dgil.trail.core.vecto.linearwindowfilter.LinearWindowFilter; 14 | import com.orange.dgil.trail.core.vecto.linearwindowfilter.LinearWindowFilterListener; 15 | 16 | import lombok.RequiredArgsConstructor; 17 | 18 | @RequiredArgsConstructor 19 | public class VectoFilter implements LinearWindowFilterListener, VectoFilterListener { 20 | 21 | private final LinearWindowFilter linearWindowFilter = new LinearWindowFilter(this); 22 | private final RawVectoFilter rawVectoFilter = new RawVectoFilter(this); 23 | private final VectoFilterListener vectoFilterListener; 24 | private final TrailPoint trailPoint = new TrailPoint(); 25 | 26 | public void reset() { 27 | linearWindowFilter.reset(); 28 | rawVectoFilter.reset(); 29 | } 30 | 31 | public void addPoint(int x, int y) { 32 | trailPoint.set(x, y); 33 | linearWindowFilter.addPoint(trailPoint); 34 | } 35 | 36 | public void epilogue() { 37 | rawVectoFilter.addPoint(linearWindowFilter.getLastPoint()); 38 | rawVectoFilter.epilogue(); 39 | } 40 | 41 | @Override 42 | public void onNewFilteredPointAvailable(int x, int y) { 43 | trailPoint.set(x, y); 44 | rawVectoFilter.addPoint(trailPoint); 45 | } 46 | 47 | @Override 48 | public void onNewVectoPointAvailable(int x, int y) { 49 | vectoFilterListener.onNewVectoPointAvailable(x, y); 50 | } 51 | 52 | @Override 53 | public void onLastVectoPointAvailable(int x, int y) { 54 | vectoFilterListener.onLastVectoPointAvailable(x, y); 55 | } 56 | 57 | public VectoSettings getVectoSettings() { 58 | return rawVectoFilter.getVectoSettings(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /demo/DroidTest/src/main/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 |