Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 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; |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 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; |
Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 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 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 44 | ViewGroup container = findViewById(R.id.container); |
Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 45 | mSceneRoot = container; |
| 46 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 47 | mImageView = findViewById(R.id.contact_picture); |
Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 48 | mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER); |
| 49 | |
| 50 | Crossfade mCrossfade = new Crossfade(); |
Chet Haase | ff58f92 | 2013-09-11 13:08:18 -0700 | [diff] [blame] | 51 | mCrossfade.addTarget(R.id.contact_picture); |
Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 52 | |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 53 | TransitionSet group = new TransitionSet(); |
Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 54 | group.setDuration(1500); |
Chet Haase | d82c8ac | 2013-08-26 14:20:16 -0700 | [diff] [blame] | 55 | group.addTransition(mCrossfade).addTransition(new ChangeBounds()); |
Chet Haase | dc57d9d | 2013-07-10 11:27:54 -0700 | [diff] [blame] | 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 | } |