├── 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 |
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 |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 |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 |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 | *