1 /* 2 * Copyright (C) 2013 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 com.android.transitiontests; 17 18 import android.app.Activity; 19 import android.os.Bundle; 20 import android.view.View; 21 import android.view.ViewGroup; 22 import android.transition.Crossfade; 23 import android.transition.ChangeBounds; 24 import android.transition.Scene; 25 import android.transition.Transition; 26 import android.transition.TransitionSet; 27 import android.transition.TransitionManager; 28 import android.widget.ImageView; 29 30 public class CrossfadeImage extends Activity { 31 ViewGroup mSceneRoot; 32 static int mCurrentScene; 33 Scene mScene1, mScene2; 34 TransitionManager mTransitionManager; 35 boolean mExpanded = false; 36 Transition mTransition; 37 ImageView mImageView; 38 39 @Override 40 public void onCreate(Bundle savedInstanceState) { 41 super.onCreate(savedInstanceState); 42 setContentView(R.layout.crossfade_image); 43 44 ViewGroup container = (ViewGroup) findViewById(R.id.container); 45 mSceneRoot = container; 46 47 mImageView = (ImageView) findViewById(R.id.contact_picture); 48 mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 49 50 Crossfade mCrossfade = new Crossfade(); 51 mCrossfade.addTarget(R.id.contact_picture); 52 53 TransitionSet group = new TransitionSet(); 54 group.setDuration(1500); 55 group.addTransition(mCrossfade).addTransition(new ChangeBounds()); 56 mTransition = group; 57 } 58 59 public void sendMessage(View view) { 60 TransitionManager.beginDelayedTransition(mSceneRoot, mTransition); 61 if (mExpanded) { 62 mImageView.setImageResource(R.drawable.self_portrait_square_100); 63 } else { 64 mImageView.setImageResource(R.drawable.self_portrait_square_200); 65 } 66 mExpanded = !mExpanded; 67 } 68 } 69