├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-nodpi │ │ │ │ ├── image1.png │ │ │ │ ├── image2.png │ │ │ │ ├── thumb1.png │ │ │ │ └── thumb2.png │ │ │ ├── drawable-hdpi │ │ │ │ ├── ic_action_new.png │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_action_info.png │ │ │ │ ├── ic_action_photo.png │ │ │ │ └── ic_list_remove.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── ic_action_new.png │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_action_info.png │ │ │ │ ├── ic_action_photo.png │ │ │ │ └── ic_list_remove.png │ │ │ ├── drawable-xhdpi │ │ │ │ ├── ic_launcher.png │ │ │ │ ├── ic_action_info.png │ │ │ │ ├── ic_action_new.png │ │ │ │ ├── ic_list_remove.png │ │ │ │ └── ic_action_photo.png │ │ │ ├── drawable-xxhdpi │ │ │ │ └── ic_launcher.png │ │ │ ├── values │ │ │ │ ├── dimens.xml │ │ │ │ ├── arrays.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── integers.xml │ │ │ │ ├── ids.xml │ │ │ │ ├── styles.xml │ │ │ │ └── strings.xml │ │ │ ├── values-w820dp │ │ │ │ └── dimens.xml │ │ │ ├── menu │ │ │ │ ├── menu_main.xml │ │ │ │ ├── activity_screen_slide.xml │ │ │ │ ├── activity_layout_changes.xml │ │ │ │ └── activity_crossfade.xml │ │ │ ├── layout │ │ │ │ ├── activity_card_flip.xml │ │ │ │ ├── activity_screen_slide.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── fragment_card_front.xml │ │ │ │ ├── excerpt_content.xml │ │ │ │ ├── activity_crossfade.xml │ │ │ │ ├── fragment_card_back.xml │ │ │ │ ├── fragment_screen_slide_page.xml │ │ │ │ ├── advanced_activity_screen_slide.xml │ │ │ │ ├── list_item_example.xml │ │ │ │ ├── activity_layout_changes.xml │ │ │ │ ├── slide_item_1.xml │ │ │ │ ├── slide_item_2.xml │ │ │ │ ├── slide_item_3.xml │ │ │ │ └── activity_zoom.xml │ │ │ └── animator │ │ │ │ ├── card_flip_left_out.xml │ │ │ │ ├── card_flip_right_out.xml │ │ │ │ ├── card_flip_left_in.xml │ │ │ │ └── card_flip_right_in.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── ted │ │ │ │ └── androidscreenslide │ │ │ │ └── app │ │ │ │ ├── DepthPageTransformer.java │ │ │ │ ├── ZoomOutPageTransformer.java │ │ │ │ ├── AdvancedScreenSlideActivity.java │ │ │ │ ├── AnimationPageTransformer.java │ │ │ │ ├── ScreenSlidePageFragment.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── TouchHighlightImageButton.java │ │ │ │ ├── LayoutChangesActivity.java │ │ │ │ ├── CrossfadeActivity.java │ │ │ │ ├── ScreenSlideActivity.java │ │ │ │ ├── CardFlipActivity.java │ │ │ │ └── ZoomActivity.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── com │ │ └── ted │ │ └── androidscreenslide │ │ └── app │ │ └── ApplicationTest.java ├── proguard-rules.pro ├── build.gradle └── app.iml ├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── scopes │ └── scope_settings.xml ├── encodings.xml ├── vcs.xml ├── modules.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── settings.gradle ├── img └── slide.gif ├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── README.md ├── gradle.properties ├── AndroidScreenSlide.iml ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | AndroidScreenSlide -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /img/slide.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/img/slide.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | /local.properties 3 | /.idea/workspace.xml 4 | /.idea/libraries 5 | .DS_Store 6 | /build 7 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-nodpi/image1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-nodpi/image2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/thumb1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-nodpi/thumb1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/thumb2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-nodpi/thumb2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-hdpi/ic_action_new.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-mdpi/ic_action_new.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-hdpi/ic_action_info.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-hdpi/ic_action_photo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_list_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-hdpi/ic_list_remove.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-mdpi/ic_action_info.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-mdpi/ic_action_photo.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_list_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-mdpi/ic_list_remove.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-xhdpi/ic_action_info.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-xhdpi/ic_action_new.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_list_remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-xhdpi/ic_list_remove.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xiongwei-git/AndroidScreenSlide/HEAD/app/src/main/res/drawable-xhdpi/ic_action_photo.png -------------------------------------------------------------------------------- /.idea/scopes/scope_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AndroidScreenSlide 2 | 参考谷歌官方针对[screen-slide](http://developer.android.com/training/animation/screen-slide.html) 写的例子。 3 | 展示了如何使用PageTransformer来给ViewPager做更好的动画。 4 | 5 | # Demo 6 | ![img](https://github.com/xiongwei-git/AndroidScreenSlide/blob/master/img/slide.gif) 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 10 15:27:10 PDT 2013 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | @color/indicator_1 5 | @color/indicator_2 6 | @color/indicator_3 7 | @color/indicator_4 8 | 9 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_main.xml: -------------------------------------------------------------------------------- 1 | 5 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ted/androidscreenslide/app/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.ted.androidscreenslide.app; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:/adt-bundle-windows-x86_64-20140702/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 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #607d8b 4 | #455a64 5 | #cfd8dc 6 | #ffc107 7 | 8 | #ffffff 9 | #000000 10 | #99444444 11 | #616161 12 | #9e9e9e 13 | #5d4037 14 | 15 | #55B3C2 16 | #64A4A4 17 | #66D7B9 18 | #FDBC7D 19 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 300 19 | 150 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_card_flip.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_screen_slide.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | -------------------------------------------------------------------------------- /AndroidScreenSlide.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_screen_slide.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_card_front.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_layout_changes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/menu/activity_crossfade.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 21 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/values/ids.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'com.android.tools.build:gradle:1.0.0' 7 | } 8 | } 9 | apply plugin: 'com.android.application' 10 | 11 | repositories { 12 | jcenter() 13 | } 14 | 15 | android { 16 | compileSdkVersion 21 17 | buildToolsVersion "21.1.2" 18 | 19 | defaultConfig { 20 | applicationId "com.ted.androidscreenslide.app" 21 | minSdkVersion 14 22 | targetSdkVersion 21 23 | versionCode 1 24 | versionName "1.0" 25 | } 26 | 27 | compileOptions { 28 | sourceCompatibility JavaVersion.VERSION_1_6 29 | targetCompatibility JavaVersion.VERSION_1_6 30 | } 31 | buildTypes { 32 | release { 33 | minifyEnabled false 34 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 35 | } 36 | } 37 | } 38 | 39 | dependencies { 40 | compile fileTree(dir: 'libs', include: ['*.jar']) 41 | compile 'com.android.support:appcompat-v7:21.0.3' 42 | compile "com.android.support:support-v13:21.0.+" 43 | compile 'com.github.chenupt.android:springindicator:1.0.1@aar' 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/excerpt_content.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 23 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_crossfade.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 27 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 30 | 31 | 34 | 35 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/DepthPageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.ted.androidscreenslide.app; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Ted on 2015/3/8. 8 | */ 9 | public class DepthPageTransformer implements ViewPager.PageTransformer { 10 | private static final float MIN_SCALE = 0.75f; 11 | 12 | public void transformPage(View view, float position) { 13 | int pageWidth = view.getWidth(); 14 | 15 | if (position < -1) { // [-Infinity,-1) 16 | // This page is way off-screen to the left. 17 | view.setAlpha(0); 18 | 19 | } else if (position <= 0) { // [-1,0] 20 | // Use the default slide transition when moving to the left page 21 | view.setAlpha(1); 22 | view.setTranslationX(0); 23 | view.setScaleX(1); 24 | view.setScaleY(1); 25 | 26 | } else if (position <= 1) { // (0,1] 27 | // Fade the page out. 28 | view.setAlpha(1 - position); 29 | 30 | // Counteract the default slide transition 31 | view.setTranslationX(pageWidth * -position); 32 | 33 | // Scale the page down (between MIN_SCALE and 1) 34 | float scaleFactor = MIN_SCALE 35 | + (1 - MIN_SCALE) * (1 - Math.abs(position)); 36 | view.setScaleX(scaleFactor); 37 | view.setScaleY(scaleFactor); 38 | 39 | } else { // (1,+Infinity] 40 | // This page is way off-screen to the right. 41 | view.setAlpha(0); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_card_back.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | 25 | 32 | 33 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_screen_slide_page.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 23 | 27 | 28 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /app/src/main/res/layout/advanced_activity_screen_slide.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 26 | 27 | 28 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/ZoomOutPageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.ted.androidscreenslide.app; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Ted on 2015/3/8. 8 | */ 9 | public class ZoomOutPageTransformer implements ViewPager.PageTransformer { 10 | private static final float MIN_SCALE = 0.85f; 11 | private static final float MIN_ALPHA = 0.5f; 12 | 13 | public void transformPage(View view, float position) { 14 | int pageWidth = view.getWidth(); 15 | int pageHeight = view.getHeight(); 16 | 17 | if (position < -1) { // [-Infinity,-1) 18 | // This page is way off-screen to the left. 19 | view.setAlpha(0); 20 | 21 | } else if (position <= 1) { // [-1,1] 22 | // Modify the default slide transition to shrink the page as well 23 | float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); 24 | float vertMargin = pageHeight * (1 - scaleFactor) / 2; 25 | float horzMargin = pageWidth * (1 - scaleFactor) / 2; 26 | if (position < 0) { 27 | view.setTranslationX(horzMargin - vertMargin / 2); 28 | } else { 29 | view.setTranslationX(-horzMargin + vertMargin / 2); 30 | } 31 | 32 | // Scale the page down (between MIN_SCALE and 1) 33 | view.setScaleX(scaleFactor); 34 | view.setScaleY(scaleFactor); 35 | 36 | // Fade the page relative to its size. 37 | view.setAlpha(MIN_ALPHA + 38 | (scaleFactor - MIN_SCALE) / 39 | (1 - MIN_SCALE) * (1 - MIN_ALPHA)); 40 | 41 | } else { // (1,+Infinity] 42 | // This page is way off-screen to the right. 43 | view.setAlpha(0); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/res/layout/list_item_example.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 25 | 26 | 27 | 33 | 34 | 35 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/animator/card_flip_left_out.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 35 | 36 | 37 | 38 | 44 | 45 | 46 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/animator/card_flip_right_out.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 35 | 36 | 37 | 38 | 44 | 45 | 46 | 52 | 53 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_layout_changes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 20 | 21 | 23 | 25 | 26 | 29 | 38 | 39 | 40 | 41 | 42 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /app/src/main/res/animator/card_flip_left_in.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 36 | 37 | 38 | 39 | 44 | 45 | 46 | 52 | 53 | 54 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/res/animator/card_flip_right_in.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 36 | 37 | 38 | 39 | 44 | 45 | 46 | 52 | 53 | 54 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/res/layout/slide_item_1.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | 25 | 26 | 35 | 36 | 37 | 47 | 48 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/slide_item_2.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | 25 | 26 | 35 | 36 | 37 | 47 | 48 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/res/layout/slide_item_3.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | 25 | 26 | 35 | 36 | 37 | 47 | 48 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/AdvancedScreenSlideActivity.java: -------------------------------------------------------------------------------- 1 | package com.ted.androidscreenslide.app; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.FragmentActivity; 5 | import android.support.v4.view.PagerAdapter; 6 | import android.support.v4.view.ViewPager; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import github.chenupt.springindicator.SpringIndicator; 11 | 12 | import java.util.ArrayList; 13 | 14 | /** 15 | * Created by Ted on 2015/3/9. 16 | */ 17 | public class AdvancedScreenSlideActivity extends FragmentActivity{ 18 | private ViewPager mViewPager; 19 | private ArrayList mViewList; 20 | private SpringIndicator mSpringIndicator; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | setContentView(R.layout.advanced_activity_screen_slide); 26 | initViews(); 27 | } 28 | 29 | private void initViews(){ 30 | mViewPager = (ViewPager)findViewById(R.id.view_pager); 31 | mSpringIndicator = (SpringIndicator)findViewById(R.id.indicator); 32 | LayoutInflater lf = LayoutInflater.from(this); 33 | View view1 = lf.inflate(R.layout.slide_item_1, null); 34 | View view2 = lf.inflate(R.layout.slide_item_2, null); 35 | View view3 = lf.inflate(R.layout.slide_item_3, null); 36 | mViewList = new ArrayList(); 37 | mViewList.add(view1); 38 | mViewList.add(view2); 39 | mViewList.add(view3); 40 | SlidePageAdapter adapter = new SlidePageAdapter(); 41 | mViewPager.setAdapter(adapter); 42 | mSpringIndicator.setViewPager(mViewPager); 43 | mViewPager.setPageTransformer(true,new AnimationPageTransformer()); 44 | //PagerModelManager modelManager; 45 | } 46 | 47 | 48 | private class SlidePageAdapter extends PagerAdapter { 49 | 50 | @Override 51 | public int getCount() { 52 | return mViewList.size(); 53 | } 54 | 55 | @Override 56 | public boolean isViewFromObject(View view, Object o) { 57 | return view == o; 58 | } 59 | 60 | @Override 61 | public void destroyItem(ViewGroup container, int position, Object object) { 62 | container.removeView(mViewList.get(position)); 63 | } 64 | 65 | @Override 66 | public Object instantiateItem(ViewGroup container, int position) { 67 | container.addView(mViewList.get(position)); 68 | return mViewList.get(position); 69 | } 70 | 71 | @Override 72 | public CharSequence getPageTitle(int position) { 73 | return (position+1)+""; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/AnimationPageTransformer.java: -------------------------------------------------------------------------------- 1 | package com.ted.androidscreenslide.app; 2 | 3 | import android.support.v4.view.ViewPager; 4 | import android.view.View; 5 | 6 | /** 7 | * Created by Ted on 2015/3/8. 8 | */ 9 | public class AnimationPageTransformer implements ViewPager.PageTransformer { 10 | private static final float MIN_SCALE = 0.85f; 11 | private static final float MIN_ALPHA = 0.5f; 12 | 13 | public void transformPage(View view, float position) { 14 | int pageWidth = view.getWidth(); 15 | int pageHeight = view.getHeight(); 16 | if(view.getId() == R.id.slide_item_1){ 17 | 18 | if (position < -1) { 19 | view.setAlpha(0); 20 | } else if (position <= 1) { 21 | view.setAlpha(1); 22 | View view1 = view.findViewById(R.id.slide_item_1_view_1); 23 | View view2 = view.findViewById(R.id.slide_item_1_view_2); 24 | View view3 = view.findViewById(R.id.slide_item_1_view_3); 25 | 26 | view1.setTranslationY(position*pageHeight/2); 27 | view2.setTranslationX(position*pageWidth/2); 28 | view3.setTranslationY(-position*pageHeight/2); 29 | 30 | } else { 31 | view.setAlpha(0); 32 | } 33 | }else if(view.getId() == R.id.slide_item_2){ 34 | 35 | if (position < -1) { 36 | view.setAlpha(0); 37 | } else if (position <= 1) { 38 | view.setAlpha(1); 39 | View view1 = view.findViewById(R.id.slide_item_2_view_1); 40 | View view2 = view.findViewById(R.id.slide_item_2_view_2); 41 | View view3 = view.findViewById(R.id.slide_item_2_view_3); 42 | 43 | view1.setTranslationY(position * pageHeight/2); 44 | view2.setTranslationX(position * pageWidth / 2); 45 | view3.setTranslationY(-position * pageHeight / 2); 46 | 47 | } else { 48 | view.setAlpha(0); 49 | } 50 | }else if(view.getId() == R.id.slide_item_3){ 51 | 52 | if (position < -1) { 53 | view.setAlpha(0); 54 | } else if (position <= 1) { 55 | view.setAlpha(1); 56 | View view1 = view.findViewById(R.id.slide_item_3_view_1); 57 | View view2 = view.findViewById(R.id.slide_item_3_view_2); 58 | View view3 = view.findViewById(R.id.slide_item_3_view_3); 59 | 60 | view1.setTranslationY(position * pageHeight/2); 61 | view2.setTranslationX(position * pageWidth / 2); 62 | view3.setTranslationY(-position * pageHeight / 2); 63 | 64 | } else { 65 | view.setAlpha(0); 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/ScreenSlidePageFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.app.Fragment; 20 | import android.os.Bundle; 21 | import android.view.LayoutInflater; 22 | import android.view.View; 23 | import android.view.ViewGroup; 24 | import android.widget.TextView; 25 | 26 | /** 27 | * A fragment representing a single step in a wizard. The fragment shows a dummy title indicating 28 | * the page number, along with some dummy text. 29 | * 30 | *

This class is used by the {@link CardFlipActivity} and {@link 31 | * ScreenSlideActivity} samples.

32 | */ 33 | public class ScreenSlidePageFragment extends Fragment { 34 | /** 35 | * The argument key for the page number this fragment represents. 36 | */ 37 | public static final String ARG_PAGE = "page"; 38 | 39 | /** 40 | * The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}. 41 | */ 42 | private int mPageNumber; 43 | 44 | /** 45 | * Factory method for this fragment class. Constructs a new fragment for the given page number. 46 | */ 47 | public static ScreenSlidePageFragment create(int pageNumber) { 48 | ScreenSlidePageFragment fragment = new ScreenSlidePageFragment(); 49 | Bundle args = new Bundle(); 50 | args.putInt(ARG_PAGE, pageNumber); 51 | fragment.setArguments(args); 52 | return fragment; 53 | } 54 | 55 | public ScreenSlidePageFragment() { 56 | } 57 | 58 | @Override 59 | public void onCreate(Bundle savedInstanceState) { 60 | super.onCreate(savedInstanceState); 61 | mPageNumber = getArguments().getInt(ARG_PAGE); 62 | } 63 | 64 | @Override 65 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 66 | Bundle savedInstanceState) { 67 | // Inflate the layout containing a title and body text. 68 | ViewGroup rootView = (ViewGroup) inflater 69 | .inflate(R.layout.fragment_screen_slide_page, container, false); 70 | 71 | // Set the title view to show the page number. 72 | ((TextView) rootView.findViewById(android.R.id.text1)).setText( 73 | getString(R.string.title_template_step, mPageNumber + 1)); 74 | 75 | return rootView; 76 | } 77 | 78 | /** 79 | * Returns the page number represented by this fragment object. 80 | */ 81 | public int getPageNumber() { 82 | return mPageNumber; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | Animations Demo 21 | Simple Crossfade 22 | Card Flip 23 | Screen Slide 24 | Zoom 25 | Layout Changes 26 | Step %1$d: Lorem 27 | Ipsum 28 | Advanced Screen Slide 29 | 30 | 31 | Toggle indicator 32 | Add item 33 | Remove item 34 | Previous 35 | Next 36 | Finish 37 | Photo info 38 | View photo 39 | 40 | 41 | Add an item above to get started. 42 | Touch a photo to expand it. 43 | 44 | 45 | Image 1 46 | Image 2 47 | Expanded image (touch to close) 48 | 49 | 50 | Angry Red Android 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.app.Activity; 20 | import android.app.ListActivity; 21 | import android.content.Intent; 22 | import android.os.Bundle; 23 | import android.view.View; 24 | import android.widget.ArrayAdapter; 25 | import android.widget.ListView; 26 | 27 | /** 28 | * The launchpad activity for this sample project. This activity launches other activities that 29 | * demonstrate implementations of common animations. 30 | */ 31 | public class MainActivity extends ListActivity { 32 | /** 33 | * This class describes an individual sample (the sample title, and the activity class that 34 | * demonstrates this sample). 35 | */ 36 | private class Sample { 37 | private CharSequence title; 38 | private Class activityClass; 39 | 40 | public Sample(int titleResId, Class activityClass) { 41 | this.activityClass = activityClass; 42 | this.title = getResources().getString(titleResId); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return title.toString(); 48 | } 49 | } 50 | 51 | /** 52 | * The collection of all samples in the app. This gets instantiated in {@link 53 | * #onCreate(android.os.Bundle)} because the {@link com.ted.androidscreenslide.app.MainActivity.Sample} constructor needs access to {@link 54 | * android.content.res.Resources}. 55 | */ 56 | private static Sample[] mSamples; 57 | 58 | public void onCreate(Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | setContentView(R.layout.activity_main); 61 | 62 | // Instantiate the list of samples. 63 | mSamples = new Sample[]{ 64 | new Sample(R.string.title_crossfade, CrossfadeActivity.class), 65 | new Sample(R.string.title_card_flip, CardFlipActivity.class), 66 | new Sample(R.string.title_screen_slide, ScreenSlideActivity.class), 67 | new Sample(R.string.title_zoom, ZoomActivity.class), 68 | new Sample(R.string.title_layout_changes, LayoutChangesActivity.class), 69 | new Sample(R.string.title_advanced_screen_slide, AdvancedScreenSlideActivity.class), 70 | }; 71 | 72 | setListAdapter(new ArrayAdapter(this, 73 | android.R.layout.simple_list_item_1, 74 | android.R.id.text1, 75 | mSamples)); 76 | } 77 | 78 | @Override 79 | protected void onListItemClick(ListView listView, View view, int position, long id) { 80 | // Launch the sample associated with this list position. 81 | startActivity(new Intent(MainActivity.this, mSamples[position].activityClass)); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_zoom.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 26 | 27 | 31 | 32 | 35 | 40 | 41 | 45 | 46 | 54 | 55 | 62 | 63 | 64 | 65 | 66 | 67 | 72 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 21 | 22 | 30 | 31 | 32 | 36 | 37 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 49 | 51 | 52 | 53 | 57 | 59 | 60 | 61 | 65 | 67 | 68 | 69 | /> 72 | 73 | 74 | 77 | 79 | 80 | 81 | > 84 | 86 | 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/TouchHighlightImageButton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.content.Context; 20 | import android.content.res.TypedArray; 21 | import android.graphics.Canvas; 22 | import android.graphics.Rect; 23 | import android.graphics.drawable.Drawable; 24 | import android.util.AttributeSet; 25 | import android.widget.ImageButton; 26 | 27 | /** 28 | * An image button that uses a blue highlight (@link android.R.attr.selectableItemBackground} to 29 | * indicate pressed and focused states. 30 | */ 31 | public class TouchHighlightImageButton extends ImageButton { 32 | /** 33 | * The highlight drawable. This generally a {@link android.graphics.drawable.StateListDrawable} 34 | * that's transparent in the default state, and contains a semi-transparent overlay 35 | * for the focused and pressed states. 36 | */ 37 | private Drawable mForegroundDrawable; 38 | 39 | /** 40 | * The cached bounds of the view. 41 | */ 42 | private Rect mCachedBounds = new Rect(); 43 | 44 | public TouchHighlightImageButton(Context context) { 45 | super(context); 46 | init(); 47 | } 48 | 49 | public TouchHighlightImageButton(Context context, AttributeSet attrs) { 50 | super(context, attrs); 51 | init(); 52 | } 53 | 54 | public TouchHighlightImageButton(Context context, AttributeSet attrs, int defStyle) { 55 | super(context, attrs, defStyle); 56 | init(); 57 | } 58 | 59 | /** 60 | * General view initialization used common to all constructors of the view. 61 | */ 62 | private void init() { 63 | // Reset default ImageButton background and padding. 64 | setBackgroundColor(0); 65 | setPadding(0, 0, 0, 0); 66 | 67 | // Retrieve the drawable resource assigned to the android.R.attr.selectableItemBackground 68 | // theme attribute from the current theme. 69 | TypedArray a = getContext() 70 | .obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground}); 71 | mForegroundDrawable = a.getDrawable(0); 72 | mForegroundDrawable.setCallback(this); 73 | a.recycle(); 74 | } 75 | 76 | @Override 77 | protected void drawableStateChanged() { 78 | super.drawableStateChanged(); 79 | 80 | // Update the state of the highlight drawable to match 81 | // the state of the button. 82 | if (mForegroundDrawable.isStateful()) { 83 | mForegroundDrawable.setState(getDrawableState()); 84 | } 85 | 86 | // Trigger a redraw. 87 | invalidate(); 88 | } 89 | 90 | @Override 91 | protected void onDraw(Canvas canvas) { 92 | // First draw the image. 93 | super.onDraw(canvas); 94 | 95 | // Then draw the highlight on top of it. If the button is neither focused 96 | // nor pressed, the drawable will be transparent, so just the image 97 | // will be drawn. 98 | mForegroundDrawable.setBounds(mCachedBounds); 99 | mForegroundDrawable.draw(canvas); 100 | } 101 | 102 | @Override 103 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 104 | super.onSizeChanged(w, h, oldw, oldh); 105 | 106 | // Cache the view bounds. 107 | mCachedBounds.set(0, 0, w, h); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/LayoutChangesActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.app.Activity; 20 | import android.content.Intent; 21 | import android.os.Bundle; 22 | import android.support.v4.app.NavUtils; 23 | import android.view.*; 24 | import android.widget.TextView; 25 | 26 | /** 27 | * This sample demonstrates how to use system-provided, automatic layout transitions. Layout 28 | * transitions are animations that occur when views are added to, removed from, or changed within 29 | * a {@link android.view.ViewGroup}. 30 | * 31 | *

In this sample, the user can add rows to and remove rows from a vertical 32 | * {@link android.widget.LinearLayout}.

33 | */ 34 | public class LayoutChangesActivity extends Activity { 35 | /** 36 | * The container view which has layout change animations turned on. In this sample, this view 37 | * is a {@link android.widget.LinearLayout}. 38 | */ 39 | private ViewGroup mContainerView; 40 | 41 | @Override 42 | protected void onCreate(Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | setContentView(R.layout.activity_layout_changes); 45 | 46 | mContainerView = (ViewGroup) findViewById(R.id.container); 47 | } 48 | 49 | @Override 50 | public boolean onCreateOptionsMenu(Menu menu) { 51 | super.onCreateOptionsMenu(menu); 52 | getMenuInflater().inflate(R.menu.activity_layout_changes, menu); 53 | return true; 54 | } 55 | 56 | @Override 57 | public boolean onOptionsItemSelected(MenuItem item) { 58 | switch (item.getItemId()) { 59 | case android.R.id.home: 60 | // Navigate "up" the demo structure to the launchpad activity. 61 | // See http://developer.android.com/design/patterns/navigation.html for more. 62 | NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); 63 | return true; 64 | 65 | case R.id.action_add_item: 66 | // Hide the "empty" view since there is now at least one item in the list. 67 | findViewById(android.R.id.empty).setVisibility(View.GONE); 68 | addItem(); 69 | return true; 70 | } 71 | 72 | return super.onOptionsItemSelected(item); 73 | } 74 | 75 | private void addItem() { 76 | // Instantiate a new "row" view. 77 | final ViewGroup newView = (ViewGroup) LayoutInflater.from(this).inflate( 78 | R.layout.list_item_example, mContainerView, false); 79 | 80 | // Set the text in the new row to a random country. 81 | ((TextView) newView.findViewById(android.R.id.text1)).setText( 82 | COUNTRIES[(int) (Math.random() * COUNTRIES.length)]); 83 | 84 | // Set a click listener for the "X" button in the row that will remove the row. 85 | newView.findViewById(R.id.delete_button).setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View view) { 88 | // Remove the row from its parent (the container view). 89 | // Because mContainerView has android:animateLayoutChanges set to true, 90 | // this removal is automatically animated. 91 | mContainerView.removeView(newView); 92 | 93 | // If there are no rows remaining, show the empty view. 94 | if (mContainerView.getChildCount() == 0) { 95 | findViewById(android.R.id.empty).setVisibility(View.VISIBLE); 96 | } 97 | } 98 | }); 99 | 100 | // Because mContainerView has android:animateLayoutChanges set to true, 101 | // adding this view is automatically animated. 102 | mContainerView.addView(newView, 0); 103 | } 104 | 105 | /** 106 | * A static list of country names. 107 | */ 108 | private static final String[] COUNTRIES = new String[]{ 109 | "Belgium", "France", "Italy", "Germany", "Spain", 110 | "Austria", "Russia", "Poland", "Croatia", "Greece", 111 | "Ukraine", 112 | }; 113 | } 114 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # For Cygwin, ensure paths are in UNIX format before anything is touched. 46 | if $cygwin ; then 47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 48 | fi 49 | 50 | # Attempt to set APP_HOME 51 | # Resolve links: $0 may be a link 52 | PRG="$0" 53 | # Need this for relative symlinks. 54 | while [ -h "$PRG" ] ; do 55 | ls=`ls -ld "$PRG"` 56 | link=`expr "$ls" : '.*-> \(.*\)$'` 57 | if expr "$link" : '/.*' > /dev/null; then 58 | PRG="$link" 59 | else 60 | PRG=`dirname "$PRG"`"/$link" 61 | fi 62 | done 63 | SAVED="`pwd`" 64 | cd "`dirname \"$PRG\"`/" >&- 65 | APP_HOME="`pwd -P`" 66 | cd "$SAVED" >&- 67 | 68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 69 | 70 | # Determine the Java command to use to start the JVM. 71 | if [ -n "$JAVA_HOME" ] ; then 72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 73 | # IBM's JDK on AIX uses strange locations for the executables 74 | JAVACMD="$JAVA_HOME/jre/sh/java" 75 | else 76 | JAVACMD="$JAVA_HOME/bin/java" 77 | fi 78 | if [ ! -x "$JAVACMD" ] ; then 79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 80 | 81 | Please set the JAVA_HOME variable in your environment to match the 82 | location of your Java installation." 83 | fi 84 | else 85 | JAVACMD="java" 86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 87 | 88 | Please set the JAVA_HOME variable in your environment to match the 89 | location of your Java installation." 90 | fi 91 | 92 | # Increase the maximum file descriptors if we can. 93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 94 | MAX_FD_LIMIT=`ulimit -H -n` 95 | if [ $? -eq 0 ] ; then 96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 97 | MAX_FD="$MAX_FD_LIMIT" 98 | fi 99 | ulimit -n $MAX_FD 100 | if [ $? -ne 0 ] ; then 101 | warn "Could not set maximum file descriptor limit: $MAX_FD" 102 | fi 103 | else 104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 105 | fi 106 | fi 107 | 108 | # For Darwin, add options to specify how the application appears in the dock 109 | if $darwin; then 110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 111 | fi 112 | 113 | # For Cygwin, switch paths to Windows format before running java 114 | if $cygwin ; then 115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 158 | function splitJvmOpts() { 159 | JVM_OPTS=("$@") 160 | } 161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 163 | 164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 165 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/CrossfadeActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.animation.Animator; 20 | import android.animation.AnimatorListenerAdapter; 21 | import android.app.Activity; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.support.v4.app.NavUtils; 25 | import android.view.Menu; 26 | import android.view.MenuItem; 27 | import android.view.View; 28 | 29 | /** 30 | * This sample demonstrates cross-fading between two overlapping views. 31 | * 32 | *

In this sample, the two overlapping views are a loading indicator and some text content. The 33 | * active view is toggled by touching the toggle button in the action bar. In real-world 34 | * applications, this toggle would occur as soon as content was available. Note that if content is 35 | * immediately available, a loading spinner shouldn't be presented and there should be no 36 | * animation.

37 | */ 38 | public class CrossfadeActivity extends Activity { 39 | /** 40 | * The flag indicating whether content is loaded (text is shown) or not (loading spinner is 41 | * shown). 42 | */ 43 | private boolean mContentLoaded; 44 | 45 | /** 46 | * The view (or view group) containing the content. This is one of two overlapping views. 47 | */ 48 | private View mContentView; 49 | 50 | /** 51 | * The view containing the loading indicator. This is the other of two overlapping views. 52 | */ 53 | private View mLoadingView; 54 | 55 | /** 56 | * The system "short" animation time duration, in milliseconds. This duration is ideal for 57 | * subtle animations or animations that occur very frequently. 58 | */ 59 | private int mShortAnimationDuration; 60 | 61 | @Override 62 | protected void onCreate(Bundle savedInstanceState) { 63 | super.onCreate(savedInstanceState); 64 | setContentView(R.layout.activity_crossfade); 65 | 66 | mContentView = findViewById(R.id.content); 67 | mLoadingView = findViewById(R.id.loading_spinner); 68 | 69 | // Initially hide the content view. 70 | mContentView.setVisibility(View.GONE); 71 | 72 | // Retrieve and cache the system's default "short" animation time. 73 | mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); 74 | } 75 | 76 | @Override 77 | public boolean onCreateOptionsMenu(Menu menu) { 78 | super.onCreateOptionsMenu(menu); 79 | getMenuInflater().inflate(R.menu.activity_crossfade, menu); 80 | return true; 81 | } 82 | 83 | @Override 84 | public boolean onOptionsItemSelected(MenuItem item) { 85 | switch (item.getItemId()) { 86 | case android.R.id.home: 87 | // Navigate "up" the demo structure to the launchpad activity. 88 | // See http://developer.android.com/design/patterns/navigation.html for more. 89 | NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); 90 | return true; 91 | 92 | case R.id.action_toggle: 93 | // Toggle whether content is loaded. 94 | mContentLoaded = !mContentLoaded; 95 | showContentOrLoadingIndicator(mContentLoaded); 96 | return true; 97 | } 98 | 99 | return super.onOptionsItemSelected(item); 100 | } 101 | 102 | /** 103 | * Cross-fades between {@link #mContentView} and {@link #mLoadingView}. 104 | */ 105 | private void showContentOrLoadingIndicator(boolean contentLoaded) { 106 | // Decide which view to hide and which to show. 107 | final View showView = contentLoaded ? mContentView : mLoadingView; 108 | final View hideView = contentLoaded ? mLoadingView : mContentView; 109 | 110 | // Set the "show" view to 0% opacity but visible, so that it is visible 111 | // (but fully transparent) during the animation. 112 | showView.setAlpha(0f); 113 | showView.setVisibility(View.VISIBLE); 114 | 115 | // Animate the "show" view to 100% opacity, and clear any animation listener set on 116 | // the view. Remember that listeners are not limited to the specific animation 117 | // describes in the chained method calls. Listeners are set on the 118 | // ViewPropertyAnimator object for the view, which persists across several 119 | // animations. 120 | showView.animate() 121 | .alpha(1f) 122 | .setDuration(mShortAnimationDuration) 123 | .setListener(null); 124 | 125 | // Animate the "hide" view to 0% opacity. After the animation ends, set its visibility 126 | // to GONE as an optimization step (it won't participate in layout passes, etc.) 127 | hideView.animate() 128 | .alpha(0f) 129 | .setDuration(mShortAnimationDuration) 130 | .setListener(new AnimatorListenerAdapter() { 131 | @Override 132 | public void onAnimationEnd(Animator animation) { 133 | hideView.setVisibility(View.GONE); 134 | } 135 | }); 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 23 | 24 | 25 | 26 | 27 | 28 | 30 | 31 | 32 | 33 | 34 | 35 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 83 | 84 | 85 | 86 | 87 | 88 | 95 | 96 | 97 | 108 | 109 | 122 | 123 | 124 | 129 | 130 | 132 | 133 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/ScreenSlideActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.app.Fragment; 20 | import android.app.FragmentManager; 21 | import android.content.Intent; 22 | import android.os.Bundle; 23 | import android.support.v13.app.FragmentStatePagerAdapter; 24 | import android.support.v4.app.FragmentActivity; 25 | import android.support.v4.app.NavUtils; 26 | import android.support.v4.view.PagerAdapter; 27 | import android.support.v4.view.ViewPager; 28 | import android.view.Menu; 29 | import android.view.MenuItem; 30 | 31 | /** 32 | * Demonstrates a "screen-slide" animation using a {@link android.support.v4.view.ViewPager}. Because {@link android.support.v4.view.ViewPager} 33 | * automatically plays such an animation when calling {@link android.support.v4.view.ViewPager#setCurrentItem(int)}, there 34 | * isn't any animation-specific code in this sample. 35 | * 36 | *

This sample shows a "next" button that advances the user to the next step in a wizard, 37 | * animating the current screen out (to the left) and the next screen in (from the right). The 38 | * reverse animation is played when the user presses the "previous" button.

39 | * 40 | * @see ScreenSlidePageFragment 41 | */ 42 | public class ScreenSlideActivity extends FragmentActivity { 43 | /** 44 | * The number of pages (wizard steps) to show in this demo. 45 | */ 46 | private static final int NUM_PAGES = 5; 47 | 48 | /** 49 | * The pager widget, which handles animation and allows swiping horizontally to access previous 50 | * and next wizard steps. 51 | */ 52 | private ViewPager mPager; 53 | 54 | /** 55 | * The pager adapter, which provides the pages to the view pager widget. 56 | */ 57 | private PagerAdapter mPagerAdapter; 58 | 59 | @Override 60 | protected void onCreate(Bundle savedInstanceState) { 61 | super.onCreate(savedInstanceState); 62 | setContentView(R.layout.activity_screen_slide); 63 | 64 | // Instantiate a ViewPager and a PagerAdapter. 65 | mPager = (ViewPager) findViewById(R.id.pager); 66 | mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager()); 67 | mPager.setAdapter(mPagerAdapter); 68 | mPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { 69 | @Override 70 | public void onPageSelected(int position) { 71 | // When changing pages, reset the action bar actions since they are dependent 72 | // on which page is currently active. An alternative approach is to have each 73 | // fragment expose actions itself (rather than the activity exposing actions), 74 | // but for simplicity, the activity provides the actions in this sample. 75 | invalidateOptionsMenu(); 76 | } 77 | }); 78 | mPager.setPageTransformer(true, new DepthPageTransformer()); 79 | } 80 | 81 | @Override 82 | public boolean onCreateOptionsMenu(Menu menu) { 83 | super.onCreateOptionsMenu(menu); 84 | getMenuInflater().inflate(R.menu.activity_screen_slide, menu); 85 | 86 | menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0); 87 | 88 | // Add either a "next" or "finish" button to the action bar, depending on which page 89 | // is currently selected. 90 | MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE, 91 | (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1) 92 | ? R.string.action_finish 93 | : R.string.action_next); 94 | item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); 95 | return true; 96 | } 97 | 98 | @Override 99 | public boolean onOptionsItemSelected(MenuItem item) { 100 | switch (item.getItemId()) { 101 | case android.R.id.home: 102 | // Navigate "up" the demo structure to the launchpad activity. 103 | // See http://developer.android.com/design/patterns/navigation.html for more. 104 | NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); 105 | return true; 106 | 107 | case R.id.action_previous: 108 | // Go to the previous step in the wizard. If there is no previous step, 109 | // setCurrentItem will do nothing. 110 | mPager.setCurrentItem(mPager.getCurrentItem() - 1); 111 | return true; 112 | 113 | case R.id.action_next: 114 | // Advance to the next step in the wizard. If there is no next step, setCurrentItem 115 | // will do nothing. 116 | mPager.setCurrentItem(mPager.getCurrentItem() + 1); 117 | return true; 118 | } 119 | 120 | return super.onOptionsItemSelected(item); 121 | } 122 | 123 | /** 124 | * A simple pager adapter that represents 5 {@link ScreenSlidePageFragment} objects, in 125 | * sequence. 126 | */ 127 | private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 128 | public ScreenSlidePagerAdapter(FragmentManager fm) { 129 | super(fm); 130 | } 131 | 132 | @Override 133 | public Fragment getItem(int position) { 134 | return ScreenSlidePageFragment.create(position); 135 | } 136 | 137 | @Override 138 | public int getCount() { 139 | return NUM_PAGES; 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/CardFlipActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.app.Activity; 20 | import android.app.Fragment; 21 | import android.app.FragmentManager; 22 | import android.content.Intent; 23 | import android.os.Bundle; 24 | import android.os.Handler; 25 | import android.support.v4.app.NavUtils; 26 | import android.view.LayoutInflater; 27 | import android.view.Menu; 28 | import android.view.MenuItem; 29 | import android.view.View; 30 | import android.view.ViewGroup; 31 | 32 | /** 33 | * Demonstrates a "card-flip" animation using custom fragment transactions ({@link 34 | * android.app.FragmentTransaction#setCustomAnimations(int, int)}). 35 | * 36 | *

This sample shows an "info" action bar button that shows the back of a "card", rotating the 37 | * front of the card out and the back of the card in. The reverse animation is played when the user 38 | * presses the system Back button or the "photo" action bar button.

39 | */ 40 | public class CardFlipActivity extends Activity 41 | implements FragmentManager.OnBackStackChangedListener { 42 | /** 43 | * A handler object, used for deferring UI operations. 44 | */ 45 | private Handler mHandler = new Handler(); 46 | 47 | /** 48 | * Whether or not we're showing the back of the card (otherwise showing the front). 49 | */ 50 | private boolean mShowingBack = false; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | setContentView(R.layout.activity_card_flip); 56 | 57 | if (savedInstanceState == null) { 58 | // If there is no saved instance state, add a fragment representing the 59 | // front of the card to this activity. If there is saved instance state, 60 | // this fragment will have already been added to the activity. 61 | getFragmentManager() 62 | .beginTransaction() 63 | .add(R.id.container, new CardFrontFragment()) 64 | .commit(); 65 | } else { 66 | mShowingBack = (getFragmentManager().getBackStackEntryCount() > 0); 67 | } 68 | 69 | // Monitor back stack changes to ensure the action bar shows the appropriate 70 | // button (either "photo" or "info"). 71 | getFragmentManager().addOnBackStackChangedListener(this); 72 | } 73 | 74 | @Override 75 | public boolean onCreateOptionsMenu(Menu menu) { 76 | super.onCreateOptionsMenu(menu); 77 | 78 | // Add either a "photo" or "finish" button to the action bar, depending on which page 79 | // is currently selected. 80 | MenuItem item = menu.add(Menu.NONE, R.id.action_flip, Menu.NONE, 81 | mShowingBack 82 | ? R.string.action_photo 83 | : R.string.action_info); 84 | item.setIcon(mShowingBack 85 | ? R.drawable.ic_action_photo 86 | : R.drawable.ic_action_info); 87 | item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); 88 | return true; 89 | } 90 | 91 | @Override 92 | public boolean onOptionsItemSelected(MenuItem item) { 93 | switch (item.getItemId()) { 94 | case android.R.id.home: 95 | // Navigate "up" the demo structure to the launchpad activity. 96 | // See http://developer.android.com/design/patterns/navigation.html for more. 97 | NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); 98 | return true; 99 | 100 | case R.id.action_flip: 101 | flipCard(); 102 | return true; 103 | } 104 | 105 | return super.onOptionsItemSelected(item); 106 | } 107 | 108 | private void flipCard() { 109 | if (mShowingBack) { 110 | getFragmentManager().popBackStack(); 111 | return; 112 | } 113 | 114 | // Flip to the back. 115 | 116 | mShowingBack = true; 117 | 118 | // Create and commit a new fragment transaction that adds the fragment for the back of 119 | // the card, uses custom animations, and is part of the fragment manager's back stack. 120 | 121 | getFragmentManager() 122 | .beginTransaction() 123 | 124 | // Replace the default fragment animations with animator resources representing 125 | // rotations when switching to the back of the card, as well as animator 126 | // resources representing rotations when flipping back to the front (e.g. when 127 | // the system Back button is pressed). 128 | .setCustomAnimations( 129 | R.animator.card_flip_right_in, R.animator.card_flip_right_out, 130 | R.animator.card_flip_left_in, R.animator.card_flip_left_out) 131 | 132 | // Replace any fragments currently in the container view with a fragment 133 | // representing the next page (indicated by the just-incremented currentPage 134 | // variable). 135 | .replace(R.id.container, new CardBackFragment()) 136 | 137 | // Add this transaction to the back stack, allowing users to press Back 138 | // to get to the front of the card. 139 | .addToBackStack(null) 140 | 141 | // Commit the transaction. 142 | .commit(); 143 | 144 | // Defer an invalidation of the options menu (on modern devices, the action bar). This 145 | // can't be done immediately because the transaction may not yet be committed. Commits 146 | // are asynchronous in that they are posted to the main thread's message loop. 147 | mHandler.post(new Runnable() { 148 | @Override 149 | public void run() { 150 | invalidateOptionsMenu(); 151 | } 152 | }); 153 | } 154 | 155 | @Override 156 | public void onBackStackChanged() { 157 | mShowingBack = (getFragmentManager().getBackStackEntryCount() > 0); 158 | 159 | // When the back stack changes, invalidate the options menu (action bar). 160 | invalidateOptionsMenu(); 161 | } 162 | 163 | /** 164 | * A fragment representing the front of the card. 165 | */ 166 | public static class CardFrontFragment extends Fragment { 167 | public CardFrontFragment() { 168 | } 169 | 170 | @Override 171 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 172 | Bundle savedInstanceState) { 173 | return inflater.inflate(R.layout.fragment_card_front, container, false); 174 | } 175 | } 176 | 177 | /** 178 | * A fragment representing the back of the card. 179 | */ 180 | public static class CardBackFragment extends Fragment { 181 | public CardBackFragment() { 182 | } 183 | 184 | @Override 185 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 186 | Bundle savedInstanceState) { 187 | return inflater.inflate(R.layout.fragment_card_back, container, false); 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /app/src/main/java/com/ted/androidscreenslide/app/ZoomActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012 The Android Open Source Project 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ted.androidscreenslide.app; 18 | 19 | import android.animation.Animator; 20 | import android.animation.AnimatorListenerAdapter; 21 | import android.animation.AnimatorSet; 22 | import android.animation.ObjectAnimator; 23 | import android.content.Intent; 24 | import android.graphics.Point; 25 | import android.graphics.Rect; 26 | import android.os.Bundle; 27 | import android.support.v4.app.FragmentActivity; 28 | import android.support.v4.app.NavUtils; 29 | import android.view.MenuItem; 30 | import android.view.View; 31 | import android.view.animation.DecelerateInterpolator; 32 | import android.widget.ImageView; 33 | 34 | /** 35 | * A sample showing how to zoom an image thumbnail to full-screen, by animating the bounds of the 36 | * zoomed image from the thumbnail bounds to the screen bounds. 37 | * 38 | *

In this sample, the user can touch one of two images. Touching an image zooms it in, covering 39 | * the entire activity content area. Touching the zoomed-in image hides it.

40 | */ 41 | public class ZoomActivity extends FragmentActivity { 42 | /** 43 | * Hold a reference to the current animator, so that it can be canceled mid-way. 44 | */ 45 | private Animator mCurrentAnimator; 46 | 47 | /** 48 | * The system "short" animation time duration, in milliseconds. This duration is ideal for 49 | * subtle animations or animations that occur very frequently. 50 | */ 51 | private int mShortAnimationDuration; 52 | 53 | @Override 54 | protected void onCreate(Bundle savedInstanceState) { 55 | super.onCreate(savedInstanceState); 56 | setContentView(R.layout.activity_zoom); 57 | 58 | // Hook up clicks on the thumbnail views. 59 | 60 | final View thumb1View = findViewById(R.id.thumb_button_1); 61 | thumb1View.setOnClickListener(new View.OnClickListener() { 62 | @Override 63 | public void onClick(View view) { 64 | zoomImageFromThumb(thumb1View, R.drawable.image1); 65 | } 66 | }); 67 | 68 | final View thumb2View = findViewById(R.id.thumb_button_2); 69 | thumb2View.setOnClickListener(new View.OnClickListener() { 70 | @Override 71 | public void onClick(View view) { 72 | zoomImageFromThumb(thumb2View, R.drawable.image2); 73 | } 74 | }); 75 | 76 | // Retrieve and cache the system's default "short" animation time. 77 | mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); 78 | } 79 | 80 | @Override 81 | public boolean onOptionsItemSelected(MenuItem item) { 82 | switch (item.getItemId()) { 83 | case android.R.id.home: 84 | // Navigate "up" the demo structure to the launchpad activity. 85 | // See http://developer.android.com/design/patterns/navigation.html for more. 86 | NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class)); 87 | return true; 88 | } 89 | 90 | return super.onOptionsItemSelected(item); 91 | } 92 | 93 | /** 94 | * "Zooms" in a thumbnail view by assigning the high resolution image to a hidden "zoomed-in" 95 | * image view and animating its bounds to fit the entire activity content area. More 96 | * specifically: 97 | * 98 | *
    99 | *
  1. Assign the high-res image to the hidden "zoomed-in" (expanded) image view.
  2. 100 | *
  3. Calculate the starting and ending bounds for the expanded view.
  4. 101 | *
  5. Animate each of four positioning/sizing properties (X, Y, SCALE_X, SCALE_Y) 102 | * simultaneously, from the starting bounds to the ending bounds.
  6. 103 | *
  7. Zoom back out by running the reverse animation on click.
  8. 104 | *
105 | * 106 | * @param thumbView The thumbnail view to zoom in. 107 | * @param imageResId The high-resolution version of the image represented by the thumbnail. 108 | */ 109 | private void zoomImageFromThumb(final View thumbView, int imageResId) { 110 | // If there's an animation in progress, cancel it immediately and proceed with this one. 111 | if (mCurrentAnimator != null) { 112 | mCurrentAnimator.cancel(); 113 | } 114 | 115 | // Load the high-resolution "zoomed-in" image. 116 | final ImageView expandedImageView = (ImageView) findViewById(R.id.expanded_image); 117 | expandedImageView.setImageResource(imageResId); 118 | 119 | // Calculate the starting and ending bounds for the zoomed-in image. This step 120 | // involves lots of math. Yay, math. 121 | final Rect startBounds = new Rect(); 122 | final Rect finalBounds = new Rect(); 123 | final Point globalOffset = new Point(); 124 | 125 | // The start bounds are the global visible rectangle of the thumbnail, and the 126 | // final bounds are the global visible rectangle of the container view. Also 127 | // set the container view's offset as the origin for the bounds, since that's 128 | // the origin for the positioning animation properties (X, Y). 129 | thumbView.getGlobalVisibleRect(startBounds); 130 | findViewById(R.id.container).getGlobalVisibleRect(finalBounds, globalOffset); 131 | startBounds.offset(-globalOffset.x, -globalOffset.y); 132 | finalBounds.offset(-globalOffset.x, -globalOffset.y); 133 | 134 | // Adjust the start bounds to be the same aspect ratio as the final bounds using the 135 | // "center crop" technique. This prevents undesirable stretching during the animation. 136 | // Also calculate the start scaling factor (the end scaling factor is always 1.0). 137 | float startScale; 138 | if ((float) finalBounds.width() / finalBounds.height() 139 | > (float) startBounds.width() / startBounds.height()) { 140 | // Extend start bounds horizontally 141 | startScale = (float) startBounds.height() / finalBounds.height(); 142 | float startWidth = startScale * finalBounds.width(); 143 | float deltaWidth = (startWidth - startBounds.width()) / 2; 144 | startBounds.left -= deltaWidth; 145 | startBounds.right += deltaWidth; 146 | } else { 147 | // Extend start bounds vertically 148 | startScale = (float) startBounds.width() / finalBounds.width(); 149 | float startHeight = startScale * finalBounds.height(); 150 | float deltaHeight = (startHeight - startBounds.height()) / 2; 151 | startBounds.top -= deltaHeight; 152 | startBounds.bottom += deltaHeight; 153 | } 154 | 155 | // Hide the thumbnail and show the zoomed-in view. When the animation begins, 156 | // it will position the zoomed-in view in the place of the thumbnail. 157 | thumbView.setAlpha(0f); 158 | expandedImageView.setVisibility(View.VISIBLE); 159 | 160 | // Set the pivot point for SCALE_X and SCALE_Y transformations to the top-left corner of 161 | // the zoomed-in view (the default is the center of the view). 162 | expandedImageView.setPivotX(0f); 163 | expandedImageView.setPivotY(0f); 164 | 165 | // Construct and run the parallel animation of the four translation and scale properties 166 | // (X, Y, SCALE_X, and SCALE_Y). 167 | AnimatorSet set = new AnimatorSet(); 168 | set 169 | .play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left, 170 | finalBounds.left)) 171 | .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top, 172 | finalBounds.top)) 173 | .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_X, startScale, 1f)) 174 | .with(ObjectAnimator.ofFloat(expandedImageView, View.SCALE_Y, startScale, 1f)); 175 | set.setDuration(mShortAnimationDuration); 176 | set.setInterpolator(new DecelerateInterpolator()); 177 | set.addListener(new AnimatorListenerAdapter() { 178 | @Override 179 | public void onAnimationEnd(Animator animation) { 180 | mCurrentAnimator = null; 181 | } 182 | 183 | @Override 184 | public void onAnimationCancel(Animator animation) { 185 | mCurrentAnimator = null; 186 | } 187 | }); 188 | set.start(); 189 | mCurrentAnimator = set; 190 | 191 | // Upon clicking the zoomed-in image, it should zoom back down to the original bounds 192 | // and show the thumbnail instead of the expanded image. 193 | final float startScaleFinal = startScale; 194 | expandedImageView.setOnClickListener(new View.OnClickListener() { 195 | @Override 196 | public void onClick(View view) { 197 | if (mCurrentAnimator != null) { 198 | mCurrentAnimator.cancel(); 199 | } 200 | 201 | // Animate the four positioning/sizing properties in parallel, back to their 202 | // original values. 203 | AnimatorSet set = new AnimatorSet(); 204 | set 205 | .play(ObjectAnimator.ofFloat(expandedImageView, View.X, startBounds.left)) 206 | .with(ObjectAnimator.ofFloat(expandedImageView, View.Y, startBounds.top)) 207 | .with(ObjectAnimator 208 | .ofFloat(expandedImageView, View.SCALE_X, startScaleFinal)) 209 | .with(ObjectAnimator 210 | .ofFloat(expandedImageView, View.SCALE_Y, startScaleFinal)); 211 | set.setDuration(mShortAnimationDuration); 212 | set.setInterpolator(new DecelerateInterpolator()); 213 | set.addListener(new AnimatorListenerAdapter() { 214 | @Override 215 | public void onAnimationEnd(Animator animation) { 216 | thumbView.setAlpha(1f); 217 | expandedImageView.setVisibility(View.GONE); 218 | mCurrentAnimator = null; 219 | } 220 | 221 | @Override 222 | public void onAnimationCancel(Animator animation) { 223 | thumbView.setAlpha(1f); 224 | expandedImageView.setVisibility(View.GONE); 225 | mCurrentAnimator = null; 226 | } 227 | }); 228 | set.start(); 229 | mCurrentAnimator = set; 230 | } 231 | }); 232 | } 233 | } 234 | --------------------------------------------------------------------------------