Skip to content

Commit 8cda81e

Browse files
author
Ta Tonthongkam
committed
Bounce Effect
1 parent badeae6 commit 8cda81e

28 files changed

+459
-3
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apply plugin: 'kotlin'
33

44
buildscript {
55
ext {
6-
kotlin_version = '1.1.2-5'
6+
kotlin_version = '1.1.4-3'
77
aac_version = '1.0.0-alpha3'
88
support_version = '25.3.1'
99
}

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':workshop1', ':workshop2'
1+
include ':workshop1', ':workshop2', ':workshop3'

workshop2/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ dependencies {
3636
exclude group: 'com.android.support', module: 'support-annotations'
3737
})
3838

39-
//Standard library foe android
39+
//Standard library for android
4040
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
4141
compile "com.android.support:appcompat-v7:$support_version"
4242
compile "com.android.support:design:$support_version"

workshop3/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

workshop3/build.gradle

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
3+
apply plugin: 'kotlin-kapt'
4+
5+
android {
6+
compileSdkVersion 25
7+
buildToolsVersion "25.0.3"
8+
defaultConfig {
9+
applicationId "ta.com.workshop3"
10+
minSdkVersion 16
11+
targetSdkVersion 25
12+
versionCode 1
13+
versionName "1.0"
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
}
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
sourceSets {
23+
main.java.srcDirs += 'src/main/kotlin'
24+
main.jniLibs.srcDirs = ['libs']
25+
androidTest.java.srcDirs += 'src/androidTest/kotlin'
26+
test.java.srcDirs += 'src/test/kotlin'
27+
}
28+
dataBinding {
29+
dataBinding.enabled true
30+
}
31+
}
32+
33+
dependencies {
34+
compile fileTree(dir: 'libs', include: ['*.jar'])
35+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
36+
exclude group: 'com.android.support', module: 'support-annotations'
37+
})
38+
39+
//Standard library for android
40+
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
41+
compile "com.android.support:appcompat-v7:$support_version"
42+
compile "com.android.support:design:$support_version"
43+
compile "com.android.support:support-vector-drawable:$support_version"
44+
compile "com.android.support:support-v4:$support_version"
45+
compile "com.android.support:cardview-v7:$support_version"
46+
47+
//Android Architecture
48+
compile "android.arch.lifecycle:runtime:$aac_version"
49+
compile "android.arch.lifecycle:extensions:$aac_version"
50+
annotationProcessor "android.arch.lifecycle:compiler:$aac_version"
51+
52+
//Kotlin binding
53+
kapt 'com.android.databinding:compiler:2.3.2'
54+
55+
compile 'com.android.support.constraint:constraint-layout:1.0.2'
56+
testCompile 'junit:junit:4.12'
57+
}
58+
59+
repositories {
60+
mavenCentral()
61+
}
62+
63+
configurations.all {
64+
resolutionStrategy {
65+
force "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
66+
}
67+
}
68+
69+
afterEvaluate {
70+
android.sourceSets.all { sourceSet ->
71+
if (!sourceSet.name.startsWith('test') || !sourceSet.name.startsWith('androidTest')) {
72+
sourceSet.kotlin.setSrcDirs([])
73+
}
74+
}
75+
}
76+
77+
kapt {
78+
generateStubs = true
79+
}

workshop3/proguard-rules.pro

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/Ta/Library/Android/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
18+
19+
# Uncomment this to preserve the line number information for
20+
# debugging stack traces.
21+
#-keepattributes SourceFile,LineNumberTable
22+
23+
# If you keep the line number information, uncomment this to
24+
# hide the original source file name.
25+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ta.com.workshop3;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("ta.com.workshop3", appContext.getPackageName());
25+
}
26+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="ta.com.workshop3">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN"/>
15+
16+
<category android:name="android.intent.category.LAUNCHER"/>
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package ta.com.workshop3
2+
3+
import android.animation.AnimatorSet
4+
import android.animation.ObjectAnimator
5+
import android.os.Bundle
6+
import android.support.v7.app.AppCompatActivity
7+
import android.support.v7.widget.CardView
8+
import android.util.Log
9+
import android.view.MotionEvent
10+
import android.widget.Toast
11+
12+
class MainActivity : AppCompatActivity() {
13+
14+
override fun onCreate(savedInstanceState: Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
setContentView(R.layout.activity_main)
17+
val cardView = findViewById(R.id.card_view) as CardView
18+
19+
cardView.setOnClickListener({ _ ->
20+
Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show()
21+
})
22+
23+
cardView.setOnTouchListener { v, event ->
24+
Log.d("ANIMATE", event.toString())
25+
when (event.action) {
26+
MotionEvent.ACTION_DOWN -> {
27+
v.animate().cancel()
28+
v.animate().scaleY(0.96f).scaleX(0.96f).setDuration(200).start()
29+
val img = v.findViewById(R.id.imageBackground)
30+
img.animate().scaleY(1.1f).scaleX(1.1f).alpha(0.7f).setDuration(200).start()
31+
32+
false
33+
}
34+
MotionEvent.ACTION_UP -> {
35+
36+
val xBigScale = ObjectAnimator.ofFloat(v, "scaleX", 1.03f)
37+
xBigScale.setDuration(160).repeatCount = 0
38+
39+
val yBigScale = ObjectAnimator.ofFloat(v, "scaleY", 1.03f)
40+
yBigScale.setDuration(160).repeatCount = 0
41+
42+
val xSmallScale = ObjectAnimator.ofFloat(v, "scaleX", 0.985f)
43+
xSmallScale.setDuration(140).repeatCount = 0
44+
45+
val ySmallScale = ObjectAnimator.ofFloat(v, "scaleY", 0.985f)
46+
ySmallScale.setDuration(140).repeatCount = 0
47+
48+
val xNormalScale = ObjectAnimator.ofFloat(v, "scaleX", 1f)
49+
xNormalScale.setDuration(70).repeatCount = 0
50+
51+
val yNormalScale = ObjectAnimator.ofFloat(v, "scaleY", 1f)
52+
yNormalScale.setDuration(70).repeatCount = 0
53+
54+
val animateSet = AnimatorSet()
55+
animateSet.play(xBigScale).with(yBigScale)
56+
animateSet.play(xSmallScale).after(xBigScale)
57+
animateSet.play(ySmallScale).after(yBigScale)
58+
animateSet.play(xNormalScale).after(xSmallScale)
59+
animateSet.play(yNormalScale).after(ySmallScale)
60+
animateSet.start()
61+
62+
val img = v.findViewById(R.id.imageBackground)
63+
64+
img.animate().scaleY(1f).scaleX(1f).alpha(1f).setDuration(370).start()
65+
66+
false
67+
}
68+
69+
MotionEvent.ACTION_CANCEL -> {
70+
val img = v.findViewById(R.id.imageBackground)
71+
v.animate().scaleY(1f).scaleX(1f).setDuration(200).start()
72+
img.animate().scaleY(1f).scaleX(1f).alpha(1f).setDuration(370).start()
73+
74+
true
75+
}
76+
77+
else -> true
78+
}
79+
80+
81+
82+
}
83+
}
84+
}
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<shape xmlns:android="http://schemas.android.com/apk/res/android">
2+
<solid android:color="#FFFFFF"/>
3+
<corners android:radius="20dip"/>
4+
<padding android:left="0dip" android:top="0dip" android:right="0dip" android:bottom="0dip" />
5+
</shape>

0 commit comments

Comments
 (0)