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