1 /* 2 * Copyright (C) 2015 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.android.tv.onboarding; 18 19 import android.animation.Animator; 20 import android.animation.AnimatorInflater; 21 import android.animation.AnimatorListenerAdapter; 22 import android.animation.AnimatorSet; 23 import android.app.Activity; 24 import android.content.Context; 25 import android.os.Bundle; 26 import android.support.annotation.Nullable; 27 import android.support.v17.leanback.app.OnboardingFragment; 28 import android.view.Gravity; 29 import android.view.LayoutInflater; 30 import android.view.View; 31 import android.view.ViewGroup; 32 import android.widget.ImageView; 33 34 import com.android.tv.R; 35 import com.android.tv.common.ui.setup.SetupActionHelper; 36 import com.android.tv.common.ui.setup.animation.SetupAnimationHelper; 37 38 import java.util.ArrayList; 39 import java.util.List; 40 41 /** 42 * A fragment for the onboarding welcome screen. 43 */ 44 public class WelcomeFragment extends OnboardingFragment { 45 public static final String ACTION_CATEGORY = "comgoogle.android.tv.onboarding.WelcomeFragment"; 46 public static final int ACTION_NEXT = 1; 47 48 private static final long START_DELAY_CLOUD_MS = 33; 49 private static final long START_DELAY_TV_MS = 567; 50 private static final long START_DELAY_TV_CONTENTS_MS = 833; 51 private static final long START_DELAY_SHADOW_MS = 567; 52 53 private static final long VIDEO_FADE_OUT_DURATION_MS = 333; 54 55 private static final long BLUE_SCREEN_HOLD_DURATION_MS = 1500; 56 57 // TODO: Use animator list xml. 58 private static final int[] TV_FRAMES_1_START = { 59 R.drawable.tv_1a_01, 60 R.drawable.tv_1a_02, 61 R.drawable.tv_1a_03, 62 R.drawable.tv_1a_04, 63 R.drawable.tv_1a_05, 64 R.drawable.tv_1a_06, 65 R.drawable.tv_1a_07, 66 R.drawable.tv_1a_08, 67 R.drawable.tv_1a_09, 68 R.drawable.tv_1a_10, 69 R.drawable.tv_1a_11, 70 R.drawable.tv_1a_12, 71 R.drawable.tv_1a_13, 72 R.drawable.tv_1a_14, 73 R.drawable.tv_1a_15, 74 R.drawable.tv_1a_16, 75 R.drawable.tv_1a_17, 76 R.drawable.tv_1a_18, 77 R.drawable.tv_1a_19, 78 R.drawable.tv_1a_20 79 }; 80 81 private static final int[] TV_FRAMES_1_END = { 82 R.drawable.tv_1b_01, 83 R.drawable.tv_1b_02, 84 R.drawable.tv_1b_03, 85 R.drawable.tv_1b_04, 86 R.drawable.tv_1b_05, 87 R.drawable.tv_1b_06, 88 R.drawable.tv_1b_07, 89 R.drawable.tv_1b_08, 90 R.drawable.tv_1b_09, 91 R.drawable.tv_1b_10, 92 R.drawable.tv_1b_11 93 }; 94 95 private static final int[] TV_FRAMES_2_START = { 96 R.drawable.tv_5a_0, 97 R.drawable.tv_5a_1, 98 R.drawable.tv_5a_2, 99 R.drawable.tv_5a_3, 100 R.drawable.tv_5a_4, 101 R.drawable.tv_5a_5, 102 R.drawable.tv_5a_6, 103 R.drawable.tv_5a_7, 104 R.drawable.tv_5a_8, 105 R.drawable.tv_5a_9, 106 R.drawable.tv_5a_10, 107 R.drawable.tv_5a_11, 108 R.drawable.tv_5a_12, 109 R.drawable.tv_5a_13, 110 R.drawable.tv_5a_14, 111 R.drawable.tv_5a_15, 112 R.drawable.tv_5a_16, 113 R.drawable.tv_5a_17, 114 R.drawable.tv_5a_18, 115 R.drawable.tv_5a_19, 116 R.drawable.tv_5a_20, 117 R.drawable.tv_5a_21, 118 R.drawable.tv_5a_22, 119 R.drawable.tv_5a_23, 120 R.drawable.tv_5a_24, 121 R.drawable.tv_5a_25, 122 R.drawable.tv_5a_26, 123 R.drawable.tv_5a_27, 124 R.drawable.tv_5a_28, 125 R.drawable.tv_5a_29, 126 R.drawable.tv_5a_30, 127 R.drawable.tv_5a_31, 128 R.drawable.tv_5a_32, 129 R.drawable.tv_5a_33, 130 R.drawable.tv_5a_34, 131 R.drawable.tv_5a_35, 132 R.drawable.tv_5a_36, 133 R.drawable.tv_5a_37, 134 R.drawable.tv_5a_38, 135 R.drawable.tv_5a_39, 136 R.drawable.tv_5a_40, 137 R.drawable.tv_5a_41, 138 R.drawable.tv_5a_42, 139 R.drawable.tv_5a_43, 140 R.drawable.tv_5a_44, 141 R.drawable.tv_5a_45, 142 R.drawable.tv_5a_46, 143 R.drawable.tv_5a_47, 144 R.drawable.tv_5a_48, 145 R.drawable.tv_5a_49, 146 R.drawable.tv_5a_50, 147 R.drawable.tv_5a_51, 148 R.drawable.tv_5a_52, 149 R.drawable.tv_5a_53, 150 R.drawable.tv_5a_54, 151 R.drawable.tv_5a_55, 152 R.drawable.tv_5a_56, 153 R.drawable.tv_5a_57, 154 R.drawable.tv_5a_58, 155 R.drawable.tv_5a_59, 156 R.drawable.tv_5a_60, 157 R.drawable.tv_5a_61, 158 R.drawable.tv_5a_62, 159 R.drawable.tv_5a_63, 160 R.drawable.tv_5a_64, 161 R.drawable.tv_5a_65, 162 R.drawable.tv_5a_66, 163 R.drawable.tv_5a_67, 164 R.drawable.tv_5a_68, 165 R.drawable.tv_5a_69, 166 R.drawable.tv_5a_70, 167 R.drawable.tv_5a_71, 168 R.drawable.tv_5a_72, 169 R.drawable.tv_5a_73, 170 R.drawable.tv_5a_74, 171 R.drawable.tv_5a_75, 172 R.drawable.tv_5a_76, 173 R.drawable.tv_5a_77, 174 R.drawable.tv_5a_78, 175 R.drawable.tv_5a_79, 176 R.drawable.tv_5a_80, 177 R.drawable.tv_5a_81, 178 R.drawable.tv_5a_82, 179 R.drawable.tv_5a_83, 180 R.drawable.tv_5a_84, 181 R.drawable.tv_5a_85, 182 R.drawable.tv_5a_86, 183 R.drawable.tv_5a_87, 184 R.drawable.tv_5a_88, 185 R.drawable.tv_5a_89, 186 R.drawable.tv_5a_90, 187 R.drawable.tv_5a_91, 188 R.drawable.tv_5a_92, 189 R.drawable.tv_5a_93, 190 R.drawable.tv_5a_94, 191 R.drawable.tv_5a_95, 192 R.drawable.tv_5a_96, 193 R.drawable.tv_5a_97, 194 R.drawable.tv_5a_98, 195 R.drawable.tv_5a_99, 196 R.drawable.tv_5a_100, 197 R.drawable.tv_5a_101, 198 R.drawable.tv_5a_102, 199 R.drawable.tv_5a_103, 200 R.drawable.tv_5a_104, 201 R.drawable.tv_5a_105, 202 R.drawable.tv_5a_106, 203 R.drawable.tv_5a_107, 204 R.drawable.tv_5a_108, 205 R.drawable.tv_5a_109, 206 R.drawable.tv_5a_110, 207 R.drawable.tv_5a_111, 208 R.drawable.tv_5a_112, 209 R.drawable.tv_5a_113, 210 R.drawable.tv_5a_114, 211 R.drawable.tv_5a_115, 212 R.drawable.tv_5a_116, 213 R.drawable.tv_5a_117, 214 R.drawable.tv_5a_118, 215 R.drawable.tv_5a_119, 216 R.drawable.tv_5a_120, 217 R.drawable.tv_5a_121, 218 R.drawable.tv_5a_122, 219 R.drawable.tv_5a_123, 220 R.drawable.tv_5a_124, 221 R.drawable.tv_5a_125, 222 R.drawable.tv_5a_126, 223 R.drawable.tv_5a_127, 224 R.drawable.tv_5a_128, 225 R.drawable.tv_5a_129, 226 R.drawable.tv_5a_130, 227 R.drawable.tv_5a_131, 228 R.drawable.tv_5a_132, 229 R.drawable.tv_5a_133, 230 R.drawable.tv_5a_134, 231 R.drawable.tv_5a_135, 232 R.drawable.tv_5a_136, 233 R.drawable.tv_5a_137, 234 R.drawable.tv_5a_138, 235 R.drawable.tv_5a_139, 236 R.drawable.tv_5a_140, 237 R.drawable.tv_5a_141, 238 R.drawable.tv_5a_142, 239 R.drawable.tv_5a_143, 240 R.drawable.tv_5a_144, 241 R.drawable.tv_5a_145, 242 R.drawable.tv_5a_146, 243 R.drawable.tv_5a_147, 244 R.drawable.tv_5a_148, 245 R.drawable.tv_5a_149, 246 R.drawable.tv_5a_150, 247 R.drawable.tv_5a_151, 248 R.drawable.tv_5a_152, 249 R.drawable.tv_5a_153, 250 R.drawable.tv_5a_154, 251 R.drawable.tv_5a_155, 252 R.drawable.tv_5a_156, 253 R.drawable.tv_5a_157, 254 R.drawable.tv_5a_158, 255 R.drawable.tv_5a_159, 256 R.drawable.tv_5a_160, 257 R.drawable.tv_5a_161, 258 R.drawable.tv_5a_162, 259 R.drawable.tv_5a_163, 260 R.drawable.tv_5a_164, 261 R.drawable.tv_5a_165, 262 R.drawable.tv_5a_166, 263 R.drawable.tv_5a_167, 264 R.drawable.tv_5a_168, 265 R.drawable.tv_5a_169, 266 R.drawable.tv_5a_170, 267 R.drawable.tv_5a_171, 268 R.drawable.tv_5a_172, 269 R.drawable.tv_5a_173, 270 R.drawable.tv_5a_174, 271 R.drawable.tv_5a_175, 272 R.drawable.tv_5a_176, 273 R.drawable.tv_5a_177, 274 R.drawable.tv_5a_178, 275 R.drawable.tv_5a_179, 276 R.drawable.tv_5a_180, 277 R.drawable.tv_5a_181, 278 R.drawable.tv_5a_182, 279 R.drawable.tv_5a_183, 280 R.drawable.tv_5a_184, 281 R.drawable.tv_5a_185, 282 R.drawable.tv_5a_186, 283 R.drawable.tv_5a_187, 284 R.drawable.tv_5a_188, 285 R.drawable.tv_5a_189, 286 R.drawable.tv_5a_190, 287 R.drawable.tv_5a_191, 288 R.drawable.tv_5a_192, 289 R.drawable.tv_5a_193, 290 R.drawable.tv_5a_194, 291 R.drawable.tv_5a_195, 292 R.drawable.tv_5a_196, 293 R.drawable.tv_5a_197, 294 R.drawable.tv_5a_198, 295 R.drawable.tv_5a_199, 296 R.drawable.tv_5a_200, 297 R.drawable.tv_5a_201, 298 R.drawable.tv_5a_202, 299 R.drawable.tv_5a_203, 300 R.drawable.tv_5a_204, 301 R.drawable.tv_5a_205, 302 R.drawable.tv_5a_206, 303 R.drawable.tv_5a_207, 304 R.drawable.tv_5a_208, 305 R.drawable.tv_5a_209, 306 R.drawable.tv_5a_210, 307 R.drawable.tv_5a_211, 308 R.drawable.tv_5a_212, 309 R.drawable.tv_5a_213, 310 R.drawable.tv_5a_214, 311 R.drawable.tv_5a_215, 312 R.drawable.tv_5a_216, 313 R.drawable.tv_5a_217, 314 R.drawable.tv_5a_218, 315 R.drawable.tv_5a_219, 316 R.drawable.tv_5a_220, 317 R.drawable.tv_5a_221, 318 R.drawable.tv_5a_222, 319 R.drawable.tv_5a_223, 320 R.drawable.tv_5a_224 321 }; 322 323 private static final int[] TV_FRAMES_3_BLUE_ARROW = { 324 R.drawable.arrow_blue_00, 325 R.drawable.arrow_blue_01, 326 R.drawable.arrow_blue_02, 327 R.drawable.arrow_blue_03, 328 R.drawable.arrow_blue_04, 329 R.drawable.arrow_blue_05, 330 R.drawable.arrow_blue_06, 331 R.drawable.arrow_blue_07, 332 R.drawable.arrow_blue_08, 333 R.drawable.arrow_blue_09, 334 R.drawable.arrow_blue_10, 335 R.drawable.arrow_blue_11, 336 R.drawable.arrow_blue_12, 337 R.drawable.arrow_blue_13, 338 R.drawable.arrow_blue_14, 339 R.drawable.arrow_blue_15, 340 R.drawable.arrow_blue_16, 341 R.drawable.arrow_blue_17, 342 R.drawable.arrow_blue_18, 343 R.drawable.arrow_blue_19, 344 R.drawable.arrow_blue_20, 345 R.drawable.arrow_blue_21, 346 R.drawable.arrow_blue_22, 347 R.drawable.arrow_blue_23, 348 R.drawable.arrow_blue_24, 349 R.drawable.arrow_blue_25, 350 R.drawable.arrow_blue_26, 351 R.drawable.arrow_blue_27, 352 R.drawable.arrow_blue_28, 353 R.drawable.arrow_blue_29, 354 R.drawable.arrow_blue_30, 355 R.drawable.arrow_blue_31, 356 R.drawable.arrow_blue_32, 357 R.drawable.arrow_blue_33, 358 R.drawable.arrow_blue_34, 359 R.drawable.arrow_blue_35, 360 R.drawable.arrow_blue_36, 361 R.drawable.arrow_blue_37, 362 R.drawable.arrow_blue_38, 363 R.drawable.arrow_blue_39, 364 R.drawable.arrow_blue_40, 365 R.drawable.arrow_blue_41, 366 R.drawable.arrow_blue_42, 367 R.drawable.arrow_blue_43, 368 R.drawable.arrow_blue_44, 369 R.drawable.arrow_blue_45, 370 R.drawable.arrow_blue_46, 371 R.drawable.arrow_blue_47, 372 R.drawable.arrow_blue_48, 373 R.drawable.arrow_blue_49, 374 R.drawable.arrow_blue_50, 375 R.drawable.arrow_blue_51, 376 R.drawable.arrow_blue_52, 377 R.drawable.arrow_blue_53, 378 R.drawable.arrow_blue_54, 379 R.drawable.arrow_blue_55, 380 R.drawable.arrow_blue_56, 381 R.drawable.arrow_blue_57, 382 R.drawable.arrow_blue_58, 383 R.drawable.arrow_blue_59, 384 R.drawable.arrow_blue_60 385 }; 386 387 private static final int[] TV_FRAMES_3_BLUE_START = { 388 R.drawable.tv_2a_01, 389 R.drawable.tv_2a_02, 390 R.drawable.tv_2a_03, 391 R.drawable.tv_2a_04, 392 R.drawable.tv_2a_05, 393 R.drawable.tv_2a_06, 394 R.drawable.tv_2a_07, 395 R.drawable.tv_2a_08, 396 R.drawable.tv_2a_09, 397 R.drawable.tv_2a_10, 398 R.drawable.tv_2a_11, 399 R.drawable.tv_2a_12, 400 R.drawable.tv_2a_13, 401 R.drawable.tv_2a_14, 402 R.drawable.tv_2a_15, 403 R.drawable.tv_2a_16, 404 R.drawable.tv_2a_17, 405 R.drawable.tv_2a_18, 406 R.drawable.tv_2a_19 407 }; 408 409 private static final int[] TV_FRAMES_3_BLUE_END = { 410 R.drawable.tv_2b_01, 411 R.drawable.tv_2b_02, 412 R.drawable.tv_2b_03, 413 R.drawable.tv_2b_04, 414 R.drawable.tv_2b_05, 415 R.drawable.tv_2b_06, 416 R.drawable.tv_2b_07, 417 R.drawable.tv_2b_08, 418 R.drawable.tv_2b_09, 419 R.drawable.tv_2b_10, 420 R.drawable.tv_2b_11, 421 R.drawable.tv_2b_12, 422 R.drawable.tv_2b_13, 423 R.drawable.tv_2b_14, 424 R.drawable.tv_2b_15, 425 R.drawable.tv_2b_16, 426 R.drawable.tv_2b_17, 427 R.drawable.tv_2b_18, 428 R.drawable.tv_2b_19 429 }; 430 431 private static final int[] TV_FRAMES_3_ORANGE_ARROW = { 432 R.drawable.arrow_orange_180, 433 R.drawable.arrow_orange_181, 434 R.drawable.arrow_orange_182, 435 R.drawable.arrow_orange_183, 436 R.drawable.arrow_orange_184, 437 R.drawable.arrow_orange_185, 438 R.drawable.arrow_orange_186, 439 R.drawable.arrow_orange_187, 440 R.drawable.arrow_orange_188, 441 R.drawable.arrow_orange_189, 442 R.drawable.arrow_orange_190, 443 R.drawable.arrow_orange_191, 444 R.drawable.arrow_orange_192, 445 R.drawable.arrow_orange_193, 446 R.drawable.arrow_orange_194, 447 R.drawable.arrow_orange_195, 448 R.drawable.arrow_orange_196, 449 R.drawable.arrow_orange_197, 450 R.drawable.arrow_orange_198, 451 R.drawable.arrow_orange_199, 452 R.drawable.arrow_orange_200, 453 R.drawable.arrow_orange_201, 454 R.drawable.arrow_orange_202, 455 R.drawable.arrow_orange_203, 456 R.drawable.arrow_orange_204, 457 R.drawable.arrow_orange_205, 458 R.drawable.arrow_orange_206, 459 R.drawable.arrow_orange_207, 460 R.drawable.arrow_orange_208, 461 R.drawable.arrow_orange_209, 462 R.drawable.arrow_orange_210, 463 R.drawable.arrow_orange_211, 464 R.drawable.arrow_orange_212, 465 R.drawable.arrow_orange_213, 466 R.drawable.arrow_orange_214, 467 R.drawable.arrow_orange_215, 468 R.drawable.arrow_orange_216, 469 R.drawable.arrow_orange_217, 470 R.drawable.arrow_orange_218, 471 R.drawable.arrow_orange_219, 472 R.drawable.arrow_orange_220, 473 R.drawable.arrow_orange_221, 474 R.drawable.arrow_orange_222, 475 R.drawable.arrow_orange_223, 476 R.drawable.arrow_orange_224, 477 R.drawable.arrow_orange_225, 478 R.drawable.arrow_orange_226, 479 R.drawable.arrow_orange_227, 480 R.drawable.arrow_orange_228, 481 R.drawable.arrow_orange_229, 482 R.drawable.arrow_orange_230, 483 R.drawable.arrow_orange_231, 484 R.drawable.arrow_orange_232, 485 R.drawable.arrow_orange_233, 486 R.drawable.arrow_orange_234, 487 R.drawable.arrow_orange_235, 488 R.drawable.arrow_orange_236, 489 R.drawable.arrow_orange_237, 490 R.drawable.arrow_orange_238, 491 R.drawable.arrow_orange_239, 492 R.drawable.arrow_orange_240 493 }; 494 495 private static final int[] TV_FRAMES_3_ORANGE_START = { 496 R.drawable.tv_2c_01, 497 R.drawable.tv_2c_02, 498 R.drawable.tv_2c_03, 499 R.drawable.tv_2c_04, 500 R.drawable.tv_2c_05, 501 R.drawable.tv_2c_06, 502 R.drawable.tv_2c_07, 503 R.drawable.tv_2c_08, 504 R.drawable.tv_2c_09, 505 R.drawable.tv_2c_10, 506 R.drawable.tv_2c_11, 507 R.drawable.tv_2c_12, 508 R.drawable.tv_2c_13, 509 R.drawable.tv_2c_14, 510 R.drawable.tv_2c_15, 511 R.drawable.tv_2c_16 512 }; 513 514 private static final int[] TV_FRAMES_4_START = { 515 R.drawable.tv_3a_01, 516 R.drawable.tv_3a_02, 517 R.drawable.tv_3a_03, 518 R.drawable.tv_3a_04, 519 R.drawable.tv_3a_05, 520 R.drawable.tv_3a_06, 521 R.drawable.tv_3a_07, 522 R.drawable.tv_3a_08, 523 R.drawable.tv_3a_09, 524 R.drawable.tv_3a_10, 525 R.drawable.tv_3a_11, 526 R.drawable.tv_3a_12, 527 R.drawable.tv_3a_13, 528 R.drawable.tv_3a_14, 529 R.drawable.tv_3a_15, 530 R.drawable.tv_3a_16, 531 R.drawable.tv_3a_17, 532 R.drawable.tv_3b_75, 533 R.drawable.tv_3b_76, 534 R.drawable.tv_3b_77, 535 R.drawable.tv_3b_78, 536 R.drawable.tv_3b_79, 537 R.drawable.tv_3b_80, 538 R.drawable.tv_3b_81, 539 R.drawable.tv_3b_82, 540 R.drawable.tv_3b_83, 541 R.drawable.tv_3b_84, 542 R.drawable.tv_3b_85, 543 R.drawable.tv_3b_86, 544 R.drawable.tv_3b_87, 545 R.drawable.tv_3b_88, 546 R.drawable.tv_3b_89, 547 R.drawable.tv_3b_90, 548 R.drawable.tv_3b_91, 549 R.drawable.tv_3b_92, 550 R.drawable.tv_3b_93, 551 R.drawable.tv_3b_94, 552 R.drawable.tv_3b_95, 553 R.drawable.tv_3b_96, 554 R.drawable.tv_3b_97, 555 R.drawable.tv_3b_98, 556 R.drawable.tv_3b_99, 557 R.drawable.tv_3b_100, 558 R.drawable.tv_3b_101, 559 R.drawable.tv_3b_102, 560 R.drawable.tv_3b_103, 561 R.drawable.tv_3b_104, 562 R.drawable.tv_3b_105, 563 R.drawable.tv_3b_106, 564 R.drawable.tv_3b_107, 565 R.drawable.tv_3b_108, 566 R.drawable.tv_3b_109, 567 R.drawable.tv_3b_110, 568 R.drawable.tv_3b_111, 569 R.drawable.tv_3b_112, 570 R.drawable.tv_3b_113, 571 R.drawable.tv_3b_114, 572 R.drawable.tv_3b_115, 573 R.drawable.tv_3b_116, 574 R.drawable.tv_3b_117, 575 R.drawable.tv_3b_118 576 }; 577 578 private String[] mPageTitles; 579 private String[] mPageDescriptions; 580 581 private ImageView mTvContentView; 582 private ImageView mArrowView; 583 584 private Animator mAnimator; 585 586 public WelcomeFragment() { 587 setExitTransition(new SetupAnimationHelper.TransitionBuilder() 588 .setSlideEdge(Gravity.START) 589 .setParentIdsForDelay(new int[]{R.id.onboarding_fragment_root}) 590 .build()); 591 } 592 593 @Override 594 public void onAttach(Context context) { 595 super.onAttach(context); 596 initialize(); 597 } 598 599 private void initialize() { 600 if (mPageTitles == null) { 601 mPageTitles = getResources().getStringArray(R.array.welcome_page_titles); 602 mPageDescriptions = getResources().getStringArray(R.array.welcome_page_descriptions); 603 } 604 } 605 606 @Nullable 607 @Override 608 public View onCreateView(LayoutInflater inflater, ViewGroup container, 609 Bundle savedInstanceState) { 610 View view = super.onCreateView(inflater, container, savedInstanceState); 611 setLogoResourceId(R.drawable.splash_logo); 612 if (savedInstanceState != null) { 613 switch (getCurrentPageIndex()) { 614 case 0: 615 mTvContentView.setImageResource( 616 TV_FRAMES_1_START[TV_FRAMES_1_START.length - 1]); 617 break; 618 case 1: 619 mTvContentView.setImageResource( 620 TV_FRAMES_2_START[TV_FRAMES_2_START.length - 1]); 621 break; 622 case 2: 623 mTvContentView.setImageResource( 624 TV_FRAMES_3_ORANGE_START[TV_FRAMES_3_ORANGE_START.length - 1]); 625 mArrowView.setImageResource(TV_FRAMES_3_BLUE_ARROW[0]); 626 break; 627 case 3: 628 default: 629 mTvContentView.setImageResource( 630 TV_FRAMES_4_START[TV_FRAMES_4_START.length - 1]); 631 break; 632 } 633 } 634 return view; 635 } 636 637 @Override 638 public int onProvideTheme() { 639 return R.style.Theme_Leanback_Onboarding; 640 } 641 642 @Override 643 protected Animator onCreateEnterAnimation() { 644 List<Animator> animators = new ArrayList<>(); 645 // Cloud 1 646 View view = getActivity().findViewById(R.id.cloud1); 647 view.setAlpha(0); 648 Animator animator = AnimatorInflater.loadAnimator(getActivity(), 649 R.animator.onboarding_welcome_cloud_enter); 650 animator.setStartDelay(START_DELAY_CLOUD_MS); 651 animator.setTarget(view); 652 animators.add(animator); 653 // Cloud 2 654 view = getActivity().findViewById(R.id.cloud2); 655 view.setAlpha(0); 656 animator = AnimatorInflater.loadAnimator(getActivity(), 657 R.animator.onboarding_welcome_cloud_enter); 658 animator.setStartDelay(START_DELAY_CLOUD_MS); 659 animator.setTarget(view); 660 animators.add(animator); 661 // TV container 662 view = getActivity().findViewById(R.id.tv_container); 663 view.setAlpha(0); 664 animator = AnimatorInflater.loadAnimator(getActivity(), 665 R.animator.onboarding_welcome_tv_enter); 666 animator.setStartDelay(START_DELAY_TV_MS); 667 animator.setTarget(view); 668 animators.add(animator); 669 // TV content 670 view = getActivity().findViewById(R.id.tv_content); 671 animator = SetupAnimationHelper.createFrameAnimator((ImageView) view, TV_FRAMES_1_START); 672 animator.setStartDelay(START_DELAY_TV_CONTENTS_MS); 673 animator.setTarget(view); 674 animators.add(animator); 675 // Shadow 676 view = getActivity().findViewById(R.id.shadow); 677 view.setAlpha(0); 678 animator = AnimatorInflater.loadAnimator(getActivity(), 679 R.animator.onboarding_welcome_shadow_enter); 680 animator.setStartDelay(START_DELAY_SHADOW_MS); 681 animator.setTarget(view); 682 animators.add(animator); 683 AnimatorSet set = new AnimatorSet(); 684 set.playTogether(animators); 685 return set; 686 } 687 688 @Nullable 689 @Override 690 protected View onCreateBackgroundView(LayoutInflater inflater, ViewGroup container) { 691 return inflater.inflate(R.layout.onboarding_welcome_background, container, false); 692 } 693 694 @Nullable 695 @Override 696 protected View onCreateContentView(LayoutInflater inflater, ViewGroup container) { 697 View view = inflater.inflate(R.layout.onboarding_welcome_content, container, false); 698 mTvContentView = (ImageView) view.findViewById(R.id.tv_content); 699 return view; 700 } 701 702 @Nullable 703 @Override 704 protected View onCreateForegroundView(LayoutInflater inflater, ViewGroup container) { 705 mArrowView = (ImageView) inflater.inflate(R.layout.onboarding_welcome_foreground, container, 706 false); 707 return mArrowView; 708 } 709 710 @Override 711 protected int getPageCount() { 712 return mPageTitles.length; 713 } 714 715 @Override 716 protected String getPageTitle(int pageIndex) { 717 return mPageTitles[pageIndex]; 718 } 719 720 @Override 721 protected String getPageDescription(int pageIndex) { 722 return mPageDescriptions[pageIndex]; 723 } 724 725 @Override 726 protected void onFinishFragment() { 727 SetupActionHelper.onActionClick(WelcomeFragment.this, ACTION_CATEGORY, ACTION_NEXT); 728 } 729 730 @Override 731 protected void onPageChanged(int newPage, int previousPage) { 732 if (mAnimator != null) { 733 mAnimator.cancel(); 734 } 735 mArrowView.setVisibility(View.GONE); 736 // TV screen hiding animator. 737 Animator hideAnimator = previousPage == 0 738 ? SetupAnimationHelper.createFrameAnimator(mTvContentView, TV_FRAMES_1_END) 739 : SetupAnimationHelper.createFadeOutAnimator(mTvContentView, 740 VIDEO_FADE_OUT_DURATION_MS, true); 741 // TV screen showing animator. 742 AnimatorSet animatorSet = new AnimatorSet(); 743 int firstFrame; 744 switch (newPage) { 745 case 0: 746 animatorSet.playSequentially(hideAnimator, 747 SetupAnimationHelper.createFrameAnimator(mTvContentView, 748 TV_FRAMES_1_START)); 749 firstFrame = TV_FRAMES_1_START[0]; 750 break; 751 case 1: 752 animatorSet.playSequentially(hideAnimator, 753 SetupAnimationHelper.createFrameAnimator(mTvContentView, 754 TV_FRAMES_2_START)); 755 firstFrame = TV_FRAMES_2_START[0]; 756 break; 757 case 2: 758 mArrowView.setVisibility(View.VISIBLE); 759 animatorSet.playSequentially(hideAnimator, 760 SetupAnimationHelper.createFrameAnimator(mArrowView, 761 TV_FRAMES_3_BLUE_ARROW), 762 SetupAnimationHelper.createFrameAnimator(mTvContentView, 763 TV_FRAMES_3_BLUE_START), 764 SetupAnimationHelper.createFrameAnimatorWithDelay(mTvContentView, 765 TV_FRAMES_3_BLUE_END, BLUE_SCREEN_HOLD_DURATION_MS), 766 SetupAnimationHelper.createFrameAnimator(mArrowView, 767 TV_FRAMES_3_ORANGE_ARROW), 768 SetupAnimationHelper.createFrameAnimator(mTvContentView, 769 TV_FRAMES_3_ORANGE_START)); 770 animatorSet.addListener(new AnimatorListenerAdapter() { 771 @Override 772 public void onAnimationEnd(Animator animation) { 773 mArrowView.setImageResource(TV_FRAMES_3_BLUE_ARROW[0]); 774 } 775 }); 776 firstFrame = TV_FRAMES_3_BLUE_START[0]; 777 break; 778 case 3: 779 default: 780 animatorSet.playSequentially(hideAnimator, 781 SetupAnimationHelper.createFrameAnimator(mTvContentView, 782 TV_FRAMES_4_START)); 783 firstFrame = TV_FRAMES_4_START[0]; 784 break; 785 } 786 final int firstImageResource = firstFrame; 787 hideAnimator.addListener(new AnimatorListenerAdapter() { 788 @Override 789 public void onAnimationEnd(Animator animation) { 790 // Shows the first frame of show animation when the hide animator is canceled. 791 mTvContentView.setImageResource(firstImageResource); 792 } 793 }); 794 mAnimator = SetupAnimationHelper.applyAnimationTimeScale(animatorSet); 795 mAnimator.start(); 796 } 797 } 798