blob: c7da6a3263a05e1582297c80ea0dd0380f1eeeb6 [file] [log] [blame]
Chet Haasefaebd8f2012-05-18 14:17:57 -07001/*
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 */
16package com.android.transitiontests;
17
18import android.app.Activity;
19import android.content.Context;
20import android.os.Bundle;
21import android.view.LayoutInflater;
22import android.view.View;
23import android.view.ViewGroup;
24import android.view.transition.Fade;
25import android.view.transition.Scene;
26import android.view.transition.Transition;
27import android.widget.ImageView;
28import android.widget.TextView;
29import android.view.transition.Crossfade;
30import android.view.transition.Move;
31import android.view.transition.Rotate;
32import android.view.transition.TransitionGroup;
33import android.view.transition.TransitionManager;
Chet Haasefaebd8f2012-05-18 14:17:57 -070034
35public class ContactsExpansion extends Activity {
36
37 String contactsData[] = {
38 "Alan Green", "56 Bob Street", "Boston, MA 02134", "617-555-5555", "blatt@blatt.com",
39 "Bob Foonman", "92 The Avenue", "Chico, CA 78456", "510-555-5556", "bob@jerk.com",
40 "Tracey Sue", "95 Houses Street", "San Jose, CA 96504", "415-555-5557", "ts@thing.com",
41 };
42
43 View currentItem = null;
44
45 TransitionGroup mMyAutoTransition = new TransitionGroup(TransitionGroup.SEQUENTIALLY);
46
47 @Override
48 protected void onCreate(Bundle savedInstanceState) {
49 super.onCreate(savedInstanceState);
50 setContentView(R.layout.contacts_list);
51 ViewGroup contactsContainer = (ViewGroup) findViewById(R.id.contactsContainer);
52
53 int contactsIndex = 0;
54 addContact(contactsContainer, contactsIndex, R.drawable.self_portrait_square_100);
55 contactsIndex += 5;
56 addContact(contactsContainer, contactsIndex, R.drawable.self_portrait_square_100);
57 contactsIndex += 5;
58 addContact(contactsContainer, contactsIndex, R.drawable.self_portrait_square_100);
59
60 }
61
62 private void addContact(ViewGroup container, int dataIndex, int thumbnailID) {
63 LayoutInflater inflater = (LayoutInflater)
64 getSystemService(Context.LAYOUT_INFLATER_SERVICE);
65 View contactItem = inflater.inflate(R.layout.contact_collapsed, container, false);
66 ImageView thumbnailView = (ImageView) contactItem.findViewById(R.id.contact_picture);
67 thumbnailView.setImageResource(thumbnailID);
68 ((TextView)contactItem.findViewById(R.id.contact_name)).setText(contactsData[dataIndex++]);
69 ((TextView)contactItem.findViewById(R.id.contact_street)).
70 setText(contactsData[dataIndex++]);
71 ((TextView)contactItem.findViewById(R.id.contact_city)).setText(contactsData[dataIndex++]);
72 ((TextView)contactItem.findViewById(R.id.contact_phone)).setText(contactsData[dataIndex++]);
73 ((TextView)contactItem.findViewById(R.id.contact_email)).setText(contactsData[dataIndex++]);
74 container.addView(contactItem);
75
76 final TransitionGroup myTransition = new TransitionGroup();
77 myTransition.addTransitions(new Fade(Fade.IN),
78 new Rotate().setTargetIds(R.id.contact_arrow),
79 new Move(), new Fade(Fade.OUT),
80 new Crossfade().setTargetIds(R.id.contact_picture));
81 final ToggleScene toggleScene = new ToggleScene(container, myTransition);
82 contactItem.setOnClickListener(new View.OnClickListener() {
83 @Override
84 public void onClick(View v) {
85 currentItem = v;
86 toggleScene.changeToScene();
87 }
88 });
89 }
90
91 class ToggleScene {
92 boolean expanded = false;
93 Scene mScene;
94 Transition mTransition;
95
96 ToggleScene(ViewGroup rootView, Transition transition) {
97 mScene = new Scene(rootView);
98 mTransition = transition;
99 mScene.setEnterAction(new Runnable() {
100 @Override
101 public void run() {
102 if (currentItem != null) {
103 System.out.println("onsceneChanged: currentItem = " + currentItem);
104 View expandedContainer = currentItem.findViewById(R.id.expanded_info);
105 expandedContainer.setVisibility(expanded ? View.GONE : View.VISIBLE);
106 ImageView thumbnailView =
107 (ImageView) currentItem.findViewById(R.id.contact_picture);
108 thumbnailView.setImageResource(expanded ? R.drawable.self_portrait_square_100 :
109 R.drawable.self_portrait_square_200);
110 ImageView arrow = (ImageView) currentItem.findViewById(R.id.contact_arrow);
111 arrow.setRotation(expanded ? 0 : 90);
112 expanded = !expanded;
113 }
114 }
115 });
116 }
117
118 void changeToScene() {
119 TransitionManager.go(mScene, mTransition);
120 }
121 };
122}