1cc671dd3caac1d0cbf3f6999ab063c9ff1f297b2Dake Gu// CHECKSTYLE:OFF Generated code
2e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee/* This file is auto-generated from OnboardingDemoFragment.java.  DO NOT MODIFY. */
3e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
4e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee/*
5e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * Copyright (C) 2014 The Android Open Source Project
6e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee *
7e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * in compliance with the License. You may obtain a copy of the License at
9e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee *
10e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * http://www.apache.org/licenses/LICENSE-2.0
11e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee *
12e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * Unless required by applicable law or agreed to in writing, software distributed under the License
13e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * or implied. See the License for the specific language governing permissions and limitations under
15e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee * the License.
16e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee */
17e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leepackage com.example.android.leanback;
18e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
19e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.animation.Animator;
20e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.animation.AnimatorListenerAdapter;
21e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.animation.AnimatorSet;
22e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.animation.ObjectAnimator;
2354746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Leeimport android.graphics.drawable.AnimationDrawable;
24e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.support.v17.leanback.app.OnboardingSupportFragment;
25e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.view.LayoutInflater;
26e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.view.View;
27e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.view.ViewGroup;
28e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport android.widget.ImageView;
29e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
30e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leeimport java.util.ArrayList;
31e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
32e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Leepublic class OnboardingDemoSupportFragment extends OnboardingSupportFragment {
33e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private static final long ANIMATION_DURATION = 1000;
34e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
3554746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee    private static final int[] CONTENT_BACKGROUNDS = {
3654746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            R.drawable.tv_bg,
3754746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            R.drawable.gallery_photo_6,
3854746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            R.drawable.gallery_photo_8
39e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    };
4054746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee
4154746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee    private static final int[] CONTENT_ANIMATIONS = {
4254746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            R.drawable.tv_content,
4354746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            android.R.drawable.stat_sys_download,
4454746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            android.R.drawable.ic_popup_sync
4554746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee    };
4654746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee
47e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private String[] mTitles;
48e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private String[] mDescriptions;
49e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
50e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private View mBackgroundView;
5154746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee    private View mContentView;
5254746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee    private ImageView mContentBackgroundView;
5354746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee    private ImageView mContentAnimationView;
54e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
55e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private Animator mContentAnimator;
56e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
57b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu    @SuppressWarnings("deprecation")
58e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
59e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    public void onAttach(android.app.Activity activity) {
60e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        super.onAttach(activity);
61e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        mTitles = getResources().getStringArray(R.array.onboarding_page_titles);
62e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        mDescriptions = getResources().getStringArray(R.array.onboarding_page_descriptions);
63c43a33fa69773625b09654d63a5bde79594e6f4aChulwoo Lee        setLogoResourceId(R.drawable.ic_launcher);
64e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
65e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
66e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
67e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected int getPageCount() {
68e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return mTitles.length;
69e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
70e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
71e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
72e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected CharSequence getPageTitle(int i) {
73e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return mTitles[i];
74e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
75e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
76e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
77e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected CharSequence getPageDescription(int i) {
78e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return mDescriptions[i];
79e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
80e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
81e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
82e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected View onCreateBackgroundView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
83e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        mBackgroundView = layoutInflater.inflate(R.layout.onboarding_image, viewGroup, false);
84e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return mBackgroundView;
85e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
86e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
87e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
88e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected View onCreateContentView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
8954746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        mContentView = layoutInflater.inflate(R.layout.onboarding_content, viewGroup, false);
9054746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        mContentBackgroundView = (ImageView) mContentView.findViewById(R.id.background_image);
9154746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        mContentAnimationView = (ImageView) mContentView.findViewById(R.id.animation_image);
92e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return mContentView;
93e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
94e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
95e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
96e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected View onCreateForegroundView(LayoutInflater layoutInflater, ViewGroup viewGroup) {
97e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return null;
98e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
99e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
100e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
101e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected Animator onCreateEnterAnimation() {
102e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        ArrayList<Animator> animators = new ArrayList<>();
103e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        animators.add(createFadeInAnimator(mBackgroundView));
10454746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        mContentBackgroundView.setImageResource(CONTENT_BACKGROUNDS[0]);
10554746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        mContentAnimationView.setImageResource(CONTENT_ANIMATIONS[0]);
106e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        mContentAnimator = createFadeInAnimator(mContentView);
107e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        animators.add(mContentAnimator);
108e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        AnimatorSet set = new AnimatorSet();
109e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        set.playTogether(animators);
11054746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        set.addListener(new AnimatorListenerAdapter() {
11154746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            @Override
11254746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            public void onAnimationEnd(Animator animation) {
11354746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee                ((AnimationDrawable) mContentAnimationView.getDrawable()).start();
11454746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            }
11554746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        });
116e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return set;
117e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
118e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
119e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
120e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected void onPageChanged(final int newPage, int previousPage) {
121e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        if (mContentAnimator != null) {
12254746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            mContentAnimator.cancel();
123e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        }
12454746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        ((AnimationDrawable) mContentAnimationView.getDrawable()).stop();
125e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        ArrayList<Animator> animators = new ArrayList<>();
126e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        Animator fadeOut = createFadeOutAnimator(mContentView);
127e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        fadeOut.addListener(new AnimatorListenerAdapter() {
128e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee            @Override
129e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee            public void onAnimationEnd(Animator animation) {
13054746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee                mContentBackgroundView.setImageResource(CONTENT_BACKGROUNDS[newPage]);
13154746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee                mContentAnimationView.setImageResource(CONTENT_ANIMATIONS[newPage]);
13254746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            }
13354746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        });
13454746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        Animator fadeIn = createFadeInAnimator(mContentView);
13554746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        fadeIn.addListener(new AnimatorListenerAdapter() {
13654746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            @Override
13754746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee            public void onAnimationEnd(Animator animation) {
13854746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee                ((AnimationDrawable) mContentAnimationView.getDrawable()).start();
139e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee            }
140e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        });
141e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        AnimatorSet set = new AnimatorSet();
14254746b4f93cf6de92c8f69fdc415ea2dff8083c2Chulwoo Lee        set.playSequentially(fadeOut, fadeIn);
143e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        set.start();
144e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        mContentAnimator = set;
145e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
146e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
147e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private Animator createFadeInAnimator(View view) {
148e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f).setDuration(ANIMATION_DURATION);
149e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
150e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
151e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    private Animator createFadeOutAnimator(View view) {
152e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        return ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f).setDuration(ANIMATION_DURATION);
153e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
154e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee
155e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    @Override
156e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    protected void onFinishFragment() {
157e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee        getActivity().finish();
158e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee    }
159e3ef610a75fd382df930699ca42b61f24ac128f8Chulwoo Lee}
160