1 /* 2 * Copyright (C) 2016 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 package android.transition.cts; 17 18 import static org.mockito.Mockito.mock; 19 20 import android.app.Activity; 21 import android.content.Intent; 22 import android.os.Bundle; 23 import android.transition.Transition; 24 import android.transition.Transition.TransitionListener; 25 import android.transition.TransitionListenerAdapter; 26 import android.view.View; 27 28 import com.android.compatibility.common.util.transition.TrackingTransition; 29 import com.android.compatibility.common.util.transition.TrackingVisibility; 30 31 import java.util.concurrent.CountDownLatch; 32 33 public class TargetActivity extends Activity { 34 public static final String EXTRA_LAYOUT_ID = "layoutId"; 35 public static final String EXTRA_USE_ANIMATOR = "useAnimator"; 36 public static final String EXTRA_EXCLUDE_ID = "excludeId"; 37 38 public TrackingVisibility enterTransition = new TrackingVisibility(); 39 public TrackingVisibility returnTransition = new TrackingVisibility(); 40 final TrackingTransition sharedElementEnterTransition = new TrackingTransition(); 41 final TrackingTransition sharedElementReturnTransition = new TrackingTransition(); 42 43 final TransitionListener enterListener = mock(TransitionListener.class); 44 final TransitionListener returnListener = mock(TransitionListener.class); 45 46 public static TargetActivity sLastCreated; 47 48 public int startVisibility = -1; 49 public int endVisibility = -1; 50 public CountDownLatch transitionComplete; 51 52 @Override 53 public void onCreate(Bundle bundle){ 54 super.onCreate(bundle); 55 Intent intent = getIntent(); 56 int layoutId = R.layout.transition_main; 57 boolean useAnimator = false; 58 int excludeId = 0; 59 if (intent != null) { 60 layoutId = intent.getIntExtra(EXTRA_LAYOUT_ID, layoutId); 61 useAnimator = intent.getBooleanExtra(EXTRA_USE_ANIMATOR, false); 62 excludeId = intent.getIntExtra(EXTRA_EXCLUDE_ID, 0); 63 } 64 65 setContentView(layoutId); 66 67 if (useAnimator) { 68 enterTransition = new TrackingVisibilityWithAnimator(); 69 returnTransition = new TrackingVisibilityWithAnimator(); 70 } 71 72 if (excludeId != 0) { 73 enterTransition.excludeTarget(excludeId, true); 74 returnTransition.excludeTarget(excludeId, true); 75 76 final View excludedView = findViewById(excludeId); 77 transitionComplete = new CountDownLatch(1); 78 79 TransitionListener excludeVisibilityCheck = new TransitionListenerAdapter() { 80 @Override 81 public void onTransitionStart(Transition transition) { 82 startVisibility = excludedView.getVisibility(); 83 } 84 85 @Override 86 public void onTransitionEnd(Transition transition) { 87 endVisibility = excludedView.getVisibility(); 88 transitionComplete.countDown(); 89 } 90 }; 91 enterTransition.addListener(excludeVisibilityCheck); 92 returnTransition.addListener(excludeVisibilityCheck); 93 } 94 95 getWindow().setEnterTransition(enterTransition); 96 getWindow().setReturnTransition(returnTransition); 97 getWindow().setSharedElementEnterTransition(sharedElementEnterTransition); 98 getWindow().setSharedElementReturnTransition(sharedElementReturnTransition); 99 enterTransition.addListener(enterListener); 100 returnTransition.addListener(returnListener); 101 102 sLastCreated = this; 103 } 104 } 105