2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "contact-card.h"
22 #include <dali-toolkit/dali-toolkit.h>
25 #include "contact-card-layout-info.h"
26 #include "clipped-image.h"
29 using namespace Dali::Toolkit;
34 * The constants below are used to create the following Unfold Animation.
36 * 0ms 50 100 150 200 250 300 350 400 Total Animation time in Milliseconds
38 * o-----------------------------------o | X Position Animation ( 0ms To 360ms)
39 * | o-----------------------------------o Y Position Animation (40ms To 400ms)
40 * o-----------------------------------o | Width Animation ( 0ms To 360ms)
41 * | o-----------------------------------o Height Animation (40ms To 400ms)
42 * o-------o | | | | | | | Fade out Name Text Animation ( 0ms To 80ms)
43 * | o-------o | | | | | Fade in Details Text Animation (80ms To 160ms)
44 * o---------------o | | | | | Fade out other cards Animation ( 0ms To 160ms)
45 * o---------------------------------------o Mesh Morph Animation ( 0ms To 400ms)
47 const TimePeriod TIME_PERIOD_UNFOLD_X( 0.0f, 0.36f ); ///< Start at 0ms, duration 360ms
48 const TimePeriod TIME_PERIOD_UNFOLD_Y( 0.04f, 0.36f ); ///< Start at 40ms, duration 360ms
49 const TimePeriod TIME_PERIOD_UNFOLD_WIDTH( 0.0f, 0.36f ); ///< Start at 0ms, duration 360ms
50 const TimePeriod TIME_PERIOD_UNFOLD_HEIGHT( 0.04f, 0.36f ); ///< Start at 40ms, duration 360ms
51 const TimePeriod TIME_PERIOD_UNFOLD_NAME_OPACITY( 0.0f, 0.08f ); ///< Start at 0ms, duration 80ms
52 const TimePeriod TIME_PERIOD_UNFOLD_DETAIL_OPACITY( 0.08f, 0.08f ); ///< Start at 80ms, duration 80ms
53 const TimePeriod TIME_PERIOD_UNFOLD_SIBLING_OPACITY( 0.0f, 0.08f ); ///< Start at 0ms, duration 80ms
54 const TimePeriod TIME_PERIOD_UNFOLD_MESH_MORPH( 0.0f, 0.4f ); ///< Start at 0ms, duration 400ms
57 * The constants below are used to create the following Fold Animation:
59 * 0ms 50 100 150 200 250 300 350 400 Total Animation time in Milliseconds
61 * | |o---------------------------------o X Position Animation ( 64ms To 400ms)
62 * o---------------------------------o| | Y Position Animation ( 0ms To 336ms)
63 * | |o---------------------------------o Width Animation ( 64ms To 400ms)
64 * o---------------------------------o| | Height Animation ( 0ms To 336ms)
65 * | o-------o | | | | | Fade in Name Text animation ( 80ms To 160ms)
66 * o-------o | | | | | | | Fade out Details Text animation ( 0ms To 80ms)
67 * | | | | | | | o-------o Fade in other cards animation (320ms To 400ms)
68 * o---------------------------------------o Morph Animation ( 0ms To 400ms)
70 const TimePeriod TIME_PERIOD_FOLD_X( 0.064f, 0.336f ); ///< Start at 64ms, duration 336ms
71 const TimePeriod TIME_PERIOD_FOLD_Y( 0.0f, 0.336f ); ///< Start at 0ms, duration 336ms
72 const TimePeriod TIME_PERIOD_FOLD_WIDTH( 0.064f, 0.336f ); ///< Start at 64ms, duration 336ms
73 const TimePeriod TIME_PERIOD_FOLD_HEIGHT( 0.0f, 0.336f ); ///< Start at 0ms, duration 336ms
74 const TimePeriod TIME_PERIOD_FOLD_NAME_OPACITY( 0.08f, 0.08f ); ///< Start at 80ms, duration 80ms
75 const TimePeriod TIME_PERIOD_FOLD_DETAIL_OPACITY( 0.0f, 0.08f ); ///< Start at 0ms, duration 80ms
76 const TimePeriod TIME_PERIOD_FOLD_SIBLING_OPACITY( 0.32f, 0.08f ); ///< Start at 320ms, duration 80ms
77 const TimePeriod TIME_PERIOD_FOLD_MESH_MORPH( 0.0f, 0.4f ); ///< Start at 0ms, duration 400ms
79 AlphaFunction ALPHA_FUNCTION_UNFOLD( AlphaFunction::DEFAULT ); ///< Alpha function used for the Unfold Animation
80 AlphaFunction ALPHA_FUNCTION_FOLD( AlphaFunction::EASE_IN_OUT ); ///< Alpha function used for the Fold Animation
82 const Vector4 HEADER_COLOR( 231.0f/255.0f, 231.0f/255.0f, 231.0f/255.0f, 1.0f ); ///< The color of the header
84 } // unnamed namespace
86 ContactCard::ContactCard(
87 const ContactCardLayoutInfo& contactCardLayoutInfo,
88 const std::string& contactName,
89 const std::string& contactAddress,
90 const std::string& imagePath,
91 const Vector2& position )
98 mSlotDelegate( this ),
99 mContactCardLayoutInfo( contactCardLayoutInfo ),
100 foldedPosition( position ),
101 mClippedImagePropertyIndex( Property::INVALID_INDEX ),
104 // Create a control which will be used for the background and to clip the contents
105 mContactCard = Control::New();
106 mContactCard.SetProperty( Control::Property::BACKGROUND,
107 Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
108 .Add( ColorVisual::Property::MIX_COLOR, Color::WHITE ) );
109 mContactCard.SetProperty( Actor::Property::CLIPPING_MODE, ClippingMode::CLIP_CHILDREN );
110 mContactCard.SetParentOrigin( ParentOrigin::TOP_LEFT );
111 mContactCard.SetAnchorPoint( AnchorPoint::TOP_LEFT );
112 mContactCard.SetPosition( foldedPosition.x, foldedPosition.y );
113 mContactCard.SetSize( mContactCardLayoutInfo.foldedSize );
114 Stage::GetCurrent().Add( mContactCard );
116 // Create the header which will be shown only when the contact is unfolded
117 mHeader = Control::New();
118 mHeader.SetSize( mContactCardLayoutInfo.headerSize );
119 mHeader.SetProperty( Control::Property::BACKGROUND,
120 Property::Map().Add( Toolkit::Visual::Property::TYPE, Visual::COLOR )
121 .Add( ColorVisual::Property::MIX_COLOR, HEADER_COLOR ) );
122 mHeader.SetParentOrigin( ParentOrigin::TOP_LEFT );
123 mHeader.SetAnchorPoint( AnchorPoint::TOP_LEFT );
124 mHeader.SetPosition( mContactCardLayoutInfo.headerFoldedPosition.x, mContactCardLayoutInfo.headerFoldedPosition.y );
126 // Create a clipped image (whose clipping can be animated)
127 mClippedImage = ClippedImage::Create( imagePath, mClippedImagePropertyIndex );
128 mClippedImage.SetSize( mContactCardLayoutInfo.imageSize );
129 mClippedImage.SetParentOrigin( ParentOrigin::TOP_LEFT );
130 mClippedImage.SetAnchorPoint( AnchorPoint::TOP_LEFT );
131 mClippedImage.SetPosition( mContactCardLayoutInfo.imageFoldedPosition.x, mContactCardLayoutInfo.imageFoldedPosition.y );
132 mContactCard.Add( mClippedImage );
134 // Add the text label for just the name
135 mNameText = TextLabel::New( contactName );
136 mNameText.SetStyleName( "ContactNameTextLabel" );
137 mNameText.SetParentOrigin( ParentOrigin::TOP_LEFT );
138 mNameText.SetAnchorPoint( AnchorPoint::TOP_LEFT );
139 mNameText.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
140 mNameText.SetPosition( mContactCardLayoutInfo.textFoldedPosition.x, mContactCardLayoutInfo.textFoldedPosition.y );
141 mContactCard.Add( mNameText );
143 // Create the detail text-label
144 std::string detailString( contactName );
145 detailString += "\n\n";
146 detailString += contactAddress;
148 mDetailText = TextLabel::New( detailString );
149 mDetailText.SetStyleName( "ContactDetailTextLabel" );
150 mDetailText.SetParentOrigin( ParentOrigin::TOP_LEFT );
151 mDetailText.SetAnchorPoint( AnchorPoint::TOP_LEFT );
152 mDetailText.SetPosition( mContactCardLayoutInfo.textFoldedPosition.x, mContactCardLayoutInfo.textFoldedPosition.y );
153 mDetailText.SetSize( Vector2( mContactCardLayoutInfo.unfoldedSize.width - mContactCardLayoutInfo.textFoldedPosition.x * 2.0f, 0.0f ) );
154 mDetailText.SetOpacity( 0.0f );
156 // Attach tap detection to the overall clip control
157 mTapDetector = TapGestureDetector::New();
158 mTapDetector.Attach( mContactCard );
159 mTapDetector.DetectedSignal().Connect( mSlotDelegate, &ContactCard::OnTap );
162 ContactCard::~ContactCard()
166 mContactCard.Unparent();
170 void ContactCard::OnTap( Actor actor, const TapGesture& gesture )
174 mContactCard.Add( mHeader );
175 mContactCard.Add( mDetailText );
177 // Animate the size of the control (and clipping area)
178 Animation animation = Animation::New( 0.0f ); // Overall duration is unimportant as superseded by TimePeriods set later
179 animation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_X ), mContactCardLayoutInfo.unfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X );
180 animation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.unfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y );
181 animation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_WIDTH ), mContactCardLayoutInfo.unfoldedSize.width, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_WIDTH );
182 animation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_HEIGHT ), mContactCardLayoutInfo.unfoldedSize.height, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_HEIGHT );
184 // Animate the header area into position
185 animation.AnimateTo( Property( mHeader, Actor::Property::POSITION_X ), mContactCardLayoutInfo.headerUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X );
186 animation.AnimateTo( Property( mHeader, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.headerUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y );
188 // Animate the clipped image into the unfolded position and into a quad
189 animation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_X ), mContactCardLayoutInfo.imageUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X );
190 animation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.imageUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y );
191 animation.AnimateTo( Property( mClippedImage, mClippedImagePropertyIndex ), ClippedImage::QUAD_GEOMETRY, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_MESH_MORPH );
193 // Fade out the opacity of the name, and animate into the unfolded position
194 animation.AnimateTo( Property( mNameText, Actor::Property::COLOR_ALPHA ), 0.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_NAME_OPACITY );
195 animation.AnimateTo( Property( mNameText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X );
196 animation.AnimateTo( Property( mNameText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y );
198 // Fade in the opacity of the detail, and animate into the unfolded position
199 animation.AnimateTo( Property( mDetailText, Actor::Property::COLOR_ALPHA ), 1.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_DETAIL_OPACITY );
200 animation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textUnfoldedPosition.x, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_X );
201 animation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textUnfoldedPosition.y, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_Y );
203 // Fade out all the siblings
204 Actor parent = actor.GetParent();
205 for( size_t i = 0; i < parent.GetChildCount(); ++i )
207 Actor sibling = parent.GetChildAt( i );
208 if( sibling != actor )
210 animation.AnimateTo( Property( sibling, Actor::Property::COLOR_ALPHA ), 0.0f, ALPHA_FUNCTION_UNFOLD, TIME_PERIOD_UNFOLD_SIBLING_OPACITY );
211 sibling.SetSensitive( false );
215 animation.FinishedSignal().Connect( mSlotDelegate, &ContactCard::OnAnimationFinished );
220 mContactCard.Add( mNameText );
222 // Animate the size of the control (and clipping area)
223 Animation animation = Animation::New( 0.0f ); // Overall duration is unimportant as superseded by TimePeriods set later
224 animation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_X ), foldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X );
225 animation.AnimateTo( Property( mContactCard, Actor::Property::POSITION_Y ), foldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y );
226 animation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_WIDTH ), mContactCardLayoutInfo.foldedSize.width, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_WIDTH );
227 animation.AnimateTo( Property( mContactCard, Actor::Property::SIZE_HEIGHT ), mContactCardLayoutInfo.foldedSize.height, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_HEIGHT );
229 // Animate the header area out of position
230 animation.AnimateTo( Property( mHeader, Actor::Property::POSITION_X ), mContactCardLayoutInfo.headerFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X );
231 animation.AnimateTo( Property( mHeader, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.headerFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y );
233 // Animate the clipped image into the folded position and into a circle
234 animation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_X ), mContactCardLayoutInfo.imageFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X );
235 animation.AnimateTo( Property( mClippedImage, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.imageFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y );
236 animation.AnimateTo( Property( mClippedImage, mClippedImagePropertyIndex ), ClippedImage::CIRCLE_GEOMETRY, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_MESH_MORPH );
238 // Fade in the opacity of the name, and animate into the folded position
239 animation.AnimateTo( Property( mNameText, Actor::Property::COLOR_ALPHA ), 1.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_NAME_OPACITY );
240 animation.AnimateTo( Property( mNameText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X );
241 animation.AnimateTo( Property( mNameText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y );
243 // Fade out the opacity of the detail, and animate into the folded position
244 animation.AnimateTo( Property( mDetailText, Actor::Property::COLOR_ALPHA ), 0.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_DETAIL_OPACITY );
245 animation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_X ), mContactCardLayoutInfo.textFoldedPosition.x, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_X );
246 animation.AnimateTo( Property( mDetailText, Actor::Property::POSITION_Y ), mContactCardLayoutInfo.textFoldedPosition.y, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_Y );
248 // Slowly fade in all the siblings
249 Actor parent = actor.GetParent();
250 for( size_t i = 0; i < parent.GetChildCount(); ++i )
252 Actor sibling = parent.GetChildAt( i );
253 if( sibling != actor )
255 animation.AnimateTo( Property( sibling, Actor::Property::COLOR_ALPHA ), 1.0f, ALPHA_FUNCTION_FOLD, TIME_PERIOD_FOLD_SIBLING_OPACITY );
256 sibling.SetSensitive( true );
260 animation.FinishedSignal().Connect( mSlotDelegate, &ContactCard::OnAnimationFinished );
267 void ContactCard::OnAnimationFinished( Dali::Animation& animation )
272 mDetailText.Unparent();
276 mNameText.Unparent();