From 7e4b48668ee0166a7be1c12c507e2dad11e218fb Mon Sep 17 00:00:00 2001 From: Ricardo Cervera Date: Fri, 7 Feb 2014 12:31:02 -0800 Subject: [PATCH] docs: Fixed ViewPager animation tutorial. Bug: 12815243 Went through the tutorial and fixed a few minor issues. There is confusion with Fragment and FragmentManager from the support library vs. the main Android APIs. Clarified this by showing some imports explicitly. Tested the new code from the page on Eclipse and it works as expected. Change-Id: I8494a72f4c760a03a6b8f3322c5754e315f22e7c Review: http://quixote.mtv.corp.google.com:8002/training/animation/screen-slide.html --- docs/html/training/animation/screen-slide.jd | 45 +++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/docs/html/training/animation/screen-slide.jd b/docs/html/training/animation/screen-slide.jd index 07d779f0f0720..a68d475f18ee4 100644 --- a/docs/html/training/animation/screen-slide.jd +++ b/docs/html/training/animation/screen-slide.jd @@ -63,22 +63,23 @@ following files for the code implementation:

contains a text view to display some text:
-<com.example.android.animationsdemo.ScrollView
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:id="@+id/content"
+<!-- fragment_screen_slide_page.xml -->
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/content"
     android:layout_width="match_parent"
-    android:layout_height="match_parent">
+    android:layout_height="match_parent" >
 
-        <TextView style="?android:textAppearanceMedium"
-            android:padding="16dp"
-            android:lineSpacingMultiplier="1.2"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:text="@string/lorem_ipsum" />
-
-</com.example.android.animationsdemo.ScrollView>
+    <TextView style="?android:textAppearanceMedium"
+        android:padding="16dp"
+        android:lineSpacingMultiplier="1.2"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/lorem_ipsum" />
+</ScrollView>
 
+

Define also a string for the contents of the fragment.

+

Create the Fragment

Create a {@link android.support.v4.app.Fragment} class that returns the layout that you just created in the {@link android.app.Fragment#onCreateView onCreateView()} @@ -87,6 +88,8 @@ that you just created in the {@link android.app.Fragment#onCreateView onCreateVi

+import android.support.v4.app.Fragment;
+...
 public class ScreenSlidePageFragment extends Fragment {
 
     @Override
@@ -111,6 +114,7 @@ fragment class that you created earlier.
 

To begin, create a layout that contains a {@link android.support.v4.view.ViewPager}:

+<!-- activity_screen_slide.xml -->
 <android.support.v4.view.ViewPager
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/pager"
@@ -133,6 +137,9 @@ fragment class that you created earlier.
 
 
 
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+...
 public class ScreenSlidePagerActivity extends FragmentActivity {
     /**
      * The number of pages (wizard steps) to show in this demo.
@@ -153,11 +160,11 @@ public class ScreenSlidePagerActivity extends FragmentActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_screen_slide_pager);
+        setContentView(R.layout.activity_screen_slide);
 
         // Instantiate a ViewPager and a PagerAdapter.
         mPager = (ViewPager) findViewById(R.id.pager);
-        mPagerAdapter = new ScreenSlidePagerAdapter(getFragmentManager());
+        mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
         mPager.setAdapter(mPagerAdapter);
     }
 
@@ -224,9 +231,9 @@ call {@link android.support.v4.view.ViewPager#setPageTransformer setPageTransfor
   ZoomOutPageTransformer, you can set your custom animations
   like this:

-ViewPager pager = (ViewPager) findViewById(R.id.pager);
+ViewPager mPager = (ViewPager) findViewById(R.id.pager);
 ...
-pager.setPageTransformer(true, new ZoomOutPageTransformer());
+mPager.setPageTransformer(true, new ZoomOutPageTransformer());
 
@@ -257,8 +264,8 @@ sections for examples and videos of a {@link android.support.v4.view.ViewPager.P
 public class ZoomOutPageTransformer implements ViewPager.PageTransformer {
-    private static float MIN_SCALE = 0.85f;
-    private static float MIN_ALPHA = 0.5f;
+    private static final float MIN_SCALE = 0.85f;
+    private static final float MIN_ALPHA = 0.5f;
 
     public void transformPage(View view, float position) {
         int pageWidth = view.getWidth();
@@ -332,7 +339,7 @@ in a working page transformer:
 
 
 public class DepthPageTransformer implements ViewPager.PageTransformer {
-    private static float MIN_SCALE = 0.75f;
+    private static final float MIN_SCALE = 0.75f;
 
     public void transformPage(View view, float position) {
         int pageWidth = view.getWidth();