blob: 86ecf8e5f9f274d8bfd50d62c3f3a9732b00d47d [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;
Chet Haased82c8ac2013-08-26 14:20:16 -070021import android.transition.ChangeBounds;
Chet Haasefaebd8f2012-05-18 14:17:57 -070022import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
Chet Haased82c8ac2013-08-26 14:20:16 -070025import android.transition.Fade;
26import android.transition.Scene;
27import android.transition.Transition;
28import android.transition.TransitionSet;
Chet Haasefaebd8f2012-05-18 14:17:57 -070029import android.widget.ImageView;
30import android.widget.TextView;
Chet Haased82c8ac2013-08-26 14:20:16 -070031import android.transition.Crossfade;
32import android.transition.Rotate;
33import android.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
Chet Haased82c8ac2013-08-26 14:20:16 -070045 TransitionSet mMyAutoTransition = new TransitionSet().
46 setOrdering(TransitionSet.ORDERING_SEQUENTIAL);
Chet Haasefaebd8f2012-05-18 14:17:57 -070047
48 @Override
49 protected void onCreate(Bundle savedInstanceState) {
50 super.onCreate(savedInstanceState);
51 setContentView(R.layout.contacts_list);
Alan Viverette51efddb2017-04-05 10:00:01 -040052 ViewGroup contactsContainer = findViewById(R.id.contactsContainer);
Chet Haasefaebd8f2012-05-18 14:17:57 -070053
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
Chet Haased82c8ac2013-08-26 14:20:16 -070077 final TransitionSet myTransition = new TransitionSet();
78 myTransition.addTransition(new Fade(Fade.IN)).
Chet Haaseff58f922013-09-11 13:08:18 -070079 addTransition(new Rotate().addTarget(R.id.contact_arrow)).
Chet Haased82c8ac2013-08-26 14:20:16 -070080 addTransition(new ChangeBounds()).
81 addTransition(new Fade(Fade.OUT)).
Chet Haaseff58f922013-09-11 13:08:18 -070082 addTransition(new Crossfade().addTarget(R.id.contact_picture));
Chet Haasefaebd8f2012-05-18 14:17:57 -070083 final ToggleScene toggleScene = new ToggleScene(container, myTransition);
84 contactItem.setOnClickListener(new View.OnClickListener() {
85 @Override
86 public void onClick(View v) {
87 currentItem = v;
88 toggleScene.changeToScene();
89 }
90 });
91 }
92
93 class ToggleScene {
94 boolean expanded = false;
95 Scene mScene;
96 Transition mTransition;
97
98 ToggleScene(ViewGroup rootView, Transition transition) {
99 mScene = new Scene(rootView);
100 mTransition = transition;
101 mScene.setEnterAction(new Runnable() {
102 @Override
103 public void run() {
104 if (currentItem != null) {
105 System.out.println("onsceneChanged: currentItem = " + currentItem);
106 View expandedContainer = currentItem.findViewById(R.id.expanded_info);
107 expandedContainer.setVisibility(expanded ? View.GONE : View.VISIBLE);
108 ImageView thumbnailView =
109 (ImageView) currentItem.findViewById(R.id.contact_picture);
110 thumbnailView.setImageResource(expanded ? R.drawable.self_portrait_square_100 :
111 R.drawable.self_portrait_square_200);
112 ImageView arrow = (ImageView) currentItem.findViewById(R.id.contact_arrow);
113 arrow.setRotation(expanded ? 0 : 90);
114 expanded = !expanded;
115 }
116 }
117 });
118 }
119
120 void changeToScene() {
121 TransitionManager.go(mScene, mTransition);
122 }
123 };
124}