Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Kotlin migration #19

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,45 @@ A little animation framework which could help you to show message in a nice look

### Usage

1. Create [`TextSurface`](library/src/main/java/su/levenetc/android/textsurface/TextSurface.java) instance or add it in your layout.
2. Create [`Text`](library/src/main/java/su/levenetc/android/textsurface/Text.java) instancies with [`TextBuilder`](library/src/main/java/su/levenetc/android/textsurface/TextBuilder.java) defining appearance of text and position:
1. Create [`TextSurface`](library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt) instance or add it in your layout.
2. Create [`Text`](library/src/main/java/su/levenetc/android/textsurface/Text.kt) instancies with [`Text.Builder`](library/src/main/java/su/levenetc/android/textsurface/Text.kt) defining appearance of text and position:

```Java
Text textDaai = TextBuilder
.create("Daai")
```Kotlin
Text textDaai = Text.Builder("Daai")
.setSize(64)
.setAlpha(0)
.setColor(Color.WHITE)
.setPosition(Align.SURFACE_CENTER).build();
```

3. Create animations and pass them to the [`TextSurface`](library/src/main/java/su/levenetc/android/textsurface/TextSurface.java) instance:
```Java
3. Create animations and pass them to the [`TextSurface`](library/src/main/java/su/levenetc/android/textsurface/TextSurface.kt) instance:
```Kotlin
textSurface.play(
new Sequential(
Sequential(
Slide.showFrom(Side.TOP, textDaai, 500),
Delay.duration(500),
Alpha.hide(textDaai, 1500)
)
);
```

See full sample [`here`](app/src/main/java/su/levenetc/android/textsurface/sample/checks/CookieThumperSample.java).
See full sample [`here`](app/src/main/java/su/levenetc/android/textsurface/sample/animations/complex.kt).

### Adjusting animations

- To play animations sequentially use [`Sequential.java`](library/src/main/java/su/levenetc/android/textsurface/animations/Sequential.java)
- To play animations simultaneously use [`Parallel.java`](library/src/main/java/su/levenetc/android/textsurface/animations/Parallel.java)
- To play animations sequentially use [`Sequential.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/sets/Sequential.kt)
- To play animations simultaneously use [`Parallel.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/sets/Parallel.kt)
- Animations/effects could be combined like this:

```Java
new Parallel(Alpha.show(textA, 500), ChangeColor.to(textA, 500, Color.RED))
```Kotlin
Parallel(Alpha.show(textA, 500), ChangeColor.to(textA, 500, Color.RED))
```
i.e. alpha and color of text will be changed simultaneously in 500ms

### Adding your own animations/effects
There're two basic classes which you could extend to add custom animation:
- [`AbstractSurfaceAnimation.java`](library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.java) to animate basic parameters like `alpha`, `translation`, `scale` and others. (See [`Alpha.java`](library/src/main/java/su/levenetc/android/textsurface/animations/Alpha.java) or [`ChangeColor.java`](library/src/main/java/su/levenetc/android/textsurface/animations/ChangeColor.java))
- [`ITextEffect.java`](library/src/main/java/su/levenetc/android/textsurface/interfaces/ITextEffect.java) interface which could be used for more complex animations. (See [`Rotate3D.java`](library/src/main/java/su/levenetc/android/textsurface/animations/Rotate3D.java) or [`ShapeReveal.java`](library/src/main/java/su/levenetc/android/textsurface/animations/ShapeReveal.java))
- [`AbstractSurfaceAnimation.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/AbstractSurfaceAnimation.kt) to animate basic parameters like `alpha`, `translation`, `scale` and others. (See [`Alpha.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/colors/Alpha.kt) or [`ChangeColor.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/colors/ChangeColor.kt))
- [`TextEffect.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/effects/TextEffect.kt) interface which could be used for more complex animations. (See [`Rotate3D.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/effects/Rotate3D.kt) or [`ShapeReveal.kt`](library/src/main/java/su/levenetc/android/textsurface/animations/effects/reveal/ShapeRevealAnimation.kt))

### Proguard configuration
The framework is based on standard android animation classes which uses `reflection` extensively. To avoid obfuscation you need to exclude classes of the framework:
Expand All @@ -61,7 +60,7 @@ repositories {
//...
dependencies {
//...
compile 'com.github.elevenetc:textsurface:0.9.1'
compile 'com.github.elevenetc:textsurface:2.0.0'
}
```
### Licence
Expand Down
4 changes: 4 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

repositories {
maven { url "https://jitpack.io" }
mavenCentral()
}

android {
Expand All @@ -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"
}
22 changes: 13 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<manifest
package="su.levenetc.android.textsurface.sample"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="su.levenetc.android.textsurface.sample">

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
android:required="true" />


<application
Expand All @@ -13,14 +12,19 @@
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="su.levenetc.android.textsurface.sample.SampleActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">
android:name=".LauncherActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AnimationSamples"
android:screenOrientation="landscape" />
<activity
android:name=".ScrollViewActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package su.levenetc.android.textsurface.sample

import android.os.Bundle
import android.view.View
import android.widget.CheckBox
import androidx.appcompat.app.AppCompatActivity
import su.levenetc.android.textsurface.TextSurface
import su.levenetc.android.textsurface.TextSurfaceDebug
import su.levenetc.android.textsurface.sample.animations.playCookieThumper

/**
* Created by Eugene Levenetc.
*/
class AnimationSamples : AppCompatActivity() {

private lateinit var textSurface: TextSurface

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.sample_activity)
textSurface = findViewById<View>(R.id.text_surface) as TextSurface
textSurface.postDelayed({ show() }, 1000)
findViewById<View>(R.id.btn_refresh).setOnClickListener { show() }
val checkDebug = findViewById<View>(R.id.check_debug) as CheckBox
checkDebug.isChecked = TextSurfaceDebug.ENABLED
checkDebug.setOnCheckedChangeListener { _, isChecked ->
TextSurfaceDebug.ENABLED = isChecked
textSurface.invalidate()
}
}

private fun show() {
textSurface.reset()
playCookieThumper(textSurface, assets)
}
}
Original file line number Diff line number Diff line change
@@ -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<View>(R.id.btn_animations_samples).setOnClickListener {
startActivity(Intent(this, AnimationSamples::class.java))
}

findViewById<View>(R.id.btn_scrollview).setOnClickListener {
startActivity(Intent(this, ScrollViewActivity::class.java))
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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.constants.Align
import su.levenetc.android.textsurface.constants.Axis
import su.levenetc.android.textsurface.constants.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)
)
)
}
Original file line number Diff line number Diff line change
@@ -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.constants.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())
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package su.levenetc.android.textsurface.sample.animations

Loading