Bug 1199859 - Add "Next" sliding. r=mfinkle
authorChenxia Liu <liuche@mozilla.com>
Wed, 09 Sep 2015 17:24:18 -0700
changeset 295954 8349bbfd8910c0c2143d635381988675314db074
parent 295953 3d97a673734c7d6c7fd885d5666c18ce3e72cbf3
child 295955 4eabe281eb8810f8e27ea986d7322d1918409995
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs1199859
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1199859 - Add "Next" sliding. r=mfinkle
mobile/android/base/BrowserApp.java
mobile/android/base/firstrun/FirstrunPager.java
mobile/android/base/firstrun/FirstrunPane.java
mobile/android/base/firstrun/FirstrunPanel.java
mobile/android/base/firstrun/ImportPanel.java
mobile/android/base/resources/layout/firstrun_import_fragment.xml
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -2579,17 +2579,17 @@ public class BrowserApp extends GeckoApp
         }
     }
 
     private void showFirstrunPager() {
         if (mFirstrunPane == null) {
             final ViewStub firstrunPagerStub = (ViewStub) findViewById(R.id.firstrun_pager_stub);
             mFirstrunPane = (FirstrunPane) firstrunPagerStub.inflate();
             mFirstrunPane.load(getApplicationContext(), getSupportFragmentManager());
-            mFirstrunPane.registerOnFinishListener(new FirstrunPane.PagerNavigation() {
+            mFirstrunPane.registerOnFinishListener(new FirstrunPane.OnFinishListener() {
                 @Override
                 public void onFinish() {
                     BrowserApp.this.mFirstrunPane = null;
                 }
             });
         }
 
         mHomePagerContainer.setVisibility(View.VISIBLE);
--- a/mobile/android/base/firstrun/FirstrunPager.java
+++ b/mobile/android/base/firstrun/FirstrunPager.java
@@ -17,39 +17,55 @@ import com.nineoldandroids.animation.Obj
 import com.nineoldandroids.view.ViewHelper;
 
 import org.mozilla.gecko.RestrictedProfiles;
 import org.mozilla.gecko.animation.TransitionsTracker;
 
 import java.util.List;
 
 public class FirstrunPager extends ViewPager {
+
     private Context context;
-    protected FirstrunPane.PagerNavigation listener;
+    protected FirstrunPanel.PagerNavigation pagerNavigation;
 
     public FirstrunPager(Context context) {
         this(context, null);
     }
 
     public FirstrunPager(Context context, AttributeSet attrs) {
         super(context, attrs);
         this.context = context;
     }
 
-    public void load(Context appContext, FragmentManager fm, FirstrunPane.PagerNavigation listener) {
+    public void load(Context appContext, FragmentManager fm, final FirstrunPane.OnFinishListener onFinishListener) {
         final List<FirstrunPagerConfig.FirstrunPanelConfig> panels;
 
         if (RestrictedProfiles.isUserRestricted(context)) {
             panels = FirstrunPagerConfig.getRestricted();
         } else {
             panels = FirstrunPagerConfig.getDefault(appContext);
         }
 
         setAdapter(new ViewPagerAdapter(fm, panels));
-        this.listener = listener;
+        this.pagerNavigation = new FirstrunPanel.PagerNavigation() {
+            @Override
+            public void next() {
+                final int currentPage = FirstrunPager.this.getCurrentItem();
+                if (currentPage < FirstrunPager.this.getChildCount() - 1) {
+                    FirstrunPager.this.setCurrentItem(currentPage + 1);
+                }
+            }
+
+            @Override
+            public void finish() {
+                if (onFinishListener != null) {
+                    onFinishListener.onFinish();
+                }
+            }
+        };
 
         animateLoad();
     }
 
     public void hide() {
         setAdapter(null);
     }
 
@@ -68,27 +84,33 @@ public class FirstrunPager extends ViewP
         set.playTogether(alphaAnimator, translateAnimator);
         set.setStartDelay(400);
         TransitionsTracker.track(set);
 
         set.start();
     }
 
     private class ViewPagerAdapter extends FragmentPagerAdapter {
-        private List<FirstrunPagerConfig.FirstrunPanelConfig> panels;
+        private final List<FirstrunPagerConfig.FirstrunPanelConfig> panels;
+        private final Fragment[] fragments;
 
         public ViewPagerAdapter(FragmentManager fm, List<FirstrunPagerConfig.FirstrunPanelConfig> panels) {
             super(fm);
             this.panels = panels;
+            this.fragments = new Fragment[panels.size()];
         }
 
         @Override
         public Fragment getItem(int i) {
-            final Fragment fragment = Fragment.instantiate(context, panels.get(i).getClassname());
-            ((FirstrunPanel) fragment).setPagerNavigation(listener);
+            Fragment fragment = this.fragments[i];
+            if (fragment == null) {
+                fragment = Fragment.instantiate(context, panels.get(i).getClassname());
+                ((FirstrunPanel) fragment).setPagerNavigation(pagerNavigation);
+                fragments[i] = fragment;
+            }
             return fragment;
         }
 
         @Override
         public int getCount() {
             return panels.size();
         }
 
--- a/mobile/android/base/firstrun/FirstrunPane.java
+++ b/mobile/android/base/firstrun/FirstrunPane.java
@@ -15,60 +15,51 @@ import com.nineoldandroids.animation.Ani
 import com.nineoldandroids.animation.AnimatorListenerAdapter;
 import com.nineoldandroids.animation.ObjectAnimator;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.animation.TransitionsTracker;
 
 public class FirstrunPane extends LinearLayout {
     public static final String PREF_FIRSTRUN_ENABLED = "startpane_enabled";
 
-    public static interface PagerNavigation {
-        public void next();
+    public static interface OnFinishListener {
         public void onFinish();
     }
 
     private FirstrunPager pager;
     private boolean visible;
-    private PagerNavigation pagerNavigation;
+    private OnFinishListener onFinishListener;
 
     public FirstrunPane(Context context) {
         this(context, null);
     }
     public FirstrunPane(Context context, AttributeSet attrs) {
         super(context, attrs);
     }
 
     public void load(Context appContext, FragmentManager fm) {
         visible = true;
         pager = (FirstrunPager) findViewById(R.id.firstrun_pager);
-        pager.load(appContext, fm, new PagerNavigation() {
-            @Override
-            public void next() {
-                final int currentPage = pager.getCurrentItem();
-                if (currentPage < pager.getChildCount() - 1) {
-                    pager.setCurrentItem(currentPage + 1);
-                }
-            }
-
+        pager.load(appContext, fm, new OnFinishListener() {
             @Override
             public void onFinish() {
                 hide();
             }
         });
     }
 
     public boolean isVisible() {
         return visible;
     }
 
     public void hide() {
         visible = false;
         pager.hide();
-        if (pagerNavigation != null) {
-            pagerNavigation.onFinish();
+        if (onFinishListener != null) {
+            onFinishListener.onFinish();
         }
         animateHide();
     }
 
     private void animateHide() {
         final Animator alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", 0);
         alphaAnimator.setDuration(150);
         alphaAnimator.addListener(new AnimatorListenerAdapter() {
@@ -78,12 +69,12 @@ public class FirstrunPane extends Linear
             }
         });
 
         TransitionsTracker.track(alphaAnimator);
 
         alphaAnimator.start();
     }
 
-    public void registerOnFinishListener(PagerNavigation listener) {
-        this.pagerNavigation = listener;
+    public void registerOnFinishListener(OnFinishListener listener) {
+        this.onFinishListener = listener;
     }
 }
--- a/mobile/android/base/firstrun/FirstrunPanel.java
+++ b/mobile/android/base/firstrun/FirstrunPanel.java
@@ -5,26 +5,30 @@
 
 package org.mozilla.gecko.firstrun;
 
 import android.support.v4.app.Fragment;
 
 public class FirstrunPanel extends Fragment {
 
     public static final int TITLE_RES = -1;
-    protected FirstrunPane.PagerNavigation pagerNavigation;
+    public interface PagerNavigation {
+        void next();
+        void finish();
+    }
+    protected PagerNavigation pagerNavigation;
 
-    public void setPagerNavigation(FirstrunPane.PagerNavigation listener) {
+    public void setPagerNavigation(PagerNavigation listener) {
         this.pagerNavigation = listener;
     }
 
     protected void next() {
         if (pagerNavigation != null) {
             pagerNavigation.next();
         }
     }
 
     protected void close() {
         if (pagerNavigation != null) {
-            pagerNavigation.onFinish();
+            pagerNavigation.finish();
         }
     }
 }
--- a/mobile/android/base/firstrun/ImportPanel.java
+++ b/mobile/android/base/firstrun/ImportPanel.java
@@ -22,16 +22,17 @@ import org.mozilla.gecko.util.ThreadUtil
 
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
 public class ImportPanel extends FirstrunPanel {
     public static final String LOGTAG = "GeckoImportPanel";
     public static final int TITLE_RES = R.string.firstrun_import_title;
+    private static final int AUTOADVANCE_DELAY_MS = 1500;
 
     // These match the item positions in R.array.pref_import_android_entries.
     private static int BOOKMARKS_INDEX = 0;
     private static int HISTORY_INDEX = 1;
 
     private ImageView confirmImage;
     private Button choiceButton;
 
@@ -116,17 +117,23 @@ public class ImportPanel extends Firstru
             public void run() {
                 ThreadUtils.postToUiThread(new Runnable() {
                     @Override
                     public void run() {
                         confirmImage.setVisibility(View.VISIBLE);
                         choiceButton.setVisibility(View.GONE);
 
                         dialog.dismiss();
-                        next();
+
+                        ThreadUtils.postDelayedToUiThread(new Runnable() {
+                            @Override
+                            public void run() {
+                                next();
+                            }
+                        }, AUTOADVANCE_DELAY_MS);
                     }
                 });
             }
         };
 
         ThreadUtils.postToBackgroundThread(
             // Constructing AndroidImport may need finding the profile,
             // which hits disk, so it needs to go into a Runnable too.
--- a/mobile/android/base/resources/layout/firstrun_import_fragment.xml
+++ b/mobile/android/base/resources/layout/firstrun_import_fragment.xml
@@ -52,17 +52,17 @@
             <Button android:id="@+id/import_action_button"
                     style="@style/Widget.Firstrun.Button"
                     android:background="@drawable/button_background_action_orange_round"
                     android:layout_gravity="center"
                     android:text="@string/firstrun_import_action"/>
 
             <ImageView android:id="@+id/confirm_check"
                        android:layout_width="wrap_content"
-                       android:layout_height="wrap_content"
+                       android:layout_height="60dp"
                        android:visibility="gone"
                        android:src="@drawable/overlay_check"/>
 
             <TextView android:id="@+id/import_link"
                       android:layout_width="@dimen/firstrun_content_width"
                       android:layout_height="wrap_content"
                       android:padding="20dp"
                       android:gravity="center"