1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- 2 * This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 package org.mozilla.gecko.firstrun; 7 8 import android.content.Context; 9 import android.support.v4.app.FragmentManager; 10 import android.util.AttributeSet; 11 12 import android.view.View; 13 import android.widget.LinearLayout; 14 import android.animation.Animator; 15 import android.animation.AnimatorListenerAdapter; 16 import android.animation.ObjectAnimator; 17 import org.mozilla.gecko.R; 18 import org.mozilla.gecko.Telemetry; 19 import org.mozilla.gecko.TelemetryContract; 20 import org.mozilla.gecko.Experiments; 21 22 /** 23 * A container for the pager and the entire first run experience. 24 * This is used for animation purposes. 25 */ 26 public class FirstrunAnimationContainer extends LinearLayout { 27 public static final String PREF_FIRSTRUN_ENABLED = "startpane_enabled"; 28 29 public static interface OnFinishListener { onFinish()30 public void onFinish(); 31 } 32 33 private FirstrunPager pager; 34 private boolean visible; 35 private OnFinishListener onFinishListener; 36 FirstrunAnimationContainer(Context context)37 public FirstrunAnimationContainer(Context context) { 38 this(context, null); 39 } FirstrunAnimationContainer(Context context, AttributeSet attrs)40 public FirstrunAnimationContainer(Context context, AttributeSet attrs) { 41 super(context, attrs); 42 } 43 load(Context appContext, FragmentManager fm)44 public void load(Context appContext, FragmentManager fm) { 45 visible = true; 46 pager = (FirstrunPager) findViewById(R.id.firstrun_pager); 47 pager.load(appContext, fm, new OnFinishListener() { 48 @Override 49 public void onFinish() { 50 hide(); 51 } 52 }); 53 } 54 isVisible()55 public boolean isVisible() { 56 return visible; 57 } 58 hide()59 public void hide() { 60 visible = false; 61 if (onFinishListener != null) { 62 onFinishListener.onFinish(); 63 } 64 animateHide(); 65 66 // Stop all versions of firstrun A/B sessions. 67 Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_B); 68 Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_C); 69 } 70 animateHide()71 private void animateHide() { 72 final Animator alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", 0); 73 alphaAnimator.setDuration(150); 74 alphaAnimator.addListener(new AnimatorListenerAdapter() { 75 @Override 76 public void onAnimationEnd(Animator animation) { 77 FirstrunAnimationContainer.this.setVisibility(View.GONE); 78 } 79 }); 80 81 alphaAnimator.start(); 82 } 83 showBrowserHint()84 public boolean showBrowserHint() { 85 final int currentPage = pager.getCurrentItem(); 86 FirstrunPanel currentPanel = (FirstrunPanel) ((FirstrunPager.ViewPagerAdapter) pager.getAdapter()).getItem(currentPage); 87 pager.cleanup(); 88 return currentPanel.shouldShowBrowserHint(); 89 } 90 registerOnFinishListener(OnFinishListener listener)91 public void registerOnFinishListener(OnFinishListener listener) { 92 this.onFinishListener = listener; 93 } 94 } 95