From 4dbdbda76184395b107e0d2286e4231467c06fb5 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Thu, 11 Feb 2021 23:20:09 +0100 Subject: [PATCH 01/18] Add kotlin support --- build.gradle | 2 ++ library/build.gradle | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/build.gradle b/build.gradle index 81a3c06..a70cd77 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.4.30' repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:4.1.2' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/library/build.gradle b/library/build.gradle index 7821419..04a36e5 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,4 +1,5 @@ apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' android { compileSdkVersion 30 @@ -22,4 +23,9 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.13.1' implementation 'androidx.appcompat:appcompat:1.2.0' + implementation "androidx.core:core-ktx:1.3.2" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" +} +repositories { + mavenCentral() } From 62a79ea3a3ffab73e908c2129d3cf03a837a8210 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Thu, 11 Feb 2021 23:20:24 +0100 Subject: [PATCH 02/18] Rename .java to .kt --- .../textsurface/sample/{SampleActivity.java => SampleActivity.kt} | 0 .../sample/checks/{AlignSample.java => AlignSample.kt} | 0 .../sample/checks/{ColorSample.java => ColorSample.kt} | 0 .../checks/{CookieThumperSample.java => CookieThumperSample.kt} | 0 .../sample/checks/{Rotation3DSample.java => Rotation3DSample.kt} | 0 .../sample/checks/{ScaleTextSample.java => ScaleTextSample.kt} | 0 .../{ShapeRevealLoopSample.java => ShapeRevealLoopSample.kt} | 0 .../checks/{ShapeRevealSample.java => ShapeRevealSample.kt} | 0 .../sample/checks/{SlideSample.java => SlideSample.kt} | 0 .../checks/{SurfaceScaleSample.java => SurfaceScaleSample.kt} | 0 .../checks/{SurfaceTransSample.java => SurfaceTransSample.kt} | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename app/src/main/java/su/levenetc/android/textsurface/sample/{SampleActivity.java => SampleActivity.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{AlignSample.java => AlignSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{ColorSample.java => ColorSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{CookieThumperSample.java => CookieThumperSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{Rotation3DSample.java => Rotation3DSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{ScaleTextSample.java => ScaleTextSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{ShapeRevealLoopSample.java => ShapeRevealLoopSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{ShapeRevealSample.java => ShapeRevealSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{SlideSample.java => SlideSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{SurfaceScaleSample.java => SurfaceScaleSample.kt} (100%) rename app/src/main/java/su/levenetc/android/textsurface/sample/checks/{SurfaceTransSample.java => SurfaceTransSample.kt} (100%) diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.java b/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.java b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt similarity index 100% rename from app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.java rename to app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt From 0df08a4bd3bf261d3be7efd51e20b55599a77a5b Mon Sep 17 00:00:00 2001 From: elevenetc Date: Thu, 11 Feb 2021 23:20:25 +0100 Subject: [PATCH 03/18] Convert java to kotlin --- app/build.gradle | 4 + .../textsurface/sample/SampleActivity.kt | 82 +++--- .../textsurface/sample/checks/AlignSample.kt | 139 +++++----- .../textsurface/sample/checks/ColorSample.kt | 53 ++-- .../sample/checks/CookieThumperSample.kt | 257 ++++++++---------- .../sample/checks/Rotation3DSample.kt | 65 +++-- .../sample/checks/ScaleTextSample.kt | 77 +++--- .../sample/checks/ShapeRevealLoopSample.kt | 119 ++++---- .../sample/checks/ShapeRevealSample.kt | 114 ++++---- .../textsurface/sample/checks/SlideSample.kt | 78 +++--- .../sample/checks/SurfaceScaleSample.kt | 61 ++--- .../sample/checks/SurfaceTransSample.kt | 57 ++-- .../levenetc/android/textsurface/Debug.java | 47 ---- .../su/levenetc/android/textsurface/Debug.kt | 40 +++ .../android/textsurface/SurfaceCamera.java | 112 -------- .../android/textsurface/SurfaceCamera.kt | 68 +++++ .../su/levenetc/android/textsurface/Text.java | 234 ---------------- .../su/levenetc/android/textsurface/Text.kt | 158 +++++++++++ .../android/textsurface/TextBuilder.java | 126 --------- .../android/textsurface/TextBuilder.kt | 121 +++++++++ .../android/textsurface/TextSurface.java | 100 ------- .../android/textsurface/TextSurface.kt | 90 ++++++ .../animations/AbstractSurfaceAnimation.java | 57 ---- .../animations/AbstractSurfaceAnimation.kt | 28 ++ .../android/textsurface/animations/Alpha.java | 59 ---- .../android/textsurface/animations/Alpha.kt | 53 ++++ .../textsurface/animations/AnimationsSet.java | 130 --------- .../textsurface/animations/AnimationsSet.kt | 97 +++++++ .../textsurface/animations/CamRot.java | 157 ----------- .../android/textsurface/animations/CamRot.kt | 134 +++++++++ .../textsurface/animations/ChangeColor.java | 74 ----- .../textsurface/animations/ChangeColor.kt | 63 +++++ .../textsurface/animations/Circle.java | 143 ---------- .../android/textsurface/animations/Delay.java | 43 --- .../android/textsurface/animations/Delay.kt | 42 +++ .../android/textsurface/animations/Just.java | 32 --- .../android/textsurface/animations/Just.kt | 31 +++ .../android/textsurface/animations/Loop.java | 38 --- .../android/textsurface/animations/Loop.kt | 31 +++ .../textsurface/animations/Parallel.java | 13 - .../textsurface/animations/Parallel.kt | 9 + .../textsurface/animations/Rotate3D.java | 209 -------------- .../textsurface/animations/Rotate3D.kt | 165 +++++++++++ .../android/textsurface/animations/Scale.java | 83 ------ .../android/textsurface/animations/Scale.kt | 49 ++++ .../textsurface/animations/ScaleSurface.java | 104 ------- .../textsurface/animations/ScaleSurface.kt | 89 ++++++ .../textsurface/animations/Sequential.java | 13 - .../textsurface/animations/Sequential.kt | 9 + .../textsurface/animations/ShapeReveal.java | 105 ------- .../textsurface/animations/SideCut.java | 129 --------- .../android/textsurface/animations/Slide.java | 181 ------------ .../android/textsurface/animations/Slide.kt | 148 ++++++++++ .../textsurface/animations/TransSurface.java | 121 --------- .../textsurface/animations/TransSurface.kt | 107 ++++++++ .../textsurface/animations/reveal/Circle.kt | 115 ++++++++ .../animations/reveal/IShapeReveal.kt | 17 ++ .../animations/reveal/ShapeReveal.kt | 72 +++++ .../textsurface/animations/reveal/SideCut.kt | 112 ++++++++ .../android/textsurface/common/Position.java | 154 ----------- .../android/textsurface/common/Position.kt | 135 +++++++++ .../textsurface/common/ScaleValue.java | 41 --- .../android/textsurface/common/ScaleValue.kt | 32 +++ .../android/textsurface/contants/Align.java | 13 - .../android/textsurface/contants/Align.kt | 24 ++ .../android/textsurface/contants/Axis.java | 10 - .../android/textsurface/contants/Axis.kt | 10 + .../textsurface/contants/Direction.java | 11 - .../android/textsurface/contants/Direction.kt | 14 + .../android/textsurface/contants/Fit.java | 9 - .../android/textsurface/contants/Fit.kt | 10 + .../android/textsurface/contants/Pivot.java | 12 - .../android/textsurface/contants/Pivot.kt | 12 + .../android/textsurface/contants/Side.java | 12 - .../android/textsurface/contants/Side.kt | 12 + .../android/textsurface/contants/TYPE.java | 8 - .../android/textsurface/contants/TYPE.kt | 8 + .../interfaces/ICameraAnimation.java | 10 - .../interfaces/ICameraAnimation.kt | 10 + .../textsurface/interfaces/IEndListener.java | 8 - .../textsurface/interfaces/IEndListener.kt | 8 + .../android/textsurface/interfaces/ISet.java | 14 - .../android/textsurface/interfaces/ISet.kt | 12 + .../interfaces/ISurfaceAnimation.java | 23 -- .../interfaces/ISurfaceAnimation.kt | 16 ++ .../textsurface/interfaces/ITextEffect.java | 11 - .../textsurface/interfaces/ITextEffect.kt | 11 + .../interfaces/ITextSurfaceAnimation.java | 16 -- .../interfaces/ITextSurfaceAnimation.kt | 11 + .../utils/AnimatorEndListener.java | 25 -- .../textsurface/utils/AnimatorEndListener.kt | 14 + .../android/textsurface/utils/Utils.java | 48 ---- .../android/textsurface/utils/Utils.kt | 44 +++ 93 files changed, 2741 insertions(+), 3331 deletions(-) delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/Debug.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/Debug.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/Text.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/Text.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/TextBuilder.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/TextSurface.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Circle.java delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Delay.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Just.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Loop.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Scale.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ShapeReveal.java delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/SideCut.java delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Slide.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/common/Position.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/common/Position.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Align.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Axis.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Direction.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Fit.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Side.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/Side.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/Utils.java create mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt diff --git a/app/build.gradle b/app/build.gradle index b6c7105..d9d50ba 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,7 +1,9 @@ apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' repositories { maven { url "https://jitpack.io" } + mavenCentral() } android { @@ -28,4 +30,6 @@ dependencies { testImplementation 'junit:junit:4.13.1' implementation 'androidx.appcompat:appcompat:1.2.0' implementation project(':library') + implementation "androidx.core:core-ktx:+" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" } diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt index cabbf24..2ba1e30 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt @@ -1,52 +1,42 @@ -package su.levenetc.android.textsurface.sample; +package su.levenetc.android.textsurface.sample -import android.os.Bundle; -import androidx.appcompat.app.AppCompatActivity; -import android.view.View; -import android.widget.CheckBox; -import android.widget.CompoundButton; - -import su.levenetc.android.textsurface.Debug; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.sample.checks.CookieThumperSample; +import android.os.Bundle +import android.view.View +import android.widget.CheckBox +import androidx.appcompat.app.AppCompatActivity +import su.levenetc.android.textsurface.Debug +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.sample.checks.* /** * Created by Eugene Levenetc. */ -public class SampleActivity extends AppCompatActivity { - - private TextSurface textSurface; - - @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.sample_activity); - textSurface = (TextSurface) findViewById(R.id.text_surface); - - textSurface.postDelayed(new Runnable() { - @Override public void run() { - show(); - } - }, 1000); - - findViewById(R.id.btn_refresh).setOnClickListener(new View.OnClickListener() { - @Override public void onClick(View v) { - show(); - } - }); - - CheckBox checkDebug = (CheckBox) findViewById(R.id.check_debug); - checkDebug.setChecked(Debug.ENABLED); - checkDebug.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - Debug.ENABLED = isChecked; - textSurface.invalidate(); - } - }); - } - - private void show() { - textSurface.reset(); - CookieThumperSample.play(textSurface, getAssets()); - } - +class SampleActivity : AppCompatActivity() { + private lateinit var textSurface: TextSurface + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.sample_activity) + textSurface = findViewById(R.id.text_surface) as TextSurface + textSurface!!.postDelayed({ show() }, 1000) + findViewById(R.id.btn_refresh).setOnClickListener { show() } + val checkDebug = findViewById(R.id.check_debug) as CheckBox + checkDebug.isChecked = Debug.ENABLED + checkDebug.setOnCheckedChangeListener { _, isChecked -> + Debug.ENABLED = isChecked + textSurface!!.invalidate() + } + } + + private fun show() { + textSurface.reset() + CookieThumperSample.play(textSurface, assets) + //AlignSample.play(textSurface) + //Rotation3DSample.play(textSurface) + //ScaleTextSample.play(textSurface) + //ShapeRevealLoopSample.play(textSurface) + //ShapeRevealSample.play(textSurface) + //SlideSample.play(textSurface) + //SurfaceScaleSample.play(textSurface) + //SurfaceTransSample.play(textSurface) + } } \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt index c74908a..5378986 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt @@ -1,82 +1,67 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.show +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.TYPE /** * Created by Eugene Levenetc. */ -public class AlignSample { - public static void play(TextSurface textSurface) { - - Text textCenter = TextBuilder.create("Center") - .setPosition(Align.SURFACE_CENTER) - .setPadding(25, 25, 25, 25) - .build(); - - // - - Text textLeft = TextBuilder.create("L") - .setPadding(20, 20, 20, 20) - .setPosition(Align.LEFT_OF | Align.CENTER_OF, textCenter) - .build(); - - Text textRight = TextBuilder.create("R") - .setPadding(20, 20, 20, 20) - .setPosition(Align.RIGHT_OF | Align.CENTER_OF, textCenter) - .build(); - - Text textTop = TextBuilder.create("T") - .setPosition(Align.TOP_OF | Align.CENTER_OF, textCenter) - .build(); - - Text textBottom = TextBuilder.create("B") - .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textCenter) - .build(); - - // - - Text textBottomBottom = TextBuilder.create("BB") - .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textBottom) - .build(); - - // - - Text textLeftTop = TextBuilder.create("LT") - .setPosition(Align.LEFT_OF | Align.TOP_OF, textCenter) - .build(); - - Text textRightTop = TextBuilder.create("RT") - .setPosition(Align.RIGHT_OF | Align.TOP_OF, textCenter) - .build(); - - Text textLeftBottom = TextBuilder.create("LB") - .setPosition(Align.LEFT_OF | Align.BOTTOM_OF, textCenter) - .build(); - - Text textRightBottom = TextBuilder.create("RB") - .setPosition(Align.BOTTOM_OF | Align.RIGHT_OF, textCenter) - .build(); - - final int duration = 125; - - textSurface.play(TYPE.SEQUENTIAL, - Alpha.show(textCenter, duration), - Alpha.show(textRight, duration), - Alpha.show(textTop, duration), - Alpha.show(textLeft, duration), - Alpha.show(textBottom, duration), - - Alpha.show(textLeftTop, duration), - Alpha.show(textLeftBottom, duration), - Alpha.show(textRightBottom, duration), - Alpha.show(textRightTop, duration), - - Alpha.show(textBottomBottom, duration) - ); - } -} +object AlignSample { + fun play(textSurface: TextSurface) { + val textCenter = create("Center") + .setPosition(Align.SURFACE_CENTER) + .setPadding(25f, 25f, 25f, 25f) + .build() + + // + val textLeft = create("L") + .setPadding(20f, 20f, 20f, 20f) + .setPosition(Align.LEFT_OF or Align.CENTER_OF, textCenter) + .build() + val textRight = create("R") + .setPadding(20f, 20f, 20f, 20f) + .setPosition(Align.RIGHT_OF or Align.CENTER_OF, textCenter) + .build() + val textTop = create("T") + .setPosition(Align.TOP_OF or Align.CENTER_OF, textCenter) + .build() + val textBottom = create("B") + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textCenter) + .build() + + // + val textBottomBottom = create("BB") + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textBottom) + .build() + + // + val textLeftTop = create("LT") + .setPosition(Align.LEFT_OF or Align.TOP_OF, textCenter) + .build() + val textRightTop = create("RT") + .setPosition(Align.RIGHT_OF or Align.TOP_OF, textCenter) + .build() + val textLeftBottom = create("LB") + .setPosition(Align.LEFT_OF or Align.BOTTOM_OF, textCenter) + .build() + val textRightBottom = create("RB") + .setPosition(Align.BOTTOM_OF or Align.RIGHT_OF, textCenter) + .build() + val duration = 125 + textSurface.play(TYPE.SEQUENTIAL, + show(textCenter, duration.toLong()), + show(textRight, duration.toLong()), + show(textTop, duration.toLong()), + show(textLeft, duration.toLong()), + show(textBottom, duration.toLong()), + show(textLeftTop, duration.toLong()), + show(textLeftBottom, duration.toLong()), + show(textRightBottom, duration.toLong()), + show(textRightTop, duration.toLong()), + show(textBottomBottom, duration.toLong()) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt index 8460d75..0f0bd44 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt @@ -1,33 +1,30 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import android.graphics.Color; - -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; -import su.levenetc.android.textsurface.animations.ChangeColor; +import android.graphics.Color +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.hide +import su.levenetc.android.textsurface.animations.Alpha.Companion.show +import su.levenetc.android.textsurface.animations.ChangeColor.Companion.fromTo +import su.levenetc.android.textsurface.animations.ChangeColor.Companion.to +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.TYPE /** * Created by Eugene Levenetc. */ -public class ColorSample { - public static void play(TextSurface textSurface) { - - Text textA = TextBuilder - .create("Now why you loer en kyk gelyk?") - .setPosition(Align.SURFACE_CENTER) - .setSize(100) - .setAlpha(0) - .build(); - - textSurface.play(TYPE.SEQUENTIAL, - Alpha.show(textA, 1000), - ChangeColor.to(textA, 1000, Color.RED), - ChangeColor.fromTo(textA, 1000, Color.BLUE, Color.CYAN), - Alpha.hide(textA, 1000) - ); - } -} +object ColorSample { + fun play(textSurface: TextSurface) { + val textA = create("Now why you loer en kyk gelyk?") + .setPosition(Align.SURFACE_CENTER) + .setSize(100f) + .setAlpha(0) + .build() + textSurface.play(TYPE.SEQUENTIAL, + show(textA, 1000), + to(textA, 1000, Color.RED), + fromTo(textA, 1000, Color.BLUE, Color.CYAN), + hide(textA, 1000) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt index 9deedfa..b98436f 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt @@ -1,144 +1,121 @@ -package su.levenetc.android.textsurface.sample.checks; - -import android.content.res.AssetManager; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.Typeface; - -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; -import su.levenetc.android.textsurface.animations.ChangeColor; -import su.levenetc.android.textsurface.animations.Circle; -import su.levenetc.android.textsurface.animations.Delay; -import su.levenetc.android.textsurface.animations.Parallel; -import su.levenetc.android.textsurface.animations.Rotate3D; -import su.levenetc.android.textsurface.animations.Sequential; -import su.levenetc.android.textsurface.animations.ShapeReveal; -import su.levenetc.android.textsurface.animations.SideCut; -import su.levenetc.android.textsurface.animations.Slide; -import su.levenetc.android.textsurface.animations.TransSurface; -import su.levenetc.android.textsurface.contants.Direction; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.contants.Side; +package su.levenetc.android.textsurface.sample.checks + +import android.content.res.AssetManager +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Typeface +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.hide +import su.levenetc.android.textsurface.animations.ChangeColor.Companion.to +import su.levenetc.android.textsurface.animations.reveal.Circle.Companion.show +import su.levenetc.android.textsurface.animations.Delay.Companion.duration +import su.levenetc.android.textsurface.animations.Parallel +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide +import su.levenetc.android.textsurface.animations.Sequential +import su.levenetc.android.textsurface.animations.reveal.ShapeReveal.Companion.create +import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.hide +import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.show +import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom +import su.levenetc.android.textsurface.animations.TransSurface +import su.levenetc.android.textsurface.animations.TransSurface.Companion.toCenter +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Direction +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.contants.Side /** * Created by Eugene Levenetc. */ -public class CookieThumperSample { - - public static void play(TextSurface textSurface, AssetManager assetManager) { - - final Typeface robotoBlack = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf"); - Paint paint = new Paint(); - paint.setAntiAlias(true); - paint.setTypeface(robotoBlack); - - Text textDaai = TextBuilder - .create("Daai") - .setPaint(paint) - .setSize(64) - .setAlpha(0) - .setColor(Color.WHITE) - .setPosition(Align.SURFACE_CENTER).build(); - - Text textBraAnies = TextBuilder - .create("bra Anies") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF, textDaai).build(); - - Text textFokkenGamBra = TextBuilder - .create(" hy's n fokken gam bra.") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.RIGHT_OF, textBraAnies).build(); - - Text textHaai = TextBuilder - .create("Haai!!") - .setPaint(paint) - .setSize(74) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF, textFokkenGamBra).build(); - - Text textDaaiAnies = TextBuilder - .create("Daai Anies") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.WHITE) - .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textHaai).build(); - - Text texThyLamInnie = TextBuilder - .create(" hy lam innie mang ja.") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.WHITE) - .setPosition(Align.RIGHT_OF, textDaaiAnies).build(); - - Text textThrowDamn = TextBuilder - .create("Throw damn") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, texThyLamInnie).build(); - - Text textDevilishGang = TextBuilder - .create("devilish gang") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textThrowDamn).build(); - - Text textSignsInTheAir = TextBuilder - .create("signs in the air.") - .setPaint(paint) - .setSize(44) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textDevilishGang).build(); - - textSurface.play( - new Sequential( - ShapeReveal.create(textDaai, 750, SideCut.show(Side.LEFT), false), - new Parallel(ShapeReveal.create(textDaai, 600, SideCut.hide(Side.LEFT), false), new Sequential(Delay.duration(300), ShapeReveal.create(textDaai, 600, SideCut.show(Side.LEFT), false))), - new Parallel(new TransSurface(500, textBraAnies, Pivot.CENTER), ShapeReveal.create(textBraAnies, 1300, SideCut.show(Side.LEFT), false)), - Delay.duration(500), - new Parallel(new TransSurface(750, textFokkenGamBra, Pivot.CENTER), Slide.showFrom(Side.LEFT, textFokkenGamBra, 750), ChangeColor.to(textFokkenGamBra, 750, Color.WHITE)), - Delay.duration(500), - new Parallel(TransSurface.toCenter(textHaai, 500), Rotate3D.showFromSide(textHaai, 750, Pivot.TOP)), - new Parallel(TransSurface.toCenter(textDaaiAnies, 500), Slide.showFrom(Side.TOP, textDaaiAnies, 500)), - new Parallel(TransSurface.toCenter(texThyLamInnie, 750), Slide.showFrom(Side.LEFT, texThyLamInnie, 500)), - Delay.duration(500), - new Parallel( - new TransSurface(1500, textSignsInTheAir, Pivot.CENTER), - new Sequential( - new Sequential(ShapeReveal.create(textThrowDamn, 500, Circle.show(Side.CENTER, Direction.OUT), false)), - new Sequential(ShapeReveal.create(textDevilishGang, 500, Circle.show(Side.CENTER, Direction.OUT), false)), - new Sequential(ShapeReveal.create(textSignsInTheAir, 500, Circle.show(Side.CENTER, Direction.OUT), false)) - ) - ), - Delay.duration(200), - new Parallel( - ShapeReveal.create(textThrowDamn, 1500, SideCut.hide(Side.LEFT), true), - new Sequential(Delay.duration(250), ShapeReveal.create(textDevilishGang, 1500, SideCut.hide(Side.LEFT), true)), - new Sequential(Delay.duration(500), ShapeReveal.create(textSignsInTheAir, 1500, SideCut.hide(Side.LEFT), true)), - Alpha.hide(texThyLamInnie, 1500), - Alpha.hide(textDaaiAnies, 1500) - ) - ) - ); - - } - -} +object CookieThumperSample { + fun play(textSurface: TextSurface?, assetManager: AssetManager?) { + val robotoBlack = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf") + val paint = Paint() + paint.isAntiAlias = true + paint.typeface = robotoBlack + val textDaai = create("Daai") + .setPaint(paint) + .setSize(64f) + .setAlpha(0) + .setColor(Color.WHITE) + .setPosition(Align.SURFACE_CENTER).build() + val textBraAnies = create("bra Anies") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF, textDaai).build() + val textFokkenGamBra = create(" hy's n fokken gam bra.") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.RIGHT_OF, textBraAnies).build() + val textHaai = create("Haai!!") + .setPaint(paint) + .setSize(74f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF, textFokkenGamBra).build() + val textDaaiAnies = create("Daai Anies") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.WHITE) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textHaai).build() + val texThyLamInnie = create(" hy lam innie mang ja.") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.WHITE) + .setPosition(Align.RIGHT_OF, textDaaiAnies).build() + val textThrowDamn = create("Throw damn") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, texThyLamInnie).build() + val textDevilishGang = create("devilish gang") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textThrowDamn).build() + val textSignsInTheAir = create("signs in the air.") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textDevilishGang).build() + textSurface!!.play( + Sequential( + create(textDaai, 750, show(Side.LEFT), false), + Parallel(create(textDaai, 600, hide(Side.LEFT), false), Sequential(duration(300), create(textDaai, 600, show(Side.LEFT), false))), + Parallel(TransSurface(500, textBraAnies, Pivot.CENTER), create(textBraAnies, 1300, show(Side.LEFT), false)), + duration(500), + Parallel(TransSurface(750, textFokkenGamBra, Pivot.CENTER), showFrom(Side.LEFT, textFokkenGamBra, 750), to(textFokkenGamBra, 750, Color.WHITE)), + duration(500), + Parallel(toCenter(textHaai, 500), showFromSide(textHaai, 750, Pivot.TOP)), + Parallel(toCenter(textDaaiAnies, 500), showFrom(Side.TOP, textDaaiAnies, 500)), + Parallel(toCenter(texThyLamInnie, 750), showFrom(Side.LEFT, texThyLamInnie, 500)), + duration(500), + Parallel( + TransSurface(1500, textSignsInTheAir, Pivot.CENTER), + Sequential( + Sequential(create(textThrowDamn, 500, show(Side.CENTER, Direction.OUT), false)), + Sequential(create(textDevilishGang, 500, show(Side.CENTER, Direction.OUT), false)), + Sequential(create(textSignsInTheAir, 500, show(Side.CENTER, Direction.OUT), false)) + ) + ), + duration(200), + Parallel( + create(textThrowDamn, 1500, hide(Side.LEFT), true), + Sequential(duration(250), create(textDevilishGang, 1500, hide(Side.LEFT), true)), + Sequential(duration(500), create(textSignsInTheAir, 1500, hide(Side.LEFT), true)), + hide(texThyLamInnie, 1500), + hide(textDaaiAnies, 1500) + ) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt index e4754b1..f10e4e2 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt @@ -1,39 +1,36 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Rotate3D; -import su.levenetc.android.textsurface.contants.Axis; -import su.levenetc.android.textsurface.contants.Direction; -import su.levenetc.android.textsurface.contants.Pivot; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.hideFromCenter +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.hideFromSide +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromCenter +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide +import su.levenetc.android.textsurface.contants.* /** * Created by Eugene Levenetc. */ -public class Rotation3DSample { - public static void play(TextSurface textSurface) { - Text textA = TextBuilder.create("How are you?").setPosition(Align.SURFACE_CENTER).build(); - Text textB = TextBuilder.create("I'm fine! And you?").setPosition(Align.SURFACE_CENTER, textA).build(); - Text textC = TextBuilder.create("Haaay!").setPosition(Align.SURFACE_CENTER, textB).build(); - int duration = 2750; - - textSurface.play(TYPE.SEQUENTIAL, - new AnimationsSet(TYPE.SEQUENTIAL, - Rotate3D.showFromCenter(textA, duration, Direction.CLOCK, Axis.X), - Rotate3D.hideFromCenter(textA, duration, Direction.CLOCK, Axis.Y) - ), - new AnimationsSet(TYPE.SEQUENTIAL, - Rotate3D.showFromSide(textB, duration, Pivot.LEFT), - Rotate3D.hideFromSide(textB, duration, Pivot.RIGHT) - ), - new AnimationsSet(TYPE.SEQUENTIAL, - Rotate3D.showFromSide(textC, duration, Pivot.TOP), - Rotate3D.hideFromSide(textC, duration, Pivot.BOTTOM) - ) - ); - } -} +object Rotation3DSample { + fun play(textSurface: TextSurface) { + val textA = create("How are you?").setPosition(Align.SURFACE_CENTER).build() + val textB = create("I'm fine! And you?").setPosition(Align.SURFACE_CENTER, textA).build() + val textC = create("Haaay!").setPosition(Align.SURFACE_CENTER, textB).build() + val duration = 2750 + textSurface.play(TYPE.SEQUENTIAL, + AnimationsSet(TYPE.SEQUENTIAL, + showFromCenter(textA, duration.toLong(), Direction.CLOCK, Axis.X), + hideFromCenter(textA, duration.toLong(), Direction.CLOCK, Axis.Y) + ), + AnimationsSet(TYPE.SEQUENTIAL, + showFromSide(textB, duration.toLong(), Pivot.LEFT), + hideFromSide(textB, duration.toLong(), Pivot.RIGHT) + ), + AnimationsSet(TYPE.SEQUENTIAL, + showFromSide(textC, duration.toLong(), Pivot.TOP), + hideFromSide(textC, duration.toLong(), Pivot.BOTTOM) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt index 39ea837..4f051f2 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt @@ -1,20 +1,19 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.animations.Sequential; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Just; -import su.levenetc.android.textsurface.animations.Scale; -import su.levenetc.android.textsurface.contants.Pivot; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Just +import su.levenetc.android.textsurface.animations.Scale +import su.levenetc.android.textsurface.animations.Sequential +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.contants.TYPE /** * Created by Eugene Levenetc. */ -public class ScaleTextSample { - public static void run(TextSurface textSurface) { +object ScaleTextSample { + fun play(textSurface: TextSurface) { // Text textA = TextBuilder.create("oat cake") //// .setScale(2.0f, Pivot.RIGHT) // .build(); @@ -23,34 +22,26 @@ public class ScaleTextSample { // //Just.show(textA) // new Scale(textA, 1000, 0.1f, 1.5f, Pivot.RIGHT) // ); - - Text textA = TextBuilder.create("textA") -// .setPosition(Align.SURFACE_CENTER) - .build(); - - Text textB = TextBuilder.create("textB") - .setPosition(Align.LEFT_OF, textA) - .build(); - - Text textC = TextBuilder.create("textC") - .setPosition(Align.RIGHT_OF, textA) - .build(); - - Text textD = TextBuilder.create("textD") - .setPosition(Align.LEFT_OF, textB) - .build(); - - Text textE = TextBuilder.create("textE") - .setPosition(Align.RIGHT_OF, textC) - .build(); - - textSurface.play(TYPE.PARALLEL, - Just.show(textA, textB), - new Sequential(new Scale(textA, 1000, 1, 2, Pivot.CENTER), new Scale(textA, 1000, 2, 1, Pivot.CENTER)) -// new Parallel(new Scale(textA, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textA, 500, 1, 1.5f, Pivot.LEFT)), -// new Sequential(Delay.duration(250), new Parallel(new Scale(textB, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textB, 500, 1, 1.5f, Pivot.LEFT))), -// new Sequential(Delay.duration(500), new Parallel(new Scale(textC, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textC, 500, 1, 1.5f, Pivot.LEFT))), -// new Sequential(Delay.duration(750), new Parallel(new Scale(textD, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textD, 500, 1, 1.5f, Pivot.LEFT))) - ); - } -} + val textA = create("textA") // .setPosition(Align.SURFACE_CENTER) + .build() + val textB = create("textB") + .setPosition(Align.LEFT_OF, textA) + .build() + val textC = create("textC") + .setPosition(Align.RIGHT_OF, textA) + .build() + val textD = create("textD") + .setPosition(Align.LEFT_OF, textB) + .build() + val textE = create("textE") + .setPosition(Align.RIGHT_OF, textC) + .build() + textSurface.play(TYPE.PARALLEL, + Just.show(textA, textB), + Sequential(Scale(textA, 1000, 1f, 2f, Pivot.CENTER), Scale(textA, 1000, 2f, 1f, Pivot.CENTER)) // new Parallel(new Scale(textA, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textA, 500, 1, 1.5f, Pivot.LEFT)), + // new Sequential(Delay.duration(250), new Parallel(new Scale(textB, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textB, 500, 1, 1.5f, Pivot.LEFT))), + // new Sequential(Delay.duration(500), new Parallel(new Scale(textC, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textC, 500, 1, 1.5f, Pivot.LEFT))), + // new Sequential(Delay.duration(750), new Parallel(new Scale(textD, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textD, 500, 1, 1.5f, Pivot.LEFT))) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt index 2551659..e006038 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt @@ -1,68 +1,61 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.animations.Circle; -import su.levenetc.android.textsurface.animations.Delay; -import su.levenetc.android.textsurface.animations.Loop; -import su.levenetc.android.textsurface.animations.Rotate3D; -import su.levenetc.android.textsurface.animations.ShapeReveal; -import su.levenetc.android.textsurface.animations.SideCut; -import su.levenetc.android.textsurface.animations.Slide; -import su.levenetc.android.textsurface.animations.TransSurface; -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.contants.Axis; -import su.levenetc.android.textsurface.contants.Direction; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.contants.Side; -import su.levenetc.android.textsurface.contants.TYPE; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.hide +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.animations.reveal.Circle.Companion.show +import su.levenetc.android.textsurface.animations.Delay.Companion.duration +import su.levenetc.android.textsurface.animations.Loop +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromCenter +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide +import su.levenetc.android.textsurface.animations.reveal.ShapeReveal.Companion.create +import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.hide +import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.show +import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom +import su.levenetc.android.textsurface.animations.TransSurface +import su.levenetc.android.textsurface.contants.* /** * Created by Eugene Levenetc. */ -public class ShapeRevealLoopSample { - public static void play(TextSurface textSurface) { - - Text textA = TextBuilder.create("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build(); - Text textB = TextBuilder.create("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textA).build(); - Text textC = TextBuilder.create("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textB).build(); - Text textD = TextBuilder.create("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textC).build(); - - final int flash = 1500; - - textSurface.play( - new Loop( - Rotate3D.showFromCenter(textA, 500, Direction.CLOCK, Axis.X), - new AnimationsSet(TYPE.PARALLEL, - ShapeReveal.create(textA, flash, SideCut.hide(Side.LEFT), false), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(flash / 4), ShapeReveal.create(textA, flash, SideCut.show(Side.LEFT), false)) - ), - new AnimationsSet(TYPE.PARALLEL, - Rotate3D.showFromSide(textB, 500, Pivot.TOP), - new TransSurface(500, textB, Pivot.CENTER) - ), - Delay.duration(500), - new AnimationsSet(TYPE.PARALLEL, - Slide.showFrom(Side.TOP, textC, 500), - new TransSurface(1000, textC, Pivot.CENTER) - ), - Delay.duration(500), - new AnimationsSet(TYPE.PARALLEL, - ShapeReveal.create(textD, 500, Circle.show(Side.CENTER, Direction.OUT), false), - new TransSurface(1500, textD, Pivot.CENTER) - ), - Delay.duration(500), - new AnimationsSet(TYPE.PARALLEL, - new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textD, 700), ShapeReveal.create(textD, 1000, SideCut.hide(Side.LEFT), true)), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(500), new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textC, 700), ShapeReveal.create(textC, 1000, SideCut.hide(Side.LEFT), true))), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(1000), new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textB, 700), ShapeReveal.create(textB, 1000, SideCut.hide(Side.LEFT), true))), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(1500), new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textA, 700), ShapeReveal.create(textA, 1000, SideCut.hide(Side.LEFT), true))), - new TransSurface(4000, textA, Pivot.CENTER) - ) - ) - ); - } -} +object ShapeRevealLoopSample { + fun play(textSurface: TextSurface) { + val textA = create("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build() + val textB = create("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() + val textC = create("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + val textD = create("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() + val flash = 1500 + textSurface.play( + Loop( + showFromCenter(textA, 500, Direction.CLOCK, Axis.X), + AnimationsSet(TYPE.PARALLEL, + create(textA, flash.toLong(), hide(Side.LEFT), false), + AnimationsSet(TYPE.SEQUENTIAL, duration((flash / 4).toLong()), create(textA, flash.toLong(), show(Side.LEFT), false)) + ), + AnimationsSet(TYPE.PARALLEL, + showFromSide(textB, 500, Pivot.TOP), + TransSurface(500, textB, Pivot.CENTER) + ), + duration(500), + AnimationsSet(TYPE.PARALLEL, + showFrom(Side.TOP, textC, 500), + TransSurface(1000, textC, Pivot.CENTER) + ), + duration(500), + AnimationsSet(TYPE.PARALLEL, + create(textD, 500, show(Side.CENTER, Direction.OUT), false), + TransSurface(1500, textD, Pivot.CENTER) + ), + duration(500), + AnimationsSet(TYPE.PARALLEL, + AnimationsSet(TYPE.PARALLEL, hide(textD, 700), create(textD, 1000, hide(Side.LEFT), true)), + AnimationsSet(TYPE.SEQUENTIAL, duration(500), AnimationsSet(TYPE.PARALLEL, hide(textC, 700), create(textC, 1000, hide(Side.LEFT), true))), + AnimationsSet(TYPE.SEQUENTIAL, duration(1000), AnimationsSet(TYPE.PARALLEL, hide(textB, 700), create(textB, 1000, hide(Side.LEFT), true))), + AnimationsSet(TYPE.SEQUENTIAL, duration(1500), AnimationsSet(TYPE.PARALLEL, hide(textA, 700), create(textA, 1000, hide(Side.LEFT), true))), + TransSurface(4000, textA, Pivot.CENTER) + ) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt index 88c1adc..8adfd18 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt @@ -1,66 +1,58 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; -import su.levenetc.android.textsurface.animations.Circle; -import su.levenetc.android.textsurface.animations.Delay; -import su.levenetc.android.textsurface.animations.Rotate3D; -import su.levenetc.android.textsurface.animations.ShapeReveal; -import su.levenetc.android.textsurface.animations.SideCut; -import su.levenetc.android.textsurface.animations.Slide; -import su.levenetc.android.textsurface.animations.TransSurface; -import su.levenetc.android.textsurface.contants.Axis; -import su.levenetc.android.textsurface.contants.Direction; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.contants.Side; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.hide +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.animations.reveal.Circle.Companion.show +import su.levenetc.android.textsurface.animations.Delay.Companion.duration +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromCenter +import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide +import su.levenetc.android.textsurface.animations.reveal.ShapeReveal.Companion.create +import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.hide +import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.show +import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom +import su.levenetc.android.textsurface.animations.TransSurface +import su.levenetc.android.textsurface.contants.* /** * Created by Eugene Levenetc. */ -public class ShapeRevealSample { - public static void play(TextSurface textSurface) { - - Text textA = TextBuilder.create("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build(); - Text textB = TextBuilder.create("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textA).build(); - Text textC = TextBuilder.create("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textB).build(); - Text textD = TextBuilder.create("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textC).build(); - - final int flash = 1500; - - textSurface.play(TYPE.SEQUENTIAL, - Rotate3D.showFromCenter(textA, 500, Direction.CLOCK, Axis.X), - new AnimationsSet(TYPE.PARALLEL, - ShapeReveal.create(textA, flash, SideCut.hide(Side.LEFT), false), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(flash / 4), ShapeReveal.create(textA, flash, SideCut.show(Side.LEFT), false)) - ), - new AnimationsSet(TYPE.PARALLEL, - Rotate3D.showFromSide(textB, 500, Pivot.TOP), - new TransSurface(500, textB, Pivot.CENTER) - ), - Delay.duration(500), - new AnimationsSet(TYPE.PARALLEL, - Slide.showFrom(Side.TOP, textC, 500), - new TransSurface(1000, textC, Pivot.CENTER) - ), - Delay.duration(500), - new AnimationsSet(TYPE.PARALLEL, - ShapeReveal.create(textD, 500, Circle.show(Side.CENTER, Direction.OUT), false), - new TransSurface(1500, textD, Pivot.CENTER) - ), - Delay.duration(500), - new AnimationsSet(TYPE.PARALLEL, - new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textD, 700), ShapeReveal.create(textD, 1000, SideCut.hide(Side.LEFT), true)), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(500), new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textC, 700), ShapeReveal.create(textC, 1000, SideCut.hide(Side.LEFT), true))), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(1000), new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textB, 700), ShapeReveal.create(textB, 1000, SideCut.hide(Side.LEFT), true))), - new AnimationsSet(TYPE.SEQUENTIAL, Delay.duration(1500), new AnimationsSet(TYPE.PARALLEL, Alpha.hide(textA, 700), ShapeReveal.create(textA, 1000, SideCut.hide(Side.LEFT), true))), - new TransSurface(4000, textA, Pivot.CENTER) - ) - - ); - } -} +object ShapeRevealSample { + fun play(textSurface: TextSurface) { + val textA = create("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build() + val textB = create("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() + val textC = create("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + val textD = create("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() + val flash = 1500 + textSurface.play(TYPE.SEQUENTIAL, + showFromCenter(textA, 500, Direction.CLOCK, Axis.X), + AnimationsSet(TYPE.PARALLEL, + create(textA, flash.toLong(), hide(Side.LEFT), false), + AnimationsSet(TYPE.SEQUENTIAL, duration((flash / 4).toLong()), create(textA, flash.toLong(), show(Side.LEFT), false)) + ), + AnimationsSet(TYPE.PARALLEL, + showFromSide(textB, 500, Pivot.TOP), + TransSurface(500, textB, Pivot.CENTER) + ), + duration(500), + AnimationsSet(TYPE.PARALLEL, + showFrom(Side.TOP, textC, 500), + TransSurface(1000, textC, Pivot.CENTER) + ), + duration(500), + AnimationsSet(TYPE.PARALLEL, + create(textD, 500, show(Side.CENTER, Direction.OUT), false), + TransSurface(1500, textD, Pivot.CENTER) + ), + duration(500), + AnimationsSet(TYPE.PARALLEL, + AnimationsSet(TYPE.PARALLEL, hide(textD, 700), create(textD, 1000, hide(Side.LEFT), true)), + AnimationsSet(TYPE.SEQUENTIAL, duration(500), AnimationsSet(TYPE.PARALLEL, hide(textC, 700), create(textC, 1000, hide(Side.LEFT), true))), + AnimationsSet(TYPE.SEQUENTIAL, duration(1000), AnimationsSet(TYPE.PARALLEL, hide(textB, 700), create(textB, 1000, hide(Side.LEFT), true))), + AnimationsSet(TYPE.SEQUENTIAL, duration(1500), AnimationsSet(TYPE.PARALLEL, hide(textA, 700), create(textA, 1000, hide(Side.LEFT), true))), + TransSurface(4000, textA, Pivot.CENTER) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt index 03610db..7783328 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt @@ -1,47 +1,41 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Slide; -import su.levenetc.android.textsurface.animations.TransSurface; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.contants.Side; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.animations.Slide.Companion.hideFrom +import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom +import su.levenetc.android.textsurface.animations.TransSurface +import su.levenetc.android.textsurface.contants.* /** * Created by Eugene Levenetc. */ -public class SlideSample { - public static void play(TextSurface textSurface) { - - Text textA = TextBuilder.create(" How are you?").build(); - Text textB = TextBuilder.create("I'm fine! ").setPosition(Align.LEFT_OF, textA).build(); - Text textC = TextBuilder.create("Are you sure?").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textB).build(); - Text textD = TextBuilder.create("Totally!").setPadding(10, 10, 10, 10).setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textC).build(); - int duration = 1250; - - textSurface.play( - TYPE.SEQUENTIAL, - new AnimationsSet(TYPE.PARALLEL, - new AnimationsSet(TYPE.SEQUENTIAL, - new AnimationsSet(TYPE.PARALLEL, Slide.showFrom(Side.LEFT, textA, duration), Slide.showFrom(Side.RIGHT, textB, duration)), - Slide.showFrom(Side.TOP, textC, duration), - Slide.showFrom(Side.BOTTOM, textD, duration) - ), - new TransSurface(duration * 3, textD, Pivot.CENTER) - ), - new AnimationsSet(TYPE.PARALLEL, - new AnimationsSet(TYPE.SEQUENTIAL, - new AnimationsSet(TYPE.PARALLEL, Slide.hideFrom(Side.LEFT, textD, duration), Slide.hideFrom(Side.RIGHT, textC, duration)), - Slide.hideFrom(Side.TOP, textB, duration), - Slide.hideFrom(Side.BOTTOM, textA, duration) - ), - new TransSurface(duration * 3, textA, Pivot.CENTER) - ) - - ); - } -} +object SlideSample { + fun play(textSurface: TextSurface) { + val textA = create(" How are you?").build() + val textB = create("I'm fine! ").setPosition(Align.LEFT_OF, textA).build() + val textC = create("Are you sure?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + val textD = create("Totally!").setPadding(10f, 10f, 10f, 10f).setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() + val duration = 1250L + textSurface.play( + TYPE.SEQUENTIAL, + AnimationsSet(TYPE.PARALLEL, + AnimationsSet(TYPE.SEQUENTIAL, + AnimationsSet(TYPE.PARALLEL, showFrom(Side.LEFT, textA, duration.toLong()), showFrom(Side.RIGHT, textB, duration.toLong())), + showFrom(Side.TOP, textC, duration.toLong()), + showFrom(Side.BOTTOM, textD, duration.toLong()) + ), + TransSurface(duration * 3, textD, Pivot.CENTER) + ), + AnimationsSet(TYPE.PARALLEL, + AnimationsSet(TYPE.SEQUENTIAL, + AnimationsSet(TYPE.PARALLEL, hideFrom(Side.LEFT, textD, duration.toLong()), hideFrom(Side.RIGHT, textC, duration.toLong())), + hideFrom(Side.TOP, textB, duration.toLong()), + hideFrom(Side.BOTTOM, textA, duration.toLong()) + ), + TransSurface(duration * 3, textA, Pivot.CENTER) + ) + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt index 2eb127b..6eeba8f 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt @@ -1,38 +1,35 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; -import su.levenetc.android.textsurface.animations.Delay; -import su.levenetc.android.textsurface.animations.ScaleSurface; -import su.levenetc.android.textsurface.contants.Fit; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.hide +import su.levenetc.android.textsurface.animations.Alpha.Companion.show +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.animations.Delay.Companion.duration +import su.levenetc.android.textsurface.animations.ScaleSurface +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Fit +import su.levenetc.android.textsurface.contants.TYPE /** * Created by Eugene Levenetc. */ -public class SurfaceScaleSample { - public static void play(TextSurface textSurface) { - - Text textA = TextBuilder.create("How are you?").setPosition(Align.SURFACE_CENTER).build(); - Text textB = TextBuilder.create("Would you mind?").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textA).build(); - Text textC = TextBuilder.create("Yes!").setPosition(Align.BOTTOM_OF | Align.CENTER_OF, textB).build(); - - - textSurface.play(TYPE.SEQUENTIAL, - Alpha.show(textA, 500), - new AnimationsSet(TYPE.PARALLEL, - new AnimationsSet(TYPE.PARALLEL, Alpha.show(textB, 500), Alpha.hide(textA, 500)), - new ScaleSurface(500, textB, Fit.WIDTH) - ), - Delay.duration(1000), - new AnimationsSet(TYPE.PARALLEL, - new AnimationsSet(TYPE.PARALLEL, Alpha.show(textC, 500), Alpha.hide(textB, 500)), - new ScaleSurface(500, textC, Fit.WIDTH) - ) - ); - } +object SurfaceScaleSample { + fun play(textSurface: TextSurface) { + val textA = create("How are you?").setPosition(Align.SURFACE_CENTER).build() + val textB = create("Would you mind?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() + val textC = create("Yes!").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + textSurface.play(TYPE.SEQUENTIAL, + show(textA, 500), + AnimationsSet(TYPE.PARALLEL, + AnimationsSet(TYPE.PARALLEL, show(textB, 500), hide(textA, 500)), + ScaleSurface(500, textB, Fit.WIDTH) + ), + duration(1000), + AnimationsSet(TYPE.PARALLEL, + AnimationsSet(TYPE.PARALLEL, show(textC, 500), hide(textB, 500)), + ScaleSurface(500, textC, Fit.WIDTH) + ) + ) + } } \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt index d43cfc1..c885f4d 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt @@ -1,35 +1,32 @@ -package su.levenetc.android.textsurface.sample.checks; +package su.levenetc.android.textsurface.sample.checks -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextBuilder; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.animations.Alpha; -import su.levenetc.android.textsurface.animations.TransSurface; +import su.levenetc.android.textsurface.TextBuilder.Companion.create +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.Alpha.Companion.show +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.animations.TransSurface +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.contants.TYPE /** * Created by Eugene Levenetc. */ -public class SurfaceTransSample { - public static void play(TextSurface textSurface) { - Text textA = TextBuilder.create("TextA").setPosition(Align.SURFACE_CENTER).build(); - Text textB = TextBuilder.create("TextB").setPosition(Align.RIGHT_OF | Align.BOTTOM_OF, textA).build(); - Text textC = TextBuilder.create("TextC").setPosition(Align.LEFT_OF | Align.BOTTOM_OF, textB).build(); - Text textD = TextBuilder.create("TextD").setPosition(Align.RIGHT_OF | Align.BOTTOM_OF, textC).build(); - - int duration = 500; - - textSurface.play(TYPE.SEQUENTIAL, - Alpha.show(textA, duration), - new AnimationsSet(TYPE.PARALLEL, Alpha.show(textB, duration), new TransSurface(duration, textB, Pivot.CENTER)), - new AnimationsSet(TYPE.PARALLEL, Alpha.show(textC, duration), new TransSurface(duration, textC, Pivot.CENTER)), - new AnimationsSet(TYPE.PARALLEL, Alpha.show(textD, duration), new TransSurface(duration, textD, Pivot.CENTER)), - new TransSurface(duration, textC, Pivot.CENTER), - new TransSurface(duration, textB, Pivot.CENTER), - new TransSurface(duration, textA, Pivot.CENTER) - ); - } -} +object SurfaceTransSample { + fun play(textSurface: TextSurface) { + val textA = create("TextA").setPosition(Align.SURFACE_CENTER).build() + val textB = create("TextB").setPosition(Align.RIGHT_OF or Align.BOTTOM_OF, textA).build() + val textC = create("TextC").setPosition(Align.LEFT_OF or Align.BOTTOM_OF, textB).build() + val textD = create("TextD").setPosition(Align.RIGHT_OF or Align.BOTTOM_OF, textC).build() + val duration = 500L + textSurface.play(TYPE.SEQUENTIAL, + show(textA, duration), + AnimationsSet(TYPE.PARALLEL, show(textB, duration), TransSurface(duration, textB, Pivot.CENTER)), + AnimationsSet(TYPE.PARALLEL, show(textC, duration), TransSurface(duration, textC, Pivot.CENTER)), + AnimationsSet(TYPE.PARALLEL, show(textD, duration), TransSurface(duration, textD, Pivot.CENTER)), + TransSurface(duration, textC, Pivot.CENTER), + TransSurface(duration, textB, Pivot.CENTER), + TransSurface(duration, textA, Pivot.CENTER) + ) + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/Debug.java b/library/src/main/java/su/levenetc/android/textsurface/Debug.java deleted file mode 100644 index ce3f543..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/Debug.java +++ /dev/null @@ -1,47 +0,0 @@ -package su.levenetc.android.textsurface; - -import android.graphics.Color; -import android.graphics.Paint; - -/** - * Created by Eugene Levenetc. - */ -public class Debug { - - public static boolean ENABLED = false; - - public static Paint RED_FILL; - public static Paint RED_STROKE; - public static Paint BLUE_STROKE; - public static Paint YELLOW_STROKE; - public static Paint GREEN_STROKE; - - static { - RED_FILL = new Paint(); - BLUE_STROKE = new Paint(); - YELLOW_STROKE = new Paint(); - GREEN_STROKE = new Paint(); - RED_STROKE = new Paint(); - - RED_FILL.setColor(Color.RED); - RED_FILL.setStyle(Paint.Style.FILL); - RED_FILL.setAntiAlias(true); - - BLUE_STROKE.setColor(Color.BLUE); - BLUE_STROKE.setStyle(Paint.Style.STROKE); - BLUE_STROKE.setAntiAlias(true); - BLUE_STROKE.setStrokeWidth(1); - - YELLOW_STROKE.setColor(Color.YELLOW); - YELLOW_STROKE.setStyle(Paint.Style.STROKE); - YELLOW_STROKE.setAntiAlias(true); - - GREEN_STROKE.setColor(Color.GREEN); - GREEN_STROKE.setStyle(Paint.Style.STROKE); - GREEN_STROKE.setAntiAlias(true); - - RED_STROKE.setColor(Color.RED); - RED_STROKE.setStyle(Paint.Style.STROKE); - RED_STROKE.setAntiAlias(true); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/Debug.kt b/library/src/main/java/su/levenetc/android/textsurface/Debug.kt new file mode 100644 index 0000000..8fff5c7 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/Debug.kt @@ -0,0 +1,40 @@ +package su.levenetc.android.textsurface + +import android.graphics.Color +import android.graphics.Paint + +/** + * Created by Eugene Levenetc. + */ +object Debug { + @JvmField + var ENABLED = false + + @JvmField + var RED_FILL: Paint = Paint() + var RED_STROKE: Paint = Paint() + + @JvmField + var BLUE_STROKE: Paint = Paint() + var YELLOW_STROKE: Paint = Paint() + var GREEN_STROKE: Paint = Paint() + + init { + RED_FILL.color = Color.RED + RED_FILL.style = Paint.Style.FILL + RED_FILL.isAntiAlias = true + BLUE_STROKE.color = Color.BLUE + BLUE_STROKE.style = Paint.Style.STROKE + BLUE_STROKE.isAntiAlias = true + BLUE_STROKE.strokeWidth = 1f + YELLOW_STROKE.color = Color.YELLOW + YELLOW_STROKE.style = Paint.Style.STROKE + YELLOW_STROKE.isAntiAlias = true + GREEN_STROKE.color = Color.GREEN + GREEN_STROKE.style = Paint.Style.STROKE + GREEN_STROKE.isAntiAlias = true + RED_STROKE.color = Color.RED + RED_STROKE.style = Paint.Style.STROKE + RED_STROKE.isAntiAlias = true + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.java b/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.java deleted file mode 100644 index eb3039f..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.java +++ /dev/null @@ -1,112 +0,0 @@ -package su.levenetc.android.textsurface; - -import android.graphics.Canvas; -import android.graphics.PointF; - -import su.levenetc.android.textsurface.common.ScaleValue; - -/** - * Created by Eugene Levenetc. - */ -public class SurfaceCamera { - - private float transX; - private float transY; - private float rotation; - private PointF rotationPivot = new PointF(); - private ScaleValue scale = new ScaleValue(); - private PointF center = new PointF(); - - public void onDraw(Canvas canvas) { - - if (Debug.ENABLED) { - canvas.save(); - canvas.drawCircle(transX, transY, 10, Debug.YELLOW_STROKE); - canvas.drawCircle(scale.getPivot().x, scale.getPivot().y, 10, Debug.GREEN_STROKE); - canvas.drawLine(scale.getPivot().x, 0, scale.getPivot().x, canvas.getHeight(), Debug.GREEN_STROKE); - canvas.drawLine(0, scale.getPivot().y, canvas.getWidth(), scale.getPivot().y, Debug.GREEN_STROKE); - - canvas.drawLine(canvas.getWidth() / 2, 0, canvas.getWidth() / 2, canvas.getHeight(), Debug.GREEN_STROKE); - canvas.drawLine(0, canvas.getHeight() / 2, canvas.getWidth(), canvas.getHeight() / 2, Debug.GREEN_STROKE); - - canvas.restore(); - } - - center.set(canvas.getWidth() / 2, canvas.getHeight() / 2); - - canvas.translate(center.x + transX, center.y + transY); - canvas.scale(scale.getScaleX(), scale.getScaleX(), scale.getPivot().x, scale.getPivot().y); - } - - public void reset() { - rotationPivot.set(0, 0); - scale.reset(); - center.set(0, 0); - transX = 0; - transY = 0; - } - - public float getCenterX() { - return center.x; - } - - public float getCenterY() { - return center.y; - } - - public void setTransX(float transX) { - this.transX = transX; - } - - public void setTransY(float transY) { - this.transY = transY; - } - - public void setRotation(float rotation) { - this.rotation = rotation; - } - - public PointF getRotationPivot() { - return rotationPivot; - } - - public float getRotation() { - return rotation; - } - - public float getTransY() { - return transY; - } - - public float getTransX() { - return transX; - } - - public float getScale() { - return scale.getScaleX(); - } - - public void setScale(float scale) { - this.scale.setValue(scale); - } - - public void setScalePivot(float x, float y) { - scale.getPivot().set(x, y); - } - - public float getScalePivotX() { - return scale.getPivot().x; - } - - public float getScalePivotY() { - return scale.getPivot().y; - } - - public void setScalePivotX(float value) { - scale.getPivot().x = value; - } - - public void setScalePivotY(float value) { - scale.getPivot().y = value; - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt b/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt new file mode 100644 index 0000000..557ea49 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt @@ -0,0 +1,68 @@ +package su.levenetc.android.textsurface + +import android.graphics.Canvas +import android.graphics.PointF +import su.levenetc.android.textsurface.common.ScaleValue + +/** + * Created by Eugene Levenetc. + */ +class SurfaceCamera { + var transX = 0f + var transY = 0f + var rotation = 0f + val rotationPivot = PointF() + private val scale = ScaleValue() + private val center = PointF() + fun onDraw(canvas: Canvas) { + if (Debug.ENABLED) { + canvas.save() + canvas.drawCircle(transX, transY, 10f, Debug.YELLOW_STROKE) + canvas.drawCircle(scale.pivot.x, scale.pivot.y, 10f, Debug.GREEN_STROKE) + canvas.drawLine(scale.pivot.x, 0f, scale.pivot.x, canvas.height.toFloat(), Debug.GREEN_STROKE) + canvas.drawLine(0f, scale.pivot.y, canvas.width.toFloat(), scale.pivot.y, Debug.GREEN_STROKE) + canvas.drawLine((canvas.width / 2).toFloat(), 0f, (canvas.width / 2).toFloat(), canvas.height.toFloat(), Debug.GREEN_STROKE) + canvas.drawLine(0f, (canvas.height / 2).toFloat(), canvas.width.toFloat(), (canvas.height / 2).toFloat(), Debug.GREEN_STROKE) + canvas.restore() + } + center[(canvas.width / 2).toFloat()] = (canvas.height / 2).toFloat() + canvas.translate(center.x + transX, center.y + transY) + canvas.scale(scale.scaleX, scale.scaleX, scale.pivot.x, scale.pivot.y) + } + + fun reset() { + rotationPivot[0f] = 0f + scale.reset() + center[0f] = 0f + transX = 0f + transY = 0f + } + + val centerX: Float + get() = center.x + val centerY: Float + get() = center.y + + fun getScale(): Float { + return scale.scaleX + } + + fun setScale(scale: Float) { + this.scale.setValue(scale) + } + + fun setScalePivot(x: Float, y: Float) { + scale.pivot[x] = y + } + + var scalePivotX: Float + get() = scale.pivot.x + set(value) { + scale.pivot.x = value + } + var scalePivotY: Float + get() = scale.pivot.y + set(value) { + scale.pivot.y = value + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/Text.java b/library/src/main/java/su/levenetc/android/textsurface/Text.java deleted file mode 100644 index b1dbc60..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/Text.java +++ /dev/null @@ -1,234 +0,0 @@ -package su.levenetc.android.textsurface; - -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.Rect; -import android.graphics.RectF; -import androidx.annotation.NonNull; - -import java.util.ArrayList; - -import su.levenetc.android.textsurface.common.Position; -import su.levenetc.android.textsurface.common.ScaleValue; -import su.levenetc.android.textsurface.interfaces.ITextEffect; -import su.levenetc.android.textsurface.utils.Utils; - -/** - * Created by Eugene Levenetc. - */ -public class Text implements Comparable { - - private Paint paint; - private final String text; - private RectF defaultSize; - private RectF currentSize = new RectF(); - private Position position; - private RectF padding; - private int index; - private ScaleValue scale = new ScaleValue(); - private Matrix matrix = new Matrix(); - private ArrayList effects = new ArrayList<>(); - private float dx; - private float fontDescent; - - public Text(String text, Position position, RectF padding, Paint paint) { - this.text = text; - this.position = position; - this.padding = padding; - this.paint = paint; - - initBounds(text); - } - - public void addEffect(ITextEffect effect) { - effects.add(effect); - } - - public float getFontDescent() { - return fontDescent; - } - - private void initBounds(String text) { - String trimmed = text.trim(); - if (trimmed.length() < text.length()) { - - int length = text.length(); - int start = text.lastIndexOf(trimmed); - int end = length - (start + trimmed.length()); - - text = Utils.genString(start) + text + Utils.genString(end); - } - - Rect tmp = new Rect(); - paint.getTextBounds(text, 0, text.length(), tmp); - - fontDescent = paint.getFontMetrics().descent; - defaultSize = new RectF(tmp); - //a little workaround because getTextBounds returns smaller width than it is - dx = paint.measureText(text) - tmp.width(); - defaultSize.left = 0; - defaultSize.right = tmp.width() + dx; - defaultSize.top = -paint.getFontSpacing(); - defaultSize.bottom = 0; - - defaultSize.set( - defaultSize.left, - defaultSize.top, - defaultSize.right, - defaultSize.bottom - ); - - currentSize.set( - defaultSize.left, - defaultSize.top, - defaultSize.right, - defaultSize.bottom - ); - } - - public void setIndex(int index) { - this.index = index; - } - - public int getIndex() { - return index; - } - - public void onDraw(Canvas canvas, TextSurface textSurface) { - - layout(textSurface); - - canvas.save(); - canvas.concat(matrix); - - final float finalX = padding.left; - - if (effects.isEmpty()) { - canvas.drawText(text, finalX, -padding.bottom - fontDescent, paint); - } else { - for (ITextEffect effect : effects) { - canvas.save(); - effect.apply(canvas, text, finalX, -padding.bottom, paint); - canvas.drawText(text, finalX, -padding.bottom, paint); - canvas.restore(); - } - - } - - canvas.restore(); - - if (Debug.ENABLED) { - canvas.drawRect( - currentSize.left, - currentSize.top - padding.bottom - padding.top, - currentSize.right + padding.left + padding.right, - currentSize.bottom, - Debug.RED_STROKE - ); - } - } - - void layout(TextSurface textSurface) { - - currentSize.set(defaultSize.left, defaultSize.top, defaultSize.right, defaultSize.bottom); - - final float sx = scale.getScaleX(); - final float sy = scale.getScaleY(); - final float sPivotX = position.getRelativeX((int) scale.getPivot().x, this, false); - final float sPivotY = position.getRelativeY((int) scale.getPivot().y, this, false); - final float x = position.getX(textSurface, getWidth() * sx); - final float y = position.getY(textSurface, getHeight() * sy); - - matrix.reset(); - matrix.preTranslate(x, y); - matrix.preScale(sx, sy, sPivotX, sPivotY); - matrix.mapRect(currentSize); - } - - public float getY(TextSurface textSurface) { - return position.getY(textSurface, getHeight()); - } - - public float getX(TextSurface textSurface) { - return position.getX(textSurface, getWidth()); - } - - public void setAlpha(int alpha) { - paint.setAlpha(alpha); - } - - public RectF bounds() { - return defaultSize; - } - - public void setPosition(Position position) { - this.position = position; - } - - public void setScaleX(float value) { - scale.setValueX(value); - } - - public void setScaleY(float value) { - scale.setValueY(value); - } - - public void setScalePivot(float x, float y) { - scale.getPivot().set(x, y); - } - - public float getScaleY() { - return scale.getScaleY(); - } - - public void setTranslationX(float value) { - position.setTranslationX(value); - } - - public void setTranslationY(float value) { - position.setTranslationY(value); - } - - @Override public int compareTo(@NonNull Text another) { - return text.compareTo(another.text); - } - - public float getWidth() { - return (currentSize.width() + padding.left + padding.right); - } - - public float getHeight() { - return (currentSize.height() + padding.top + padding.bottom); - } - - public Position getPosition() { - return position; - } - - public void onAnimationEnd() { - position.onAnimationEnd(); - } - - public float getScaleX() { - return scale.getScaleX(); - } - - @Override public String toString() { - return "Text{" + - "text='" + text + '\'' + - '}'; - } - - public void removeEffect(ITextEffect effect) { - effects.remove(effect); - } - - public String getValue() { - return text; - } - - public Paint getPaint() { - return paint; - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/Text.kt b/library/src/main/java/su/levenetc/android/textsurface/Text.kt new file mode 100644 index 0000000..a30014f --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/Text.kt @@ -0,0 +1,158 @@ +package su.levenetc.android.textsurface + +import android.graphics.* +import su.levenetc.android.textsurface.common.Position +import su.levenetc.android.textsurface.common.ScaleValue +import su.levenetc.android.textsurface.interfaces.ITextEffect +import su.levenetc.android.textsurface.utils.Utils +import java.util.* + +/** + * Created by Eugene Levenetc. + */ +class Text(val value: String, var position: Position, private val padding: RectF, val paint: Paint) : Comparable { + private var defaultSize: RectF? = null + private val currentSize = RectF() + var index = 0 + private val scale = ScaleValue() + private val matrix = Matrix() + private val effects = ArrayList() + private var dx = 0f + var fontDescent = 0f + private set + + fun addEffect(effect: ITextEffect) { + effects.add(effect) + } + + private fun initBounds(text: String) { + var text = text + val trimmed = text.trim { it <= ' ' } + if (trimmed.length < text.length) { + val length = text.length + val start = text.lastIndexOf(trimmed) + val end = length - (start + trimmed.length) + text = Utils.genString(start) + text + Utils.genString(end) + } + val tmp = Rect() + paint.getTextBounds(text, 0, text.length, tmp) + fontDescent = paint.fontMetrics.descent + defaultSize = RectF(tmp) + //a little workaround because getTextBounds returns smaller width than it is + dx = paint.measureText(text) - tmp.width() + defaultSize!!.left = 0f + defaultSize!!.right = tmp.width() + dx + defaultSize!!.top = -paint.fontSpacing + defaultSize!!.bottom = 0f + defaultSize!![defaultSize!!.left, defaultSize!!.top, defaultSize!!.right] = defaultSize!!.bottom + currentSize[defaultSize!!.left, defaultSize!!.top, defaultSize!!.right] = defaultSize!!.bottom + } + + fun onDraw(canvas: Canvas, textSurface: TextSurface?) { + layout(textSurface) + canvas.save() + canvas.concat(matrix) + val finalX = padding.left + if (effects.isEmpty()) { + canvas.drawText(value, finalX, -padding.bottom - fontDescent, paint) + } else { + for (effect in effects) { + canvas.save() + effect.apply(canvas, value, finalX, -padding.bottom, paint) + canvas.drawText(value, finalX, -padding.bottom, paint) + canvas.restore() + } + } + canvas.restore() + if (Debug.ENABLED) { + canvas.drawRect( + currentSize.left, + currentSize.top - padding.bottom - padding.top, + currentSize.right + padding.left + padding.right, + currentSize.bottom, + Debug.RED_STROKE + ) + } + } + + fun layout(textSurface: TextSurface?) { + currentSize[defaultSize!!.left, defaultSize!!.top, defaultSize!!.right] = defaultSize!!.bottom + val sx = scale.scaleX + val sy = scale.scaleY + val sPivotX = position.getRelativeX(scale.pivot.x.toInt(), this, false) + val sPivotY = position.getRelativeY(scale.pivot.y.toInt(), this, false) + val x = position.getX(textSurface, width * sx) + val y = position.getY(textSurface, height * sy) + matrix.reset() + matrix.preTranslate(x, y) + matrix.preScale(sx, sy, sPivotX, sPivotY) + matrix.mapRect(currentSize) + } + + fun getY(textSurface: TextSurface?): Float { + return position.getY(textSurface, height) + } + + fun getX(textSurface: TextSurface?): Float { + return position.getX(textSurface, width) + } + + fun setAlpha(alpha: Int) { + paint.alpha = alpha + } + + fun bounds(): RectF? { + return defaultSize + } + + fun setScalePivot(x: Float, y: Float) { + scale.pivot[x] = y + } + + var scaleY: Float + get() = scale.scaleY + set(value) { + scale.setValueY(value) + } + + fun setTranslationX(value: Float) { + position.setTranslationX(value) + } + + fun setTranslationY(value: Float) { + position.setTranslationY(value) + } + + override fun compareTo(another: Text): Int { + return value.compareTo(another.value) + } + + val width: Float + get() = currentSize.width() + padding.left + padding.right + val height: Float + get() = currentSize.height() + padding.top + padding.bottom + + fun onAnimationEnd() { + position.onAnimationEnd() + } + + var scaleX: Float + get() = scale.scaleX + set(value) { + scale.setValueX(value) + } + + override fun toString(): String { + return "Text{" + + "text='" + value + '\'' + + '}' + } + + fun removeEffect(effect: ITextEffect) { + effects.remove(effect) + } + + init { + initBounds(value) + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.java b/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.java deleted file mode 100644 index 1d0e40f..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.java +++ /dev/null @@ -1,126 +0,0 @@ -package su.levenetc.android.textsurface; - -import android.content.res.Resources; -import android.graphics.Color; -import android.graphics.Paint; -import android.graphics.PointF; -import android.graphics.RectF; -import android.util.TypedValue; - -import su.levenetc.android.textsurface.common.Position; -import su.levenetc.android.textsurface.contants.Pivot; - -/** - * Created by Eugene Levenetc. - */ -public class TextBuilder { - - private String text; - private int showTime; - private Position position = new Position(); - private RectF padding = new RectF(); - private Paint paint = new Paint(); - private float scale = 1; - private int scalePivot = Pivot.CENTER; - - private TextBuilder(String text) { - this.text = text; - paint.setColor(Color.WHITE); - paint.setAntiAlias(true); - paint.setTextSize(110); - setSize(18); - } - - public static TextBuilder create(String text) { - return new TextBuilder(text); - } - - public TextBuilder setShowTime(int showTime) { - this.showTime = showTime; - return this; - } - - public TextBuilder setPosition(float px, float py) { - position = new Position(new PointF(px, py)); - return this; - } - - public TextBuilder setPosition(int align) { - position = new Position(align); - return this; - } - - public TextBuilder setPosition(int align, Text alignText) { - position = new Position(align, alignText); - return this; - } - - /** - * params are in pixels - */ - public TextBuilder setPadding(float left, float top, float right, float bottom) { - padding.set(left, top, right, bottom); - return this; - } - - /** - * params are in pixels - */ - public TextBuilder setLeftPadding(float left) { - padding.set(left, padding.top, padding.right, padding.bottom); - return this; - } - - public TextBuilder setPadding(RectF padding) { - this.padding.set(padding); - return this; - } - - public TextBuilder setPosition(Position position) { - this.position.set(position); - return this; - } - - /** - * Overrides all previously set paint properties - */ - public TextBuilder setPaint(Paint paint) { - this.paint = new Paint(paint); - return this; - } - - /** - * @param alpha from 0 to 255 - */ - public TextBuilder setAlpha(int alpha) { - this.paint.setAlpha(alpha); - return this; - } - - public TextBuilder setColor(int color) { - this.paint.setColor(color); - return this; - } - - public TextBuilder setSize(float sp) { - paint.setTextSize( - TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sp, Resources.getSystem().getDisplayMetrics()) - ); - return this; - } - - public TextBuilder setScale(float scale, int scalePivot) { - this.scale = scale; - this.scalePivot = scalePivot; - return this; - } - - public Text build() { - Text result = new Text(this.text, position, padding, paint); - result.setScaleX(scale); - result.setScaleY(scale); - result.setScalePivot(scalePivot, scalePivot); - return result; - } - -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt b/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt new file mode 100644 index 0000000..ac5cd38 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt @@ -0,0 +1,121 @@ +package su.levenetc.android.textsurface + +import android.content.res.Resources +import android.graphics.Color +import android.graphics.Paint +import android.graphics.PointF +import android.graphics.RectF +import android.util.TypedValue +import su.levenetc.android.textsurface.common.Position +import su.levenetc.android.textsurface.contants.Pivot + +/** + * Created by Eugene Levenetc. + */ +class TextBuilder private constructor(private val text: String) { + private var showTime = 0 + private var position = Position() + private val padding = RectF() + private var paint = Paint() + private var scale = 1f + private var scalePivot = Pivot.CENTER + fun setShowTime(showTime: Int): TextBuilder { + this.showTime = showTime + return this + } + + fun setPosition(px: Float, py: Float): TextBuilder { + position = Position(PointF(px, py)) + return this + } + + fun setPosition(align: Int): TextBuilder { + position = Position(align) + return this + } + + fun setPosition(align: Int, alignText: Text?): TextBuilder { + position = Position(align, alignText) + return this + } + + /** + * params are in pixels + */ + fun setPadding(left: Float, top: Float, right: Float, bottom: Float): TextBuilder { + padding[left, top, right] = bottom + return this + } + + /** + * params are in pixels + */ + fun setLeftPadding(left: Float): TextBuilder { + padding[left, padding.top, padding.right] = padding.bottom + return this + } + + fun setPadding(padding: RectF?): TextBuilder { + this.padding.set(padding!!) + return this + } + + fun setPosition(position: Position): TextBuilder { + this.position.set(position) + return this + } + + /** + * Overrides all previously set paint properties + */ + fun setPaint(paint: Paint?): TextBuilder { + this.paint = Paint(paint) + return this + } + + /** + * @param alpha from 0 to 255 + */ + fun setAlpha(alpha: Int): TextBuilder { + paint.alpha = alpha + return this + } + + fun setColor(color: Int): TextBuilder { + paint.color = color + return this + } + + fun setSize(sp: Float): TextBuilder { + paint.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sp, Resources.getSystem().displayMetrics) + return this + } + + fun setScale(scale: Float, scalePivot: Int): TextBuilder { + this.scale = scale + this.scalePivot = scalePivot + return this + } + + fun build(): Text { + val result = Text(text, position, padding, paint) + result.scaleX = scale + result.scaleY = scale + result.setScalePivot(scalePivot.toFloat(), scalePivot.toFloat()) + return result + } + + companion object { + @JvmStatic + fun create(text: String): TextBuilder { + return TextBuilder(text) + } + } + + init { + paint.color = Color.WHITE + paint.isAntiAlias = true + paint.textSize = 110f + setSize(18f) + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/TextSurface.java b/library/src/main/java/su/levenetc/android/textsurface/TextSurface.java deleted file mode 100644 index 2b1911a..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/TextSurface.java +++ /dev/null @@ -1,100 +0,0 @@ -package su.levenetc.android.textsurface; - -import android.content.Context; -import android.graphics.Canvas; -import android.util.AttributeSet; -import android.widget.FrameLayout; - -import java.util.Iterator; -import java.util.LinkedList; -import java.util.TreeSet; - -import su.levenetc.android.textsurface.animations.AnimationsSet; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.interfaces.ICameraAnimation; -import su.levenetc.android.textsurface.interfaces.ISet; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; -import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation; - -/** - * Created by Eugene Levenetc. - */ -public class TextSurface extends FrameLayout { - - private TreeSet textsTree = new TreeSet<>(); - private SurfaceCamera camera = new SurfaceCamera(); - private ISurfaceAnimation currentAnimation = null; - - public TextSurface(Context context) { - super(context); - config(); - } - - public TextSurface(Context context, AttributeSet attrs) { - super(context, attrs); - config(); - } - - private void config() { - setWillNotDraw(false); - } - - public SurfaceCamera getCamera() { - return camera; - } - - public void play(TYPE type, ISurfaceAnimation... animations) { - play(new AnimationsSet(type, animations)); - } - - public void play(ISurfaceAnimation... animations) { - play(new AnimationsSet(TYPE.PARALLEL, animations)); - } - - public void play(ISurfaceAnimation animation) { - configAnimations(animation); - animation.setTextSurface(this); - layout(); - currentAnimation = animation; - currentAnimation.start(null); - } - - private void layout() { - Iterator iterator = textsTree.iterator(); - while (iterator.hasNext()) iterator.next().layout(this); - } - - @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - super.onLayout(changed, left, top, right, bottom); - } - - private void configAnimations(ISurfaceAnimation animation) { - - if (animation instanceof ICameraAnimation) { - ((ICameraAnimation) animation).setCamera(camera); - } else if (animation instanceof ISet) { - LinkedList animations = ((ISet) animation).getAnimations(); - for (ISurfaceAnimation a : animations) configAnimations(a); - } else if (animation instanceof ITextSurfaceAnimation) { - ITextSurfaceAnimation textAnimation = (ITextSurfaceAnimation) animation; - Text text = textAnimation.getText(); - if (text != null && textsTree.add(text)) textAnimation.setInitValues(text); - } - } - - @Override protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - camera.onDraw(canvas); - for (Text text : textsTree) text.onDraw(canvas, this); - } - - public void reset() { - if (currentAnimation != null) { - currentAnimation.cancel(); - currentAnimation = null; - } - textsTree.clear(); - camera.reset(); - invalidate(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt new file mode 100644 index 0000000..d885f6b --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt @@ -0,0 +1,90 @@ +package su.levenetc.android.textsurface + +import android.content.Context +import android.graphics.Canvas +import android.util.AttributeSet +import android.widget.FrameLayout +import su.levenetc.android.textsurface.animations.AnimationsSet +import su.levenetc.android.textsurface.contants.TYPE +import su.levenetc.android.textsurface.interfaces.* +import java.util.* + +/** + * Created by Eugene Levenetc. + */ +class TextSurface : FrameLayout { + private val textsTree = TreeSet() + val camera = SurfaceCamera() + private var currentAnimation: ISurfaceAnimation? = null + + constructor(context: Context?) : super(context!!) { + config() + } + + constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) { + config() + } + + private fun config() { + setWillNotDraw(false) + } + + fun play(type: TYPE, vararg animations: ISurfaceAnimation) { + play(AnimationsSet(type, *animations)) + } + + fun play(vararg animations: ISurfaceAnimation?) { + play(AnimationsSet(TYPE.PARALLEL, *animations)) + } + + fun play(animation: ISurfaceAnimation) { + configAnimations(animation) + animation.textSurface = this + layout() + currentAnimation = animation + currentAnimation!!.start(object : IEndListener { + override fun onAnimationEnd(animation: ISurfaceAnimation) { + //TODO: remove empty listener + } + + }) + } + + private fun layout() { + val iterator: Iterator = textsTree.iterator() + while (iterator.hasNext()) iterator.next().layout(this) + } + + override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { + super.onLayout(changed, left, top, right, bottom) + } + + private fun configAnimations(animation: ISurfaceAnimation) { + if (animation is ICameraAnimation) { + animation.setCamera(camera) + } else if (animation is ISet) { + val animations = animation.animations + for (a in animations) configAnimations(a) + } else if (animation is ITextSurfaceAnimation) { + val textAnimation = animation + val text = textAnimation.text + if (text != null && textsTree.add(text)) textAnimation.setInitValues(text) + } + } + + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + camera.onDraw(canvas) + for (text in textsTree) text.onDraw(canvas, this) + } + + fun reset() { + if (currentAnimation != null) { + currentAnimation!!.cancel() + currentAnimation = null + } + textsTree.clear() + camera.reset() + invalidate() + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.java b/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.java deleted file mode 100644 index dbbe2c6..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.java +++ /dev/null @@ -1,57 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ValueAnimator; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation; - -/** - * Created by Eugene Levenetc. - */ -public class AbstractSurfaceAnimation implements ITextSurfaceAnimation, ValueAnimator.AnimatorUpdateListener { - - protected final Text text; - protected final int duration; - protected TextSurface textSurface; - - public AbstractSurfaceAnimation(Text text, int duration) { - this.text = text; - this.duration = duration; - } - - @Override public void setInitValues(@NonNull Text text) { - - } - - @NonNull @Override public Text getText() { - return text; - } - - @Override public void onStart() { - - } - - @Override public void start(final @Nullable IEndListener listener) { - - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt new file mode 100644 index 0000000..4cd45ff --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt @@ -0,0 +1,28 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +abstract class AbstractSurfaceAnimation( + override val text: Text, + override val duration: Long +) : ITextSurfaceAnimation, AnimatorUpdateListener { + + abstract override var textSurface: TextSurface + + override fun setInitValues(text: Text) {} + override fun onStart() {} + override fun start(listener: IEndListener) {} + override fun cancel() {} + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface.invalidate() + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.java deleted file mode 100644 index ed289ae..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.java +++ /dev/null @@ -1,59 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.Animator; -import android.animation.ValueAnimator; -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.utils.AnimatorEndListener; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.interfaces.IEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class Alpha extends AbstractSurfaceAnimation { - - private int to; - private int from; - private ValueAnimator animator; - - public static Alpha hide(Text text, int duration) { - return new Alpha(text, duration, 255, 0); - } - - public static Alpha show(Text text, int duration) { - return new Alpha(text, duration, 0, 255); - } - - public Alpha(Text text, int duration, int from, int to) { - super(text, duration); - this.from = from; - this.to = to; - } - - @Override public void start(@Nullable final IEndListener listener) { - animator = ValueAnimator.ofInt(from, to); - animator.setDuration(duration); - animator.addUpdateListener(this); - - animator.addListener(new AnimatorEndListener() { - @Override public void onAnimationEnd(Animator animation) { - if (listener != null) listener.onAnimationEnd(Alpha.this); - } - }); - - animator.start(); - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - super.onAnimationUpdate(animation); - text.setAlpha((int) animation.getAnimatedValue()); - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt new file mode 100644 index 0000000..cd7a775 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt @@ -0,0 +1,53 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.Animator +import android.animation.ValueAnimator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.utils.AnimatorEndListener + +/** + * Created by Eugene Levenetc. + */ +class Alpha(text: Text, duration: Long, private val from: Int, private val to: Int) : AbstractSurfaceAnimation(text, duration) { + + private var animator: ValueAnimator? = null + override lateinit var textSurface: TextSurface + + override fun start(listener: IEndListener) { + animator = ValueAnimator.ofInt(from, to) + animator?.duration = duration + animator?.addUpdateListener(this) + animator?.addListener(object : AnimatorEndListener() { + override fun onAnimationEnd(animation: Animator) { + listener.onAnimationEnd(this@Alpha) + } + }) + animator?.start() + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + super.onAnimationUpdate(animation) + text.setAlpha(animation.animatedValue as Int) + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + companion object { + @kotlin.jvm.JvmStatic + fun hide(text: Text, duration: Long): Alpha { + return Alpha(text, duration, 255, 0) + } + + @kotlin.jvm.JvmStatic + fun show(text: Text, duration: Long): Alpha { + return Alpha(text, duration, 0, 255) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.java b/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.java deleted file mode 100644 index 396e330..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.java +++ /dev/null @@ -1,130 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import androidx.annotation.NonNull; -import android.util.Log; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; -import java.util.LinkedList; - -import su.levenetc.android.textsurface.Debug; -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ISet; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; - -/** - * Created by Eugene Levenetc. - */ -public class AnimationsSet implements IEndListener, ISet { - - - private LinkedList animations; - private TYPE type; - private ISurfaceAnimation currentAnimation; - private ISurfaceAnimation lastAnimation;//type == PARALLEL - private int index; - private IEndListener listener; - private boolean canceled; - private static final DurationComparator DURATION_COMPARATOR = new DurationComparator(); - - public AnimationsSet(TYPE type, ISurfaceAnimation... animations) { - this.type = type; - this.animations = new LinkedList<>(Arrays.asList(animations)); - } - - @Override public void onAnimationEnd(ISurfaceAnimation animation) { - if (Debug.ENABLED) Log.i("endAnimation", animation.toString()); - - if (canceled) { - finalizeAnimation(); - return; - } - - if (type == TYPE.SEQUENTIAL) { - if (index < animations.size()) { - setCurrentAnimation(animations.get(index++)); - } else { - finalizeAnimation(); - } - } else { - if (animation == lastAnimation) finalizeAnimation(); - } - - } - - private void finalizeAnimation() { - if (listener != null) listener.onAnimationEnd(this); - } - - @Override public void onStart() { - - } - - @Override public void start(IEndListener listener) { - this.listener = listener; - index = 0; - canceled = false; - - if (type == TYPE.SEQUENTIAL) { - setCurrentAnimation(animations.get(index++)); - } else if (type == TYPE.PARALLEL) { - - Collections.sort(animations, DURATION_COMPARATOR); - lastAnimation = animations.getLast(); - - for (ISurfaceAnimation animation : animations) setCurrentAnimation(animation); - } - } - - private void setCurrentAnimation(ISurfaceAnimation animation) { - if (Debug.ENABLED) Log.i("startedAnimation", animation.toString()); - currentAnimation = animation; - currentAnimation.onStart(); - currentAnimation.start(this); - } - - @Override public TYPE getType() { - return type; - } - - // @Override public Text getText() { -// return currentAnimation.getText(); -// } - -// @Override public void setText(@NonNull Text text) { -// for (ISurfaceAnimation animation : animations) animation.setText(text); -// } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - for (ISurfaceAnimation animation : animations) animation.setTextSurface(textSurface); - } - - @Override public long getDuration() { - return 0; - } - - @Override public void cancel() { - canceled = true; - if (type == TYPE.SEQUENTIAL) { - if (currentAnimation != null) { - currentAnimation.cancel(); - } - } else { - for (ISurfaceAnimation animation : animations) animation.cancel(); - } - } - - @Override public LinkedList getAnimations() { - return animations; - } - - private static class DurationComparator implements Comparator { - @Override public int compare(ISurfaceAnimation lhs, ISurfaceAnimation rhs) { - return (int) (lhs.getDuration() - rhs.getDuration()); - } - } - -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt new file mode 100644 index 0000000..cf28bb6 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt @@ -0,0 +1,97 @@ +package su.levenetc.android.textsurface.animations + +import android.util.Log +import su.levenetc.android.textsurface.Debug +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.TYPE +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISet +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation +import java.util.* + +/** + * Created by Eugene Levenetc. + */ +open class AnimationsSet(override val type: TYPE, vararg animations: ISurfaceAnimation?) : IEndListener, ISet { + override val animations: LinkedList + private var currentAnimation: ISurfaceAnimation? = null + private var lastAnimation //type == PARALLEL + : ISurfaceAnimation? = null + private var index = 0 + private var listener: IEndListener? = null + private var canceled = false + override fun onAnimationEnd(animation: ISurfaceAnimation) { + if (Debug.ENABLED) Log.i("endAnimation", animation.toString()) + if (canceled) { + finalizeAnimation() + return + } + if (type == TYPE.SEQUENTIAL) { + if (index < animations.size) { + setCurrentAnimation(animations[index++]) + } else { + finalizeAnimation() + } + } else { + if (animation === lastAnimation) finalizeAnimation() + } + } + + private fun finalizeAnimation() { + if (listener != null) listener!!.onAnimationEnd(this) + } + + override fun onStart() {} + override fun start(listener: IEndListener) { + this.listener = listener + index = 0 + canceled = false + if (type == TYPE.SEQUENTIAL) { + setCurrentAnimation(animations[index++]) + } else if (type == TYPE.PARALLEL) { + Collections.sort(animations, DURATION_COMPARATOR) + lastAnimation = animations.last + for (animation in animations) setCurrentAnimation(animation) + } + } + + private fun setCurrentAnimation(animation: ISurfaceAnimation) { + if (Debug.ENABLED) Log.i("startedAnimation", animation.toString()) + currentAnimation = animation + currentAnimation!!.onStart() + currentAnimation!!.start(this) + } + + override val duration: Long + get() = 0 + override var textSurface: TextSurface + get() = null!! + set(value) { + animations.forEach { it.textSurface = value } + } + + override fun cancel() { + canceled = true + if (type == TYPE.SEQUENTIAL) { + if (currentAnimation != null) { + currentAnimation!!.cancel() + } + } else { + for (animation in animations) animation.cancel() + } + } + + private class DurationComparator : Comparator { + override fun compare(lhs: ISurfaceAnimation, rhs: ISurfaceAnimation): Int { + return (lhs.duration - rhs.duration).toInt() + } + } + + companion object { + private val DURATION_COMPARATOR = DurationComparator() + } + + init { + this.animations = LinkedList(listOf(*animations)) + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.java b/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.java deleted file mode 100644 index cd76caf..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.java +++ /dev/null @@ -1,157 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.Animator; -import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; -import android.graphics.PointF; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.utils.AnimatorEndListener; -import su.levenetc.android.textsurface.interfaces.ICameraAnimation; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.SurfaceCamera; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; - -/** - * Created by Eugene Levenetc. - */ -public class CamRot implements ICameraAnimation, ValueAnimator.AnimatorUpdateListener { - - public float rotationDelta; - private float pivotX; - private float pivotY; - private int duration; - private TextSurface textSurface; - private SurfaceCamera camera; - private Text textPivot; - private int pivotAlign; - private ObjectAnimator animator; - - public CamRot(int duration, float rotationDelta) { - this.duration = duration; - this.rotationDelta = rotationDelta; - } - - public CamRot(int duration, float rotationDelta, float pivotX, float pivotY) { - this.duration = duration; - this.rotationDelta = rotationDelta; - this.pivotX = pivotX; - this.pivotY = pivotY; - } - - public CamRot(int duration, float rotationDelta, Text textPivot, int pivotAlign) { - this.duration = duration; - this.rotationDelta = rotationDelta; - this.textPivot = textPivot; - this.pivotAlign = pivotAlign; - } - - @Override public void onStart() { - - } - - @Override public void start(@Nullable final IEndListener listener) { - - setPivot(); - float from = camera.getRotation(); - float to = camera.getRotation() + rotationDelta; - animator = ObjectAnimator.ofFloat(camera, "rotation", from, to); - animator.setDuration(duration); - animator.addUpdateListener(this); - animator.addListener(new AnimatorEndListener() { - @Override public void onAnimationEnd(Animator animation) { - if (listener != null) listener.onAnimationEnd(CamRot.this); - } - }); - - animator.start(); - } - - private PointF tmpPoint = new PointF(); - - private void setPivot() { - - PointF rotationPivot = camera.getRotationPivot(); - - if (textPivot != null) { - if ((pivotAlign & Pivot.LEFT) == Pivot.LEFT) { - pivotX = textPivot.getX(textSurface); - } else if ((pivotAlign & Pivot.RIGHT) == Pivot.RIGHT) { - pivotX = textPivot.getX(textSurface) + textPivot.getWidth(); - } - - if ((pivotAlign & Pivot.BOTTOM) == Pivot.BOTTOM) { - pivotY = textPivot.getY(textSurface); - } else if ((pivotAlign & Pivot.TOP) == Pivot.TOP) { - pivotY = textPivot.getY(textSurface) - textPivot.getHeight(); - } - - if ((pivotAlign & Pivot.CENTER) == Pivot.CENTER) { - pivotX = textPivot.getX(textSurface) + textPivot.getWidth() / 2; - pivotY = textPivot.getY(textSurface) - textPivot.getHeight() / 2; - } - - } - - tmpPoint.set(pivotX, pivotY); -// rotatePoint(tmpPoint, camera.getRotationPivot(), camera.getRotation()); - rotatePoint2(tmpPoint, camera.getRotationPivot(), camera.getRotation()); - rotationPivot.set(tmpPoint.x, tmpPoint.y); - } - - private static void rotatePoint2(PointF point, PointF center, float angle) { - - float x = angle; - float centerX = center.x; - float centerY = center.y; - float point2x = point.x; - float point2y = point.y; - - double newX = centerX + (point2x - centerX) * Math.cos(x) - (point2y - centerY) * Math.sin(x); - double newY = centerY + (point2x - centerX) * Math.sin(x) + (point2y - centerY) * Math.cos(x); - point.set((float) newX, (float) newY); - } - - private static void rotatePoint(PointF point, PointF center, float angle) { - - if (angle == 0) return; - - double x1 = point.x - center.x; - double y1 = point.y - center.y; - - //APPLY ROTATION - double xTemp = x1; - x1 = x1 * Math.cos(angle) - y1 * Math.sin(angle); - y1 = xTemp * Math.sin(angle) + y1 * Math.cos(angle); - - //TRANSLATE BACK - point.x = (int) Math.ceil(x1) + center.x; - point.y = (int) Math.ceil(y1) + center.y; - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } - - @Override public void setCamera(SurfaceCamera camera) { - this.camera = camera; - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt new file mode 100644 index 0000000..5f26fbe --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt @@ -0,0 +1,134 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.Animator +import android.animation.ObjectAnimator +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.annotation.SuppressLint +import android.graphics.PointF +import su.levenetc.android.textsurface.SurfaceCamera +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.interfaces.ICameraAnimation +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.utils.AnimatorEndListener + +/** + * Created by Eugene Levenetc. + */ +class CamRot : ICameraAnimation, AnimatorUpdateListener { + var rotationDelta: Float + private var pivotX = 0f + private var pivotY = 0f + override var duration: Long + override lateinit var textSurface: TextSurface + private var camera: SurfaceCamera? = null + private var textPivot: Text? = null + private var pivotAlign = 0 + private var animator: ObjectAnimator? = null + + constructor(duration: Long, rotationDelta: Float) { + this.duration = duration + this.rotationDelta = rotationDelta + } + + constructor(duration: Long, rotationDelta: Float, pivotX: Float, pivotY: Float) { + this.duration = duration + this.rotationDelta = rotationDelta + this.pivotX = pivotX + this.pivotY = pivotY + } + + constructor(duration: Long, rotationDelta: Float, textPivot: Text?, pivotAlign: Int) { + this.duration = duration + this.rotationDelta = rotationDelta + this.textPivot = textPivot + this.pivotAlign = pivotAlign + } + + override fun onStart() {} + + @SuppressLint("ObjectAnimatorBinding") + override fun start(listener: IEndListener) { + setPivot() + val from = camera!!.rotation + val to = camera!!.rotation + rotationDelta + animator = ObjectAnimator.ofFloat(camera, "rotation", from, to) + animator!!.setDuration(duration.toLong()) + animator!!.addUpdateListener(this) + animator!!.addListener(object : AnimatorEndListener() { + override fun onAnimationEnd(animation: Animator) { + listener.onAnimationEnd(this@CamRot) + } + }) + animator!!.start() + } + + private val tmpPoint = PointF() + private fun setPivot() { + val rotationPivot = camera!!.rotationPivot + if (textPivot != null) { + if (pivotAlign and Pivot.LEFT == Pivot.LEFT) { + pivotX = textPivot!!.getX(textSurface) + } else if (pivotAlign and Pivot.RIGHT == Pivot.RIGHT) { + pivotX = textPivot!!.getX(textSurface) + textPivot!!.width + } + if (pivotAlign and Pivot.BOTTOM == Pivot.BOTTOM) { + pivotY = textPivot!!.getY(textSurface) + } else if (pivotAlign and Pivot.TOP == Pivot.TOP) { + pivotY = textPivot!!.getY(textSurface) - textPivot!!.height + } + if (pivotAlign and Pivot.CENTER == Pivot.CENTER) { + pivotX = textPivot!!.getX(textSurface) + textPivot!!.width / 2 + pivotY = textPivot!!.getY(textSurface) - textPivot!!.height / 2 + } + } + tmpPoint[pivotX] = pivotY + // rotatePoint(tmpPoint, camera.getRotationPivot(), camera.getRotation()); + rotatePoint2(tmpPoint, camera!!.rotationPivot, camera!!.rotation) + rotationPivot[tmpPoint.x] = tmpPoint.y + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface!!.invalidate() + } + + override fun setCamera(camera: SurfaceCamera?) { + this.camera = camera + } + + companion object { + private fun rotatePoint2(point: PointF, center: PointF, angle: Float) { + val centerX = center.x + val centerY = center.y + val point2x = point.x + val point2y = point.y + val newX = centerX + (point2x - centerX) * Math.cos(angle.toDouble()) - (point2y - centerY) * Math.sin(angle.toDouble()) + val newY = centerY + (point2x - centerX) * Math.sin(angle.toDouble()) + (point2y - centerY) * Math.cos(angle.toDouble()) + point[newX.toFloat()] = newY.toFloat() + } + + private fun rotatePoint(point: PointF, center: PointF, angle: Float) { + if (angle == 0f) return + var x1 = (point.x - center.x).toDouble() + var y1 = (point.y - center.y).toDouble() + + //APPLY ROTATION + val xTemp = x1 + x1 = x1 * Math.cos(angle.toDouble()) - y1 * Math.sin(angle.toDouble()) + y1 = xTemp * Math.sin(angle.toDouble()) + y1 * Math.cos(angle.toDouble()) + + //TRANSLATE BACK + point.x = Math.ceil(x1).toInt() + center.x + point.y = Math.ceil(y1).toInt() + center.y + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.java b/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.java deleted file mode 100644 index 1fca15f..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.java +++ /dev/null @@ -1,74 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.Animator; -import android.animation.ValueAnimator; -import android.graphics.Color; -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.utils.AnimatorEndListener; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.interfaces.IEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class ChangeColor extends AbstractSurfaceAnimation { - - private int from; - private int to; - final float[] fromTriplet = new float[3]; - final float[] toTriplet = new float[3]; - final float[] hsv = new float[3]; - private ValueAnimator animator; - - public static ChangeColor fromTo(Text text, int duration, int from, int to) { - return new ChangeColor(text, duration, from, to); - } - - public static ChangeColor to(Text text, int duration, int to) { - return new ChangeColor(text, duration, -1, to); - } - - public ChangeColor(Text text, int duration, int from, int to) { - super(text, duration); - this.from = from; - this.to = to; - } - - @Override public void start(@Nullable final IEndListener listener) { - - if (from == -1) from = text.getPaint().getColor(); - - Color.colorToHSV(from, fromTriplet); - Color.colorToHSV(to, toTriplet); - - animator = ValueAnimator.ofFloat(0, 1); - animator.setDuration(duration); - animator.addUpdateListener(this); - - animator.addListener(new AnimatorEndListener() { - @Override public void onAnimationEnd(Animator animation) { - if (listener != null) listener.onAnimationEnd(ChangeColor.this); - } - }); - - animator.start(); - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - hsv[0] = fromTriplet[0] + (toTriplet[0] - fromTriplet[0]) * animation.getAnimatedFraction(); - hsv[1] = fromTriplet[1] + (toTriplet[1] - fromTriplet[1]) * animation.getAnimatedFraction(); - hsv[2] = fromTriplet[2] + (toTriplet[2] - fromTriplet[2]) * animation.getAnimatedFraction(); - - text.getPaint().setColor(Color.HSVToColor(hsv)); - super.onAnimationUpdate(animation); - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt new file mode 100644 index 0000000..af87224 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt @@ -0,0 +1,63 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.Animator +import android.animation.ValueAnimator +import android.graphics.Color +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.ChangeColor +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.utils.AnimatorEndListener + +/** + * Created by Eugene Levenetc. + */ +class ChangeColor(text: Text, override var duration: Long, private var from: Int, private val to: Int) : AbstractSurfaceAnimation(text, duration) { + val fromTriplet = FloatArray(3) + val toTriplet = FloatArray(3) + val hsv = FloatArray(3) + private var animator: ValueAnimator? = null + override lateinit var textSurface: TextSurface + + override fun start(listener: IEndListener) { + if (from == -1) from = text.paint.color + Color.colorToHSV(from, fromTriplet) + Color.colorToHSV(to, toTriplet) + animator = ValueAnimator.ofFloat(0f, 1f) + animator!!.duration = duration + animator!!.addUpdateListener(this) + animator!!.addListener(object : AnimatorEndListener() { + override fun onAnimationEnd(animation: Animator) { + listener?.onAnimationEnd(this@ChangeColor) + } + }) + animator!!.start() + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + hsv[0] = fromTriplet[0] + (toTriplet[0] - fromTriplet[0]) * animation.animatedFraction + hsv[1] = fromTriplet[1] + (toTriplet[1] - fromTriplet[1]) * animation.animatedFraction + hsv[2] = fromTriplet[2] + (toTriplet[2] - fromTriplet[2]) * animation.animatedFraction + text.paint.color = Color.HSVToColor(hsv) + super.onAnimationUpdate(animation) + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + companion object { + @kotlin.jvm.JvmStatic + fun fromTo(text: Text, duration: Long, from: Int, to: Int): ChangeColor { + return ChangeColor(text, duration, from, to) + } + + @kotlin.jvm.JvmStatic + fun to(text: Text, duration: Long, to: Int): ChangeColor { + return ChangeColor(text, duration, -1, to) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Circle.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Circle.java deleted file mode 100644 index c47eb20..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Circle.java +++ /dev/null @@ -1,143 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ValueAnimator; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Path; -import android.graphics.Region; - -import su.levenetc.android.textsurface.Debug; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.contants.Direction; -import su.levenetc.android.textsurface.contants.Side; - -/** - * Created by Eugene Levenetc. - */ -public class Circle implements ShapeReveal.IRevealShape, ValueAnimator.AnimatorUpdateListener { - - private float radius; - private Text text; - private Path clipPath = new Path(); - private ValueAnimator animator; - private TextSurface textSurface; - private final boolean toShow; - private final int side; - private int direction; - private float circX; - private float circY; - - /** - * @param side {@link Side} - * @param direction {@link Direction} Direction.IN or Direction.OUT - */ - public static Circle show(int side, int direction) { - return new Circle(true, side, direction); - } - - /** - * @param side {@link Side} - * @param direction {@link Direction} Direction.IN or Direction.OUT - */ - public static Circle hide(int side, int direction) { - return new Circle(false, side, direction); - } - - private Circle(boolean toShow, int side, int direction) { - this.toShow = toShow; - this.side = side; - this.direction = direction; - } - - public void setText(Text text) { - this.text = text; - } - - @Override public void setTextSurface(TextSurface textSurface) { - this.textSurface = textSurface; - } - - public ValueAnimator getAnimator() { - - final float width = text.getWidth(); - final float height = text.getHeight(); - final float textX = text.getX(textSurface); - final float textY = text.getY(textSurface); - - float toRad = 0; - float fromRad = 0; - float cathA, cathB; - - if (side == Side.CENTER) { - this.circX = width / 2; - this.circY = -(height / 2); - cathA = width / 2; - cathB = height / 2; - } else { - - if ((side & Side.LEFT) == Side.LEFT) { - this.circX = 0; - } else if ((side & Side.RIGHT) == Side.RIGHT) { - this.circX = width; - } - - if ((side & Side.TOP) == Side.TOP) { - this.circY = -height; - } else if ((side & Side.BOTTOM) == Side.BOTTOM) { - this.circY = 0; - } - - cathA = width; - cathB = height; - - } - - final float hypo = (float) Math.sqrt(cathA * cathA + cathB * cathB); - - if (toShow) { - if (direction == Direction.OUT) { - toRad = hypo; - } else { - clipOp = Region.Op.DIFFERENCE; - fromRad = hypo; - } - } else { - if (direction == Direction.OUT) { - clipOp = Region.Op.DIFFERENCE; - toRad = hypo; - } else { - fromRad = hypo; - } - } - - animator = ValueAnimator.ofFloat(fromRad, toRad); - animator.addUpdateListener(this); - return animator; - } - - @Override public void clip(Canvas canvas, String textValue, float x, float y, Paint paint) { - - clipPath.reset(); - clipPath.addCircle(circX, circY, radius, Path.Direction.CCW); - - if (Debug.ENABLED) { - canvas.drawPath(clipPath, Debug.BLUE_STROKE); - canvas.drawCircle(circX, circY, 10, Debug.RED_FILL); - } - - canvas.translate(0, -(text.getFontDescent())); - canvas.clipPath(clipPath, clipOp); - } - - private Region.Op clipOp = Region.Op.INTERSECT; - - @Override public boolean isToShow() { - return toShow; - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - radius = (float) animation.getAnimatedValue(); - textSurface.invalidate(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.java deleted file mode 100644 index f9beb87..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.java +++ /dev/null @@ -1,43 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.interfaces.IEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class Delay extends AbstractSurfaceAnimation { - - public static Delay duration(int duration) { - return new Delay(duration); - } - - private Runnable action = null; - - public Delay(int duration) { - super(null, duration); - } - - @Override public void start(@Nullable final IEndListener listener) { - action = new Runnable() { - @Override public void run() { - if (listener != null) listener.onAnimationEnd(Delay.this); - } - }; - textSurface.postDelayed(action, duration); - } - - @Override public void cancel() { - if (action != null) { - textSurface.removeCallbacks(action); - action = null; - } - } - - @Override public String toString() { - return "Delay{" + - "duration=" + duration + - '}'; - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt new file mode 100644 index 0000000..0374c35 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt @@ -0,0 +1,42 @@ +package su.levenetc.android.textsurface.animations + +import android.graphics.Paint +import android.graphics.RectF +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.common.Position +import su.levenetc.android.textsurface.interfaces.IEndListener + + +class Delay(duration: Long) : AbstractSurfaceAnimation(EMPTY_TEXT, duration) { + private var action: Runnable? = null + override lateinit var textSurface: TextSurface + + override fun start(listener: IEndListener) { + action = Runnable { listener?.onAnimationEnd(this@Delay) } + textSurface!!.postDelayed(action, duration.toLong()) + } + + override fun cancel() { + if (action != null) { + textSurface!!.removeCallbacks(action) + action = null + } + } + + override fun toString(): String { + return "Delay{" + + "duration=" + duration + + '}' + } + + companion object { + + private val EMPTY_TEXT = Text("", Position(), RectF(), Paint()) + + @kotlin.jvm.JvmStatic + fun duration(duration: Long): Delay { + return Delay(duration) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Just.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Just.java deleted file mode 100644 index 4408fca..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Just.java +++ /dev/null @@ -1,32 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.interfaces.IEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class Just extends AbstractSurfaceAnimation { - - public static AnimationsSet show(Text... texts) { - Just[] justs = new Just[texts.length]; - for (int i = 0; i < texts.length; i++) justs[i] = Just.show(texts[i]); - return new AnimationsSet(TYPE.PARALLEL, justs); - } - - public static Just show(Text text) { - return new Just(text); - } - - private Just(Text text) { - super(text, 0); - } - - @Override public void start(@Nullable IEndListener listener) { - textSurface.invalidate(); - if (listener != null) listener.onAnimationEnd(this); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt new file mode 100644 index 0000000..5a27e07 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt @@ -0,0 +1,31 @@ +package su.levenetc.android.textsurface.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.TYPE +import su.levenetc.android.textsurface.interfaces.IEndListener + +/** + * Created by Eugene Levenetc. + */ +class Just private constructor(text: Text) : AbstractSurfaceAnimation(text, 0) { + //TODO: check unused textSurface + override lateinit var textSurface: TextSurface + + override fun start(listener: IEndListener) { + textSurface!!.invalidate() + listener?.onAnimationEnd(this) + } + + companion object { + fun show(vararg texts: Text): AnimationsSet { + val justs = arrayOfNulls(texts.size) + for (i in texts.indices) justs[i] = show(texts[i]) + return AnimationsSet(TYPE.PARALLEL, *justs) + } + + fun show(text: Text): Just { + return Just(text) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.java deleted file mode 100644 index d588cc4..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.java +++ /dev/null @@ -1,38 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; - -/** - * Created by ogaclejapan. - */ -public class Loop extends Sequential { - - private final IEndListener restartListener = new IEndListener() { - @Override public void onAnimationEnd(ISurfaceAnimation animation) { - if (canceled) { - if (endListener != null) endListener.onAnimationEnd(Loop.this); - } else { - Loop.super.start(restartListener); - } - } - }; - - private IEndListener endListener; - private boolean canceled; - - public Loop(ISurfaceAnimation... animations) { - super(animations); - } - - @Override public void start(IEndListener listener) { - endListener = listener; - canceled = false; - super.start(restartListener); - } - - @Override public void cancel() { - canceled = true; - super.cancel(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt new file mode 100644 index 0000000..6fb0770 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt @@ -0,0 +1,31 @@ +package su.levenetc.android.textsurface.animations + +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation + +/** + * Created by ogaclejapan. + */ +class Loop(vararg animations: ISurfaceAnimation) : Sequential(*animations) { + private val restartListener: IEndListener = object : IEndListener { + override fun onAnimationEnd(animation: ISurfaceAnimation) { + if (canceled) { + if (endListener != null) endListener!!.onAnimationEnd(this@Loop) + } else { + super@Loop.start(this) + } + } + } + private var endListener: IEndListener? = null + private var canceled = false + override fun start(listener: IEndListener) { + endListener = listener + canceled = false + super.start(restartListener) + } + + override fun cancel() { + canceled = true + super.cancel() + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.java deleted file mode 100644 index e6d5a91..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.java +++ /dev/null @@ -1,13 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; - -/** - * Created by Eugene Levenetc. - */ -public class Parallel extends AnimationsSet { - public Parallel(ISurfaceAnimation... animations) { - super(TYPE.PARALLEL, animations); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt new file mode 100644 index 0000000..e6fab9d --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt @@ -0,0 +1,9 @@ +package su.levenetc.android.textsurface.animations + +import su.levenetc.android.textsurface.contants.TYPE +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +class Parallel(vararg animations: ISurfaceAnimation?) : AnimationsSet(TYPE.PARALLEL, *animations) \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.java deleted file mode 100644 index 219ecca..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.java +++ /dev/null @@ -1,209 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.animation.ValueAnimator; -import android.graphics.Camera; -import android.graphics.Canvas; -import android.graphics.Matrix; -import android.graphics.Paint; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; - -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.contants.Axis; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; -import su.levenetc.android.textsurface.interfaces.ITextEffect; - -/** - * Created by Eugene Levenetc. - */ -public class Rotate3D implements ITextEffect, ValueAnimator.AnimatorUpdateListener { - - private Text text; - private int duration; - private int pivot; - protected final Camera camera = new Camera(); - protected final Matrix cameraMatrix = new Matrix(); - private float rotationX; - private float rotationY; - private TextSurface textSurface; - private float cameraTransXPre; - private float cameraTransYPre; - private float cameraTransXPost; - private float cameraTransYPost; - private int direction; - private int axis; - private boolean show; - private ObjectAnimator animator; - - public static Rotate3D showFromSide(Text text, int duration, int pivot) { - return new Rotate3D(text, duration, pivot, 0, 0, true); - } - - public static Rotate3D showFromCenter(Text text, int duration, int direction, int axis) { - return new Rotate3D(text, duration, Pivot.CENTER, direction, axis, true); - } - - public static Rotate3D hideFromSide(Text text, int duration, int pivot) { - return new Rotate3D(text, duration, pivot, 0, 0, false); - } - - public static Rotate3D hideFromCenter(Text text, int duration, int direction, int axis) { - return new Rotate3D(text, duration, Pivot.CENTER, direction, axis, false); - } - - private Rotate3D( - Text text, - int duration, - int pivot, - int direction, - int axis, - boolean show - ) { - this.text = text; - this.duration = duration; - this.pivot = pivot; - this.direction = direction; - this.axis = axis; - this.show = show; - } - - @Override public void apply(Canvas canvas, String textValue, float x, float y, Paint paint) { - - camera.getMatrix(cameraMatrix); - camera.save(); - camera.rotateX(rotationX); - camera.rotateY(rotationY); - camera.getMatrix(cameraMatrix); - - cameraMatrix.preTranslate(cameraTransXPre, cameraTransYPre); - cameraMatrix.postTranslate(cameraTransXPost, cameraTransYPost); - - camera.restore(); - - canvas.concat(cameraMatrix); - } - - @Override public void setInitValues(@NonNull Text text) { - if (show) { - text.setAlpha(0); - } - } - - @NonNull @Override public Text getText() { - return text; - } - - @Override public void onStart() { - text.addEffect(this); - } - - @Override public void start(@Nullable final IEndListener listener) { - - - PropertyValuesHolder valHolder = null; - - int fromDegree; - int toDegree; - - text.setAlpha(255); - - if (show) { - fromDegree = 90; - toDegree = 0; - } else { - fromDegree = 0; - toDegree = -90; - } - - if ((pivot & Pivot.BOTTOM) == Pivot.BOTTOM) { - - valHolder = PropertyValuesHolder.ofFloat("rotationX", fromDegree, toDegree); - cameraTransXPre = -text.getWidth() / 2; - cameraTransXPost = text.getWidth() / 2; - cameraTransYPre = -text.getFontDescent(); - cameraTransYPost = 0; - } else if ((pivot & Pivot.TOP) == Pivot.TOP) { - valHolder = PropertyValuesHolder.ofFloat("rotationX", -fromDegree, toDegree); - cameraTransXPre = -text.getWidth() / 2; - cameraTransXPost = text.getWidth() / 2; - cameraTransYPre = text.getHeight() - text.getFontDescent(); - cameraTransYPost = -text.getHeight(); - } - - if ((pivot & Pivot.LEFT) == Pivot.LEFT) { - valHolder = PropertyValuesHolder.ofFloat("rotationY", fromDegree, toDegree); - cameraTransXPre = 0; - cameraTransXPost = 0; - cameraTransYPre = text.getHeight() / 2 - text.getFontDescent(); - cameraTransYPost = text.getHeight() / 2 - text.getHeight(); - } else if ((pivot & Pivot.RIGHT) == Pivot.RIGHT) { - valHolder = PropertyValuesHolder.ofFloat("rotationY", -fromDegree, toDegree); - cameraTransXPre = -text.getWidth(); - cameraTransXPost = text.getWidth(); - cameraTransYPre = text.getHeight() / 2 - text.getFontDescent(); - cameraTransYPost = text.getHeight() / 2 - text.getHeight(); - } - - if ((pivot & Pivot.CENTER) == Pivot.CENTER) { - valHolder = PropertyValuesHolder.ofFloat(axis == Axis.Y ? "rotationY" : "rotationX", fromDegree, toDegree); - cameraTransXPre = -text.getWidth() / 2; - cameraTransXPost = text.getWidth() / 2; - cameraTransYPre = text.getHeight() / 2 - text.getFontDescent(); - cameraTransYPost = text.getHeight() / 2 - text.getHeight(); - } - - if (valHolder != null) { - animator = ObjectAnimator.ofPropertyValuesHolder(this, valHolder); - animator.setInterpolator(new FastOutSlowInInterpolator()); - Utils.addEndListener(this, animator, new IEndListener() { - @Override public void onAnimationEnd(ISurfaceAnimation animation) { - text.removeEffect(Rotate3D.this); - if (!show) text.setAlpha(0); - if (listener != null) listener.onAnimationEnd(Rotate3D.this); - } - }); - animator.setDuration(duration); - animator.addUpdateListener(this); - animator.start(); - - } else { - throw new RuntimeException(getClass().getSuperclass() + " was not configured properly. Pivot:" + pivot); - } - - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - - public void setRotationX(float rotationX) { - this.rotationX = rotationX; - } - - public void setRotationY(float rotationY) { - this.rotationY = rotationY; - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt new file mode 100644 index 0000000..1d19bf9 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt @@ -0,0 +1,165 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.graphics.* +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Axis +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation +import su.levenetc.android.textsurface.interfaces.ITextEffect +import su.levenetc.android.textsurface.utils.Utils.addEndListener + +/** + * Created by Eugene Levenetc. + */ +class Rotate3D private constructor( + override val text: Text, + override var duration: Long, + private val pivot: Int, + private val direction: Int, + private val axis: Int, + private val show: Boolean +) : ITextEffect, AnimatorUpdateListener { + protected val camera = Camera() + protected val cameraMatrix = Matrix() + private var rotationX = 0f + private var rotationY = 0f + override lateinit var textSurface: TextSurface + private var cameraTransXPre = 0f + private var cameraTransYPre = 0f + private var cameraTransXPost = 0f + private var cameraTransYPost = 0f + private var animator: ObjectAnimator? = null + + override fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) { + camera.getMatrix(cameraMatrix) + camera.save() + camera.rotateX(rotationX) + camera.rotateY(rotationY) + camera.getMatrix(cameraMatrix) + cameraMatrix.preTranslate(cameraTransXPre, cameraTransYPre) + cameraMatrix.postTranslate(cameraTransXPost, cameraTransYPost) + camera.restore() + canvas.concat(cameraMatrix) + } + + override fun setInitValues(text: Text) { + if (show) { + text.setAlpha(0) + } + } + + override fun onStart() { + text.addEffect(this) + } + + override fun start(listener: IEndListener) { + var valHolder: PropertyValuesHolder? = null + val fromDegree: Int + val toDegree: Int + text.setAlpha(255) + if (show) { + fromDegree = 90 + toDegree = 0 + } else { + fromDegree = 0 + toDegree = -90 + } + if (pivot and Pivot.BOTTOM == Pivot.BOTTOM) { + valHolder = PropertyValuesHolder.ofFloat("rotationX", fromDegree.toFloat(), toDegree.toFloat()) + cameraTransXPre = -text.width / 2 + cameraTransXPost = text.width / 2 + cameraTransYPre = -text.fontDescent + cameraTransYPost = 0f + } else if (pivot and Pivot.TOP == Pivot.TOP) { + valHolder = PropertyValuesHolder.ofFloat("rotationX", -fromDegree.toFloat(), toDegree.toFloat()) + cameraTransXPre = -text.width / 2 + cameraTransXPost = text.width / 2 + cameraTransYPre = text.height - text.fontDescent + cameraTransYPost = -text.height + } + if (pivot and Pivot.LEFT == Pivot.LEFT) { + valHolder = PropertyValuesHolder.ofFloat("rotationY", fromDegree.toFloat(), toDegree.toFloat()) + cameraTransXPre = 0f + cameraTransXPost = 0f + cameraTransYPre = text.height / 2 - text.fontDescent + cameraTransYPost = text.height / 2 - text.height + } else if (pivot and Pivot.RIGHT == Pivot.RIGHT) { + valHolder = PropertyValuesHolder.ofFloat("rotationY", -fromDegree.toFloat(), toDegree.toFloat()) + cameraTransXPre = -text.width + cameraTransXPost = text.width + cameraTransYPre = text.height / 2 - text.fontDescent + cameraTransYPost = text.height / 2 - text.height + } + if (pivot and Pivot.CENTER == Pivot.CENTER) { + valHolder = PropertyValuesHolder.ofFloat(if (axis == Axis.Y) "rotationY" else "rotationX", fromDegree.toFloat(), toDegree.toFloat()) + cameraTransXPre = -text.width / 2 + cameraTransXPost = text.width / 2 + cameraTransYPre = text.height / 2 - text.fontDescent + cameraTransYPost = text.height / 2 - text.height + } + if (valHolder != null) { + animator = ObjectAnimator.ofPropertyValuesHolder(this, valHolder) + animator!!.interpolator = FastOutSlowInInterpolator() + addEndListener(this, animator!!, object : IEndListener { + override fun onAnimationEnd(animation: ISurfaceAnimation) { + text.removeEffect(this@Rotate3D) + if (!show) text.setAlpha(0) + listener.onAnimationEnd(this@Rotate3D) + } + }) + animator!!.duration = duration.toLong() + animator!!.addUpdateListener(this) + animator!!.start() + } else { + throw RuntimeException(javaClass.superclass.toString() + " was not configured properly. Pivot:" + pivot) + } + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + fun setRotationX(rotationX: Float) { + this.rotationX = rotationX + } + + fun setRotationY(rotationY: Float) { + this.rotationY = rotationY + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface!!.invalidate() + } + + companion object { + @kotlin.jvm.JvmStatic + fun showFromSide(text: Text, duration: Long, pivot: Int): Rotate3D { + return Rotate3D(text, duration, pivot, 0, 0, true) + } + + @kotlin.jvm.JvmStatic + fun showFromCenter(text: Text, duration: Long, direction: Int, axis: Int): Rotate3D { + return Rotate3D(text, duration, Pivot.CENTER, direction, axis, true) + } + + @kotlin.jvm.JvmStatic + fun hideFromSide(text: Text, duration: Long, pivot: Int): Rotate3D { + return Rotate3D(text, duration, pivot, 0, 0, false) + } + + @kotlin.jvm.JvmStatic + fun hideFromCenter(text: Text, duration: Long, direction: Int, axis: Int): Rotate3D { + return Rotate3D(text, duration, Pivot.CENTER, direction, axis, false) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.java deleted file mode 100644 index 410a7a2..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.java +++ /dev/null @@ -1,83 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.animation.ValueAnimator; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation; - -/** - * Created by Eugene Levenetc. - */ -public class Scale implements ITextSurfaceAnimation, ValueAnimator.AnimatorUpdateListener { - - private int duration; - private final float from; - private final float to; - private final int pivot; - private Text text; - private TextSurface textSurface; - private ObjectAnimator animator; - - public Scale(Text text, int duration, float from, float to, int pivot) { - this.text = text; - this.duration = duration; - this.from = from; - this.to = to; - this.pivot = pivot; - } - - @Override public void setInitValues(@NonNull Text text) { - - } - - @NonNull @Override public Text getText() { - return text; - } - - @Override public void onStart() { - - } - - @Override public void start(@Nullable IEndListener listener) { - text.setScalePivot(pivot, pivot); - PropertyValuesHolder sX = PropertyValuesHolder.ofFloat("scaleX", from, to); - PropertyValuesHolder sY = PropertyValuesHolder.ofFloat("scaleY", from, to); - animator = ObjectAnimator.ofPropertyValuesHolder(text, sX, sY); - Utils.addEndListener(this, animator, listener); - animator.setDuration(duration); - animator.addUpdateListener(this); - animator.start(); - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } - - @Override public String toString() { - return "Scale{" + - "text=" + text + - '}'; - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt new file mode 100644 index 0000000..1a8b46d --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt @@ -0,0 +1,49 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation +import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation +import su.levenetc.android.textsurface.utils.Utils.addEndListener + +/** + * Created by Eugene Levenetc. + */ +class Scale(override val text: Text, override val duration: Long, private val from: Float, private val to: Float, private val pivot: Int) : ITextSurfaceAnimation, AnimatorUpdateListener { + override lateinit var textSurface: TextSurface + private var animator: ObjectAnimator? = null + override fun setInitValues(text: Text) {} + override fun onStart() {} + override fun start(listener: IEndListener) { + text.setScalePivot(pivot.toFloat(), pivot.toFloat()) + val sX = PropertyValuesHolder.ofFloat("scaleX", from, to) + val sY = PropertyValuesHolder.ofFloat("scaleY", from, to) + animator = ObjectAnimator.ofPropertyValuesHolder(text, sX, sY) + addEndListener(this, animator!!, listener) + animator!!.duration = duration.toLong() + animator!!.addUpdateListener(this) + animator!!.start() + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface.invalidate() + } + + override fun toString(): String { + return "Scale{" + + "text=" + text + + '}' + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.java b/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.java deleted file mode 100644 index c64c0a4..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.java +++ /dev/null @@ -1,104 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.animation.ValueAnimator; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; - -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.SurfaceCamera; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.interfaces.ICameraAnimation; -import su.levenetc.android.textsurface.interfaces.IEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class ScaleSurface implements ICameraAnimation, ValueAnimator.AnimatorUpdateListener { - - private SurfaceCamera camera; - private TextSurface textSurface; - private int duration; - private final Text textPivot; - private int fit = -1; - private int pivot; - private float toScale; - private ObjectAnimator animator; - - public ScaleSurface(int duration, Text textPivot, int pivot, float toScale) { - this.duration = duration; - this.textPivot = textPivot; - this.pivot = pivot; - this.toScale = toScale; - } - - public ScaleSurface(int duration, Text textPivot, int fit) { - this.duration = duration; - this.textPivot = textPivot; - this.fit = fit; - } - - @Override public void setCamera(SurfaceCamera camera) { - this.camera = camera; - } - - @Override public void onStart() { - - } - - @Override public void start(@Nullable IEndListener listener) { - - float pivotX; - float pivotY; - - if (fit == -1) { - pivotX = textPivot.getPosition().getRelativeX(pivot, textPivot, true); - pivotY = textPivot.getPosition().getRelativeY(pivot, textPivot, true); - } else { - int surfaceWidth = textSurface.getWidth(); - float textWidth = textPivot.getWidth(); - toScale = surfaceWidth / textWidth; - pivotX = textPivot.getPosition().getRelativeX(Pivot.CENTER, textPivot, true); - pivotY = textPivot.getPosition().getRelativeY(Pivot.CENTER, textPivot, true); - } - - PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", camera.getScale(), toScale); - PropertyValuesHolder pivotXHolder = PropertyValuesHolder.ofFloat("scalePivotX", camera.getScalePivotX(), pivotX); - PropertyValuesHolder pivotYHolder = PropertyValuesHolder.ofFloat("scalePivotY", camera.getScalePivotY(), pivotY); - - animator = ObjectAnimator.ofPropertyValuesHolder(camera, scaleHolder, pivotXHolder, pivotYHolder); - animator.setInterpolator(new FastOutSlowInInterpolator()); - animator.setDuration(duration); - animator.addUpdateListener(this); - Utils.addEndListener(this, animator, listener); - animator.start(); - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - } - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } - - @Override public String toString() { - return "ScaleSurface{" + - "textPivot=" + ((textPivot == null) ? "null" : textPivot.toString()) + - '}'; - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt new file mode 100644 index 0000000..10cc877 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt @@ -0,0 +1,89 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.annotation.SuppressLint +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.SurfaceCamera +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.interfaces.ICameraAnimation +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.utils.Utils.addEndListener + +/** + * Created by Eugene Levenetc. + */ +class ScaleSurface : ICameraAnimation, AnimatorUpdateListener { + private var camera: SurfaceCamera? = null + override lateinit var textSurface: TextSurface + override var duration: Long + private val textPivot: Text? + private var fit = -1 + private var pivot = 0 + private var toScale = 0f + private var animator: ObjectAnimator? = null + + constructor(duration: Long, textPivot: Text?, pivot: Int, toScale: Float) { + this.duration = duration + this.textPivot = textPivot + this.pivot = pivot + this.toScale = toScale + } + + constructor(duration: Long, textPivot: Text?, fit: Int) { + this.duration = duration + this.textPivot = textPivot + this.fit = fit + } + + override fun setCamera(camera: SurfaceCamera?) { + this.camera = camera + } + + override fun onStart() {} + + @SuppressLint("ObjectAnimatorBinding") + override fun start(listener: IEndListener) { + val pivotX: Float + val pivotY: Float + if (fit == -1) { + pivotX = textPivot!!.position.getRelativeX(pivot, textPivot, true) + pivotY = textPivot.position.getRelativeY(pivot, textPivot, true) + } else { + val surfaceWidth = textSurface!!.width + val textWidth = textPivot!!.width + toScale = surfaceWidth / textWidth + pivotX = textPivot.position.getRelativeX(Pivot.CENTER, textPivot, true) + pivotY = textPivot.position.getRelativeY(Pivot.CENTER, textPivot, true) + } + val scaleHolder = PropertyValuesHolder.ofFloat("scale", camera!!.getScale(), toScale) + val pivotXHolder = PropertyValuesHolder.ofFloat("scalePivotX", camera!!.scalePivotX, pivotX) + val pivotYHolder = PropertyValuesHolder.ofFloat("scalePivotY", camera!!.scalePivotY, pivotY) + animator = ObjectAnimator.ofPropertyValuesHolder(camera, scaleHolder, pivotXHolder, pivotYHolder) + animator!!.interpolator = FastOutSlowInInterpolator() + animator!!.duration = duration.toLong() + animator!!.addUpdateListener(this) + addEndListener(this, animator!!, listener) + animator!!.start() + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + } + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface!!.invalidate() + } + + override fun toString(): String { + return "ScaleSurface{" + + "textPivot=" + (textPivot?.toString() ?: "null") + + '}' + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.java deleted file mode 100644 index dcf106c..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.java +++ /dev/null @@ -1,13 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import su.levenetc.android.textsurface.contants.TYPE; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; - -/** - * Created by Eugene Levenetc. - */ -public class Sequential extends AnimationsSet { - public Sequential(ISurfaceAnimation... animations) { - super(TYPE.SEQUENTIAL, animations); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt new file mode 100644 index 0000000..442f271 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt @@ -0,0 +1,9 @@ +package su.levenetc.android.textsurface.animations + +import su.levenetc.android.textsurface.contants.TYPE +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +open class Sequential(vararg animations: ISurfaceAnimation) : AnimationsSet(TYPE.SEQUENTIAL, *animations) \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ShapeReveal.java b/library/src/main/java/su/levenetc/android/textsurface/animations/ShapeReveal.java deleted file mode 100644 index 5f14a96..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/ShapeReveal.java +++ /dev/null @@ -1,105 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ValueAnimator; -import android.graphics.Canvas; -import android.graphics.Paint; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; - -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; -import su.levenetc.android.textsurface.interfaces.ITextEffect; - -/** - * Created by Eugene Levenetc. - */ -public class ShapeReveal implements ITextEffect, ValueAnimator.AnimatorUpdateListener { - - private final Text text; - private final int duration; - private TextSurface textSurface; - private IRevealShape revealShape; - private boolean hideOnEnd; - private ValueAnimator animator; - - public static ShapeReveal create(Text text, int duration, IRevealShape revealShape, boolean hideOnEnd) { - return new ShapeReveal(text, duration, revealShape, hideOnEnd); - } - - private ShapeReveal(Text text, int duration, IRevealShape revealShape, boolean hideOnEnd) { - this.text = text; - this.duration = duration; - this.revealShape = revealShape; - this.hideOnEnd = hideOnEnd; - revealShape.setText(text); - } - - @Override public void apply(Canvas canvas, String textValue, float x, float y, Paint paint) { - revealShape.clip(canvas, textValue, x, y, paint); - } - - @Override public void setInitValues(@NonNull Text text) { - if (revealShape.isToShow()) text.setAlpha(0); - } - - @NonNull @Override public Text getText() { - return text; - } - - @Override public void onStart() { - text.addEffect(this); - } - - @Override public void start(@Nullable final IEndListener listener) { - - text.setAlpha(255); - animator = revealShape.getAnimator(); - animator.setInterpolator(new FastOutSlowInInterpolator()); - Utils.addEndListener(this, animator, new IEndListener() { - @Override public void onAnimationEnd(ISurfaceAnimation animation) { - text.removeEffect(ShapeReveal.this); - if (hideOnEnd) text.setAlpha(0); - if (listener != null) listener.onAnimationEnd(ShapeReveal.this); - } - }); - animator.setDuration(duration); - animator.start(); - - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - revealShape.setTextSurface(textSurface); - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return 0; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } - - public interface IRevealShape { - void setText(Text text); - - void setTextSurface(TextSurface textSurface); - - ValueAnimator getAnimator(); - - void clip(Canvas canvas, String textValue, float x, float y, Paint paint); - - boolean isToShow(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/SideCut.java b/library/src/main/java/su/levenetc/android/textsurface/animations/SideCut.java deleted file mode 100644 index 01065c3..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/SideCut.java +++ /dev/null @@ -1,129 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ValueAnimator; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Path; - -import su.levenetc.android.textsurface.Debug; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.contants.Side; - -/** - * Created by Eugene Levenetc. - */ -public class SideCut implements ShapeReveal.IRevealShape, ValueAnimator.AnimatorUpdateListener { - - private float diffX; - private Text text; - private static final float CUT_SIZE = Utils.dpToPx(20); - private Path clipPath = new Path(); - private ValueAnimator animator; - private TextSurface textSurface; - private final boolean toShow; - private final int side; - - public static SideCut show(int side) { - return new SideCut(true, side); - } - - public static SideCut hide(int side) { - return new SideCut(false, side); - } - - private SideCut(boolean toShow, int side) { - this.toShow = toShow; - this.side = side; - } - - public void setText(Text text) { - this.text = text; - } - - @Override public void setTextSurface(TextSurface textSurface) { - this.textSurface = textSurface; - } - - public ValueAnimator getAnimator() { - final float width = text.getWidth(); - float toX = 0; - float fromX = 0; - - if (toShow) { - if (side == Side.LEFT) { - fromX = -(width + CUT_SIZE); - } else if (side == Side.RIGHT) { - fromX = width; - toX = -CUT_SIZE; - } - } else { - if (side == Side.LEFT) { - fromX = -CUT_SIZE; - toX = width; - } else if (side == Side.RIGHT) { - fromX = width; - toX = -CUT_SIZE; - } - } - - - animator = ValueAnimator.ofFloat(fromX, toX); - animator.addUpdateListener(this); - return animator; - } - - @Override public void clip(Canvas canvas, String textValue, float x, float y, Paint paint) { - final float width = text.getWidth(); - final float height = text.getHeight(); - - if (toShow) { - if (side == Side.LEFT) { - clipPath.reset(); - clipPath.moveTo(x + diffX, y - height); - clipPath.rLineTo(width, 0); - clipPath.rLineTo(CUT_SIZE, height + text.getFontDescent()); - clipPath.rLineTo(-(width + CUT_SIZE), 0); - clipPath.close(); - } else if (side == Side.RIGHT) { - clipPath.reset(); - clipPath.moveTo(x + diffX, y - height); - clipPath.rLineTo(CUT_SIZE, height); - clipPath.rLineTo(width, 0); - clipPath.rLineTo(0, -height); - clipPath.close(); - } - } else { - if (side == Side.LEFT) { - clipPath.reset(); - clipPath.moveTo(x + diffX, y - height); - clipPath.rLineTo(width + CUT_SIZE, 0); - clipPath.rLineTo(0, height + text.getFontDescent()); - clipPath.rLineTo(-width, 0); - clipPath.close(); - } else if (side == Side.RIGHT) { - clipPath.reset(); - clipPath.moveTo(x + diffX, y - height); - clipPath.rLineTo(CUT_SIZE, height); - clipPath.rLineTo(width, 0); - clipPath.rLineTo(0, -height); - clipPath.close(); - } - } - - if (Debug.ENABLED) canvas.drawPath(clipPath, Debug.BLUE_STROKE); - - canvas.translate(0, -(text.getFontDescent())); - canvas.clipPath(clipPath); - } - - @Override public boolean isToShow() { - return toShow; - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - diffX = (float) animation.getAnimatedValue(); - textSurface.invalidate(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.java b/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.java deleted file mode 100644 index 4346386..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.java +++ /dev/null @@ -1,181 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.animation.ValueAnimator; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Region; -import android.os.Build; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; - -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.contants.Side; -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; -import su.levenetc.android.textsurface.interfaces.ITextEffect; - -/** - * Created by Eugene Levenetc. - */ -public class Slide implements ITextEffect, ValueAnimator.AnimatorUpdateListener { - - private Text text; - private int duration; - private int side; - private float xOffset; - private float yOffset; - private TextSurface textSurface; - private boolean toShow; - private ObjectAnimator animator; - - public static Slide showFrom(int side, Text text, int duration) { - return new Slide(side, text, duration, true); - } - - public static Slide hideFrom(int side, Text text, int duration) { - return new Slide(side, text, duration, false); - } - - private Slide(int side, Text text, int duration, boolean toShow) { - this.text = text; - this.side = side; - this.duration = duration; - this.toShow = toShow; - } - - @Override public void setInitValues(@NonNull Text text) { - if (toShow) { - text.setAlpha(0); - } - } - - @NonNull @Override public Text getText() { - return text; - } - - @Override public void onStart() { - text.addEffect(this); - } - - @Override public void start(@Nullable final IEndListener listener) { - - text.setAlpha(255); - - PropertyValuesHolder hHolder = null; - PropertyValuesHolder vHolder = null; - float fromX = 0; - float toX = 0; - float fromY = 0; - float toY = 0; - - if ((side & Side.LEFT) == side) { - - if (toShow) { - fromX = -text.getWidth(); - } else { - toX = -text.getWidth(); - } - - hHolder = PropertyValuesHolder.ofFloat("xOffset", fromX, toX); - } else if ((side & Side.RIGHT) == side) { - - if (toShow) { - fromX = text.getWidth(); - } else { - toX = text.getWidth(); - } - - hHolder = PropertyValuesHolder.ofFloat("xOffset", fromX, toX); - } - - if ((side & Side.TOP) == side) { - - if (toShow) { - fromY = -text.getHeight(); - } else { - toY = -text.getHeight(); - } - - vHolder = PropertyValuesHolder.ofFloat("yOffset", fromY, toY); - } else if ((side & Side.BOTTOM) == side) { - - if (toShow) { - fromY = text.getHeight(); - } else { - toY = text.getHeight(); - } - - vHolder = PropertyValuesHolder.ofFloat("yOffset", fromY, toY); - } - - if (hHolder != null && vHolder != null) { - animator = ObjectAnimator.ofPropertyValuesHolder(this, hHolder, vHolder); - } else if (hHolder != null) { - animator = ObjectAnimator.ofPropertyValuesHolder(this, hHolder); - } else { - animator = ObjectAnimator.ofPropertyValuesHolder(this, vHolder); - } - - animator.setInterpolator(new FastOutSlowInInterpolator()); - Utils.addEndListener(this, animator, new IEndListener() { - @Override public void onAnimationEnd(ISurfaceAnimation animation) { - text.removeEffect(Slide.this); - if (!toShow) text.setAlpha(0); - if (listener != null) listener.onAnimationEnd(Slide.this); - } - }); - animator.setDuration(duration); - animator.addUpdateListener(this); - animator.start(); - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - - @Override public void apply(Canvas canvas, String textValue, float x, float y, Paint paint) { - - float width = this.text.getWidth(); - float height = this.text.getHeight(); - - //canvas.save(); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - canvas.clipRect(x, y - height, width, 0); - }else{ - canvas.clipRect(x, y - height, width, 0, Region.Op.REPLACE); - } - - canvas.translate(xOffset, yOffset - text.getFontDescent()); - //canvas.drawText(textValue, x, y, paint); - //canvas.restore(); - } - - public void setXOffset(float value) { - xOffset = value; - } - - public void setYOffset(float value) { - yOffset = value; - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt new file mode 100644 index 0000000..92ef22a --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt @@ -0,0 +1,148 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Region +import android.os.Build +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Side +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation +import su.levenetc.android.textsurface.interfaces.ITextEffect +import su.levenetc.android.textsurface.utils.Utils + +/** + * Created by Eugene Levenetc. + */ +class Slide private constructor(private val side: Int, override val text: Text, override val duration: Long, private val toShow: Boolean) : ITextEffect, AnimatorUpdateListener { + + private var xOffset = 0f + private var yOffset = 0f + private var animator: ObjectAnimator? = null + override lateinit var textSurface: TextSurface + + override fun setInitValues(text: Text) { + if (toShow) { + text.setAlpha(0) + } + } + + override fun onStart() { + text.addEffect(this) + } + + override fun start(listener: IEndListener) { + text.setAlpha(255) + var hHolder: PropertyValuesHolder? = null + var vHolder: PropertyValuesHolder? = null + var fromX = 0f + var toX = 0f + var fromY = 0f + var toY = 0f + if (side and Side.LEFT == side) { + if (toShow) { + fromX = -text.width + } else { + toX = -text.width + } + hHolder = PropertyValuesHolder.ofFloat("xOffset", fromX, toX) + } else if (side and Side.RIGHT == side) { + if (toShow) { + fromX = text.width + } else { + toX = text.width + } + hHolder = PropertyValuesHolder.ofFloat("xOffset", fromX, toX) + } + if (side and Side.TOP == side) { + if (toShow) { + fromY = -text.height + } else { + toY = -text.height + } + vHolder = PropertyValuesHolder.ofFloat("yOffset", fromY, toY) + } else if (side and Side.BOTTOM == side) { + if (toShow) { + fromY = text.height + } else { + toY = text.height + } + vHolder = PropertyValuesHolder.ofFloat("yOffset", fromY, toY) + } + animator = if (hHolder != null && vHolder != null) { + ObjectAnimator.ofPropertyValuesHolder(this, hHolder, vHolder) + } else if (hHolder != null) { + ObjectAnimator.ofPropertyValuesHolder(this, hHolder) + } else { + ObjectAnimator.ofPropertyValuesHolder(this, vHolder) + } + + animator?.run { + this.interpolator = FastOutSlowInInterpolator() + Utils.addEndListener(this@Slide, this, object : IEndListener { + override fun onAnimationEnd(animation: ISurfaceAnimation) { + text.removeEffect(this@Slide) + if (!toShow) text.setAlpha(0) + listener.onAnimationEnd(this@Slide) + } + }) + this.duration = duration + this.addUpdateListener(this@Slide) + this.start() + } + + + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + override fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) { + val width = text.width + val height = text.height + + //canvas.save(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + canvas.clipRect(x, y - height, width, 0f) + } else { + canvas.clipRect(x, y - height, width, 0f, Region.Op.REPLACE) + } + canvas.translate(xOffset, yOffset - text.fontDescent) + //canvas.drawText(textValue, x, y, paint); + //canvas.restore(); + } + + fun setXOffset(value: Float) { + xOffset = value + } + + fun setYOffset(value: Float) { + yOffset = value + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface!!.invalidate() + } + + companion object { + @JvmStatic + fun showFrom(side: Int, text: Text, duration: Long): Slide { + return Slide(side, text, duration, true) + } + + @JvmStatic + fun hideFrom(side: Int, text: Text, duration: Long): Slide { + return Slide(side, text, duration, false) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.java b/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.java deleted file mode 100644 index 3735a0f..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.java +++ /dev/null @@ -1,121 +0,0 @@ -package su.levenetc.android.textsurface.animations; - -import android.animation.ObjectAnimator; -import android.animation.PropertyValuesHolder; -import android.animation.ValueAnimator; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.interpolator.view.animation.FastOutSlowInInterpolator; -import android.util.Log; - -import su.levenetc.android.textsurface.Debug; -import su.levenetc.android.textsurface.SurfaceCamera; -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.contants.Pivot; -import su.levenetc.android.textsurface.utils.Utils; -import su.levenetc.android.textsurface.interfaces.ICameraAnimation; -import su.levenetc.android.textsurface.interfaces.IEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class TransSurface implements ICameraAnimation, ValueAnimator.AnimatorUpdateListener { - - public float dx; - public float dy; - private int duration; - private Text textPivot; - private int pivot; - private TextSurface textSurface; - private SurfaceCamera camera; - private ObjectAnimator animator; - - public static TransSurface toCenter(Text textPivot, int duration){ - return new TransSurface(duration, textPivot, Pivot.CENTER); - } - - public TransSurface(int duration, Text textPivot, int pivot) { - this.duration = duration; - this.textPivot = textPivot; - this.pivot = pivot; - } - - public TransSurface(int duration, Text textPivot) { - this.duration = duration; - this.textPivot = textPivot; - } - - public TransSurface(int duration, float dx, float dy) { - this.duration = duration; - this.dx = dx; - this.dy = dy; - } - - @Override public void onStart() { - - } - - @Override public void start(@Nullable final IEndListener listener) { - - float fromX = camera.getTransX(); - float fromY = camera.getTransY(); - - float toX; - float toY; - - if (textPivot == null) { - toX = camera.getTransX() + dx; - toY = camera.getTransY() + dy; - } else { - toX = textPivot.getPosition().getRelativeX(pivot, textPivot, true) * camera.getScale() * -1; - toY = textPivot.getPosition().getRelativeY(pivot, textPivot, true) * camera.getScale() * -1; - } - - debugTranslation(fromX, fromY, toX, toY); - - PropertyValuesHolder dxHolder = PropertyValuesHolder.ofFloat("transX", fromX, toX); - PropertyValuesHolder dyHolder = PropertyValuesHolder.ofFloat("transY", fromY, toY); - - animator = ObjectAnimator.ofPropertyValuesHolder(camera, dxHolder, dyHolder); - animator.setInterpolator(new FastOutSlowInInterpolator()); - Utils.addEndListener(this, animator, listener); - animator.setDuration(duration); - animator.addUpdateListener(this); - animator.start(); - } - - private void debugTranslation(float fromX, float fromY, float toX, float toY) { - if (Debug.ENABLED && fromX == toX && fromY == toY) - Log.e(getClass().getSimpleName(), "No translation to " + textPivot + " from:" + fromX + ":" + fromY + " to:" + toX + ":" + toY); - } - - @Override public void setTextSurface(@NonNull TextSurface textSurface) { - this.textSurface = textSurface; - } - - @Override public long getDuration() { - return duration; - } - - @Override public void cancel() { - if (animator != null && animator.isRunning()) { - animator.cancel(); - animator = null; - } - } - - @Override public void onAnimationUpdate(ValueAnimator animation) { - textSurface.invalidate(); - } - - @Override public void setCamera(SurfaceCamera camera) { - this.camera = camera; - } - - @Override public String toString() { - return "TransSurface{" + - "textPivot=" + ((textPivot == null) ? "null" : textPivot.toString()) + - '}'; - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt new file mode 100644 index 0000000..70e470a --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt @@ -0,0 +1,107 @@ +package su.levenetc.android.textsurface.animations + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.annotation.SuppressLint +import android.util.Log +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Debug +import su.levenetc.android.textsurface.SurfaceCamera +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.interfaces.ICameraAnimation +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.utils.Utils.addEndListener + +/** + * Created by Eugene Levenetc. + */ +class TransSurface : ICameraAnimation, AnimatorUpdateListener { + var dx = 0f + var dy = 0f + + override val duration: Long + private var textPivot: Text? = null + private var pivot = 0 + private var camera: SurfaceCamera? = null + private var animator: ObjectAnimator? = null + override lateinit var textSurface: TextSurface + + constructor(duration: Long, textPivot: Text?, pivot: Int) { + this.duration = duration + this.textPivot = textPivot + this.pivot = pivot + } + + constructor(duration: Long, textPivot: Text?) { + this.duration = duration + this.textPivot = textPivot + } + + constructor(duration: Long, dx: Float, dy: Float) { + this.duration = duration + this.dx = dx + this.dy = dy + } + + override fun onStart() {} + + @SuppressLint("ObjectAnimatorBinding") + override fun start(listener: IEndListener) { + val fromX = camera!!.transX + val fromY = camera!!.transY + val toX: Float + val toY: Float + if (textPivot == null) { + toX = camera!!.transX + dx + toY = camera!!.transY + dy + } else { + toX = textPivot!!.position.getRelativeX(pivot, textPivot, true) * camera!!.getScale() * -1 + toY = textPivot!!.position.getRelativeY(pivot, textPivot, true) * camera!!.getScale() * -1 + } + debugTranslation(fromX, fromY, toX, toY) + val dxHolder = PropertyValuesHolder.ofFloat("transX", fromX, toX) + val dyHolder = PropertyValuesHolder.ofFloat("transY", fromY, toY) + animator = ObjectAnimator.ofPropertyValuesHolder(camera, dxHolder, dyHolder) + animator!!.interpolator = FastOutSlowInInterpolator() + addEndListener(this, animator!!, listener) + animator!!.duration = duration.toLong() + animator!!.addUpdateListener(this) + animator!!.start() + } + + private fun debugTranslation(fromX: Float, fromY: Float, toX: Float, toY: Float) { + if (Debug.ENABLED && fromX == toX && fromY == toY) Log.e(javaClass.simpleName, "No translation to $textPivot from:$fromX:$fromY to:$toX:$toY") + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface!!.invalidate() + } + + override fun setCamera(camera: SurfaceCamera?) { + this.camera = camera + } + + override fun toString(): String { + return "TransSurface{" + + "textPivot=" + (if (textPivot == null) "null" else textPivot.toString()) + + '}' + } + + companion object { + @kotlin.jvm.JvmStatic + fun toCenter(textPivot: Text?, duration: Long): TransSurface { + return TransSurface(duration, textPivot, Pivot.CENTER) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt new file mode 100644 index 0000000..0719049 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt @@ -0,0 +1,115 @@ +package su.levenetc.android.textsurface.animations.reveal + +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Path +import android.graphics.Region +import su.levenetc.android.textsurface.Debug +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Direction +import su.levenetc.android.textsurface.contants.Side + +/** + * Created by Eugene Levenetc. + */ +class Circle private constructor(override val isToShow: Boolean, private val side: Int, private val direction: Int) : IRevealShape, AnimatorUpdateListener { + private var radius = 0f + private var text: Text? = null + private val clipPath = Path() + private var animator: ValueAnimator? = null + override lateinit var textSurface: TextSurface + private var circX = 0f + private var circY = 0f + private var clipOp = Region.Op.INTERSECT + + override fun setText(text: Text?) { + this.text = text + } + + override fun getAnimator(): ValueAnimator? { + val width = text!!.width + val height = text!!.height + val textX = text!!.getX(textSurface) + val textY = text!!.getY(textSurface) + var toRad = 0f + var fromRad = 0f + val cathA: Float + val cathB: Float + if (side == Side.CENTER) { + circX = width / 2 + circY = -(height / 2) + cathA = width / 2 + cathB = height / 2 + } else { + if (side and Side.LEFT == Side.LEFT) { + circX = 0f + } else if (side and Side.RIGHT == Side.RIGHT) { + circX = width + } + if (side and Side.TOP == Side.TOP) { + circY = -height + } else if (side and Side.BOTTOM == Side.BOTTOM) { + circY = 0f + } + cathA = width + cathB = height + } + val hypo = Math.sqrt((cathA * cathA + cathB * cathB).toDouble()).toFloat() + if (isToShow) { + if (direction == Direction.OUT) { + toRad = hypo + } else { + clipOp = Region.Op.DIFFERENCE + fromRad = hypo + } + } else { + if (direction == Direction.OUT) { + clipOp = Region.Op.DIFFERENCE + toRad = hypo + } else { + fromRad = hypo + } + } + animator = ValueAnimator.ofFloat(fromRad, toRad) + animator!!.addUpdateListener(this) + return animator + } + + override fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint?) { + clipPath.reset() + clipPath.addCircle(circX, circY, radius, Path.Direction.CCW) + if (Debug.ENABLED) { + canvas.drawPath(clipPath, Debug.BLUE_STROKE!!) + canvas.drawCircle(circX, circY, 10f, Debug.RED_FILL!!) + } + canvas.translate(0f, -text!!.fontDescent) + canvas.clipPath(clipPath, clipOp) + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + radius = animation.animatedValue as Float + textSurface!!.invalidate() + } + + companion object { + /** + * @param side [Side] + * @param direction [Direction] Direction.IN or Direction.OUT + */ + @kotlin.jvm.JvmStatic + fun show(side: Int, direction: Int): Circle { + return Circle(true, side, direction) + } + + /** + * @param side [Side] + * @param direction [Direction] Direction.IN or Direction.OUT + */ + fun hide(side: Int, direction: Int): Circle { + return Circle(false, side, direction) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt new file mode 100644 index 0000000..04d014d --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt @@ -0,0 +1,17 @@ +package su.levenetc.android.textsurface.animations.reveal + +import android.animation.ValueAnimator +import android.graphics.Canvas +import android.graphics.Paint +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface + +interface IRevealShape { + + val isToShow: Boolean + var textSurface: TextSurface + + fun setText(text: Text?) + fun getAnimator(): ValueAnimator? + fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint?) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt new file mode 100644 index 0000000..731d22a --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt @@ -0,0 +1,72 @@ +package su.levenetc.android.textsurface.animations.reveal + +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.graphics.Canvas +import android.graphics.Paint +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation +import su.levenetc.android.textsurface.interfaces.ITextEffect +import su.levenetc.android.textsurface.utils.Utils.addEndListener + +/** + * Created by Eugene Levenetc. + */ +class ShapeReveal private constructor(override val text: Text, override var duration: Long, private val revealShape: IRevealShape, private val hideOnEnd: Boolean) : ITextEffect, AnimatorUpdateListener { + + init { + revealShape.setText(text) + } + + override lateinit var textSurface: TextSurface + private var animator: ValueAnimator? = null + override fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) { + revealShape.clip(canvas, textValue, x, y, paint) + } + + override fun setInitValues(text: Text) { + if (revealShape.isToShow) text.setAlpha(0) + } + + override fun onStart() { + text.addEffect(this) + } + + override fun start(listener: IEndListener) { + text.setAlpha(255) + revealShape.textSurface = textSurface + animator = revealShape.getAnimator() + animator!!.interpolator = FastOutSlowInInterpolator() + addEndListener(this, animator!!, object : IEndListener { + override fun onAnimationEnd(animation: ISurfaceAnimation) { + text.removeEffect(this@ShapeReveal) + if (hideOnEnd) text.setAlpha(0) + listener?.onAnimationEnd(this@ShapeReveal) + } + }) + animator!!.duration = duration + animator!!.start() + } + + override fun cancel() { + if (animator != null && animator!!.isRunning) { + animator!!.cancel() + animator = null + } + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface!!.invalidate() + } + + + companion object { + @kotlin.jvm.JvmStatic + fun create(text: Text, duration: Long, revealShape: IRevealShape, hideOnEnd: Boolean): ShapeReveal { + return ShapeReveal(text, duration, revealShape, hideOnEnd) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt new file mode 100644 index 0000000..1fad7bc --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt @@ -0,0 +1,112 @@ +package su.levenetc.android.textsurface.animations.reveal + +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.graphics.Canvas +import android.graphics.Paint +import android.graphics.Path +import su.levenetc.android.textsurface.Debug +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Side +import su.levenetc.android.textsurface.utils.Utils.dpToPx + +/** + * Created by Eugene Levenetc. + */ +class SideCut private constructor(override val isToShow: Boolean, private val side: Int) : IRevealShape, AnimatorUpdateListener { + private var diffX = 0f + private var text: Text? = null + private val clipPath = Path() + private var animator: ValueAnimator? = null + override lateinit var textSurface: TextSurface + + override fun setText(text: Text?) { + this.text = text + } + + override fun getAnimator(): ValueAnimator? { + val width = text!!.width + var toX = 0f + var fromX = 0f + if (isToShow) { + if (side == Side.LEFT) { + fromX = -(width + CUT_SIZE) + } else if (side == Side.RIGHT) { + fromX = width + toX = -CUT_SIZE + } + } else { + if (side == Side.LEFT) { + fromX = -CUT_SIZE + toX = width + } else if (side == Side.RIGHT) { + fromX = width + toX = -CUT_SIZE + } + } + animator = ValueAnimator.ofFloat(fromX, toX) + animator!!.addUpdateListener(this) + return animator + } + + override fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint?) { + val width = text!!.width + val height = text!!.height + if (isToShow) { + if (side == Side.LEFT) { + clipPath.reset() + clipPath.moveTo(x + diffX, y - height) + clipPath.rLineTo(width, 0f) + clipPath.rLineTo(CUT_SIZE, height + text!!.fontDescent) + clipPath.rLineTo(-(width + CUT_SIZE), 0f) + clipPath.close() + } else if (side == Side.RIGHT) { + clipPath.reset() + clipPath.moveTo(x + diffX, y - height) + clipPath.rLineTo(CUT_SIZE, height) + clipPath.rLineTo(width, 0f) + clipPath.rLineTo(0f, -height) + clipPath.close() + } + } else { + if (side == Side.LEFT) { + clipPath.reset() + clipPath.moveTo(x + diffX, y - height) + clipPath.rLineTo(width + CUT_SIZE, 0f) + clipPath.rLineTo(0f, height + text!!.fontDescent) + clipPath.rLineTo(-width, 0f) + clipPath.close() + } else if (side == Side.RIGHT) { + clipPath.reset() + clipPath.moveTo(x + diffX, y - height) + clipPath.rLineTo(CUT_SIZE, height) + clipPath.rLineTo(width, 0f) + clipPath.rLineTo(0f, -height) + clipPath.close() + } + } + if (Debug.ENABLED) canvas.drawPath(clipPath, Debug.BLUE_STROKE!!) + canvas.translate(0f, -text!!.fontDescent) + canvas.clipPath(clipPath) + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + diffX = animation.animatedValue as Float + textSurface!!.invalidate() + } + + companion object { + private val CUT_SIZE = dpToPx(20f) + + @kotlin.jvm.JvmStatic + fun show(side: Int): SideCut { + return SideCut(true, side) + } + + @kotlin.jvm.JvmStatic + fun hide(side: Int): SideCut { + return SideCut(false, side) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/common/Position.java b/library/src/main/java/su/levenetc/android/textsurface/common/Position.java deleted file mode 100644 index ecc7d54..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/common/Position.java +++ /dev/null @@ -1,154 +0,0 @@ -package su.levenetc.android.textsurface.common; - -import android.graphics.PointF; - -import su.levenetc.android.textsurface.Text; -import su.levenetc.android.textsurface.TextSurface; -import su.levenetc.android.textsurface.contants.Align; -import su.levenetc.android.textsurface.contants.Pivot; - -/** - * Created by Eugene Levenetc. - */ -public class Position { - - private int align; - private Text alignText; - private PointF point = new PointF(); - private float translationX; - private float translationY; - - public Position() { - point = new PointF(); - } - - public Position(Position src) { - align = src.align; - alignText = src.alignText; - point.set(src.point); - translationX = src.translationX; - translationY = src.translationY; - } - - public Position(PointF point) { - this.point = point; - } - - public Position(int align) { - this.align = align; - } - - public Position(int align, Text alignText) { - this.align = align; - this.alignText = alignText; - } - - public void set(Position src) { - align = src.align; - alignText = src.alignText; - point.set(src.point); - translationX = src.translationX; - translationY = src.translationY; - } - - public PointF getPoint() { - return point; - } - - public float getRelativeX(int pivot, Text text, boolean global) { - float result = 0; - - if ((pivot & Pivot.LEFT) == Pivot.LEFT) { -// result = point.x; - } else if ((pivot & Pivot.RIGHT) == Pivot.RIGHT) { - result += text.getWidth(); - } else if ((pivot & Pivot.CENTER) == Pivot.CENTER) { - result += text.getWidth() / 2; - } - - return global ? (result + point.x + translationX) : result; - } - - public float getRelativeY(int pivot, Text text, boolean global) { - float result = 0; - - - if ((pivot & Pivot.BOTTOM) == Pivot.BOTTOM) { - //result = text.getY(textSurface); - } else if ((pivot & Pivot.TOP) == Pivot.TOP) { - result -= text.getHeight(); - } else if ((pivot & Pivot.CENTER) == Pivot.CENTER) { - result -= text.getHeight() / 2; - } - - return global ? (result + point.y + translationY) : result; - } - - public float getX(TextSurface textSurface, float textWidth) { - - - if (isAligned()) { - - if (alignedWith(Align.SURFACE_CENTER)) { - point.x = -textWidth / 2; - } else if (alignedWith(Align.RIGHT_OF)) { - point.x = alignText.getX(textSurface) + alignText.getWidth(); - } else if (alignedWith(Align.LEFT_OF)) { - point.x = alignText.getX(textSurface) - textWidth; - } else if (alignedWith(Align.CENTER_OF)) { - point.x = alignText.getX(textSurface) + (alignText.getWidth() - textWidth) / 2; - } else { - point.x = alignText.getX(textSurface); - } - } - - return point.x + translationX; - } - - private boolean alignedWith(int align) { - return (this.align & align) == align; - } - - public float getY(TextSurface textSurface, float textHeight) { - - if (isAligned()) { - if (alignedWith(Align.SURFACE_CENTER)) { - point.y = textHeight / 2; - } else if (alignedWith(Align.TOP_OF)) { - point.y = alignText.getY(textSurface) - alignText.getHeight(); - } else if (alignedWith(Align.BOTTOM_OF)) { - point.y = alignText.getY(textSurface) + textHeight; - } else if (alignedWith(Align.CENTER_OF)) { - point.y = alignText.getY(textSurface) - (alignText.getHeight() - textHeight) / 2; - } else { - point.y = alignText.getY(textSurface); - } - } - - return point.y + translationY; - } - - public boolean isAligned() { - return align != 0; - } - - public void setY(float y) { - if (point != null) point.y = y; - } - - public void setX(float x) { - if (point != null) point.x = x; - } - - public void setTranslationX(float x) { - translationX = x; - } - - public void setTranslationY(float y) { - translationY = y; - } - - public void onAnimationEnd() { - - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt b/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt new file mode 100644 index 0000000..607fbf0 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt @@ -0,0 +1,135 @@ +package su.levenetc.android.textsurface.common + +import android.graphics.PointF +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Pivot + +/** + * Created by Eugene Levenetc. + */ +class Position { + private var align = 0 + private var alignText: Text? = null + var point: PointF? = PointF() + private set + private var translationX = 0f + private var translationY = 0f + + constructor() { + point = PointF() + } + + constructor(src: Position) { + align = src.align + alignText = src.alignText + point!!.set(src.point!!) + translationX = src.translationX + translationY = src.translationY + } + + constructor(point: PointF?) { + this.point = point + } + + constructor(align: Int) { + this.align = align + } + + constructor(align: Int, alignText: Text?) { + this.align = align + this.alignText = alignText + } + + fun set(src: Position) { + align = src.align + alignText = src.alignText + point!!.set(src.point!!) + translationX = src.translationX + translationY = src.translationY + } + + fun getRelativeX(pivot: Int, text: Text?, global: Boolean): Float { + var result = 0f + if (pivot and Pivot.LEFT == Pivot.LEFT) { +// result = point.x; + } else if (pivot and Pivot.RIGHT == Pivot.RIGHT) { + result += text!!.width + } else if (pivot and Pivot.CENTER == Pivot.CENTER) { + result += text!!.width / 2 + } + return if (global) result + point!!.x + translationX else result + } + + fun getRelativeY(pivot: Int, text: Text?, global: Boolean): Float { + var result = 0f + if (pivot and Pivot.BOTTOM == Pivot.BOTTOM) { + //result = text.getY(textSurface); + } else if (pivot and Pivot.TOP == Pivot.TOP) { + result -= text!!.height + } else if (pivot and Pivot.CENTER == Pivot.CENTER) { + result -= text!!.height / 2 + } + return if (global) result + point!!.y + translationY else result + } + + fun getX(textSurface: TextSurface?, textWidth: Float): Float { + if (isAligned) { + if (alignedWith(Align.SURFACE_CENTER)) { + point!!.x = -textWidth / 2 + } else if (alignedWith(Align.RIGHT_OF)) { + point!!.x = alignText!!.getX(textSurface) + alignText!!.width + } else if (alignedWith(Align.LEFT_OF)) { + point!!.x = alignText!!.getX(textSurface) - textWidth + } else if (alignedWith(Align.CENTER_OF)) { + point!!.x = alignText!!.getX(textSurface) + (alignText!!.width - textWidth) / 2 + } else { + point!!.x = alignText!!.getX(textSurface) + } + } + return point!!.x + translationX + } + + private fun alignedWith(align: Int): Boolean { + return this.align and align == align + } + + fun getY(textSurface: TextSurface?, textHeight: Float): Float { + if (isAligned) { + if (alignedWith(Align.SURFACE_CENTER)) { + point!!.y = textHeight / 2 + } else if (alignedWith(Align.TOP_OF)) { + point!!.y = alignText!!.getY(textSurface) - alignText!!.height + } else if (alignedWith(Align.BOTTOM_OF)) { + point!!.y = alignText!!.getY(textSurface) + textHeight + } else if (alignedWith(Align.CENTER_OF)) { + point!!.y = alignText!!.getY(textSurface) - (alignText!!.height - textHeight) / 2 + } else { + point!!.y = alignText!!.getY(textSurface) + } + } + return point!!.y + translationY + } + + val isAligned: Boolean + get() = align != 0 + + fun setY(y: Float) { + if (point != null) point!!.y = y + } + + fun setX(x: Float) { + if (point != null) point!!.x = x + } + + fun setTranslationX(x: Float) { + translationX = x + } + + fun setTranslationY(y: Float) { + translationY = y + } + + fun onAnimationEnd() {} +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.java b/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.java deleted file mode 100644 index 061a6b3..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.java +++ /dev/null @@ -1,41 +0,0 @@ -package su.levenetc.android.textsurface.common; - -import android.graphics.PointF; - -/** - * Created by Eugene Levenetc. - */ -public class ScaleValue { - - private PointF scale = new PointF(1, 1); - private PointF pivot = new PointF(); - - public void setValue(float scale) { - this.scale.set(scale, scale); - } - - public void setValueX(float x) { - scale.set(x, scale.y); - } - - public void setValueY(float y) { - scale.set(scale.x, y); - } - - public float getScaleX() { - return scale.x; - } - - public float getScaleY() { - return scale.y; - } - - public PointF getPivot() { - return pivot; - } - - public void reset() { - scale.set(1, 1); - pivot.set(0, 0); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt b/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt new file mode 100644 index 0000000..42c6157 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt @@ -0,0 +1,32 @@ +package su.levenetc.android.textsurface.common + +import android.graphics.PointF + +/** + * Created by Eugene Levenetc. + */ +class ScaleValue { + private val scale = PointF(1f, 1f) + val pivot = PointF() + fun setValue(scale: Float) { + this.scale[scale] = scale + } + + fun setValueX(x: Float) { + scale[x] = scale.y + } + + fun setValueY(y: Float) { + scale[scale.x] = y + } + + val scaleX: Float + get() = scale.x + val scaleY: Float + get() = scale.y + + fun reset() { + scale[1f] = 1f + pivot[0f] = 0f + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Align.java b/library/src/main/java/su/levenetc/android/textsurface/contants/Align.java deleted file mode 100644 index 9ead589..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Align.java +++ /dev/null @@ -1,13 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public class Align { - public static int RIGHT_OF = 2; - public static int LEFT_OF = 4; - public static int TOP_OF = 16; - public static int BOTTOM_OF = 32; - public static int CENTER_OF = 64; - public static int SURFACE_CENTER = 128; -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt new file mode 100644 index 0000000..21621b0 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt @@ -0,0 +1,24 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +object Align { + @kotlin.jvm.JvmField + var RIGHT_OF = 2 + + @kotlin.jvm.JvmField + var LEFT_OF = 4 + + @kotlin.jvm.JvmField + var TOP_OF = 16 + + @kotlin.jvm.JvmField + var BOTTOM_OF = 32 + + @kotlin.jvm.JvmField + var CENTER_OF = 64 + + @kotlin.jvm.JvmField + var SURFACE_CENTER = 128 +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.java b/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.java deleted file mode 100644 index 650c707..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.java +++ /dev/null @@ -1,10 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public class Axis { - public static final int X = 1; - public static final int Y = 2; - public static final int Z = 4; -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt new file mode 100644 index 0000000..82c7be0 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt @@ -0,0 +1,10 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +object Axis { + const val X = 1 + const val Y = 2 + const val Z = 4 +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.java b/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.java deleted file mode 100644 index a2ba9de..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.java +++ /dev/null @@ -1,11 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public class Direction { - public static int CLOCK = 1; - public static int COUNTER_CLOCK = 2; - public static int IN = 4; - public static int OUT = 16; -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt new file mode 100644 index 0000000..9f50a63 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt @@ -0,0 +1,14 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +object Direction { + @kotlin.jvm.JvmField + var CLOCK = 1 + var COUNTER_CLOCK = 2 + var IN = 4 + + @kotlin.jvm.JvmField + var OUT = 16 +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.java b/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.java deleted file mode 100644 index b2373ab..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.java +++ /dev/null @@ -1,9 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public class Fit { - public static int WIDTH = 2; - public static int HEIGTH = 4; -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt new file mode 100644 index 0000000..529912b --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt @@ -0,0 +1,10 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +object Fit { + @kotlin.jvm.JvmField + var WIDTH = 2 + var HEIGTH = 4 +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.java b/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.java deleted file mode 100644 index e97a8f2..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.java +++ /dev/null @@ -1,12 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public class Pivot { - public static final int TOP = 1; - public static final int BOTTOM = 2; - public static final int LEFT = 4; - public static final int RIGHT = 16; - public static final int CENTER = 32; -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt new file mode 100644 index 0000000..29e908e --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt @@ -0,0 +1,12 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +object Pivot { + const val TOP = 1 + const val BOTTOM = 2 + const val LEFT = 4 + const val RIGHT = 16 + const val CENTER = 32 +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Side.java b/library/src/main/java/su/levenetc/android/textsurface/contants/Side.java deleted file mode 100644 index dd04d2d..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Side.java +++ /dev/null @@ -1,12 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public class Side { - public static final int LEFT = 1; - public static final int RIGHT = 2; - public static final int TOP = 4; - public static final int BOTTOM = 16; - public static final int CENTER = 64; -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Side.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Side.kt new file mode 100644 index 0000000..b43b3d5 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Side.kt @@ -0,0 +1,12 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +object Side { + const val LEFT = 1 + const val RIGHT = 2 + const val TOP = 4 + const val BOTTOM = 16 + const val CENTER = 64 +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.java b/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.java deleted file mode 100644 index 2b90cde..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.java +++ /dev/null @@ -1,8 +0,0 @@ -package su.levenetc.android.textsurface.contants; - -/** - * Created by Eugene Levenetc. - */ -public enum TYPE { - SEQUENTIAL, PARALLEL -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt new file mode 100644 index 0000000..42b725b --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt @@ -0,0 +1,8 @@ +package su.levenetc.android.textsurface.contants + +/** + * Created by Eugene Levenetc. + */ +enum class TYPE { + SEQUENTIAL, PARALLEL +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.java b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.java deleted file mode 100644 index 98259a7..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.java +++ /dev/null @@ -1,10 +0,0 @@ -package su.levenetc.android.textsurface.interfaces; - -import su.levenetc.android.textsurface.SurfaceCamera; - -/** - * Created by Eugene Levenetc. - */ -public interface ICameraAnimation extends ISurfaceAnimation { - void setCamera(SurfaceCamera camera); -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt new file mode 100644 index 0000000..f46ce46 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt @@ -0,0 +1,10 @@ +package su.levenetc.android.textsurface.interfaces + +import su.levenetc.android.textsurface.SurfaceCamera + +/** + * Created by Eugene Levenetc. + */ +interface ICameraAnimation : ISurfaceAnimation { + fun setCamera(camera: SurfaceCamera?) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.java b/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.java deleted file mode 100644 index 41a6576..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package su.levenetc.android.textsurface.interfaces; - -/** - * Created by Eugene Levenetc. - */ -public interface IEndListener { - void onAnimationEnd(ISurfaceAnimation animation); -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt new file mode 100644 index 0000000..6352de1 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt @@ -0,0 +1,8 @@ +package su.levenetc.android.textsurface.interfaces + +/** + * Created by Eugene Levenetc. + */ +interface IEndListener { + fun onAnimationEnd(animation: ISurfaceAnimation) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.java b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.java deleted file mode 100644 index dd1c518..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.java +++ /dev/null @@ -1,14 +0,0 @@ -package su.levenetc.android.textsurface.interfaces; - -import java.util.LinkedList; - -import su.levenetc.android.textsurface.contants.TYPE; - -/** - * Created by Eugene Levenetc. - */ -public interface ISet extends ISurfaceAnimation { - TYPE getType(); - - LinkedList getAnimations(); -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt new file mode 100644 index 0000000..39f65d4 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt @@ -0,0 +1,12 @@ +package su.levenetc.android.textsurface.interfaces + +import su.levenetc.android.textsurface.contants.TYPE +import java.util.* + +/** + * Created by Eugene Levenetc. + */ +interface ISet : ISurfaceAnimation { + val type: TYPE + val animations: LinkedList +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.java b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.java deleted file mode 100644 index 40d6faa..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.java +++ /dev/null @@ -1,23 +0,0 @@ -package su.levenetc.android.textsurface.interfaces; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import su.levenetc.android.textsurface.TextSurface; - -/** - * Created by Eugene Levenetc. - */ -public interface ISurfaceAnimation { - - void onStart(); - - void start(@Nullable IEndListener listener); - - void setTextSurface(@NonNull TextSurface textSurface); - - long getDuration(); - - void cancel(); - -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt new file mode 100644 index 0000000..2c52071 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt @@ -0,0 +1,16 @@ +package su.levenetc.android.textsurface.interfaces + +import su.levenetc.android.textsurface.TextSurface + +/** + * Created by Eugene Levenetc. + */ +interface ISurfaceAnimation { + + val duration: Long + var textSurface: TextSurface + + fun onStart() + fun start(listener: IEndListener) + fun cancel() +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.java b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.java deleted file mode 100644 index 51dd9c1..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.java +++ /dev/null @@ -1,11 +0,0 @@ -package su.levenetc.android.textsurface.interfaces; - -import android.graphics.Canvas; -import android.graphics.Paint; - -/** - * Created by Eugene Levenetc. - */ -public interface ITextEffect extends ITextSurfaceAnimation { - void apply(Canvas canvas, String textValue, float x, float y, Paint paint); -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt new file mode 100644 index 0000000..36a4723 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt @@ -0,0 +1,11 @@ +package su.levenetc.android.textsurface.interfaces + +import android.graphics.Canvas +import android.graphics.Paint + +/** + * Created by Eugene Levenetc. + */ +interface ITextEffect : ITextSurfaceAnimation { + fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.java b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.java deleted file mode 100644 index 56c3574..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.java +++ /dev/null @@ -1,16 +0,0 @@ -package su.levenetc.android.textsurface.interfaces; - -import androidx.annotation.NonNull; - -import su.levenetc.android.textsurface.Text; - -/** - * Created by Eugene Levenetc. - */ -public interface ITextSurfaceAnimation extends ISurfaceAnimation { - - void setInitValues(@NonNull Text text); - - Text getText(); - -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt new file mode 100644 index 0000000..bc89bc8 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt @@ -0,0 +1,11 @@ +package su.levenetc.android.textsurface.interfaces + +import su.levenetc.android.textsurface.Text + +/** + * Created by Eugene Levenetc. + */ +interface ITextSurfaceAnimation : ISurfaceAnimation { + val text: Text + fun setInitValues(text: Text) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.java b/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.java deleted file mode 100644 index 593f8b8..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.java +++ /dev/null @@ -1,25 +0,0 @@ -package su.levenetc.android.textsurface.utils; - -import android.animation.Animator; - -/** - * Created by Eugene Levenetc. - */ -public abstract class AnimatorEndListener implements Animator.AnimatorListener { - - @Override public void onAnimationStart(Animator animation) { - - } - - @Override public void onAnimationEnd(Animator animation) { - - } - - @Override public void onAnimationCancel(Animator animation) { - - } - - @Override public void onAnimationRepeat(Animator animation) { - - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt new file mode 100644 index 0000000..e7c8d77 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt @@ -0,0 +1,14 @@ +package su.levenetc.android.textsurface.utils + +import android.animation.Animator +import android.animation.Animator.AnimatorListener + +/** + * Created by Eugene Levenetc. + */ +abstract class AnimatorEndListener : AnimatorListener { + override fun onAnimationStart(animation: Animator) {} + override fun onAnimationEnd(animation: Animator) {} + override fun onAnimationCancel(animation: Animator) {} + override fun onAnimationRepeat(animation: Animator) {} +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.java b/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.java deleted file mode 100644 index bf9a16c..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.java +++ /dev/null @@ -1,48 +0,0 @@ -package su.levenetc.android.textsurface.utils; - -import android.animation.Animator; -import android.content.res.Resources; -import android.util.DisplayMetrics; - -import java.util.Arrays; - -import su.levenetc.android.textsurface.interfaces.IEndListener; -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation; -import su.levenetc.android.textsurface.utils.AnimatorEndListener; - -/** - * Created by Eugene Levenetc. - */ -public class Utils { - - /** - * Generates string of "`" char - * Not effective on large sizes - */ - public static String genString(int size) { - char[] array = new char[size]; - Arrays.fill(array, '\''); - return String.valueOf(array); - } - - - public static T[] concat(T[] first, T[] second) { - T[] result = Arrays.copyOf(first, first.length + second.length); - System.arraycopy(second, 0, result, first.length, second.length); - return result; - } - - public static void addEndListener(final ISurfaceAnimation animation, Animator animator, final IEndListener listener) { - if (listener == null) return; - animator.addListener(new AnimatorEndListener() { - @Override public void onAnimationEnd(Animator a) { - listener.onAnimationEnd(animation); - } - }); - } - - public static float dpToPx(float dp) { - DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics(); - return dp * (metrics.densityDpi / 160f); - } -} diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt new file mode 100644 index 0000000..1d730dd --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt @@ -0,0 +1,44 @@ +package su.levenetc.android.textsurface.utils + +import android.animation.Animator +import android.content.res.Resources +import su.levenetc.android.textsurface.interfaces.IEndListener +import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation +import java.util.* + +/** + * Created by Eugene Levenetc. + */ +object Utils { + /** + * Generates string of "`" char + * Not effective on large sizes + */ + fun genString(size: Int): String { + val array = CharArray(size) + Arrays.fill(array, '\'') + return String(array) + } + + fun concat(first: Array, second: Array): Array { + val result = Arrays.copyOf(first, first.size + second.size) + System.arraycopy(second, 0, result, first.size, second.size) + return result + } + + @JvmStatic + fun addEndListener(animation: ISurfaceAnimation, animator: Animator, listener: IEndListener? = null) { + if (listener == null) return + animator.addListener(object : AnimatorEndListener() { + override fun onAnimationEnd(a: Animator) { + listener.onAnimationEnd(animation) + } + }) + } + + @JvmStatic + fun dpToPx(dp: Float): Float { + val metrics = Resources.getSystem().displayMetrics + return dp * (metrics.densityDpi / 160f) + } +} \ No newline at end of file From 63d695a27bf8cb62895bead8cbd4ef36a30dd763 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Mon, 15 Feb 2021 01:32:55 +0100 Subject: [PATCH 04/18] Refactor animations package --- .../animations/AbstractSurfaceAnimation.kt | 21 ++-- .../android/textsurface/animations/Alpha.kt | 53 --------- .../textsurface/animations/AnimationsSet.kt | 97 ---------------- .../textsurface/animations/ChangeColor.kt | 63 ----------- .../android/textsurface/animations/Delay.kt | 42 ------- .../android/textsurface/animations/Just.kt | 31 ----- .../android/textsurface/animations/Loop.kt | 31 ----- .../textsurface/animations/Parallel.kt | 9 -- .../android/textsurface/animations/Scale.kt | 49 -------- .../textsurface/animations/ScaleSurface.kt | 89 --------------- .../textsurface/animations/Sequential.kt | 9 -- .../animations/SurfaceAnimation.kt | 27 +++++ .../animations/TextSurfaceAnimation.kt | 16 +++ .../textsurface/animations/TransSurface.kt | 107 ------------------ .../animations/camera/CameraAnimation.kt | 11 ++ .../{CamRot.kt => camera/CameraRotation.kt} | 84 +++++--------- .../animations/camera/ScaleSurface.kt | 64 +++++++++++ .../animations/camera/TransSurface.kt | 69 +++++++++++ .../textsurface/animations/colors/Alpha.kt | 35 ++++++ .../animations/colors/ChangeColor.kt | 41 +++++++ .../animations/{ => effects}/Rotate3D.kt | 79 +++++-------- .../animations/{ => effects}/Slide.kt | 59 +++------- .../animations/effects/TextEffect.kt | 20 ++++ .../animations/{ => effects}/reveal/Circle.kt | 47 ++++---- .../animations/effects/reveal/ShapeReveal.kt | 52 +++++++++ .../effects/reveal/ShapeRevealAnimation.kt | 16 +++ .../{ => effects}/reveal/SideCut.kt | 51 ++++----- .../textsurface/animations/generic/Delay.kt | 38 +++++++ .../textsurface/animations/generic/Just.kt | 29 +++++ .../textsurface/animations/generic/Scale.kt | 32 ++++++ .../animations/reveal/IShapeReveal.kt | 17 --- .../animations/reveal/ShapeReveal.kt | 72 ------------ .../animations/sets/AnimationsSet.kt | 43 +++++++ .../textsurface/animations/sets/Loop.kt | 22 ++++ .../textsurface/animations/sets/Parallel.kt | 28 +++++ .../textsurface/animations/sets/Sequential.kt | 30 +++++ 36 files changed, 692 insertions(+), 891 deletions(-) delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/SurfaceAnimation.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/TextSurfaceAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraAnimation.kt rename library/src/main/java/su/levenetc/android/textsurface/animations/{CamRot.kt => camera/CameraRotation.kt} (50%) create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/camera/ScaleSurface.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/camera/TransSurface.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/colors/Alpha.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/colors/ChangeColor.kt rename library/src/main/java/su/levenetc/android/textsurface/animations/{ => effects}/Rotate3D.kt (64%) rename library/src/main/java/su/levenetc/android/textsurface/animations/{ => effects}/Slide.kt (63%) create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/effects/TextEffect.kt rename library/src/main/java/su/levenetc/android/textsurface/animations/{ => effects}/reveal/Circle.kt (67%) create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeReveal.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeRevealAnimation.kt rename library/src/main/java/su/levenetc/android/textsurface/animations/{ => effects}/reveal/SideCut.kt (64%) create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/generic/Delay.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/generic/Just.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/generic/Scale.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/sets/AnimationsSet.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/sets/Loop.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/sets/Parallel.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/animations/sets/Sequential.kt diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt index 4cd45ff..8fb1531 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt @@ -3,24 +3,23 @@ package su.levenetc.android.textsurface.animations import android.animation.ValueAnimator import android.animation.ValueAnimator.AnimatorUpdateListener import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation /** * Created by Eugene Levenetc. */ abstract class AbstractSurfaceAnimation( - override val text: Text, - override val duration: Long -) : ITextSurfaceAnimation, AnimatorUpdateListener { + text: Text, + duration: Long +) : TextSurfaceAnimation(text, duration), AnimatorUpdateListener { - abstract override var textSurface: TextSurface + lateinit var animator: ValueAnimator - override fun setInitValues(text: Text) {} - override fun onStart() {} - override fun start(listener: IEndListener) {} - override fun cancel() {} + override fun cancel() { + super.cancel() + if (this::animator.isInitialized) { + animator.cancel() + } + } override fun onAnimationUpdate(animation: ValueAnimator) { textSurface.invalidate() diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt deleted file mode 100644 index cd7a775..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.kt +++ /dev/null @@ -1,53 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.animation.Animator -import android.animation.ValueAnimator -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.utils.AnimatorEndListener - -/** - * Created by Eugene Levenetc. - */ -class Alpha(text: Text, duration: Long, private val from: Int, private val to: Int) : AbstractSurfaceAnimation(text, duration) { - - private var animator: ValueAnimator? = null - override lateinit var textSurface: TextSurface - - override fun start(listener: IEndListener) { - animator = ValueAnimator.ofInt(from, to) - animator?.duration = duration - animator?.addUpdateListener(this) - animator?.addListener(object : AnimatorEndListener() { - override fun onAnimationEnd(animation: Animator) { - listener.onAnimationEnd(this@Alpha) - } - }) - animator?.start() - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - super.onAnimationUpdate(animation) - text.setAlpha(animation.animatedValue as Int) - } - - override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } - } - - companion object { - @kotlin.jvm.JvmStatic - fun hide(text: Text, duration: Long): Alpha { - return Alpha(text, duration, 255, 0) - } - - @kotlin.jvm.JvmStatic - fun show(text: Text, duration: Long): Alpha { - return Alpha(text, duration, 0, 255) - } - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt deleted file mode 100644 index cf28bb6..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/AnimationsSet.kt +++ /dev/null @@ -1,97 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.util.Log -import su.levenetc.android.textsurface.Debug -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.contants.TYPE -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISet -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation -import java.util.* - -/** - * Created by Eugene Levenetc. - */ -open class AnimationsSet(override val type: TYPE, vararg animations: ISurfaceAnimation?) : IEndListener, ISet { - override val animations: LinkedList - private var currentAnimation: ISurfaceAnimation? = null - private var lastAnimation //type == PARALLEL - : ISurfaceAnimation? = null - private var index = 0 - private var listener: IEndListener? = null - private var canceled = false - override fun onAnimationEnd(animation: ISurfaceAnimation) { - if (Debug.ENABLED) Log.i("endAnimation", animation.toString()) - if (canceled) { - finalizeAnimation() - return - } - if (type == TYPE.SEQUENTIAL) { - if (index < animations.size) { - setCurrentAnimation(animations[index++]) - } else { - finalizeAnimation() - } - } else { - if (animation === lastAnimation) finalizeAnimation() - } - } - - private fun finalizeAnimation() { - if (listener != null) listener!!.onAnimationEnd(this) - } - - override fun onStart() {} - override fun start(listener: IEndListener) { - this.listener = listener - index = 0 - canceled = false - if (type == TYPE.SEQUENTIAL) { - setCurrentAnimation(animations[index++]) - } else if (type == TYPE.PARALLEL) { - Collections.sort(animations, DURATION_COMPARATOR) - lastAnimation = animations.last - for (animation in animations) setCurrentAnimation(animation) - } - } - - private fun setCurrentAnimation(animation: ISurfaceAnimation) { - if (Debug.ENABLED) Log.i("startedAnimation", animation.toString()) - currentAnimation = animation - currentAnimation!!.onStart() - currentAnimation!!.start(this) - } - - override val duration: Long - get() = 0 - override var textSurface: TextSurface - get() = null!! - set(value) { - animations.forEach { it.textSurface = value } - } - - override fun cancel() { - canceled = true - if (type == TYPE.SEQUENTIAL) { - if (currentAnimation != null) { - currentAnimation!!.cancel() - } - } else { - for (animation in animations) animation.cancel() - } - } - - private class DurationComparator : Comparator { - override fun compare(lhs: ISurfaceAnimation, rhs: ISurfaceAnimation): Int { - return (lhs.duration - rhs.duration).toInt() - } - } - - companion object { - private val DURATION_COMPARATOR = DurationComparator() - } - - init { - this.animations = LinkedList(listOf(*animations)) - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt deleted file mode 100644 index af87224..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.kt +++ /dev/null @@ -1,63 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.animation.Animator -import android.animation.ValueAnimator -import android.graphics.Color -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.ChangeColor -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.utils.AnimatorEndListener - -/** - * Created by Eugene Levenetc. - */ -class ChangeColor(text: Text, override var duration: Long, private var from: Int, private val to: Int) : AbstractSurfaceAnimation(text, duration) { - val fromTriplet = FloatArray(3) - val toTriplet = FloatArray(3) - val hsv = FloatArray(3) - private var animator: ValueAnimator? = null - override lateinit var textSurface: TextSurface - - override fun start(listener: IEndListener) { - if (from == -1) from = text.paint.color - Color.colorToHSV(from, fromTriplet) - Color.colorToHSV(to, toTriplet) - animator = ValueAnimator.ofFloat(0f, 1f) - animator!!.duration = duration - animator!!.addUpdateListener(this) - animator!!.addListener(object : AnimatorEndListener() { - override fun onAnimationEnd(animation: Animator) { - listener?.onAnimationEnd(this@ChangeColor) - } - }) - animator!!.start() - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - hsv[0] = fromTriplet[0] + (toTriplet[0] - fromTriplet[0]) * animation.animatedFraction - hsv[1] = fromTriplet[1] + (toTriplet[1] - fromTriplet[1]) * animation.animatedFraction - hsv[2] = fromTriplet[2] + (toTriplet[2] - fromTriplet[2]) * animation.animatedFraction - text.paint.color = Color.HSVToColor(hsv) - super.onAnimationUpdate(animation) - } - - override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } - } - - companion object { - @kotlin.jvm.JvmStatic - fun fromTo(text: Text, duration: Long, from: Int, to: Int): ChangeColor { - return ChangeColor(text, duration, from, to) - } - - @kotlin.jvm.JvmStatic - fun to(text: Text, duration: Long, to: Int): ChangeColor { - return ChangeColor(text, duration, -1, to) - } - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt deleted file mode 100644 index 0374c35..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Delay.kt +++ /dev/null @@ -1,42 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.graphics.Paint -import android.graphics.RectF -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.common.Position -import su.levenetc.android.textsurface.interfaces.IEndListener - - -class Delay(duration: Long) : AbstractSurfaceAnimation(EMPTY_TEXT, duration) { - private var action: Runnable? = null - override lateinit var textSurface: TextSurface - - override fun start(listener: IEndListener) { - action = Runnable { listener?.onAnimationEnd(this@Delay) } - textSurface!!.postDelayed(action, duration.toLong()) - } - - override fun cancel() { - if (action != null) { - textSurface!!.removeCallbacks(action) - action = null - } - } - - override fun toString(): String { - return "Delay{" + - "duration=" + duration + - '}' - } - - companion object { - - private val EMPTY_TEXT = Text("", Position(), RectF(), Paint()) - - @kotlin.jvm.JvmStatic - fun duration(duration: Long): Delay { - return Delay(duration) - } - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt deleted file mode 100644 index 5a27e07..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Just.kt +++ /dev/null @@ -1,31 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.contants.TYPE -import su.levenetc.android.textsurface.interfaces.IEndListener - -/** - * Created by Eugene Levenetc. - */ -class Just private constructor(text: Text) : AbstractSurfaceAnimation(text, 0) { - //TODO: check unused textSurface - override lateinit var textSurface: TextSurface - - override fun start(listener: IEndListener) { - textSurface!!.invalidate() - listener?.onAnimationEnd(this) - } - - companion object { - fun show(vararg texts: Text): AnimationsSet { - val justs = arrayOfNulls(texts.size) - for (i in texts.indices) justs[i] = show(texts[i]) - return AnimationsSet(TYPE.PARALLEL, *justs) - } - - fun show(text: Text): Just { - return Just(text) - } - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt deleted file mode 100644 index 6fb0770..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Loop.kt +++ /dev/null @@ -1,31 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation - -/** - * Created by ogaclejapan. - */ -class Loop(vararg animations: ISurfaceAnimation) : Sequential(*animations) { - private val restartListener: IEndListener = object : IEndListener { - override fun onAnimationEnd(animation: ISurfaceAnimation) { - if (canceled) { - if (endListener != null) endListener!!.onAnimationEnd(this@Loop) - } else { - super@Loop.start(this) - } - } - } - private var endListener: IEndListener? = null - private var canceled = false - override fun start(listener: IEndListener) { - endListener = listener - canceled = false - super.start(restartListener) - } - - override fun cancel() { - canceled = true - super.cancel() - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt deleted file mode 100644 index e6fab9d..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.kt +++ /dev/null @@ -1,9 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import su.levenetc.android.textsurface.contants.TYPE -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation - -/** - * Created by Eugene Levenetc. - */ -class Parallel(vararg animations: ISurfaceAnimation?) : AnimationsSet(TYPE.PARALLEL, *animations) \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt deleted file mode 100644 index 1a8b46d..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Scale.kt +++ /dev/null @@ -1,49 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.animation.ObjectAnimator -import android.animation.PropertyValuesHolder -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation -import su.levenetc.android.textsurface.interfaces.ITextSurfaceAnimation -import su.levenetc.android.textsurface.utils.Utils.addEndListener - -/** - * Created by Eugene Levenetc. - */ -class Scale(override val text: Text, override val duration: Long, private val from: Float, private val to: Float, private val pivot: Int) : ITextSurfaceAnimation, AnimatorUpdateListener { - override lateinit var textSurface: TextSurface - private var animator: ObjectAnimator? = null - override fun setInitValues(text: Text) {} - override fun onStart() {} - override fun start(listener: IEndListener) { - text.setScalePivot(pivot.toFloat(), pivot.toFloat()) - val sX = PropertyValuesHolder.ofFloat("scaleX", from, to) - val sY = PropertyValuesHolder.ofFloat("scaleY", from, to) - animator = ObjectAnimator.ofPropertyValuesHolder(text, sX, sY) - addEndListener(this, animator!!, listener) - animator!!.duration = duration.toLong() - animator!!.addUpdateListener(this) - animator!!.start() - } - - override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface.invalidate() - } - - override fun toString(): String { - return "Scale{" + - "text=" + text + - '}' - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt deleted file mode 100644 index 10cc877..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/ScaleSurface.kt +++ /dev/null @@ -1,89 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.animation.ObjectAnimator -import android.animation.PropertyValuesHolder -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener -import android.annotation.SuppressLint -import androidx.interpolator.view.animation.FastOutSlowInInterpolator -import su.levenetc.android.textsurface.SurfaceCamera -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.interfaces.ICameraAnimation -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.utils.Utils.addEndListener - -/** - * Created by Eugene Levenetc. - */ -class ScaleSurface : ICameraAnimation, AnimatorUpdateListener { - private var camera: SurfaceCamera? = null - override lateinit var textSurface: TextSurface - override var duration: Long - private val textPivot: Text? - private var fit = -1 - private var pivot = 0 - private var toScale = 0f - private var animator: ObjectAnimator? = null - - constructor(duration: Long, textPivot: Text?, pivot: Int, toScale: Float) { - this.duration = duration - this.textPivot = textPivot - this.pivot = pivot - this.toScale = toScale - } - - constructor(duration: Long, textPivot: Text?, fit: Int) { - this.duration = duration - this.textPivot = textPivot - this.fit = fit - } - - override fun setCamera(camera: SurfaceCamera?) { - this.camera = camera - } - - override fun onStart() {} - - @SuppressLint("ObjectAnimatorBinding") - override fun start(listener: IEndListener) { - val pivotX: Float - val pivotY: Float - if (fit == -1) { - pivotX = textPivot!!.position.getRelativeX(pivot, textPivot, true) - pivotY = textPivot.position.getRelativeY(pivot, textPivot, true) - } else { - val surfaceWidth = textSurface!!.width - val textWidth = textPivot!!.width - toScale = surfaceWidth / textWidth - pivotX = textPivot.position.getRelativeX(Pivot.CENTER, textPivot, true) - pivotY = textPivot.position.getRelativeY(Pivot.CENTER, textPivot, true) - } - val scaleHolder = PropertyValuesHolder.ofFloat("scale", camera!!.getScale(), toScale) - val pivotXHolder = PropertyValuesHolder.ofFloat("scalePivotX", camera!!.scalePivotX, pivotX) - val pivotYHolder = PropertyValuesHolder.ofFloat("scalePivotY", camera!!.scalePivotY, pivotY) - animator = ObjectAnimator.ofPropertyValuesHolder(camera, scaleHolder, pivotXHolder, pivotYHolder) - animator!!.interpolator = FastOutSlowInInterpolator() - animator!!.duration = duration.toLong() - animator!!.addUpdateListener(this) - addEndListener(this, animator!!, listener) - animator!!.start() - } - - override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - } - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface!!.invalidate() - } - - override fun toString(): String { - return "ScaleSurface{" + - "textPivot=" + (textPivot?.toString() ?: "null") + - '}' - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt deleted file mode 100644 index 442f271..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.kt +++ /dev/null @@ -1,9 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import su.levenetc.android.textsurface.contants.TYPE -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation - -/** - * Created by Eugene Levenetc. - */ -open class Sequential(vararg animations: ISurfaceAnimation) : AnimationsSet(TYPE.SEQUENTIAL, *animations) \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/SurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/SurfaceAnimation.kt new file mode 100644 index 0000000..4bb44e7 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/SurfaceAnimation.kt @@ -0,0 +1,27 @@ +package su.levenetc.android.textsurface.animations + +import androidx.annotation.CallSuper +import su.levenetc.android.textsurface.TextSurface + +/** + * Created by Eugene Levenetc. + */ +open class SurfaceAnimation(open val duration: Long) { + + open lateinit var textSurface: TextSurface + var endListener: (SurfaceAnimation) -> Unit = {} + var canceled = false + + open fun onStart() { + + } + + open fun start() { + + } + + @CallSuper + open fun cancel() { + canceled = true + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/TextSurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/TextSurfaceAnimation.kt new file mode 100644 index 0000000..5c5876b --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/TextSurfaceAnimation.kt @@ -0,0 +1,16 @@ +package su.levenetc.android.textsurface.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface + +/** + * Created by Eugene Levenetc. + */ +open class TextSurfaceAnimation(val text: Text, duration: Long) : SurfaceAnimation(duration) { + /** + * Called by [TextSurface] on initial configuration of texts + */ + open fun setInitValues(text: Text) { + + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt deleted file mode 100644 index 70e470a..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/TransSurface.kt +++ /dev/null @@ -1,107 +0,0 @@ -package su.levenetc.android.textsurface.animations - -import android.animation.ObjectAnimator -import android.animation.PropertyValuesHolder -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener -import android.annotation.SuppressLint -import android.util.Log -import androidx.interpolator.view.animation.FastOutSlowInInterpolator -import su.levenetc.android.textsurface.Debug -import su.levenetc.android.textsurface.SurfaceCamera -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.interfaces.ICameraAnimation -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.utils.Utils.addEndListener - -/** - * Created by Eugene Levenetc. - */ -class TransSurface : ICameraAnimation, AnimatorUpdateListener { - var dx = 0f - var dy = 0f - - override val duration: Long - private var textPivot: Text? = null - private var pivot = 0 - private var camera: SurfaceCamera? = null - private var animator: ObjectAnimator? = null - override lateinit var textSurface: TextSurface - - constructor(duration: Long, textPivot: Text?, pivot: Int) { - this.duration = duration - this.textPivot = textPivot - this.pivot = pivot - } - - constructor(duration: Long, textPivot: Text?) { - this.duration = duration - this.textPivot = textPivot - } - - constructor(duration: Long, dx: Float, dy: Float) { - this.duration = duration - this.dx = dx - this.dy = dy - } - - override fun onStart() {} - - @SuppressLint("ObjectAnimatorBinding") - override fun start(listener: IEndListener) { - val fromX = camera!!.transX - val fromY = camera!!.transY - val toX: Float - val toY: Float - if (textPivot == null) { - toX = camera!!.transX + dx - toY = camera!!.transY + dy - } else { - toX = textPivot!!.position.getRelativeX(pivot, textPivot, true) * camera!!.getScale() * -1 - toY = textPivot!!.position.getRelativeY(pivot, textPivot, true) * camera!!.getScale() * -1 - } - debugTranslation(fromX, fromY, toX, toY) - val dxHolder = PropertyValuesHolder.ofFloat("transX", fromX, toX) - val dyHolder = PropertyValuesHolder.ofFloat("transY", fromY, toY) - animator = ObjectAnimator.ofPropertyValuesHolder(camera, dxHolder, dyHolder) - animator!!.interpolator = FastOutSlowInInterpolator() - addEndListener(this, animator!!, listener) - animator!!.duration = duration.toLong() - animator!!.addUpdateListener(this) - animator!!.start() - } - - private fun debugTranslation(fromX: Float, fromY: Float, toX: Float, toY: Float) { - if (Debug.ENABLED && fromX == toX && fromY == toY) Log.e(javaClass.simpleName, "No translation to $textPivot from:$fromX:$fromY to:$toX:$toY") - } - - override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface!!.invalidate() - } - - override fun setCamera(camera: SurfaceCamera?) { - this.camera = camera - } - - override fun toString(): String { - return "TransSurface{" + - "textPivot=" + (if (textPivot == null) "null" else textPivot.toString()) + - '}' - } - - companion object { - @kotlin.jvm.JvmStatic - fun toCenter(textPivot: Text?, duration: Long): TransSurface { - return TransSurface(duration, textPivot, Pivot.CENTER) - } - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraAnimation.kt new file mode 100644 index 0000000..fe0fcf0 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraAnimation.kt @@ -0,0 +1,11 @@ +package su.levenetc.android.textsurface.animations.camera + +import su.levenetc.android.textsurface.animations.SurfaceAnimation +import su.levenetc.android.textsurface.camera.SurfaceCamera + +/** + * Created by Eugene Levenetc. + */ +open class CameraAnimation(duration: Long) : SurfaceAnimation(duration) { + lateinit var camera: SurfaceCamera +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraRotation.kt similarity index 50% rename from library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt rename to library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraRotation.kt index 5f26fbe..a7c8140 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/CamRot.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/CameraRotation.kt @@ -1,73 +1,55 @@ -package su.levenetc.android.textsurface.animations +package su.levenetc.android.textsurface.animations.camera -import android.animation.Animator import android.animation.ObjectAnimator -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener import android.annotation.SuppressLint import android.graphics.PointF -import su.levenetc.android.textsurface.SurfaceCamera import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.interfaces.ICameraAnimation -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.utils.AnimatorEndListener +import su.levenetc.android.textsurface.utils.setupAndStart +import kotlin.math.ceil +import kotlin.math.cos +import kotlin.math.sin /** * Created by Eugene Levenetc. */ -class CamRot : ICameraAnimation, AnimatorUpdateListener { - var rotationDelta: Float +class CameraRotation : CameraAnimation { + + private var rotationDelta = 0f private var pivotX = 0f private var pivotY = 0f - override var duration: Long - override lateinit var textSurface: TextSurface - private var camera: SurfaceCamera? = null - private var textPivot: Text? = null private var pivotAlign = 0 + private var textPivot: Text? = null private var animator: ObjectAnimator? = null - constructor(duration: Long, rotationDelta: Float) { - this.duration = duration + constructor(duration: Long, rotationDelta: Float) : super(duration) { this.rotationDelta = rotationDelta } - constructor(duration: Long, rotationDelta: Float, pivotX: Float, pivotY: Float) { - this.duration = duration + constructor(duration: Long, rotationDelta: Float, pivotX: Float, pivotY: Float) : super(duration) { this.rotationDelta = rotationDelta this.pivotX = pivotX this.pivotY = pivotY } - constructor(duration: Long, rotationDelta: Float, textPivot: Text?, pivotAlign: Int) { - this.duration = duration + constructor(duration: Long, rotationDelta: Float, textPivot: Text?, pivotAlign: Int) : super(duration) { this.rotationDelta = rotationDelta this.textPivot = textPivot this.pivotAlign = pivotAlign } - override fun onStart() {} - @SuppressLint("ObjectAnimatorBinding") - override fun start(listener: IEndListener) { + override fun start() { setPivot() - val from = camera!!.rotation - val to = camera!!.rotation + rotationDelta + val from = camera.rotation + val to = camera.rotation + rotationDelta animator = ObjectAnimator.ofFloat(camera, "rotation", from, to) - animator!!.setDuration(duration.toLong()) - animator!!.addUpdateListener(this) - animator!!.addListener(object : AnimatorEndListener() { - override fun onAnimationEnd(animation: Animator) { - listener.onAnimationEnd(this@CamRot) - } - }) - animator!!.start() + animator!!.setupAndStart(this) } - private val tmpPoint = PointF() private fun setPivot() { - val rotationPivot = camera!!.rotationPivot + + val rotationPivot = camera.rotationPivot if (textPivot != null) { if (pivotAlign and Pivot.LEFT == Pivot.LEFT) { pivotX = textPivot!!.getX(textSurface) @@ -84,25 +66,15 @@ class CamRot : ICameraAnimation, AnimatorUpdateListener { pivotY = textPivot!!.getY(textSurface) - textPivot!!.height / 2 } } + val tmpPoint = PointF() tmpPoint[pivotX] = pivotY - // rotatePoint(tmpPoint, camera.getRotationPivot(), camera.getRotation()); - rotatePoint2(tmpPoint, camera!!.rotationPivot, camera!!.rotation) + rotatePoint2(tmpPoint, camera.rotationPivot, camera.rotation) rotationPivot[tmpPoint.x] = tmpPoint.y } override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface!!.invalidate() - } - - override fun setCamera(camera: SurfaceCamera?) { - this.camera = camera + super.cancel() + animator?.cancel() } companion object { @@ -111,8 +83,8 @@ class CamRot : ICameraAnimation, AnimatorUpdateListener { val centerY = center.y val point2x = point.x val point2y = point.y - val newX = centerX + (point2x - centerX) * Math.cos(angle.toDouble()) - (point2y - centerY) * Math.sin(angle.toDouble()) - val newY = centerY + (point2x - centerX) * Math.sin(angle.toDouble()) + (point2y - centerY) * Math.cos(angle.toDouble()) + val newX = centerX + (point2x - centerX) * cos(angle.toDouble()) - (point2y - centerY) * sin(angle.toDouble()) + val newY = centerY + (point2x - centerX) * sin(angle.toDouble()) + (point2y - centerY) * cos(angle.toDouble()) point[newX.toFloat()] = newY.toFloat() } @@ -123,12 +95,12 @@ class CamRot : ICameraAnimation, AnimatorUpdateListener { //APPLY ROTATION val xTemp = x1 - x1 = x1 * Math.cos(angle.toDouble()) - y1 * Math.sin(angle.toDouble()) - y1 = xTemp * Math.sin(angle.toDouble()) + y1 * Math.cos(angle.toDouble()) + x1 = x1 * cos(angle.toDouble()) - y1 * sin(angle.toDouble()) + y1 = xTemp * sin(angle.toDouble()) + y1 * cos(angle.toDouble()) //TRANSLATE BACK - point.x = Math.ceil(x1).toInt() + center.x - point.y = Math.ceil(y1).toInt() + center.y + point.x = ceil(x1).toInt() + center.x + point.y = ceil(y1).toInt() + center.y } } } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/camera/ScaleSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/ScaleSurface.kt new file mode 100644 index 0000000..1c348c0 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/ScaleSurface.kt @@ -0,0 +1,64 @@ +package su.levenetc.android.textsurface.animations.camera + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.annotation.SuppressLint +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.contants.Fit +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.utils.setupAndStart + +/** + * Created by Eugene Levenetc. + */ +class ScaleSurface : CameraAnimation { + + private var fit: Fit = Fit.UNDEFINED + private var pivot = Pivot.UNDEFINED + private var toScale = 0f + private val textPivot: Text + private var animator: ObjectAnimator? = null + + constructor(duration: Long, textPivot: Text, pivot: Int, toScale: Float) : super(duration) { + this.textPivot = textPivot + this.pivot = pivot + this.toScale = toScale + } + + constructor(duration: Long, textPivot: Text, fit: Fit) : super(duration) { + this.textPivot = textPivot + this.fit = fit + } + + @SuppressLint("ObjectAnimatorBinding") + override fun start() { + val pivotX: Float + val pivotY: Float + if (fit == Fit.UNDEFINED) { + pivotX = textPivot.position.getRelativeX(pivot, textPivot, true) + pivotY = textPivot.position.getRelativeY(pivot, textPivot, true) + } else { + val surfaceWidth = textSurface.width + val textWidth = textPivot.width + toScale = surfaceWidth / textWidth + pivotX = textPivot.position.getRelativeX(Pivot.CENTER, textPivot, true) + pivotY = textPivot.position.getRelativeY(Pivot.CENTER, textPivot, true) + } + val scaleHolder = PropertyValuesHolder.ofFloat("scale", camera.getScale(), toScale) + val pivotXHolder = PropertyValuesHolder.ofFloat("scalePivotX", camera.scalePivotX, pivotX) + val pivotYHolder = PropertyValuesHolder.ofFloat("scalePivotY", camera.scalePivotY, pivotY) + animator = ObjectAnimator.ofPropertyValuesHolder(camera, scaleHolder, pivotXHolder, pivotYHolder) + animator!!.interpolator = FastOutSlowInInterpolator() + animator!!.setupAndStart(this) + } + + override fun cancel() { + super.cancel() + animator?.cancel() + } + + override fun toString(): String { + return "ScaleSurface{textPivot=$textPivot}" + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/camera/TransSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/TransSurface.kt new file mode 100644 index 0000000..b2ac880 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/camera/TransSurface.kt @@ -0,0 +1,69 @@ +package su.levenetc.android.textsurface.animations.camera + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import android.animation.ValueAnimator +import android.animation.ValueAnimator.AnimatorUpdateListener +import android.annotation.SuppressLint +import android.util.Log +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurfaceDebug +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.utils.setupAndStart + +/** + * Created by Eugene Levenetc. + */ +class TransSurface : CameraAnimation, AnimatorUpdateListener { + + private var pivot = 0 + private var animator: ObjectAnimator? = null + private val textPivot: Text + + constructor(duration: Long, textPivot: Text, pivot: Int) : super(duration) { + this.textPivot = textPivot + this.pivot = pivot + } + + constructor(duration: Long, textPivot: Text) : super(duration) { + this.textPivot = textPivot + } + + @SuppressLint("ObjectAnimatorBinding") + override fun start() { + val fromX = camera.transX + val fromY = camera.transY + val toX: Float = textPivot.position.getRelativeX(pivot, textPivot, true) * camera.getScale() * -1 + val toY: Float = textPivot.position.getRelativeY(pivot, textPivot, true) * camera.getScale() * -1 + debugTranslation(fromX, fromY, toX, toY) + val dxHolder = PropertyValuesHolder.ofFloat("transX", fromX, toX) + val dyHolder = PropertyValuesHolder.ofFloat("transY", fromY, toY) + animator = ObjectAnimator.ofPropertyValuesHolder(camera, dxHolder, dyHolder) + animator!!.interpolator = FastOutSlowInInterpolator() + animator!!.setupAndStart(this) + } + + private fun debugTranslation(fromX: Float, fromY: Float, toX: Float, toY: Float) { + if (TextSurfaceDebug.ENABLED && fromX == toX && fromY == toY) Log.e(javaClass.simpleName, "No translation to $textPivot from:$fromX:$fromY to:$toX:$toY") + } + + override fun cancel() { + super.cancel() + animator?.cancel() + } + + override fun onAnimationUpdate(animation: ValueAnimator) { + textSurface.invalidate() + } + + override fun toString(): String { + return "TransSurface{textPivot=$textPivot}" + } + + companion object { + fun toCenterOf(textPivot: Text, duration: Long): TransSurface { + return TransSurface(duration, textPivot, Pivot.CENTER) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/colors/Alpha.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/colors/Alpha.kt new file mode 100644 index 0000000..5cddaef --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/colors/Alpha.kt @@ -0,0 +1,35 @@ +package su.levenetc.android.textsurface.animations.colors + +import android.animation.ValueAnimator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.AbstractSurfaceAnimation +import su.levenetc.android.textsurface.utils.setupAndStart + +/** + * Created by Eugene Levenetc. + */ +class Alpha( + text: Text, + duration: Long, + private val from: Int, + private val to: Int +) : AbstractSurfaceAnimation(text, duration) { + + override fun start() { + animator = ValueAnimator.ofInt(from, to) + animator.setupAndStart(this, { + text.setAlpha(it.animatedValue as Int) + }) + } + + companion object { + + fun hide(text: Text, duration: Long): Alpha { + return Alpha(text, duration, 255, 0) + } + + fun show(text: Text, duration: Long): Alpha { + return Alpha(text, duration, 0, 255) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/colors/ChangeColor.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/colors/ChangeColor.kt new file mode 100644 index 0000000..c6ed2f8 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/colors/ChangeColor.kt @@ -0,0 +1,41 @@ +package su.levenetc.android.textsurface.animations.colors + +import android.animation.ValueAnimator +import android.graphics.Color +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.AbstractSurfaceAnimation +import su.levenetc.android.textsurface.utils.setupAndStart + +/** + * Created by Eugene Levenetc. + */ +class ChangeColor(text: Text, duration: Long, private var from: Int, private val to: Int) : AbstractSurfaceAnimation(text, duration) { + + private val fromTriplet = FloatArray(3) + private val toTriplet = FloatArray(3) + private val hsv = FloatArray(3) + + override fun start() { + if (from == -1) from = text.paint.color + Color.colorToHSV(from, fromTriplet) + Color.colorToHSV(to, toTriplet) + animator = ValueAnimator.ofFloat(0f, 1f) + + animator.setupAndStart(this, { + hsv[0] = fromTriplet[0] + (toTriplet[0] - fromTriplet[0]) * it.animatedFraction + hsv[1] = fromTriplet[1] + (toTriplet[1] - fromTriplet[1]) * it.animatedFraction + hsv[2] = fromTriplet[2] + (toTriplet[2] - fromTriplet[2]) * it.animatedFraction + text.paint.color = Color.HSVToColor(hsv) + }) + } + + companion object { + fun fromTo(text: Text, duration: Long, from: Int, to: Int): ChangeColor { + return ChangeColor(text, duration, from, to) + } + + fun to(text: Text, duration: Long, to: Int): ChangeColor { + return ChangeColor(text, duration, -1, to) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/Rotate3D.kt similarity index 64% rename from library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt rename to library/src/main/java/su/levenetc/android/textsurface/animations/effects/Rotate3D.kt index 1d19bf9..c098ac1 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/Rotate3D.kt @@ -1,36 +1,32 @@ -package su.levenetc.android.textsurface.animations +package su.levenetc.android.textsurface.animations.effects import android.animation.ObjectAnimator import android.animation.PropertyValuesHolder -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener -import android.graphics.* +import android.graphics.Camera +import android.graphics.Canvas +import android.graphics.Matrix +import android.graphics.Paint import androidx.interpolator.view.animation.FastOutSlowInInterpolator import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface import su.levenetc.android.textsurface.contants.Axis import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation -import su.levenetc.android.textsurface.interfaces.ITextEffect -import su.levenetc.android.textsurface.utils.Utils.addEndListener +import su.levenetc.android.textsurface.utils.setupAndStart /** * Created by Eugene Levenetc. */ class Rotate3D private constructor( - override val text: Text, - override var duration: Long, + text: Text, + duration: Long, private val pivot: Int, - private val direction: Int, - private val axis: Int, + private val axis: Axis, private val show: Boolean -) : ITextEffect, AnimatorUpdateListener { - protected val camera = Camera() - protected val cameraMatrix = Matrix() +) : TextEffect(text, duration) { + + private val camera = Camera() + private val cameraMatrix = Matrix() private var rotationX = 0f private var rotationY = 0f - override lateinit var textSurface: TextSurface private var cameraTransXPre = 0f private var cameraTransYPre = 0f private var cameraTransXPost = 0f @@ -50,16 +46,10 @@ class Rotate3D private constructor( } override fun setInitValues(text: Text) { - if (show) { - text.setAlpha(0) - } - } - - override fun onStart() { - text.addEffect(this) + if (show) text.setAlpha(0) } - override fun start(listener: IEndListener) { + override fun start() { var valHolder: PropertyValuesHolder? = null val fromDegree: Int val toDegree: Int @@ -107,26 +97,19 @@ class Rotate3D private constructor( if (valHolder != null) { animator = ObjectAnimator.ofPropertyValuesHolder(this, valHolder) animator!!.interpolator = FastOutSlowInInterpolator() - addEndListener(this, animator!!, object : IEndListener { - override fun onAnimationEnd(animation: ISurfaceAnimation) { - text.removeEffect(this@Rotate3D) - if (!show) text.setAlpha(0) - listener.onAnimationEnd(this@Rotate3D) - } + + animator!!.setupAndStart(this, endDelegate = { + text.removeEffect(this) + if (!show) text.setAlpha(0) }) - animator!!.duration = duration.toLong() - animator!!.addUpdateListener(this) - animator!!.start() } else { throw RuntimeException(javaClass.superclass.toString() + " was not configured properly. Pivot:" + pivot) } } override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } + super.cancel() + animator?.cancel() } fun setRotationX(rotationX: Float) { @@ -137,29 +120,21 @@ class Rotate3D private constructor( this.rotationY = rotationY } - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface!!.invalidate() - } - companion object { - @kotlin.jvm.JvmStatic fun showFromSide(text: Text, duration: Long, pivot: Int): Rotate3D { - return Rotate3D(text, duration, pivot, 0, 0, true) + return Rotate3D(text, duration, pivot, Axis.Undefined, true) } - @kotlin.jvm.JvmStatic - fun showFromCenter(text: Text, duration: Long, direction: Int, axis: Int): Rotate3D { - return Rotate3D(text, duration, Pivot.CENTER, direction, axis, true) + fun showFromCenter(text: Text, duration: Long, axis: Axis): Rotate3D { + return Rotate3D(text, duration, Pivot.CENTER, axis, true) } - @kotlin.jvm.JvmStatic fun hideFromSide(text: Text, duration: Long, pivot: Int): Rotate3D { - return Rotate3D(text, duration, pivot, 0, 0, false) + return Rotate3D(text, duration, pivot, Axis.Undefined, false) } - @kotlin.jvm.JvmStatic - fun hideFromCenter(text: Text, duration: Long, direction: Int, axis: Int): Rotate3D { - return Rotate3D(text, duration, Pivot.CENTER, direction, axis, false) + fun hideFromCenter(text: Text, duration: Long, axis: Axis): Rotate3D { + return Rotate3D(text, duration, Pivot.CENTER, axis, false) } } } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/Slide.kt similarity index 63% rename from library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt rename to library/src/main/java/su/levenetc/android/textsurface/animations/effects/Slide.kt index 92ef22a..7e05dc3 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/Slide.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/Slide.kt @@ -1,43 +1,30 @@ -package su.levenetc.android.textsurface.animations +package su.levenetc.android.textsurface.animations.effects import android.animation.ObjectAnimator import android.animation.PropertyValuesHolder -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener import android.graphics.Canvas import android.graphics.Paint import android.graphics.Region import android.os.Build import androidx.interpolator.view.animation.FastOutSlowInInterpolator import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface import su.levenetc.android.textsurface.contants.Side -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation -import su.levenetc.android.textsurface.interfaces.ITextEffect -import su.levenetc.android.textsurface.utils.Utils +import su.levenetc.android.textsurface.utils.setupAndStart /** * Created by Eugene Levenetc. */ -class Slide private constructor(private val side: Int, override val text: Text, override val duration: Long, private val toShow: Boolean) : ITextEffect, AnimatorUpdateListener { +class Slide private constructor(private val side: Int, text: Text, duration: Long, private val toShow: Boolean) : TextEffect(text, duration) { private var xOffset = 0f private var yOffset = 0f private var animator: ObjectAnimator? = null - override lateinit var textSurface: TextSurface override fun setInitValues(text: Text) { - if (toShow) { - text.setAlpha(0) - } - } - - override fun onStart() { - text.addEffect(this) + if (toShow) text.setAlpha(0) } - override fun start(listener: IEndListener) { + override fun start() { text.setAlpha(255) var hHolder: PropertyValuesHolder? = null var vHolder: PropertyValuesHolder? = null @@ -83,43 +70,28 @@ class Slide private constructor(private val side: Int, override val text: Text, ObjectAnimator.ofPropertyValuesHolder(this, vHolder) } - animator?.run { - this.interpolator = FastOutSlowInInterpolator() - Utils.addEndListener(this@Slide, this, object : IEndListener { - override fun onAnimationEnd(animation: ISurfaceAnimation) { - text.removeEffect(this@Slide) - if (!toShow) text.setAlpha(0) - listener.onAnimationEnd(this@Slide) - } - }) - this.duration = duration - this.addUpdateListener(this@Slide) - this.start() - } - - + animator!!.interpolator = FastOutSlowInInterpolator() + animator!!.setupAndStart(this, endDelegate = { + text.removeEffect(this) + if (!toShow) text.setAlpha(0) + }) } override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } + super.cancel() + animator?.cancel() } override fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) { val width = text.width val height = text.height - //canvas.save(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { canvas.clipRect(x, y - height, width, 0f) } else { canvas.clipRect(x, y - height, width, 0f, Region.Op.REPLACE) } canvas.translate(xOffset, yOffset - text.fontDescent) - //canvas.drawText(textValue, x, y, paint); - //canvas.restore(); } fun setXOffset(value: Float) { @@ -130,17 +102,12 @@ class Slide private constructor(private val side: Int, override val text: Text, yOffset = value } - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface!!.invalidate() - } - companion object { - @JvmStatic + fun showFrom(side: Int, text: Text, duration: Long): Slide { return Slide(side, text, duration, true) } - @JvmStatic fun hideFrom(side: Int, text: Text, duration: Long): Slide { return Slide(side, text, duration, false) } diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/effects/TextEffect.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/TextEffect.kt new file mode 100644 index 0000000..d0720f5 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/TextEffect.kt @@ -0,0 +1,20 @@ +package su.levenetc.android.textsurface.animations.effects + +import android.graphics.Canvas +import android.graphics.Paint +import androidx.annotation.CallSuper +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.TextSurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +abstract class TextEffect(text: Text, duration: Long) : TextSurfaceAnimation(text, duration) { + + abstract fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) + + @CallSuper + override fun onStart() { + text.addEffect(this) + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/Circle.kt similarity index 67% rename from library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt rename to library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/Circle.kt index 0719049..bd2956e 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/Circle.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/Circle.kt @@ -1,4 +1,4 @@ -package su.levenetc.android.textsurface.animations.reveal +package su.levenetc.android.textsurface.animations.effects.reveal import android.animation.ValueAnimator import android.animation.ValueAnimator.AnimatorUpdateListener @@ -6,34 +6,29 @@ import android.graphics.Canvas import android.graphics.Paint import android.graphics.Path import android.graphics.Region -import su.levenetc.android.textsurface.Debug -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.TextSurfaceDebug import su.levenetc.android.textsurface.contants.Direction import su.levenetc.android.textsurface.contants.Side +import kotlin.math.sqrt /** * Created by Eugene Levenetc. */ -class Circle private constructor(override val isToShow: Boolean, private val side: Int, private val direction: Int) : IRevealShape, AnimatorUpdateListener { +class Circle private constructor( + isToShow: Boolean, + private val side: Int, + private val direction: Int +) : ShapeRevealAnimation(isToShow), AnimatorUpdateListener { + private var radius = 0f - private var text: Text? = null private val clipPath = Path() - private var animator: ValueAnimator? = null - override lateinit var textSurface: TextSurface private var circX = 0f private var circY = 0f private var clipOp = Region.Op.INTERSECT - override fun setText(text: Text?) { - this.text = text - } - - override fun getAnimator(): ValueAnimator? { - val width = text!!.width - val height = text!!.height - val textX = text!!.getX(textSurface) - val textY = text!!.getY(textSurface) + override fun initAnimator(): ValueAnimator { + val width = text.width + val height = text.height var toRad = 0f var fromRad = 0f val cathA: Float @@ -57,7 +52,7 @@ class Circle private constructor(override val isToShow: Boolean, private val sid cathA = width cathB = height } - val hypo = Math.sqrt((cathA * cathA + cathB * cathB).toDouble()).toFloat() + val hypo = sqrt((cathA * cathA + cathB * cathB).toDouble()).toFloat() if (isToShow) { if (direction == Direction.OUT) { toRad = hypo @@ -73,25 +68,24 @@ class Circle private constructor(override val isToShow: Boolean, private val sid fromRad = hypo } } - animator = ValueAnimator.ofFloat(fromRad, toRad) - animator!!.addUpdateListener(this) + val animator = ValueAnimator.ofFloat(fromRad, toRad) + animator.addUpdateListener(this) return animator } - override fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint?) { + override fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint) { clipPath.reset() clipPath.addCircle(circX, circY, radius, Path.Direction.CCW) - if (Debug.ENABLED) { - canvas.drawPath(clipPath, Debug.BLUE_STROKE!!) - canvas.drawCircle(circX, circY, 10f, Debug.RED_FILL!!) + if (TextSurfaceDebug.ENABLED) { + canvas.drawPath(clipPath, TextSurfaceDebug.BLUE_STROKE) + canvas.drawCircle(circX, circY, 10f, TextSurfaceDebug.RED_FILL) } - canvas.translate(0f, -text!!.fontDescent) + canvas.translate(0f, -text.fontDescent) canvas.clipPath(clipPath, clipOp) } override fun onAnimationUpdate(animation: ValueAnimator) { radius = animation.animatedValue as Float - textSurface!!.invalidate() } companion object { @@ -99,7 +93,6 @@ class Circle private constructor(override val isToShow: Boolean, private val sid * @param side [Side] * @param direction [Direction] Direction.IN or Direction.OUT */ - @kotlin.jvm.JvmStatic fun show(side: Int, direction: Int): Circle { return Circle(true, side, direction) } diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeReveal.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeReveal.kt new file mode 100644 index 0000000..8cc78fb --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeReveal.kt @@ -0,0 +1,52 @@ +package su.levenetc.android.textsurface.animations.effects.reveal + +import android.animation.ValueAnimator +import android.graphics.Canvas +import android.graphics.Paint +import androidx.interpolator.view.animation.FastOutSlowInInterpolator +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.effects.TextEffect +import su.levenetc.android.textsurface.utils.setupAndStart + +/** + * Created by Eugene Levenetc. + */ +class ShapeReveal private constructor(text: Text, duration: Long, private val shapeRevealShape: ShapeRevealAnimation, private val hideOnEnd: Boolean) : TextEffect(text, duration) { + + init { + shapeRevealShape.text = text + } + + private var animator: ValueAnimator? = null + + override fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) { + shapeRevealShape.clip(canvas, textValue, x, y, paint) + } + + override fun setInitValues(text: Text) { + if (shapeRevealShape.isToShow) text.setAlpha(0) + } + + override fun start() { + text.setAlpha(255) + shapeRevealShape.textSurface = textSurface + animator = shapeRevealShape.initAnimator() + animator!!.interpolator = FastOutSlowInInterpolator() + animator!!.setupAndStart(this, endDelegate = { + text.removeEffect(this) + if (hideOnEnd) text.setAlpha(0) + }) + } + + override fun cancel() { + super.cancel() + animator?.cancel() + } + + + companion object { + fun reveal(text: Text, duration: Long, shapeRevealShape: ShapeRevealAnimation, hideOnEnd: Boolean = false): ShapeReveal { + return ShapeReveal(text, duration, shapeRevealShape, hideOnEnd) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeRevealAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeRevealAnimation.kt new file mode 100644 index 0000000..ce8c865 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeRevealAnimation.kt @@ -0,0 +1,16 @@ +package su.levenetc.android.textsurface.animations.effects.reveal + +import android.animation.ValueAnimator +import android.graphics.Canvas +import android.graphics.Paint +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface + +abstract class ShapeRevealAnimation(val isToShow: Boolean) { + + lateinit var textSurface: TextSurface + lateinit var text: Text + + abstract fun initAnimator(): ValueAnimator + abstract fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/SideCut.kt similarity index 64% rename from library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt rename to library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/SideCut.kt index 1fad7bc..03f64a1 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/SideCut.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/SideCut.kt @@ -1,32 +1,24 @@ -package su.levenetc.android.textsurface.animations.reveal +package su.levenetc.android.textsurface.animations.effects.reveal import android.animation.ValueAnimator import android.animation.ValueAnimator.AnimatorUpdateListener import android.graphics.Canvas import android.graphics.Paint import android.graphics.Path -import su.levenetc.android.textsurface.Debug -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.TextSurfaceDebug import su.levenetc.android.textsurface.contants.Side -import su.levenetc.android.textsurface.utils.Utils.dpToPx +import su.levenetc.android.textsurface.utils.toScaledPx /** * Created by Eugene Levenetc. */ -class SideCut private constructor(override val isToShow: Boolean, private val side: Int) : IRevealShape, AnimatorUpdateListener { +class SideCut private constructor(isToShow: Boolean, private val side: Int) : ShapeRevealAnimation(isToShow), AnimatorUpdateListener { + private var diffX = 0f - private var text: Text? = null private val clipPath = Path() - private var animator: ValueAnimator? = null - override lateinit var textSurface: TextSurface - - override fun setText(text: Text?) { - this.text = text - } - override fun getAnimator(): ValueAnimator? { - val width = text!!.width + override fun initAnimator(): ValueAnimator { + val width = text.width var toX = 0f var fromX = 0f if (isToShow) { @@ -45,20 +37,20 @@ class SideCut private constructor(override val isToShow: Boolean, private val si toX = -CUT_SIZE } } - animator = ValueAnimator.ofFloat(fromX, toX) - animator!!.addUpdateListener(this) + val animator = ValueAnimator.ofFloat(fromX, toX) + animator.addUpdateListener(this) return animator } - override fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint?) { - val width = text!!.width - val height = text!!.height + override fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint) { + val width = text.width + val height = text.height if (isToShow) { if (side == Side.LEFT) { clipPath.reset() clipPath.moveTo(x + diffX, y - height) clipPath.rLineTo(width, 0f) - clipPath.rLineTo(CUT_SIZE, height + text!!.fontDescent) + clipPath.rLineTo(CUT_SIZE, height + text.fontDescent) clipPath.rLineTo(-(width + CUT_SIZE), 0f) clipPath.close() } else if (side == Side.RIGHT) { @@ -74,7 +66,7 @@ class SideCut private constructor(override val isToShow: Boolean, private val si clipPath.reset() clipPath.moveTo(x + diffX, y - height) clipPath.rLineTo(width + CUT_SIZE, 0f) - clipPath.rLineTo(0f, height + text!!.fontDescent) + clipPath.rLineTo(0f, height + text.fontDescent) clipPath.rLineTo(-width, 0f) clipPath.close() } else if (side == Side.RIGHT) { @@ -86,26 +78,25 @@ class SideCut private constructor(override val isToShow: Boolean, private val si clipPath.close() } } - if (Debug.ENABLED) canvas.drawPath(clipPath, Debug.BLUE_STROKE!!) - canvas.translate(0f, -text!!.fontDescent) + if (TextSurfaceDebug.ENABLED) canvas.drawPath(clipPath, TextSurfaceDebug.BLUE_STROKE) + canvas.translate(0f, -text.fontDescent) canvas.clipPath(clipPath) } override fun onAnimationUpdate(animation: ValueAnimator) { diffX = animation.animatedValue as Float - textSurface!!.invalidate() + textSurface.invalidate() } companion object { - private val CUT_SIZE = dpToPx(20f) - @kotlin.jvm.JvmStatic - fun show(side: Int): SideCut { + private val CUT_SIZE = 20f.toScaledPx() + + fun showSideCut(side: Int): SideCut { return SideCut(true, side) } - @kotlin.jvm.JvmStatic - fun hide(side: Int): SideCut { + fun hideSideCut(side: Int): SideCut { return SideCut(false, side) } } diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Delay.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Delay.kt new file mode 100644 index 0000000..12be7c7 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Delay.kt @@ -0,0 +1,38 @@ +package su.levenetc.android.textsurface.animations.generic + +import android.graphics.Paint +import android.graphics.RectF +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.AbstractSurfaceAnimation +import su.levenetc.android.textsurface.common.Position + + +class Delay(duration: Long) : AbstractSurfaceAnimation(EMPTY_TEXT, duration) { + + private var action: Runnable? = null + + override fun start() { + action = Runnable { endListener(this) } + textSurface.postDelayed(action, duration) + } + + override fun cancel() { + super.cancel() + action?.let { + textSurface.removeCallbacks(action) + } + } + + override fun toString(): String { + return "Delay{duration=$duration}" + } + + companion object { + + private val EMPTY_TEXT = Text("", Position(), RectF(), Paint()) + + fun delay(duration: Long): Delay { + return Delay(duration) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Just.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Just.kt new file mode 100644 index 0000000..6bc89a4 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Just.kt @@ -0,0 +1,29 @@ +package su.levenetc.android.textsurface.animations.generic + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.AbstractSurfaceAnimation +import su.levenetc.android.textsurface.animations.sets.AnimationsSet +import su.levenetc.android.textsurface.animations.sets.Parallel + +/** + * Created by Eugene Levenetc. + */ +class Just private constructor(text: Text) : AbstractSurfaceAnimation(text, 0) { + + override fun start() { + textSurface.invalidate() + endListener(this) + } + + companion object { + fun show(vararg texts: Text): AnimationsSet { + return Parallel(* texts.map { + show(it) + }.toTypedArray()) + } + + fun show(text: Text): Just { + return Just(text) + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Scale.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Scale.kt new file mode 100644 index 0000000..c283132 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/generic/Scale.kt @@ -0,0 +1,32 @@ +package su.levenetc.android.textsurface.animations.generic + +import android.animation.ObjectAnimator +import android.animation.PropertyValuesHolder +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.animations.TextSurfaceAnimation +import su.levenetc.android.textsurface.utils.setupAndStart + +/** + * Created by Eugene Levenetc. + */ +class Scale(text: Text, duration: Long, private val from: Float, private val to: Float, private val pivot: Int) : TextSurfaceAnimation(text, duration) { + + private var animator: ObjectAnimator? = null + + override fun start() { + text.setScalePivot(pivot.toFloat(), pivot.toFloat()) + val sX = PropertyValuesHolder.ofFloat("scaleX", from, to) + val sY = PropertyValuesHolder.ofFloat("scaleY", from, to) + animator = ObjectAnimator.ofPropertyValuesHolder(text, sX, sY) + animator!!.setupAndStart(this) + } + + override fun cancel() { + super.cancel() + animator?.cancel() + } + + override fun toString(): String { + return "Scale{text=$text}" + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt deleted file mode 100644 index 04d014d..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/IShapeReveal.kt +++ /dev/null @@ -1,17 +0,0 @@ -package su.levenetc.android.textsurface.animations.reveal - -import android.animation.ValueAnimator -import android.graphics.Canvas -import android.graphics.Paint -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface - -interface IRevealShape { - - val isToShow: Boolean - var textSurface: TextSurface - - fun setText(text: Text?) - fun getAnimator(): ValueAnimator? - fun clip(canvas: Canvas, textValue: String?, x: Float, y: Float, paint: Paint?) -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt deleted file mode 100644 index 731d22a..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/animations/reveal/ShapeReveal.kt +++ /dev/null @@ -1,72 +0,0 @@ -package su.levenetc.android.textsurface.animations.reveal - -import android.animation.ValueAnimator -import android.animation.ValueAnimator.AnimatorUpdateListener -import android.graphics.Canvas -import android.graphics.Paint -import androidx.interpolator.view.animation.FastOutSlowInInterpolator -import su.levenetc.android.textsurface.Text -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation -import su.levenetc.android.textsurface.interfaces.ITextEffect -import su.levenetc.android.textsurface.utils.Utils.addEndListener - -/** - * Created by Eugene Levenetc. - */ -class ShapeReveal private constructor(override val text: Text, override var duration: Long, private val revealShape: IRevealShape, private val hideOnEnd: Boolean) : ITextEffect, AnimatorUpdateListener { - - init { - revealShape.setText(text) - } - - override lateinit var textSurface: TextSurface - private var animator: ValueAnimator? = null - override fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) { - revealShape.clip(canvas, textValue, x, y, paint) - } - - override fun setInitValues(text: Text) { - if (revealShape.isToShow) text.setAlpha(0) - } - - override fun onStart() { - text.addEffect(this) - } - - override fun start(listener: IEndListener) { - text.setAlpha(255) - revealShape.textSurface = textSurface - animator = revealShape.getAnimator() - animator!!.interpolator = FastOutSlowInInterpolator() - addEndListener(this, animator!!, object : IEndListener { - override fun onAnimationEnd(animation: ISurfaceAnimation) { - text.removeEffect(this@ShapeReveal) - if (hideOnEnd) text.setAlpha(0) - listener?.onAnimationEnd(this@ShapeReveal) - } - }) - animator!!.duration = duration - animator!!.start() - } - - override fun cancel() { - if (animator != null && animator!!.isRunning) { - animator!!.cancel() - animator = null - } - } - - override fun onAnimationUpdate(animation: ValueAnimator) { - textSurface!!.invalidate() - } - - - companion object { - @kotlin.jvm.JvmStatic - fun create(text: Text, duration: Long, revealShape: IRevealShape, hideOnEnd: Boolean): ShapeReveal { - return ShapeReveal(text, duration, revealShape, hideOnEnd) - } - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/sets/AnimationsSet.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/AnimationsSet.kt new file mode 100644 index 0000000..27beb1c --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/AnimationsSet.kt @@ -0,0 +1,43 @@ +package su.levenetc.android.textsurface.animations.sets + +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.SurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +abstract class AnimationsSet(duration: Long, vararg animations: SurfaceAnimation) : SurfaceAnimation(duration) { + + val animations: List = animations.toList() + private var currentAnimation: SurfaceAnimation? = null + + override var textSurface: TextSurface + get() = super.textSurface + set(value) { + animations.forEach { it.textSurface = value } + } + + override fun cancel() { + super.cancel() + animations.forEach { it.cancel() } + } + + protected abstract fun onCurrentAnimationFinished(animation: SurfaceAnimation) + + protected fun finalizeAnimation() { + endListener(this) + } + + protected fun initCurrentAnimation(animation: SurfaceAnimation) { + currentAnimation = animation + currentAnimation!!.onStart() + currentAnimation!!.endListener = { + if (canceled) { + finalizeAnimation() + } else { + onCurrentAnimationFinished(it) + } + } + currentAnimation!!.start() + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Loop.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Loop.kt new file mode 100644 index 0000000..71c02cc --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Loop.kt @@ -0,0 +1,22 @@ +package su.levenetc.android.textsurface.animations.sets + +import su.levenetc.android.textsurface.animations.SurfaceAnimation + +/** + * Created by ogaclejapan. + */ +class Loop(vararg animations: SurfaceAnimation) : AnimationsSet(Long.MAX_VALUE, *animations) { + + private var index = 0 + + override fun onCurrentAnimationFinished(animation: SurfaceAnimation) { + if (canceled) return + if (index > animations.size - 1) index = 0 + initCurrentAnimation(animations[index++]) + } + + override fun start() { + super.start() + initCurrentAnimation(animations[index++]) + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Parallel.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Parallel.kt new file mode 100644 index 0000000..65a8a9d --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Parallel.kt @@ -0,0 +1,28 @@ +package su.levenetc.android.textsurface.animations.sets + +import su.levenetc.android.textsurface.animations.SurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +class Parallel(vararg animations: SurfaceAnimation) : AnimationsSet(getDuration(animations), * animations) { + + private var lastAnimation: SurfaceAnimation? = null + + override fun onCurrentAnimationFinished(animation: SurfaceAnimation) { + if (animation === lastAnimation) finalizeAnimation() + } + + override fun start() { + lastAnimation = animations.maxByOrNull { it.duration } + animations.forEach { initCurrentAnimation(it) } + super.start() + } + + companion object { + private fun getDuration(animations: Array): Long { + return animations.maxByOrNull { a -> a.duration }?.duration ?: 0 + } + } + +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Sequential.kt b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Sequential.kt new file mode 100644 index 0000000..43f81b0 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/animations/sets/Sequential.kt @@ -0,0 +1,30 @@ +package su.levenetc.android.textsurface.animations.sets + +import su.levenetc.android.textsurface.animations.SurfaceAnimation + +/** + * Created by Eugene Levenetc. + */ +open class Sequential(vararg animations: SurfaceAnimation) : AnimationsSet(getDuration(animations), *animations) { + + private var index = 0 + + override fun start() { + super.start() + initCurrentAnimation(animations[index++]) + } + + override fun onCurrentAnimationFinished(animation: SurfaceAnimation) { + if (index < animations.size) { + initCurrentAnimation(animations[index++]) + } else { + finalizeAnimation() + } + } + + companion object { + private fun getDuration(animations: Array): Long { + return animations.sumOf { it.duration } + } + } +} \ No newline at end of file From 6ccd3e055b22bb49c7ef4c5ddf1d8ebc90185b62 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Mon, 15 Feb 2021 01:33:56 +0100 Subject: [PATCH 05/18] Delete interfaces package --- .../textsurface/interfaces/ICameraAnimation.kt | 10 ---------- .../textsurface/interfaces/IEndListener.kt | 8 -------- .../android/textsurface/interfaces/ISet.kt | 12 ------------ .../textsurface/interfaces/ISurfaceAnimation.kt | 16 ---------------- .../textsurface/interfaces/ITextEffect.kt | 11 ----------- .../interfaces/ITextSurfaceAnimation.kt | 11 ----------- 6 files changed, 68 deletions(-) delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt deleted file mode 100644 index f46ce46..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ICameraAnimation.kt +++ /dev/null @@ -1,10 +0,0 @@ -package su.levenetc.android.textsurface.interfaces - -import su.levenetc.android.textsurface.SurfaceCamera - -/** - * Created by Eugene Levenetc. - */ -interface ICameraAnimation : ISurfaceAnimation { - fun setCamera(camera: SurfaceCamera?) -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt deleted file mode 100644 index 6352de1..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/IEndListener.kt +++ /dev/null @@ -1,8 +0,0 @@ -package su.levenetc.android.textsurface.interfaces - -/** - * Created by Eugene Levenetc. - */ -interface IEndListener { - fun onAnimationEnd(animation: ISurfaceAnimation) -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt deleted file mode 100644 index 39f65d4..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISet.kt +++ /dev/null @@ -1,12 +0,0 @@ -package su.levenetc.android.textsurface.interfaces - -import su.levenetc.android.textsurface.contants.TYPE -import java.util.* - -/** - * Created by Eugene Levenetc. - */ -interface ISet : ISurfaceAnimation { - val type: TYPE - val animations: LinkedList -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt deleted file mode 100644 index 2c52071..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ISurfaceAnimation.kt +++ /dev/null @@ -1,16 +0,0 @@ -package su.levenetc.android.textsurface.interfaces - -import su.levenetc.android.textsurface.TextSurface - -/** - * Created by Eugene Levenetc. - */ -interface ISurfaceAnimation { - - val duration: Long - var textSurface: TextSurface - - fun onStart() - fun start(listener: IEndListener) - fun cancel() -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt deleted file mode 100644 index 36a4723..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.kt +++ /dev/null @@ -1,11 +0,0 @@ -package su.levenetc.android.textsurface.interfaces - -import android.graphics.Canvas -import android.graphics.Paint - -/** - * Created by Eugene Levenetc. - */ -interface ITextEffect : ITextSurfaceAnimation { - fun apply(canvas: Canvas, textValue: String, x: Float, y: Float, paint: Paint) -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt b/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt deleted file mode 100644 index bc89bc8..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextSurfaceAnimation.kt +++ /dev/null @@ -1,11 +0,0 @@ -package su.levenetc.android.textsurface.interfaces - -import su.levenetc.android.textsurface.Text - -/** - * Created by Eugene Levenetc. - */ -interface ITextSurfaceAnimation : ISurfaceAnimation { - val text: Text - fun setInitValues(text: Text) -} \ No newline at end of file From 08addb3f1d954ef8629d217725050b3c243f0705 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Mon, 15 Feb 2021 01:34:48 +0100 Subject: [PATCH 06/18] Cleanup constants and common classes --- .../android/textsurface/common/Position.kt | 178 ++++++++---------- .../android/textsurface/common/ScaleValue.kt | 5 +- .../android/textsurface/contants/Align.kt | 25 +-- .../android/textsurface/contants/Axis.kt | 6 +- .../android/textsurface/contants/Direction.kt | 11 +- .../android/textsurface/contants/Fit.kt | 6 +- .../android/textsurface/contants/Pivot.kt | 3 + .../android/textsurface/contants/TYPE.kt | 8 - 8 files changed, 100 insertions(+), 142 deletions(-) delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt diff --git a/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt b/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt index 607fbf0..7b13479 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/common/Position.kt @@ -9,127 +9,107 @@ import su.levenetc.android.textsurface.contants.Pivot /** * Created by Eugene Levenetc. */ -class Position { - private var align = 0 - private var alignText: Text? = null - var point: PointF? = PointF() - private set - private var translationX = 0f - private var translationY = 0f - - constructor() { - point = PointF() - } - - constructor(src: Position) { - align = src.align - alignText = src.alignText - point!!.set(src.point!!) - translationX = src.translationX - translationY = src.translationY - } - - constructor(point: PointF?) { - this.point = point - } - - constructor(align: Int) { - this.align = align - } - - constructor(align: Int, alignText: Text?) { - this.align = align - this.alignText = alignText - } - - fun set(src: Position) { - align = src.align - alignText = src.alignText - point!!.set(src.point!!) - translationX = src.translationX - translationY = src.translationY - } - - fun getRelativeX(pivot: Int, text: Text?, global: Boolean): Float { +data class Position( + var align: Int = 0, + var point: PointF = PointF(), + var translationX: Float = 0f, + var translationY: Float = 0f, + var alignText: Text? = null +) { + + fun getRelativeX(pivot: Int, text: Text, global: Boolean): Float { var result = 0f - if (pivot and Pivot.LEFT == Pivot.LEFT) { -// result = point.x; - } else if (pivot and Pivot.RIGHT == Pivot.RIGHT) { - result += text!!.width - } else if (pivot and Pivot.CENTER == Pivot.CENTER) { - result += text!!.width / 2 + when { + pivot and Pivot.LEFT == Pivot.LEFT -> { + //result = point.x; + } + pivot and Pivot.RIGHT == Pivot.RIGHT -> { + result += text.width + } + pivot and Pivot.CENTER == Pivot.CENTER -> { + result += text.width / 2 + } } - return if (global) result + point!!.x + translationX else result + return if (global) result + point.x + translationX else result } - fun getRelativeY(pivot: Int, text: Text?, global: Boolean): Float { + fun getRelativeY(pivot: Int, text: Text, global: Boolean): Float { var result = 0f - if (pivot and Pivot.BOTTOM == Pivot.BOTTOM) { - //result = text.getY(textSurface); - } else if (pivot and Pivot.TOP == Pivot.TOP) { - result -= text!!.height - } else if (pivot and Pivot.CENTER == Pivot.CENTER) { - result -= text!!.height / 2 + when { + pivot and Pivot.BOTTOM == Pivot.BOTTOM -> { + //result = text.getY(textSurface); + } + pivot and Pivot.TOP == Pivot.TOP -> { + result -= text.height + } + pivot and Pivot.CENTER == Pivot.CENTER -> { + result -= text.height / 2 + } } - return if (global) result + point!!.y + translationY else result + return if (global) result + point.y + translationY else result } - fun getX(textSurface: TextSurface?, textWidth: Float): Float { - if (isAligned) { - if (alignedWith(Align.SURFACE_CENTER)) { - point!!.x = -textWidth / 2 - } else if (alignedWith(Align.RIGHT_OF)) { - point!!.x = alignText!!.getX(textSurface) + alignText!!.width - } else if (alignedWith(Align.LEFT_OF)) { - point!!.x = alignText!!.getX(textSurface) - textWidth - } else if (alignedWith(Align.CENTER_OF)) { - point!!.x = alignText!!.getX(textSurface) + (alignText!!.width - textWidth) / 2 - } else { - point!!.x = alignText!!.getX(textSurface) + fun getX(textSurface: TextSurface, textWidth: Float): Float { + alignText?.let { alignText -> + if (align != Align.UNDEFINED) { + when { + alignedWith(Align.SURFACE_CENTER) -> { + point.x = -textWidth / 2 + } + alignedWith(Align.RIGHT_OF) -> { + point.x = alignText.getX(textSurface) + alignText.width + } + alignedWith(Align.LEFT_OF) -> { + point.x = alignText.getX(textSurface) - textWidth + } + alignedWith(Align.CENTER_OF) -> { + point.x = alignText.getX(textSurface) + (alignText.width - textWidth) / 2 + } + else -> { + point.x = alignText.getX(textSurface) + } + } } } - return point!!.x + translationX - } - - private fun alignedWith(align: Int): Boolean { - return this.align and align == align + return point.x + translationX } fun getY(textSurface: TextSurface?, textHeight: Float): Float { - if (isAligned) { - if (alignedWith(Align.SURFACE_CENTER)) { - point!!.y = textHeight / 2 - } else if (alignedWith(Align.TOP_OF)) { - point!!.y = alignText!!.getY(textSurface) - alignText!!.height - } else if (alignedWith(Align.BOTTOM_OF)) { - point!!.y = alignText!!.getY(textSurface) + textHeight - } else if (alignedWith(Align.CENTER_OF)) { - point!!.y = alignText!!.getY(textSurface) - (alignText!!.height - textHeight) / 2 - } else { - point!!.y = alignText!!.getY(textSurface) + alignText?.let { alignText -> + if (align != Align.UNDEFINED) { + when { + alignedWith(Align.SURFACE_CENTER) -> { + point.y = textHeight / 2 + } + alignedWith(Align.TOP_OF) -> { + point.y = alignText.getY(textSurface) - alignText.height + } + alignedWith(Align.BOTTOM_OF) -> { + point.y = alignText.getY(textSurface) + textHeight + } + alignedWith(Align.CENTER_OF) -> { + point.y = alignText.getY(textSurface) - (alignText.height - textHeight) / 2 + } + else -> { + point.y = alignText.getY(textSurface) + } + } } } - return point!!.y + translationY - } - val isAligned: Boolean - get() = align != 0 - fun setY(y: Float) { - if (point != null) point!!.y = y + return point.y + translationY } - fun setX(x: Float) { - if (point != null) point!!.x = x + fun setY(y: Float) { + point.y = y } - fun setTranslationX(x: Float) { - translationX = x + fun setX(x: Float) { + point.x = x } - fun setTranslationY(y: Float) { - translationY = y + private fun alignedWith(align: Int): Boolean { + return this.align and align == align } - - fun onAnimationEnd() {} } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt b/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt index 42c6157..572ae98 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/common/ScaleValue.kt @@ -5,9 +5,8 @@ import android.graphics.PointF /** * Created by Eugene Levenetc. */ -class ScaleValue { - private val scale = PointF(1f, 1f) - val pivot = PointF() +data class ScaleValue(val scale: PointF = PointF(1f, 1f), val pivot: PointF = PointF()) { + fun setValue(scale: Float) { this.scale[scale] = scale } diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt index 21621b0..a62540d 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Align.kt @@ -4,21 +4,12 @@ package su.levenetc.android.textsurface.contants * Created by Eugene Levenetc. */ object Align { - @kotlin.jvm.JvmField - var RIGHT_OF = 2 - - @kotlin.jvm.JvmField - var LEFT_OF = 4 - - @kotlin.jvm.JvmField - var TOP_OF = 16 - - @kotlin.jvm.JvmField - var BOTTOM_OF = 32 - - @kotlin.jvm.JvmField - var CENTER_OF = 64 - - @kotlin.jvm.JvmField - var SURFACE_CENTER = 128 + const val UNDEFINED = 0 + + const val RIGHT_OF = 2 + const val LEFT_OF = 4 + const val TOP_OF = 16 + const val BOTTOM_OF = 32 + const val CENTER_OF = 64 + const val SURFACE_CENTER = 128 } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt index 82c7be0..55db7a0 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Axis.kt @@ -3,8 +3,6 @@ package su.levenetc.android.textsurface.contants /** * Created by Eugene Levenetc. */ -object Axis { - const val X = 1 - const val Y = 2 - const val Z = 4 +enum class Axis { + X, Y, Z, Undefined } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt index 9f50a63..3d747eb 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Direction.kt @@ -4,11 +4,8 @@ package su.levenetc.android.textsurface.contants * Created by Eugene Levenetc. */ object Direction { - @kotlin.jvm.JvmField - var CLOCK = 1 - var COUNTER_CLOCK = 2 - var IN = 4 - - @kotlin.jvm.JvmField - var OUT = 16 + const val CLOCK = 1 + const val COUNTER_CLOCK = 2 + const val IN = 4 + const val OUT = 16 } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt index 529912b..56623de 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Fit.kt @@ -3,8 +3,6 @@ package su.levenetc.android.textsurface.contants /** * Created by Eugene Levenetc. */ -object Fit { - @kotlin.jvm.JvmField - var WIDTH = 2 - var HEIGTH = 4 +enum class Fit { + WIDTH, HEIGHT, UNDEFINED } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt index 29e908e..abbe141 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/contants/Pivot.kt @@ -4,6 +4,9 @@ package su.levenetc.android.textsurface.contants * Created by Eugene Levenetc. */ object Pivot { + + const val UNDEFINED = 0 + const val TOP = 1 const val BOTTOM = 2 const val LEFT = 4 diff --git a/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt b/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt deleted file mode 100644 index 42b725b..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/contants/TYPE.kt +++ /dev/null @@ -1,8 +0,0 @@ -package su.levenetc.android.textsurface.contants - -/** - * Created by Eugene Levenetc. - */ -enum class TYPE { - SEQUENTIAL, PARALLEL -} \ No newline at end of file From 8aa702613ce560cee7b5fd9f0e0edf98ee8d0c56 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Mon, 15 Feb 2021 01:35:23 +0100 Subject: [PATCH 07/18] Add utils extensions, remove unused ones --- .../textsurface/utils/AnimatorEndListener.kt | 14 ------ .../textsurface/utils/AnimatorExtensions.kt | 21 +++++++++ .../android/textsurface/utils/LayoutUtils.kt | 38 ++++++++++++++++ .../textsurface/utils/PlatformExtensions.kt | 13 ++++++ .../textsurface/utils/PrimitiveExtensions.kt | 23 ++++++++++ .../android/textsurface/utils/Utils.kt | 44 ------------------- 6 files changed, 95 insertions(+), 58 deletions(-) delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorExtensions.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/LayoutUtils.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/PlatformExtensions.kt create mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/PrimitiveExtensions.kt delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt deleted file mode 100644 index e7c8d77..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorEndListener.kt +++ /dev/null @@ -1,14 +0,0 @@ -package su.levenetc.android.textsurface.utils - -import android.animation.Animator -import android.animation.Animator.AnimatorListener - -/** - * Created by Eugene Levenetc. - */ -abstract class AnimatorEndListener : AnimatorListener { - override fun onAnimationStart(animation: Animator) {} - override fun onAnimationEnd(animation: Animator) {} - override fun onAnimationCancel(animation: Animator) {} - override fun onAnimationRepeat(animation: Animator) {} -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorExtensions.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorExtensions.kt new file mode 100644 index 0000000..4511d93 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/utils/AnimatorExtensions.kt @@ -0,0 +1,21 @@ +package su.levenetc.android.textsurface.utils + +import android.animation.ValueAnimator +import androidx.core.animation.doOnEnd +import su.levenetc.android.textsurface.animations.SurfaceAnimation + +internal fun ValueAnimator.setupAndStart( + animation: SurfaceAnimation, + updateDelegate: (ValueAnimator) -> Unit = {}, + endDelegate: (SurfaceAnimation) -> Unit = {}) { + duration = animation.duration + addUpdateListener { + updateDelegate(it) + animation.textSurface.invalidate() + } + doOnEnd { + animation.endListener(animation) + endDelegate(animation) + } + start() +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/LayoutUtils.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/LayoutUtils.kt new file mode 100644 index 0000000..55cf519 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/utils/LayoutUtils.kt @@ -0,0 +1,38 @@ +package su.levenetc.android.textsurface.utils + +import android.view.View +import android.view.ViewGroup + + +internal fun measureDimension(desiredSize: Int, measureSpec: Int): Int { + var result: Int + val mode = View.MeasureSpec.getMode(measureSpec) + val size = View.MeasureSpec.getSize(measureSpec) + if (mode == View.MeasureSpec.EXACTLY) { + result = size + } else { + result = desiredSize + if (mode == View.MeasureSpec.AT_MOST) { + result = result.coerceAtMost(size) + } + } + return result +} + +internal fun getDesiredSize(layoutParamValue: Int, minSize: Int, spec: Int): Int { + return if (minSize != 0) { + minSize + } else { + when (layoutParamValue) { + ViewGroup.LayoutParams.MATCH_PARENT -> { + View.MeasureSpec.getSize(spec) + } + ViewGroup.LayoutParams.WRAP_CONTENT -> { + 0 + } + else -> { + layoutParamValue + } + } + } +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/PlatformExtensions.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/PlatformExtensions.kt new file mode 100644 index 0000000..067ca4a --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/utils/PlatformExtensions.kt @@ -0,0 +1,13 @@ +package su.levenetc.android.textsurface.utils + +import android.content.res.Resources +import android.util.TypedValue + +internal fun Float.toScaledPx(): Float { + val metrics = Resources.getSystem().displayMetrics + return this * (metrics.densityDpi / 160f) +} + +internal fun Float.toSp(): Float { + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this, Resources.getSystem().displayMetrics) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/PrimitiveExtensions.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/PrimitiveExtensions.kt new file mode 100644 index 0000000..74a9ea2 --- /dev/null +++ b/library/src/main/java/su/levenetc/android/textsurface/utils/PrimitiveExtensions.kt @@ -0,0 +1,23 @@ +package su.levenetc.android.textsurface.utils + +import java.util.* + +internal fun Int.verifiedRange(from: Int, to: Int): Int { + return when { + this < from -> { + from + } + this > to -> { + to + } + else -> { + this + } + } +} + +internal fun Int.toEscapedString(): String { + val array = CharArray(this) + Arrays.fill(array, '\'') + return String(array) +} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt b/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt deleted file mode 100644 index 1d730dd..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/utils/Utils.kt +++ /dev/null @@ -1,44 +0,0 @@ -package su.levenetc.android.textsurface.utils - -import android.animation.Animator -import android.content.res.Resources -import su.levenetc.android.textsurface.interfaces.IEndListener -import su.levenetc.android.textsurface.interfaces.ISurfaceAnimation -import java.util.* - -/** - * Created by Eugene Levenetc. - */ -object Utils { - /** - * Generates string of "`" char - * Not effective on large sizes - */ - fun genString(size: Int): String { - val array = CharArray(size) - Arrays.fill(array, '\'') - return String(array) - } - - fun concat(first: Array, second: Array): Array { - val result = Arrays.copyOf(first, first.size + second.size) - System.arraycopy(second, 0, result, first.size, second.size) - return result - } - - @JvmStatic - fun addEndListener(animation: ISurfaceAnimation, animator: Animator, listener: IEndListener? = null) { - if (listener == null) return - animator.addListener(object : AnimatorEndListener() { - override fun onAnimationEnd(a: Animator) { - listener.onAnimationEnd(animation) - } - }) - } - - @JvmStatic - fun dpToPx(dp: Float): Float { - val metrics = Resources.getSystem().displayMetrics - return dp * (metrics.densityDpi / 160f) - } -} \ No newline at end of file From 157a5898ff20b36004bcb627a4973005703e8846 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Mon, 15 Feb 2021 01:36:20 +0100 Subject: [PATCH 08/18] Refactor and cleanup core entities: Text, Text.Builder, TextSurface, SurfaceCamera --- .../su/levenetc/android/textsurface/Text.kt | 205 +++++++++++++----- .../android/textsurface/TextBuilder.kt | 121 ----------- .../android/textsurface/TextSurface.kt | 106 +++++---- .../{Debug.kt => TextSurfaceDebug.kt} | 6 +- .../textsurface/{ => camera}/SurfaceCamera.kt | 56 ++--- 5 files changed, 232 insertions(+), 262 deletions(-) delete mode 100644 library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt rename library/src/main/java/su/levenetc/android/textsurface/{Debug.kt => TextSurfaceDebug.kt} (94%) rename library/src/main/java/su/levenetc/android/textsurface/{ => camera}/SurfaceCamera.kt (75%) diff --git a/library/src/main/java/su/levenetc/android/textsurface/Text.kt b/library/src/main/java/su/levenetc/android/textsurface/Text.kt index a30014f..3723f44 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/Text.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/Text.kt @@ -1,54 +1,74 @@ package su.levenetc.android.textsurface import android.graphics.* +import su.levenetc.android.textsurface.animations.effects.TextEffect import su.levenetc.android.textsurface.common.Position import su.levenetc.android.textsurface.common.ScaleValue -import su.levenetc.android.textsurface.interfaces.ITextEffect -import su.levenetc.android.textsurface.utils.Utils -import java.util.* +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.utils.toEscapedString +import su.levenetc.android.textsurface.utils.toSp +import su.levenetc.android.textsurface.utils.verifiedRange /** * Created by Eugene Levenetc. */ class Text(val value: String, var position: Position, private val padding: RectF, val paint: Paint) : Comparable { - private var defaultSize: RectF? = null + + private var bounds: RectF private val currentSize = RectF() - var index = 0 private val scale = ScaleValue() private val matrix = Matrix() - private val effects = ArrayList() + private val effects = mutableListOf() private var dx = 0f + var fontDescent = 0f private set - fun addEffect(effect: ITextEffect) { - effects.add(effect) - } + val width: Float + get() = currentSize.width() + padding.left + padding.right + val height: Float + get() = currentSize.height() + padding.top + padding.bottom + + var scaleY: Float + get() = scale.scaleY + set(value) { + scale.setValueY(value) + } + + var scaleX: Float + get() = scale.scaleX + set(value) { + scale.setValueX(value) + } - private fun initBounds(text: String) { - var text = text + init { + var text = value val trimmed = text.trim { it <= ' ' } if (trimmed.length < text.length) { val length = text.length val start = text.lastIndexOf(trimmed) val end = length - (start + trimmed.length) - text = Utils.genString(start) + text + Utils.genString(end) + text = start.toEscapedString() + text + end.toEscapedString() } val tmp = Rect() paint.getTextBounds(text, 0, text.length, tmp) fontDescent = paint.fontMetrics.descent - defaultSize = RectF(tmp) + bounds = RectF(tmp) //a little workaround because getTextBounds returns smaller width than it is dx = paint.measureText(text) - tmp.width() - defaultSize!!.left = 0f - defaultSize!!.right = tmp.width() + dx - defaultSize!!.top = -paint.fontSpacing - defaultSize!!.bottom = 0f - defaultSize!![defaultSize!!.left, defaultSize!!.top, defaultSize!!.right] = defaultSize!!.bottom - currentSize[defaultSize!!.left, defaultSize!!.top, defaultSize!!.right] = defaultSize!!.bottom + bounds.left = 0f + bounds.right = tmp.width() + dx + bounds.top = -paint.fontSpacing + bounds.bottom = 0f + bounds[bounds.left, bounds.top, bounds.right] = bounds.bottom + currentSize[bounds.left, bounds.top, bounds.right] = bounds.bottom } - fun onDraw(canvas: Canvas, textSurface: TextSurface?) { + fun addEffect(effect: TextEffect) { + effects.add(effect) + } + + fun onDraw(canvas: Canvas, textSurface: TextSurface) { layout(textSurface) canvas.save() canvas.concat(matrix) @@ -64,19 +84,19 @@ class Text(val value: String, var position: Position, private val padding: RectF } } canvas.restore() - if (Debug.ENABLED) { + if (TextSurfaceDebug.ENABLED) { canvas.drawRect( currentSize.left, currentSize.top - padding.bottom - padding.top, currentSize.right + padding.left + padding.right, currentSize.bottom, - Debug.RED_STROKE + TextSurfaceDebug.RED_STROKE ) } } - fun layout(textSurface: TextSurface?) { - currentSize[defaultSize!!.left, defaultSize!!.top, defaultSize!!.right] = defaultSize!!.bottom + fun layout(textSurface: TextSurface) { + currentSize[bounds.left, bounds.top, bounds.right] = bounds.bottom val sx = scale.scaleX val sy = scale.scaleY val sPivotX = position.getRelativeX(scale.pivot.x.toInt(), this, false) @@ -93,7 +113,7 @@ class Text(val value: String, var position: Position, private val padding: RectF return position.getY(textSurface, height) } - fun getX(textSurface: TextSurface?): Float { + fun getX(textSurface: TextSurface): Float { return position.getX(textSurface, width) } @@ -101,58 +121,131 @@ class Text(val value: String, var position: Position, private val padding: RectF paint.alpha = alpha } - fun bounds(): RectF? { - return defaultSize - } - fun setScalePivot(x: Float, y: Float) { scale.pivot[x] = y } - var scaleY: Float - get() = scale.scaleY - set(value) { - scale.setValueY(value) - } - fun setTranslationX(value: Float) { - position.setTranslationX(value) + position.translationX = value } fun setTranslationY(value: Float) { - position.setTranslationY(value) + position.translationY = value } override fun compareTo(another: Text): Int { return value.compareTo(another.value) } - val width: Float - get() = currentSize.width() + padding.left + padding.right - val height: Float - get() = currentSize.height() + padding.top + padding.bottom - fun onAnimationEnd() { - position.onAnimationEnd() + } - var scaleX: Float - get() = scale.scaleX - set(value) { - scale.setValueX(value) - } + fun removeEffect(effect: TextEffect) { + effects.remove(effect) + } override fun toString(): String { - return "Text{" + - "text='" + value + '\'' + - '}' + return "Text{text='$value'}" } - fun removeEffect(effect: ITextEffect) { - effects.remove(effect) - } + class Builder(private val text: String) { - init { - initBounds(value) + private var showTime = 0 + private var position = Position() + private val padding = RectF() + private var scale = 1f + private var scalePivot = Pivot.CENTER + private var paint = Paint().apply { + color = Color.WHITE + isAntiAlias = true + textSize = 18f.toSp() + } + + fun setShowTime(showTime: Int): Builder { + this.showTime = showTime + return this + } + + fun setPosition(px: Float, py: Float): Builder { + position = Position(point = PointF(px, py)) + return this + } + + fun setPosition(align: Int): Builder { + position = Position(align) + return this + } + + fun setPosition(align: Int, alignText: Text): Builder { + position = Position(align, alignText = alignText) + return this + } + + /** + * params are in pixels + */ + fun setPadding(left: Float, top: Float, right: Float, bottom: Float): Builder { + padding[left, top, right] = bottom + return this + } + + /** + * params are in pixels + */ + fun setLeftPadding(left: Float): Builder { + padding[left, padding.top, padding.right] = padding.bottom + return this + } + + fun setPadding(padding: RectF?): Builder { + this.padding.set(padding!!) + return this + } + + fun setPosition(position: Position): Builder { + this.position = position.copy() + return this + } + + /** + * Overrides all previously set paint properties + */ + fun setPaint(paint: Paint?): Builder { + this.paint = Paint(paint) + return this + } + + /** + * @param alpha from 0 to 255 + */ + fun setAlpha(alpha: Int): Builder { + paint.alpha = alpha.verifiedRange(0, 255) + return this + } + + fun setColor(color: Int): Builder { + paint.color = color + return this + } + + fun setSize(size: Float): Builder { + paint.textSize = size.toSp() + return this + } + + fun setScale(scale: Float, scalePivot: Int): Builder { + this.scale = scale + this.scalePivot = scalePivot + return this + } + + fun build(): Text { + val result = Text(text, position, padding, paint) + result.scaleX = scale + result.scaleY = scale + result.setScalePivot(scalePivot.toFloat(), scalePivot.toFloat()) + return result + } } } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt b/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt deleted file mode 100644 index ac5cd38..0000000 --- a/library/src/main/java/su/levenetc/android/textsurface/TextBuilder.kt +++ /dev/null @@ -1,121 +0,0 @@ -package su.levenetc.android.textsurface - -import android.content.res.Resources -import android.graphics.Color -import android.graphics.Paint -import android.graphics.PointF -import android.graphics.RectF -import android.util.TypedValue -import su.levenetc.android.textsurface.common.Position -import su.levenetc.android.textsurface.contants.Pivot - -/** - * Created by Eugene Levenetc. - */ -class TextBuilder private constructor(private val text: String) { - private var showTime = 0 - private var position = Position() - private val padding = RectF() - private var paint = Paint() - private var scale = 1f - private var scalePivot = Pivot.CENTER - fun setShowTime(showTime: Int): TextBuilder { - this.showTime = showTime - return this - } - - fun setPosition(px: Float, py: Float): TextBuilder { - position = Position(PointF(px, py)) - return this - } - - fun setPosition(align: Int): TextBuilder { - position = Position(align) - return this - } - - fun setPosition(align: Int, alignText: Text?): TextBuilder { - position = Position(align, alignText) - return this - } - - /** - * params are in pixels - */ - fun setPadding(left: Float, top: Float, right: Float, bottom: Float): TextBuilder { - padding[left, top, right] = bottom - return this - } - - /** - * params are in pixels - */ - fun setLeftPadding(left: Float): TextBuilder { - padding[left, padding.top, padding.right] = padding.bottom - return this - } - - fun setPadding(padding: RectF?): TextBuilder { - this.padding.set(padding!!) - return this - } - - fun setPosition(position: Position): TextBuilder { - this.position.set(position) - return this - } - - /** - * Overrides all previously set paint properties - */ - fun setPaint(paint: Paint?): TextBuilder { - this.paint = Paint(paint) - return this - } - - /** - * @param alpha from 0 to 255 - */ - fun setAlpha(alpha: Int): TextBuilder { - paint.alpha = alpha - return this - } - - fun setColor(color: Int): TextBuilder { - paint.color = color - return this - } - - fun setSize(sp: Float): TextBuilder { - paint.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sp, Resources.getSystem().displayMetrics) - return this - } - - fun setScale(scale: Float, scalePivot: Int): TextBuilder { - this.scale = scale - this.scalePivot = scalePivot - return this - } - - fun build(): Text { - val result = Text(text, position, padding, paint) - result.scaleX = scale - result.scaleY = scale - result.setScalePivot(scalePivot.toFloat(), scalePivot.toFloat()) - return result - } - - companion object { - @JvmStatic - fun create(text: String): TextBuilder { - return TextBuilder(text) - } - } - - init { - paint.color = Color.WHITE - paint.isAntiAlias = true - paint.textSize = 110f - setSize(18f) - } -} \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt b/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt index d885f6b..797252b 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt @@ -3,88 +3,84 @@ package su.levenetc.android.textsurface import android.content.Context import android.graphics.Canvas import android.util.AttributeSet -import android.widget.FrameLayout -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.contants.TYPE -import su.levenetc.android.textsurface.interfaces.* -import java.util.* +import android.view.View +import su.levenetc.android.textsurface.animations.SurfaceAnimation +import su.levenetc.android.textsurface.animations.TextSurfaceAnimation +import su.levenetc.android.textsurface.animations.camera.CameraAnimation +import su.levenetc.android.textsurface.animations.sets.AnimationsSet +import su.levenetc.android.textsurface.animations.sets.Parallel +import su.levenetc.android.textsurface.animations.sets.Sequential +import su.levenetc.android.textsurface.camera.SurfaceCamera +import su.levenetc.android.textsurface.utils.getDesiredSize +import su.levenetc.android.textsurface.utils.measureDimension /** * Created by Eugene Levenetc. */ -class TextSurface : FrameLayout { - private val textsTree = TreeSet() - val camera = SurfaceCamera() - private var currentAnimation: ISurfaceAnimation? = null +class TextSurface : View { - constructor(context: Context?) : super(context!!) { - config() - } - - constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) { - config() - } + private val camera = SurfaceCamera() + private val texts = mutableSetOf() + private lateinit var currentAnimation: SurfaceAnimation - private fun config() { + init { setWillNotDraw(false) } - fun play(type: TYPE, vararg animations: ISurfaceAnimation) { - play(AnimationsSet(type, *animations)) + constructor(context: Context?) : super(context!!) + constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) + + fun playParallel(vararg animations: SurfaceAnimation) { + play(Parallel(* animations)) } - fun play(vararg animations: ISurfaceAnimation?) { - play(AnimationsSet(TYPE.PARALLEL, *animations)) + fun playSequential(vararg animations: SurfaceAnimation) { + play(Sequential(* animations)) } - fun play(animation: ISurfaceAnimation) { + fun play(animation: SurfaceAnimation) { configAnimations(animation) animation.textSurface = this layout() currentAnimation = animation - currentAnimation!!.start(object : IEndListener { - override fun onAnimationEnd(animation: ISurfaceAnimation) { - //TODO: remove empty listener - } + currentAnimation.start() + } - }) + override fun onDraw(canvas: Canvas) { + super.onDraw(canvas) + camera.onDraw(canvas) + texts.forEach { it.onDraw(canvas, this) } } - private fun layout() { - val iterator: Iterator = textsTree.iterator() - while (iterator.hasNext()) iterator.next().layout(this) + fun reset() { + if (this::currentAnimation.isInitialized) currentAnimation.cancel() + texts.clear() + camera.reset() + invalidate() } - override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) { - super.onLayout(changed, left, top, right, bottom) + private fun layout() { + texts.forEach { it.layout(this) } } - private fun configAnimations(animation: ISurfaceAnimation) { - if (animation is ICameraAnimation) { - animation.setCamera(camera) - } else if (animation is ISet) { - val animations = animation.animations - for (a in animations) configAnimations(a) - } else if (animation is ITextSurfaceAnimation) { - val textAnimation = animation - val text = textAnimation.text - if (text != null && textsTree.add(text)) textAnimation.setInitValues(text) + private fun configAnimations(animation: SurfaceAnimation) { + if (animation is CameraAnimation) { + animation.camera = camera + } else if (animation is AnimationsSet) { + animation.animations.forEach { configAnimations(it) } + } else if (animation is TextSurfaceAnimation) { + val text = animation.text + if (texts.add(text)) animation.setInitValues(text) } } - override fun onDraw(canvas: Canvas) { - super.onDraw(canvas) - camera.onDraw(canvas) - for (text in textsTree) text.onDraw(canvas, this) - } + override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { + val desiredWidth = getDesiredSize(layoutParams.width, suggestedMinimumWidth, widthMeasureSpec) + val desiredHeight = getDesiredSize(layoutParams.height, suggestedMinimumHeight, heightMeasureSpec) - fun reset() { - if (currentAnimation != null) { - currentAnimation!!.cancel() - currentAnimation = null - } - textsTree.clear() - camera.reset() - invalidate() + setMeasuredDimension( + measureDimension(desiredWidth, widthMeasureSpec), + measureDimension(desiredHeight, heightMeasureSpec) + ) } } \ No newline at end of file diff --git a/library/src/main/java/su/levenetc/android/textsurface/Debug.kt b/library/src/main/java/su/levenetc/android/textsurface/TextSurfaceDebug.kt similarity index 94% rename from library/src/main/java/su/levenetc/android/textsurface/Debug.kt rename to library/src/main/java/su/levenetc/android/textsurface/TextSurfaceDebug.kt index 8fff5c7..9cec353 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/Debug.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/TextSurfaceDebug.kt @@ -6,15 +6,13 @@ import android.graphics.Paint /** * Created by Eugene Levenetc. */ -object Debug { - @JvmField +object TextSurfaceDebug { + var ENABLED = false - @JvmField var RED_FILL: Paint = Paint() var RED_STROKE: Paint = Paint() - @JvmField var BLUE_STROKE: Paint = Paint() var YELLOW_STROKE: Paint = Paint() var GREEN_STROKE: Paint = Paint() diff --git a/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt b/library/src/main/java/su/levenetc/android/textsurface/camera/SurfaceCamera.kt similarity index 75% rename from library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt rename to library/src/main/java/su/levenetc/android/textsurface/camera/SurfaceCamera.kt index 557ea49..07eea17 100644 --- a/library/src/main/java/su/levenetc/android/textsurface/SurfaceCamera.kt +++ b/library/src/main/java/su/levenetc/android/textsurface/camera/SurfaceCamera.kt @@ -1,28 +1,48 @@ -package su.levenetc.android.textsurface +package su.levenetc.android.textsurface.camera import android.graphics.Canvas import android.graphics.PointF +import su.levenetc.android.textsurface.TextSurfaceDebug import su.levenetc.android.textsurface.common.ScaleValue /** * Created by Eugene Levenetc. */ class SurfaceCamera { - var transX = 0f - var transY = 0f + var rotation = 0f val rotationPivot = PointF() + var transX = 0f + var transY = 0f + + var scalePivotX: Float + get() = scale.pivot.x + set(value) { + scale.pivot.x = value + } + var scalePivotY: Float + get() = scale.pivot.y + set(value) { + scale.pivot.y = value + } + + val centerX: Float + get() = center.x + val centerY: Float + get() = center.y + private val scale = ScaleValue() private val center = PointF() + fun onDraw(canvas: Canvas) { - if (Debug.ENABLED) { + if (TextSurfaceDebug.ENABLED) { canvas.save() - canvas.drawCircle(transX, transY, 10f, Debug.YELLOW_STROKE) - canvas.drawCircle(scale.pivot.x, scale.pivot.y, 10f, Debug.GREEN_STROKE) - canvas.drawLine(scale.pivot.x, 0f, scale.pivot.x, canvas.height.toFloat(), Debug.GREEN_STROKE) - canvas.drawLine(0f, scale.pivot.y, canvas.width.toFloat(), scale.pivot.y, Debug.GREEN_STROKE) - canvas.drawLine((canvas.width / 2).toFloat(), 0f, (canvas.width / 2).toFloat(), canvas.height.toFloat(), Debug.GREEN_STROKE) - canvas.drawLine(0f, (canvas.height / 2).toFloat(), canvas.width.toFloat(), (canvas.height / 2).toFloat(), Debug.GREEN_STROKE) + canvas.drawCircle(transX, transY, 10f, TextSurfaceDebug.YELLOW_STROKE) + canvas.drawCircle(scale.pivot.x, scale.pivot.y, 10f, TextSurfaceDebug.GREEN_STROKE) + canvas.drawLine(scale.pivot.x, 0f, scale.pivot.x, canvas.height.toFloat(), TextSurfaceDebug.GREEN_STROKE) + canvas.drawLine(0f, scale.pivot.y, canvas.width.toFloat(), scale.pivot.y, TextSurfaceDebug.GREEN_STROKE) + canvas.drawLine((canvas.width / 2).toFloat(), 0f, (canvas.width / 2).toFloat(), canvas.height.toFloat(), TextSurfaceDebug.GREEN_STROKE) + canvas.drawLine(0f, (canvas.height / 2).toFloat(), canvas.width.toFloat(), (canvas.height / 2).toFloat(), TextSurfaceDebug.GREEN_STROKE) canvas.restore() } center[(canvas.width / 2).toFloat()] = (canvas.height / 2).toFloat() @@ -38,11 +58,6 @@ class SurfaceCamera { transY = 0f } - val centerX: Float - get() = center.x - val centerY: Float - get() = center.y - fun getScale(): Float { return scale.scaleX } @@ -54,15 +69,4 @@ class SurfaceCamera { fun setScalePivot(x: Float, y: Float) { scale.pivot[x] = y } - - var scalePivotX: Float - get() = scale.pivot.x - set(value) { - scale.pivot.x = value - } - var scalePivotY: Float - get() = scale.pivot.y - set(value) { - scale.pivot.y = value - } } \ No newline at end of file From 9b9b01b55a5292f97cb3ddfc57b72a640d936855 Mon Sep 17 00:00:00 2001 From: elevenetc Date: Mon, 15 Feb 2021 01:36:45 +0100 Subject: [PATCH 09/18] Update and cleanup sample app --- app/src/main/AndroidManifest.xml | 22 ++-- ...{SampleActivity.kt => AnimationSamples.kt} | 26 ++-- .../textsurface/sample/LauncherActivity.kt | 20 +++ .../textsurface/sample/ScrollViewActivity.kt | 14 ++ .../textsurface/sample/animations/3d.kt | 30 +++++ .../sample/animations/alignment.kt | 61 +++++++++ .../textsurface/sample/animations/colors.kt | 2 + .../textsurface/sample/animations/complex.kt | 116 +++++++++++++++++ .../textsurface/sample/animations/reveals.kt | 92 +++++++++++++ .../textsurface/sample/animations/scale.kt | 33 +++++ .../textsurface/sample/animations/sliding.kt | 37 ++++++ .../textsurface/sample/animations/surface.kt | 47 +++++++ .../textsurface/sample/checks/AlignSample.kt | 67 ---------- .../textsurface/sample/checks/ColorSample.kt | 30 ----- .../sample/checks/CookieThumperSample.kt | 121 ------------------ .../sample/checks/Rotation3DSample.kt | 36 ------ .../sample/checks/ScaleTextSample.kt | 47 ------- .../sample/checks/ShapeRevealLoopSample.kt | 61 --------- .../sample/checks/ShapeRevealSample.kt | 58 --------- .../textsurface/sample/checks/SlideSample.kt | 41 ------ .../sample/checks/SurfaceScaleSample.kt | 35 ----- .../sample/checks/SurfaceTransSample.kt | 32 ----- app/src/main/res/layout/launcher_activity.xml | 19 +++ app/src/main/res/layout/sample_activity.xml | 1 + .../main/res/layout/scrollview_activity.xml | 13 ++ 25 files changed, 508 insertions(+), 553 deletions(-) rename app/src/main/java/su/levenetc/android/textsurface/sample/{SampleActivity.kt => AnimationSamples.kt} (53%) create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/LauncherActivity.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/ScrollViewActivity.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/3d.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/alignment.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/colors.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/complex.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/reveals.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/scale.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/sliding.kt create mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/animations/surface.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt delete mode 100644 app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt create mode 100644 app/src/main/res/layout/launcher_activity.xml create mode 100644 app/src/main/res/layout/scrollview_activity.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 14b1ce5..e5b8b49 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,10 +1,9 @@ - + + android:required="true" /> + android:name=".LauncherActivity" + android:label="@string/app_name"> - - + + + + diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/AnimationSamples.kt similarity index 53% rename from app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt rename to app/src/main/java/su/levenetc/android/textsurface/sample/AnimationSamples.kt index 2ba1e30..e6160ee 100644 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/SampleActivity.kt +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/AnimationSamples.kt @@ -4,39 +4,33 @@ import android.os.Bundle import android.view.View import android.widget.CheckBox import androidx.appcompat.app.AppCompatActivity -import su.levenetc.android.textsurface.Debug import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.sample.checks.* +import su.levenetc.android.textsurface.TextSurfaceDebug +import su.levenetc.android.textsurface.sample.animations.playCookieThumper /** * Created by Eugene Levenetc. */ -class SampleActivity : AppCompatActivity() { +class AnimationSamples : AppCompatActivity() { + private lateinit var textSurface: TextSurface + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.sample_activity) textSurface = findViewById(R.id.text_surface) as TextSurface - textSurface!!.postDelayed({ show() }, 1000) + textSurface.postDelayed({ show() }, 1000) findViewById(R.id.btn_refresh).setOnClickListener { show() } val checkDebug = findViewById(R.id.check_debug) as CheckBox - checkDebug.isChecked = Debug.ENABLED + checkDebug.isChecked = TextSurfaceDebug.ENABLED checkDebug.setOnCheckedChangeListener { _, isChecked -> - Debug.ENABLED = isChecked - textSurface!!.invalidate() + TextSurfaceDebug.ENABLED = isChecked + textSurface.invalidate() } } private fun show() { textSurface.reset() - CookieThumperSample.play(textSurface, assets) - //AlignSample.play(textSurface) - //Rotation3DSample.play(textSurface) - //ScaleTextSample.play(textSurface) - //ShapeRevealLoopSample.play(textSurface) - //ShapeRevealSample.play(textSurface) - //SlideSample.play(textSurface) - //SurfaceScaleSample.play(textSurface) - //SurfaceTransSample.play(textSurface) + playCookieThumper(textSurface, assets) } } \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/LauncherActivity.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/LauncherActivity.kt new file mode 100644 index 0000000..e6a985f --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/LauncherActivity.kt @@ -0,0 +1,20 @@ +package su.levenetc.android.textsurface.sample + +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.appcompat.app.AppCompatActivity + +class LauncherActivity : AppCompatActivity(R.layout.launcher_activity) { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + findViewById(R.id.btn_animations_samples).setOnClickListener { + startActivity(Intent(this, AnimationSamples::class.java)) + } + + findViewById(R.id.btn_scrollview).setOnClickListener { + startActivity(Intent(this, ScrollViewActivity::class.java)) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/ScrollViewActivity.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/ScrollViewActivity.kt new file mode 100644 index 0000000..25a28e4 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/ScrollViewActivity.kt @@ -0,0 +1,14 @@ +package su.levenetc.android.textsurface.sample + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.sample.animations.surfaceTransSample + +class ScrollViewActivity : AppCompatActivity(R.layout.scrollview_activity) { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + val textSurface: TextSurface = findViewById(R.id.text_surface) + surfaceTransSample(textSurface) + } +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/3d.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/3d.kt new file mode 100644 index 0000000..d49c5b8 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/3d.kt @@ -0,0 +1,30 @@ +package su.levenetc.android.textsurface.sample.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.effects.Rotate3D +import su.levenetc.android.textsurface.animations.sets.Sequential +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Axis +import su.levenetc.android.textsurface.contants.Pivot + +fun rotation3DSample(textSurface: TextSurface) { + val textA = Text.Builder("How are you?").setPosition(Align.SURFACE_CENTER).build() + val textB = Text.Builder("I'm fine! And you?").setPosition(Align.SURFACE_CENTER, textA).build() + val textC = Text.Builder("Haaay!").setPosition(Align.SURFACE_CENTER, textB).build() + val duration = 2750 + textSurface.playSequential( + Sequential( + Rotate3D.showFromCenter(textA, duration.toLong(), Axis.X), + Rotate3D.hideFromCenter(textA, duration.toLong(), Axis.Y) + ), + Sequential( + Rotate3D.showFromSide(textB, duration.toLong(), Pivot.LEFT), + Rotate3D.hideFromSide(textB, duration.toLong(), Pivot.RIGHT) + ), + Sequential( + Rotate3D.showFromSide(textC, duration.toLong(), Pivot.TOP), + Rotate3D.hideFromSide(textC, duration.toLong(), Pivot.BOTTOM) + ) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/alignment.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/alignment.kt new file mode 100644 index 0000000..7e77915 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/alignment.kt @@ -0,0 +1,61 @@ +package su.levenetc.android.textsurface.sample.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.colors.Alpha +import su.levenetc.android.textsurface.contants.Align + +fun alignSample(textSurface: TextSurface) { + val textCenter = Text.Builder("Center") + .setPosition(Align.SURFACE_CENTER) + .setPadding(25f, 25f, 25f, 25f) + .build() + + // + val textLeft = Text.Builder("L") + .setPadding(20f, 20f, 20f, 20f) + .setPosition(Align.LEFT_OF or Align.CENTER_OF, textCenter) + .build() + val textRight = Text.Builder("R") + .setPadding(20f, 20f, 20f, 20f) + .setPosition(Align.RIGHT_OF or Align.CENTER_OF, textCenter) + .build() + val textTop = Text.Builder("T") + .setPosition(Align.TOP_OF or Align.CENTER_OF, textCenter) + .build() + val textBottom = Text.Builder("B") + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textCenter) + .build() + + // + val textBottomBottom = Text.Builder("BB") + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textBottom) + .build() + + // + val textLeftTop = Text.Builder("LT") + .setPosition(Align.LEFT_OF or Align.TOP_OF, textCenter) + .build() + val textRightTop = Text.Builder("RT") + .setPosition(Align.RIGHT_OF or Align.TOP_OF, textCenter) + .build() + val textLeftBottom = Text.Builder("LB") + .setPosition(Align.LEFT_OF or Align.BOTTOM_OF, textCenter) + .build() + val textRightBottom = Text.Builder("RB") + .setPosition(Align.BOTTOM_OF or Align.RIGHT_OF, textCenter) + .build() + val duration = 125 + textSurface.playSequential( + Alpha.show(textCenter, duration.toLong()), + Alpha.show(textRight, duration.toLong()), + Alpha.show(textTop, duration.toLong()), + Alpha.show(textLeft, duration.toLong()), + Alpha.show(textBottom, duration.toLong()), + Alpha.show(textLeftTop, duration.toLong()), + Alpha.show(textLeftBottom, duration.toLong()), + Alpha.show(textRightBottom, duration.toLong()), + Alpha.show(textRightTop, duration.toLong()), + Alpha.show(textBottomBottom, duration.toLong()) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/colors.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/colors.kt new file mode 100644 index 0000000..85c82e6 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/colors.kt @@ -0,0 +1,2 @@ +package su.levenetc.android.textsurface.sample.animations + diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/complex.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/complex.kt new file mode 100644 index 0000000..ebc2761 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/complex.kt @@ -0,0 +1,116 @@ +package su.levenetc.android.textsurface.sample.animations + +import android.content.res.AssetManager +import android.graphics.Color +import android.graphics.Paint +import android.graphics.Typeface +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.camera.TransSurface +import su.levenetc.android.textsurface.animations.colors.Alpha +import su.levenetc.android.textsurface.animations.colors.ChangeColor +import su.levenetc.android.textsurface.animations.effects.Rotate3D +import su.levenetc.android.textsurface.animations.effects.Slide +import su.levenetc.android.textsurface.animations.effects.reveal.Circle +import su.levenetc.android.textsurface.animations.effects.reveal.ShapeReveal +import su.levenetc.android.textsurface.animations.effects.reveal.SideCut +import su.levenetc.android.textsurface.animations.generic.Delay +import su.levenetc.android.textsurface.animations.sets.Parallel +import su.levenetc.android.textsurface.animations.sets.Sequential +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Direction +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.contants.Side + +fun playCookieThumper(textSurface: TextSurface, assetManager: AssetManager) { + + val paint = Paint().apply { + isAntiAlias = true + typeface = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf") + } + + val textDaai = Text.Builder("Daai") + .setPaint(paint) + .setSize(64f) + .setAlpha(0) + .setColor(Color.WHITE) + .setPosition(Align.SURFACE_CENTER).build() + val textBraAnies = Text.Builder("bra Anies") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF, textDaai).build() + val textFokkenGamBra = Text.Builder(" hy's n fokken gam bra.") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.RIGHT_OF, textBraAnies).build() + val textHaai = Text.Builder("Haai!!") + .setPaint(paint) + .setSize(74f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF, textFokkenGamBra).build() + val textDaaiAnies = Text.Builder("Daai Anies") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.WHITE) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textHaai).build() + val texThyLamInnie = Text.Builder(" hy lam innie mang ja.") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.WHITE) + .setPosition(Align.RIGHT_OF, textDaaiAnies).build() + val textThrowDamn = Text.Builder("Throw damn") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, texThyLamInnie).build() + val textDevilishGang = Text.Builder("devilish gang") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textThrowDamn).build() + val textSignsInTheAir = Text.Builder("signs in the air.") + .setPaint(paint) + .setSize(44f) + .setAlpha(0) + .setColor(Color.RED) + .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textDevilishGang).build() + textSurface.play( + Sequential( + ShapeReveal.reveal(textDaai, 750, SideCut.showSideCut(Side.LEFT)), + Parallel(ShapeReveal.reveal(textDaai, 600, SideCut.hideSideCut(Side.LEFT)), Sequential(Delay.delay(300), ShapeReveal.reveal(textDaai, 600, SideCut.showSideCut(Side.LEFT)))), + Parallel(TransSurface(500, textBraAnies, Pivot.CENTER), ShapeReveal.reveal(textBraAnies, 1300, SideCut.showSideCut(Side.LEFT))), + Delay.delay(500), + Parallel(TransSurface(750, textFokkenGamBra, Pivot.CENTER), Slide.showFrom(Side.LEFT, textFokkenGamBra, 750), ChangeColor.to(textFokkenGamBra, 750, Color.WHITE)), + Delay.delay(500), + Parallel(TransSurface.toCenterOf(textHaai, 500), Rotate3D.showFromSide(textHaai, 750, Pivot.TOP)), + Parallel(TransSurface.toCenterOf(textDaaiAnies, 500), Slide.showFrom(Side.TOP, textDaaiAnies, 500)), + Parallel(TransSurface.toCenterOf(texThyLamInnie, 750), Slide.showFrom(Side.LEFT, texThyLamInnie, 500)), + Delay.delay(500), + Parallel( + TransSurface(1500, textSignsInTheAir, Pivot.CENTER), + Sequential( + Sequential(ShapeReveal.reveal(textThrowDamn, 500, Circle.show(Side.CENTER, Direction.OUT))), + Sequential(ShapeReveal.reveal(textDevilishGang, 500, Circle.show(Side.CENTER, Direction.OUT))), + Sequential(ShapeReveal.reveal(textSignsInTheAir, 500, Circle.show(Side.CENTER, Direction.OUT))) + ) + ), + Delay.delay(200), + Parallel( + ShapeReveal.reveal(textThrowDamn, 1500, SideCut.hideSideCut(Side.LEFT), true), + Sequential(Delay.delay(250), ShapeReveal.reveal(textDevilishGang, 1500, SideCut.hideSideCut(Side.LEFT), true)), + Sequential(Delay.delay(500), ShapeReveal.reveal(textSignsInTheAir, 1500, SideCut.hideSideCut(Side.LEFT), true)), + Alpha.hide(texThyLamInnie, 1500), + Alpha.hide(textDaaiAnies, 1500) + ) + ) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/reveals.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/reveals.kt new file mode 100644 index 0000000..4102106 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/reveals.kt @@ -0,0 +1,92 @@ +package su.levenetc.android.textsurface.sample.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.camera.TransSurface +import su.levenetc.android.textsurface.animations.colors.Alpha +import su.levenetc.android.textsurface.animations.effects.Rotate3D +import su.levenetc.android.textsurface.animations.effects.Slide +import su.levenetc.android.textsurface.animations.effects.reveal.Circle +import su.levenetc.android.textsurface.animations.effects.reveal.ShapeReveal +import su.levenetc.android.textsurface.animations.effects.reveal.SideCut +import su.levenetc.android.textsurface.animations.generic.Delay +import su.levenetc.android.textsurface.animations.sets.Loop +import su.levenetc.android.textsurface.animations.sets.Parallel +import su.levenetc.android.textsurface.animations.sets.Sequential +import su.levenetc.android.textsurface.contants.* + +fun shapeRevealSample(textSurface: TextSurface) { + val textA = Text.Builder("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build() + val textB = Text.Builder("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() + val textC = Text.Builder("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + val textD = Text.Builder("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() + val flash = 1500 + textSurface.playSequential( + Rotate3D.showFromCenter(textA, 500, Axis.X), + Parallel( + ShapeReveal.reveal(textA, flash.toLong(), SideCut.hideSideCut(Side.LEFT), false), + Sequential(Delay.delay((flash / 4).toLong()), ShapeReveal.reveal(textA, flash.toLong(), SideCut.showSideCut(Side.LEFT), false)) + ), + Parallel( + Rotate3D.showFromSide(textB, 500, Pivot.TOP), + TransSurface(500, textB, Pivot.CENTER) + ), + Delay.delay(500), + Parallel( + Slide.showFrom(Side.TOP, textC, 500), + TransSurface(1000, textC, Pivot.CENTER) + ), + Delay.delay(500), + Parallel( + ShapeReveal.reveal(textD, 500, Circle.show(Side.CENTER, Direction.OUT), false), + TransSurface(1500, textD, Pivot.CENTER) + ), + Delay.delay(500), + Parallel( + Parallel(Alpha.hide(textD, 700), ShapeReveal.reveal(textD, 1000, SideCut.hideSideCut(Side.LEFT), true)), + Sequential(Delay.delay(500), Parallel(Alpha.hide(textC, 700), ShapeReveal.reveal(textC, 1000, SideCut.hideSideCut(Side.LEFT), true))), + Sequential(Delay.delay(1000), Parallel(Alpha.hide(textB, 700), ShapeReveal.reveal(textB, 1000, SideCut.hideSideCut(Side.LEFT), true))), + Sequential(Delay.delay(1500), Parallel(Alpha.hide(textA, 700), ShapeReveal.reveal(textA, 1000, SideCut.hideSideCut(Side.LEFT), true))), + TransSurface(4000, textA, Pivot.CENTER) + ) + ) +} + +fun shapeRevealLoopSample(textSurface: TextSurface) { + val textA = Text.Builder("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build() + val textB = Text.Builder("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() + val textC = Text.Builder("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + val textD = Text.Builder("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() + val flash = 1500 + textSurface.play( + Loop( + Rotate3D.showFromCenter(textA, 500, Axis.X), + Parallel( + ShapeReveal.reveal(textA, flash.toLong(), SideCut.hideSideCut(Side.LEFT), false), + Sequential(Delay.delay((flash / 4).toLong()), ShapeReveal.reveal(textA, flash.toLong(), SideCut.showSideCut(Side.LEFT), false)) + ), + Parallel( + Rotate3D.showFromSide(textB, 500, Pivot.TOP), + TransSurface(500, textB, Pivot.CENTER) + ), + Delay.delay(500), + Parallel( + Slide.showFrom(Side.TOP, textC, 500), + TransSurface(1000, textC, Pivot.CENTER) + ), + Delay.delay(500), + Parallel( + ShapeReveal.reveal(textD, 500, Circle.show(Side.CENTER, Direction.OUT), false), + TransSurface(1500, textD, Pivot.CENTER) + ), + Delay.delay(500), + Parallel( + Parallel(Alpha.hide(textD, 700), ShapeReveal.reveal(textD, 1000, SideCut.hideSideCut(Side.LEFT), true)), + Sequential(Delay.delay(500), Parallel(Alpha.hide(textC, 700), ShapeReveal.reveal(textC, 1000, SideCut.hideSideCut(Side.LEFT), true))), + Sequential(Delay.delay(1000), Parallel(Alpha.hide(textB, 700), ShapeReveal.reveal(textB, 1000, SideCut.hideSideCut(Side.LEFT), true))), + Sequential(Delay.delay(1500), Parallel(Alpha.hide(textA, 700), ShapeReveal.reveal(textA, 1000, SideCut.hideSideCut(Side.LEFT), true))), + TransSurface(4000, textA, Pivot.CENTER) + ) + ) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/scale.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/scale.kt new file mode 100644 index 0000000..bf32897 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/scale.kt @@ -0,0 +1,33 @@ +package su.levenetc.android.textsurface.sample.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.generic.Just +import su.levenetc.android.textsurface.animations.generic.Scale +import su.levenetc.android.textsurface.animations.sets.Sequential +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Pivot + +fun scaleTextSample(textSurface: TextSurface) { + val textA = Text.Builder("textA") + .build() + val textB = Text.Builder("textB") + .setPosition(Align.LEFT_OF, textA) + .build() + val textC = Text.Builder("textC") + .setPosition(Align.RIGHT_OF, textA) + .build() + val textD = Text.Builder("textD") + .setPosition(Align.LEFT_OF, textB) + .build() + val textE = Text.Builder("textE") + .setPosition(Align.RIGHT_OF, textC) + .build() + textSurface.playParallel( + Just.show(textA, textB), + Sequential(Scale(textA, 1000, 1f, 2f, Pivot.CENTER), Scale(textA, 1000, 2f, 1f, Pivot.CENTER)) // new Parallel(new Scale(textA, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textA, 500, 1, 1.5f, Pivot.LEFT)), + // new Sequential(Delay.duration(250), new Parallel(new Scale(textB, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textB, 500, 1, 1.5f, Pivot.LEFT))), + // new Sequential(Delay.duration(500), new Parallel(new Scale(textC, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textC, 500, 1, 1.5f, Pivot.LEFT))), + // new Sequential(Delay.duration(750), new Parallel(new Scale(textD, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textD, 500, 1, 1.5f, Pivot.LEFT))) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/sliding.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/sliding.kt new file mode 100644 index 0000000..2938637 --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/sliding.kt @@ -0,0 +1,37 @@ +package su.levenetc.android.textsurface.sample.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.camera.TransSurface +import su.levenetc.android.textsurface.animations.effects.Slide +import su.levenetc.android.textsurface.animations.sets.Parallel +import su.levenetc.android.textsurface.animations.sets.Sequential +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Pivot +import su.levenetc.android.textsurface.contants.Side + +fun slideSample(textSurface: TextSurface) { + val textA = Text.Builder(" How are you?").build() + val textB = Text.Builder("I'm fine! ").setPosition(Align.LEFT_OF, textA).build() + val textC = Text.Builder("Are you sure?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + val textD = Text.Builder("Totally!").setPadding(10f, 10f, 10f, 10f).setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() + val duration = 1250L + textSurface.playSequential( + Parallel( + Sequential( + Parallel(Slide.showFrom(Side.LEFT, textA, duration), Slide.showFrom(Side.RIGHT, textB, duration)), + Slide.showFrom(Side.TOP, textC, duration), + Slide.showFrom(Side.BOTTOM, textD, duration) + ), + TransSurface(duration * 3, textD, Pivot.CENTER) + ), + Parallel( + Sequential( + Parallel(Slide.hideFrom(Side.LEFT, textD, duration), Slide.hideFrom(Side.RIGHT, textC, duration)), + Slide.hideFrom(Side.TOP, textB, duration), + Slide.hideFrom(Side.BOTTOM, textA, duration) + ), + TransSurface(duration * 3, textA, Pivot.CENTER) + ) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/animations/surface.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/surface.kt new file mode 100644 index 0000000..c0cd68b --- /dev/null +++ b/app/src/main/java/su/levenetc/android/textsurface/sample/animations/surface.kt @@ -0,0 +1,47 @@ +package su.levenetc.android.textsurface.sample.animations + +import su.levenetc.android.textsurface.Text +import su.levenetc.android.textsurface.TextSurface +import su.levenetc.android.textsurface.animations.camera.ScaleSurface +import su.levenetc.android.textsurface.animations.camera.TransSurface +import su.levenetc.android.textsurface.animations.colors.Alpha +import su.levenetc.android.textsurface.animations.generic.Delay +import su.levenetc.android.textsurface.animations.sets.Parallel +import su.levenetc.android.textsurface.contants.Align +import su.levenetc.android.textsurface.contants.Fit +import su.levenetc.android.textsurface.contants.Pivot + +fun surfaceScaleSample(textSurface: TextSurface) { + val textA = Text.Builder("How are you?").setPosition(Align.SURFACE_CENTER).build() + val textB = Text.Builder("Would you mind?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() + val textC = Text.Builder("Yes!").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() + textSurface.playSequential( + Alpha.show(textA, 500), + Parallel( + Parallel(Alpha.show(textB, 500), Alpha.hide(textA, 500)), + ScaleSurface(500, textB, Fit.WIDTH) + ), + Delay.delay(1000), + Parallel( + Parallel(Alpha.show(textC, 500), Alpha.hide(textB, 500)), + ScaleSurface(500, textC, Fit.HEIGHT) + ) + ) +} + +fun surfaceTransSample(textSurface: TextSurface) { + val textA = Text.Builder("TextA").setPosition(Align.SURFACE_CENTER).build() + val textB = Text.Builder("TextB").setPosition(Align.RIGHT_OF or Align.BOTTOM_OF, textA).build() + val textC = Text.Builder("TextC").setPosition(Align.LEFT_OF or Align.BOTTOM_OF, textB).build() + val textD = Text.Builder("TextD").setPosition(Align.RIGHT_OF or Align.BOTTOM_OF, textC).build() + val duration = 500L + textSurface.playSequential( + Alpha.show(textA, duration), + Parallel(Alpha.show(textB, duration), TransSurface(duration, textB, Pivot.CENTER)), + Parallel(Alpha.show(textC, duration), TransSurface(duration, textC, Pivot.CENTER)), + Parallel(Alpha.show(textD, duration), TransSurface(duration, textD, Pivot.CENTER)), + TransSurface(duration, textC, Pivot.CENTER), + TransSurface(duration, textB, Pivot.CENTER), + TransSurface(duration, textA, Pivot.CENTER) + ) +} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt deleted file mode 100644 index 5378986..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/AlignSample.kt +++ /dev/null @@ -1,67 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.show -import su.levenetc.android.textsurface.contants.Align -import su.levenetc.android.textsurface.contants.TYPE - -/** - * Created by Eugene Levenetc. - */ -object AlignSample { - fun play(textSurface: TextSurface) { - val textCenter = create("Center") - .setPosition(Align.SURFACE_CENTER) - .setPadding(25f, 25f, 25f, 25f) - .build() - - // - val textLeft = create("L") - .setPadding(20f, 20f, 20f, 20f) - .setPosition(Align.LEFT_OF or Align.CENTER_OF, textCenter) - .build() - val textRight = create("R") - .setPadding(20f, 20f, 20f, 20f) - .setPosition(Align.RIGHT_OF or Align.CENTER_OF, textCenter) - .build() - val textTop = create("T") - .setPosition(Align.TOP_OF or Align.CENTER_OF, textCenter) - .build() - val textBottom = create("B") - .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textCenter) - .build() - - // - val textBottomBottom = create("BB") - .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textBottom) - .build() - - // - val textLeftTop = create("LT") - .setPosition(Align.LEFT_OF or Align.TOP_OF, textCenter) - .build() - val textRightTop = create("RT") - .setPosition(Align.RIGHT_OF or Align.TOP_OF, textCenter) - .build() - val textLeftBottom = create("LB") - .setPosition(Align.LEFT_OF or Align.BOTTOM_OF, textCenter) - .build() - val textRightBottom = create("RB") - .setPosition(Align.BOTTOM_OF or Align.RIGHT_OF, textCenter) - .build() - val duration = 125 - textSurface.play(TYPE.SEQUENTIAL, - show(textCenter, duration.toLong()), - show(textRight, duration.toLong()), - show(textTop, duration.toLong()), - show(textLeft, duration.toLong()), - show(textBottom, duration.toLong()), - show(textLeftTop, duration.toLong()), - show(textLeftBottom, duration.toLong()), - show(textRightBottom, duration.toLong()), - show(textRightTop, duration.toLong()), - show(textBottomBottom, duration.toLong()) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt deleted file mode 100644 index 0f0bd44..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ColorSample.kt +++ /dev/null @@ -1,30 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import android.graphics.Color -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.hide -import su.levenetc.android.textsurface.animations.Alpha.Companion.show -import su.levenetc.android.textsurface.animations.ChangeColor.Companion.fromTo -import su.levenetc.android.textsurface.animations.ChangeColor.Companion.to -import su.levenetc.android.textsurface.contants.Align -import su.levenetc.android.textsurface.contants.TYPE - -/** - * Created by Eugene Levenetc. - */ -object ColorSample { - fun play(textSurface: TextSurface) { - val textA = create("Now why you loer en kyk gelyk?") - .setPosition(Align.SURFACE_CENTER) - .setSize(100f) - .setAlpha(0) - .build() - textSurface.play(TYPE.SEQUENTIAL, - show(textA, 1000), - to(textA, 1000, Color.RED), - fromTo(textA, 1000, Color.BLUE, Color.CYAN), - hide(textA, 1000) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt deleted file mode 100644 index b98436f..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.kt +++ /dev/null @@ -1,121 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import android.content.res.AssetManager -import android.graphics.Color -import android.graphics.Paint -import android.graphics.Typeface -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.hide -import su.levenetc.android.textsurface.animations.ChangeColor.Companion.to -import su.levenetc.android.textsurface.animations.reveal.Circle.Companion.show -import su.levenetc.android.textsurface.animations.Delay.Companion.duration -import su.levenetc.android.textsurface.animations.Parallel -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide -import su.levenetc.android.textsurface.animations.Sequential -import su.levenetc.android.textsurface.animations.reveal.ShapeReveal.Companion.create -import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.hide -import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.show -import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom -import su.levenetc.android.textsurface.animations.TransSurface -import su.levenetc.android.textsurface.animations.TransSurface.Companion.toCenter -import su.levenetc.android.textsurface.contants.Align -import su.levenetc.android.textsurface.contants.Direction -import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.contants.Side - -/** - * Created by Eugene Levenetc. - */ -object CookieThumperSample { - fun play(textSurface: TextSurface?, assetManager: AssetManager?) { - val robotoBlack = Typeface.createFromAsset(assetManager, "fonts/Roboto-Black.ttf") - val paint = Paint() - paint.isAntiAlias = true - paint.typeface = robotoBlack - val textDaai = create("Daai") - .setPaint(paint) - .setSize(64f) - .setAlpha(0) - .setColor(Color.WHITE) - .setPosition(Align.SURFACE_CENTER).build() - val textBraAnies = create("bra Anies") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF, textDaai).build() - val textFokkenGamBra = create(" hy's n fokken gam bra.") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.RIGHT_OF, textBraAnies).build() - val textHaai = create("Haai!!") - .setPaint(paint) - .setSize(74f) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF, textFokkenGamBra).build() - val textDaaiAnies = create("Daai Anies") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.WHITE) - .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textHaai).build() - val texThyLamInnie = create(" hy lam innie mang ja.") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.WHITE) - .setPosition(Align.RIGHT_OF, textDaaiAnies).build() - val textThrowDamn = create("Throw damn") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, texThyLamInnie).build() - val textDevilishGang = create("devilish gang") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textThrowDamn).build() - val textSignsInTheAir = create("signs in the air.") - .setPaint(paint) - .setSize(44f) - .setAlpha(0) - .setColor(Color.RED) - .setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textDevilishGang).build() - textSurface!!.play( - Sequential( - create(textDaai, 750, show(Side.LEFT), false), - Parallel(create(textDaai, 600, hide(Side.LEFT), false), Sequential(duration(300), create(textDaai, 600, show(Side.LEFT), false))), - Parallel(TransSurface(500, textBraAnies, Pivot.CENTER), create(textBraAnies, 1300, show(Side.LEFT), false)), - duration(500), - Parallel(TransSurface(750, textFokkenGamBra, Pivot.CENTER), showFrom(Side.LEFT, textFokkenGamBra, 750), to(textFokkenGamBra, 750, Color.WHITE)), - duration(500), - Parallel(toCenter(textHaai, 500), showFromSide(textHaai, 750, Pivot.TOP)), - Parallel(toCenter(textDaaiAnies, 500), showFrom(Side.TOP, textDaaiAnies, 500)), - Parallel(toCenter(texThyLamInnie, 750), showFrom(Side.LEFT, texThyLamInnie, 500)), - duration(500), - Parallel( - TransSurface(1500, textSignsInTheAir, Pivot.CENTER), - Sequential( - Sequential(create(textThrowDamn, 500, show(Side.CENTER, Direction.OUT), false)), - Sequential(create(textDevilishGang, 500, show(Side.CENTER, Direction.OUT), false)), - Sequential(create(textSignsInTheAir, 500, show(Side.CENTER, Direction.OUT), false)) - ) - ), - duration(200), - Parallel( - create(textThrowDamn, 1500, hide(Side.LEFT), true), - Sequential(duration(250), create(textDevilishGang, 1500, hide(Side.LEFT), true)), - Sequential(duration(500), create(textSignsInTheAir, 1500, hide(Side.LEFT), true)), - hide(texThyLamInnie, 1500), - hide(textDaaiAnies, 1500) - ) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt deleted file mode 100644 index f10e4e2..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/Rotation3DSample.kt +++ /dev/null @@ -1,36 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.hideFromCenter -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.hideFromSide -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromCenter -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide -import su.levenetc.android.textsurface.contants.* - -/** - * Created by Eugene Levenetc. - */ -object Rotation3DSample { - fun play(textSurface: TextSurface) { - val textA = create("How are you?").setPosition(Align.SURFACE_CENTER).build() - val textB = create("I'm fine! And you?").setPosition(Align.SURFACE_CENTER, textA).build() - val textC = create("Haaay!").setPosition(Align.SURFACE_CENTER, textB).build() - val duration = 2750 - textSurface.play(TYPE.SEQUENTIAL, - AnimationsSet(TYPE.SEQUENTIAL, - showFromCenter(textA, duration.toLong(), Direction.CLOCK, Axis.X), - hideFromCenter(textA, duration.toLong(), Direction.CLOCK, Axis.Y) - ), - AnimationsSet(TYPE.SEQUENTIAL, - showFromSide(textB, duration.toLong(), Pivot.LEFT), - hideFromSide(textB, duration.toLong(), Pivot.RIGHT) - ), - AnimationsSet(TYPE.SEQUENTIAL, - showFromSide(textC, duration.toLong(), Pivot.TOP), - hideFromSide(textC, duration.toLong(), Pivot.BOTTOM) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt deleted file mode 100644 index 4f051f2..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ScaleTextSample.kt +++ /dev/null @@ -1,47 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Just -import su.levenetc.android.textsurface.animations.Scale -import su.levenetc.android.textsurface.animations.Sequential -import su.levenetc.android.textsurface.contants.Align -import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.contants.TYPE - -/** - * Created by Eugene Levenetc. - */ -object ScaleTextSample { - fun play(textSurface: TextSurface) { -// Text textA = TextBuilder.create("oat cake") -//// .setScale(2.0f, Pivot.RIGHT) -// .build(); -// -// textSurface.play(TYPE.SEQUENTIAL, -// //Just.show(textA) -// new Scale(textA, 1000, 0.1f, 1.5f, Pivot.RIGHT) -// ); - val textA = create("textA") // .setPosition(Align.SURFACE_CENTER) - .build() - val textB = create("textB") - .setPosition(Align.LEFT_OF, textA) - .build() - val textC = create("textC") - .setPosition(Align.RIGHT_OF, textA) - .build() - val textD = create("textD") - .setPosition(Align.LEFT_OF, textB) - .build() - val textE = create("textE") - .setPosition(Align.RIGHT_OF, textC) - .build() - textSurface.play(TYPE.PARALLEL, - Just.show(textA, textB), - Sequential(Scale(textA, 1000, 1f, 2f, Pivot.CENTER), Scale(textA, 1000, 2f, 1f, Pivot.CENTER)) // new Parallel(new Scale(textA, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textA, 500, 1, 1.5f, Pivot.LEFT)), - // new Sequential(Delay.duration(250), new Parallel(new Scale(textB, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textB, 500, 1, 1.5f, Pivot.LEFT))), - // new Sequential(Delay.duration(500), new Parallel(new Scale(textC, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textC, 500, 1, 1.5f, Pivot.LEFT))), - // new Sequential(Delay.duration(750), new Parallel(new Scale(textD, 500, 1.5f, 1f, Pivot.LEFT), new Scale(textD, 500, 1, 1.5f, Pivot.LEFT))) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt deleted file mode 100644 index e006038..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealLoopSample.kt +++ /dev/null @@ -1,61 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.hide -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.animations.reveal.Circle.Companion.show -import su.levenetc.android.textsurface.animations.Delay.Companion.duration -import su.levenetc.android.textsurface.animations.Loop -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromCenter -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide -import su.levenetc.android.textsurface.animations.reveal.ShapeReveal.Companion.create -import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.hide -import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.show -import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom -import su.levenetc.android.textsurface.animations.TransSurface -import su.levenetc.android.textsurface.contants.* - -/** - * Created by Eugene Levenetc. - */ -object ShapeRevealLoopSample { - fun play(textSurface: TextSurface) { - val textA = create("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build() - val textB = create("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() - val textC = create("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() - val textD = create("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() - val flash = 1500 - textSurface.play( - Loop( - showFromCenter(textA, 500, Direction.CLOCK, Axis.X), - AnimationsSet(TYPE.PARALLEL, - create(textA, flash.toLong(), hide(Side.LEFT), false), - AnimationsSet(TYPE.SEQUENTIAL, duration((flash / 4).toLong()), create(textA, flash.toLong(), show(Side.LEFT), false)) - ), - AnimationsSet(TYPE.PARALLEL, - showFromSide(textB, 500, Pivot.TOP), - TransSurface(500, textB, Pivot.CENTER) - ), - duration(500), - AnimationsSet(TYPE.PARALLEL, - showFrom(Side.TOP, textC, 500), - TransSurface(1000, textC, Pivot.CENTER) - ), - duration(500), - AnimationsSet(TYPE.PARALLEL, - create(textD, 500, show(Side.CENTER, Direction.OUT), false), - TransSurface(1500, textD, Pivot.CENTER) - ), - duration(500), - AnimationsSet(TYPE.PARALLEL, - AnimationsSet(TYPE.PARALLEL, hide(textD, 700), create(textD, 1000, hide(Side.LEFT), true)), - AnimationsSet(TYPE.SEQUENTIAL, duration(500), AnimationsSet(TYPE.PARALLEL, hide(textC, 700), create(textC, 1000, hide(Side.LEFT), true))), - AnimationsSet(TYPE.SEQUENTIAL, duration(1000), AnimationsSet(TYPE.PARALLEL, hide(textB, 700), create(textB, 1000, hide(Side.LEFT), true))), - AnimationsSet(TYPE.SEQUENTIAL, duration(1500), AnimationsSet(TYPE.PARALLEL, hide(textA, 700), create(textA, 1000, hide(Side.LEFT), true))), - TransSurface(4000, textA, Pivot.CENTER) - ) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt deleted file mode 100644 index 8adfd18..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/ShapeRevealSample.kt +++ /dev/null @@ -1,58 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.hide -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.animations.reveal.Circle.Companion.show -import su.levenetc.android.textsurface.animations.Delay.Companion.duration -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromCenter -import su.levenetc.android.textsurface.animations.Rotate3D.Companion.showFromSide -import su.levenetc.android.textsurface.animations.reveal.ShapeReveal.Companion.create -import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.hide -import su.levenetc.android.textsurface.animations.reveal.SideCut.Companion.show -import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom -import su.levenetc.android.textsurface.animations.TransSurface -import su.levenetc.android.textsurface.contants.* - -/** - * Created by Eugene Levenetc. - */ -object ShapeRevealSample { - fun play(textSurface: TextSurface) { - val textA = create("Now why you loer en kyk gelyk?").setPosition(Align.SURFACE_CENTER).build() - val textB = create("Is ek miskien van goud gemake?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() - val textC = create("You want to fight, you come tonight.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() - val textD = create("Ek moer jou sleg! So jy hardloop weg.").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() - val flash = 1500 - textSurface.play(TYPE.SEQUENTIAL, - showFromCenter(textA, 500, Direction.CLOCK, Axis.X), - AnimationsSet(TYPE.PARALLEL, - create(textA, flash.toLong(), hide(Side.LEFT), false), - AnimationsSet(TYPE.SEQUENTIAL, duration((flash / 4).toLong()), create(textA, flash.toLong(), show(Side.LEFT), false)) - ), - AnimationsSet(TYPE.PARALLEL, - showFromSide(textB, 500, Pivot.TOP), - TransSurface(500, textB, Pivot.CENTER) - ), - duration(500), - AnimationsSet(TYPE.PARALLEL, - showFrom(Side.TOP, textC, 500), - TransSurface(1000, textC, Pivot.CENTER) - ), - duration(500), - AnimationsSet(TYPE.PARALLEL, - create(textD, 500, show(Side.CENTER, Direction.OUT), false), - TransSurface(1500, textD, Pivot.CENTER) - ), - duration(500), - AnimationsSet(TYPE.PARALLEL, - AnimationsSet(TYPE.PARALLEL, hide(textD, 700), create(textD, 1000, hide(Side.LEFT), true)), - AnimationsSet(TYPE.SEQUENTIAL, duration(500), AnimationsSet(TYPE.PARALLEL, hide(textC, 700), create(textC, 1000, hide(Side.LEFT), true))), - AnimationsSet(TYPE.SEQUENTIAL, duration(1000), AnimationsSet(TYPE.PARALLEL, hide(textB, 700), create(textB, 1000, hide(Side.LEFT), true))), - AnimationsSet(TYPE.SEQUENTIAL, duration(1500), AnimationsSet(TYPE.PARALLEL, hide(textA, 700), create(textA, 1000, hide(Side.LEFT), true))), - TransSurface(4000, textA, Pivot.CENTER) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt deleted file mode 100644 index 7783328..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SlideSample.kt +++ /dev/null @@ -1,41 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.animations.Slide.Companion.hideFrom -import su.levenetc.android.textsurface.animations.Slide.Companion.showFrom -import su.levenetc.android.textsurface.animations.TransSurface -import su.levenetc.android.textsurface.contants.* - -/** - * Created by Eugene Levenetc. - */ -object SlideSample { - fun play(textSurface: TextSurface) { - val textA = create(" How are you?").build() - val textB = create("I'm fine! ").setPosition(Align.LEFT_OF, textA).build() - val textC = create("Are you sure?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() - val textD = create("Totally!").setPadding(10f, 10f, 10f, 10f).setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textC).build() - val duration = 1250L - textSurface.play( - TYPE.SEQUENTIAL, - AnimationsSet(TYPE.PARALLEL, - AnimationsSet(TYPE.SEQUENTIAL, - AnimationsSet(TYPE.PARALLEL, showFrom(Side.LEFT, textA, duration.toLong()), showFrom(Side.RIGHT, textB, duration.toLong())), - showFrom(Side.TOP, textC, duration.toLong()), - showFrom(Side.BOTTOM, textD, duration.toLong()) - ), - TransSurface(duration * 3, textD, Pivot.CENTER) - ), - AnimationsSet(TYPE.PARALLEL, - AnimationsSet(TYPE.SEQUENTIAL, - AnimationsSet(TYPE.PARALLEL, hideFrom(Side.LEFT, textD, duration.toLong()), hideFrom(Side.RIGHT, textC, duration.toLong())), - hideFrom(Side.TOP, textB, duration.toLong()), - hideFrom(Side.BOTTOM, textA, duration.toLong()) - ), - TransSurface(duration * 3, textA, Pivot.CENTER) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt deleted file mode 100644 index 6eeba8f..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceScaleSample.kt +++ /dev/null @@ -1,35 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.hide -import su.levenetc.android.textsurface.animations.Alpha.Companion.show -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.animations.Delay.Companion.duration -import su.levenetc.android.textsurface.animations.ScaleSurface -import su.levenetc.android.textsurface.contants.Align -import su.levenetc.android.textsurface.contants.Fit -import su.levenetc.android.textsurface.contants.TYPE - -/** - * Created by Eugene Levenetc. - */ -object SurfaceScaleSample { - fun play(textSurface: TextSurface) { - val textA = create("How are you?").setPosition(Align.SURFACE_CENTER).build() - val textB = create("Would you mind?").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textA).build() - val textC = create("Yes!").setPosition(Align.BOTTOM_OF or Align.CENTER_OF, textB).build() - textSurface.play(TYPE.SEQUENTIAL, - show(textA, 500), - AnimationsSet(TYPE.PARALLEL, - AnimationsSet(TYPE.PARALLEL, show(textB, 500), hide(textA, 500)), - ScaleSurface(500, textB, Fit.WIDTH) - ), - duration(1000), - AnimationsSet(TYPE.PARALLEL, - AnimationsSet(TYPE.PARALLEL, show(textC, 500), hide(textB, 500)), - ScaleSurface(500, textC, Fit.WIDTH) - ) - ) - } -} \ No newline at end of file diff --git a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt b/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt deleted file mode 100644 index c885f4d..0000000 --- a/app/src/main/java/su/levenetc/android/textsurface/sample/checks/SurfaceTransSample.kt +++ /dev/null @@ -1,32 +0,0 @@ -package su.levenetc.android.textsurface.sample.checks - -import su.levenetc.android.textsurface.TextBuilder.Companion.create -import su.levenetc.android.textsurface.TextSurface -import su.levenetc.android.textsurface.animations.Alpha.Companion.show -import su.levenetc.android.textsurface.animations.AnimationsSet -import su.levenetc.android.textsurface.animations.TransSurface -import su.levenetc.android.textsurface.contants.Align -import su.levenetc.android.textsurface.contants.Pivot -import su.levenetc.android.textsurface.contants.TYPE - -/** - * Created by Eugene Levenetc. - */ -object SurfaceTransSample { - fun play(textSurface: TextSurface) { - val textA = create("TextA").setPosition(Align.SURFACE_CENTER).build() - val textB = create("TextB").setPosition(Align.RIGHT_OF or Align.BOTTOM_OF, textA).build() - val textC = create("TextC").setPosition(Align.LEFT_OF or Align.BOTTOM_OF, textB).build() - val textD = create("TextD").setPosition(Align.RIGHT_OF or Align.BOTTOM_OF, textC).build() - val duration = 500L - textSurface.play(TYPE.SEQUENTIAL, - show(textA, duration), - AnimationsSet(TYPE.PARALLEL, show(textB, duration), TransSurface(duration, textB, Pivot.CENTER)), - AnimationsSet(TYPE.PARALLEL, show(textC, duration), TransSurface(duration, textC, Pivot.CENTER)), - AnimationsSet(TYPE.PARALLEL, show(textD, duration), TransSurface(duration, textD, Pivot.CENTER)), - TransSurface(duration, textC, Pivot.CENTER), - TransSurface(duration, textB, Pivot.CENTER), - TransSurface(duration, textA, Pivot.CENTER) - ) - } -} \ No newline at end of file diff --git a/app/src/main/res/layout/launcher_activity.xml b/app/src/main/res/layout/launcher_activity.xml new file mode 100644 index 0000000..bac18ac --- /dev/null +++ b/app/src/main/res/layout/launcher_activity.xml @@ -0,0 +1,19 @@ + + + +