2 * Copyright (c) 2018 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.
20 #include <dali/public-api/adaptor-framework/application.h>
21 #include <dali/public-api/adaptor-framework/key.h>
22 #include <dali/public-api/common/stage.h>
23 #include <dali/public-api/events/key-event.h>
24 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
27 #include "contact-card-layouter.h"
28 #include "contact-data.h"
31 using namespace Dali::Toolkit;
35 const Vector4 STAGE_COLOR( 211.0f / 255.0f, 211.0f / 255.0f, 211.0f / 255.0f, 1.0f ); ///< The color of the stage
36 const char * const THEME_PATH( DEMO_STYLE_DIR "contact-cards-example-theme.json" ); ///< The theme used for this example
37 } // unnamed namespace
40 * @brief Creates several contact cards that animate between a folded and unfolded state.
42 * This demonstrates how different animations can start and stop at different times within the same Animation function.
43 * Additionally, this also shows how to morph between two different geometries.
45 * ContactCardLayouter: This class is used to lay out the different contact cards on the screen.
46 * This takes stage size into account but does not support relayouting.
47 * ContactCard: This class represents each contact card on the screen.
48 * Two animations are set up in this class which animate several properties with multiple start and stop times.
49 * An overview of the two animations can be found in contact-card.cpp.
50 * ContactCardLayoutInfo: This is a structure to store common layout information and is created by the ContactCardLayouter and used by each ContactCard.
51 * ContactData: This namespace contains a table which has the contact information we use to populate the contact cards.
52 * ClippedImage: This namespace provides a helper function which creates an ImageView which is added to a control that has clipping.
53 * This clipping comes in the form of a Circle or Quad.
54 * The Vertex shader mixes in the Circle and Quad geometry depending on the value of a uniform float.
55 * Animating this float between CIRCLE_GEOMETRY and QUAD_GEOMETRY is what enables the morphing between the two geometries.
56 * MaskedImage: This namespace provides a helper function which creates an ImageView with a mask that matches the Circle geometry provided by ClippedImage.
57 * Using a mask yields much better quality than when using an image with a circle geometry, so this is ONLY used when the contact card is folded.
59 class ContactCardController : public ConnectionTracker // Inherit from ConnectionTracker so that our signals can be automatically disconnected upon our destruction.
65 * @param[in] application A reference to the Application class.
67 ContactCardController( Application& application )
68 : mApplication( application )
70 // Connect to the Application's Init signal
71 mApplication.InitSignal().Connect( this, &ContactCardController::Create );
77 * @brief Called to initialise the application content
78 * @param[in] application A reference to the Application class.
80 void Create( Application& application )
82 // Hide the indicator bar
83 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
85 // Set the stage background color and connect to the stage's key signal to allow Back and Escape to exit.
86 Stage stage = Stage::GetCurrent();
87 stage.SetBackgroundColor( STAGE_COLOR );
88 stage.KeyEventSignal().Connect( this, &ContactCardController::OnKeyEvent );
90 // Add all the contacts to the layouter
91 for( size_t i = 0; i < ContactData::TABLE_SIZE; ++i )
93 mContactCardLayouter.AddContact( ContactData::TABLE[ i ].name, ContactData::TABLE[ i ].address, ContactData::TABLE[ i ].imagePath );
98 * @brief Called when any key event is received
100 * Will use this to quit the application if Back or the Escape key is received
101 * @param[in] event The key event information
103 void OnKeyEvent( const KeyEvent& event )
105 if( event.state == KeyEvent::Down )
107 KeyInputFocusManager keyInputFocusManager = KeyInputFocusManager::Get();
108 if( ! keyInputFocusManager.GetCurrentFocusControl() ) // Don't quit if a control has focus
110 if ( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
118 Application& mApplication; ///< Reference to the application class.
119 ContactCardLayouter mContactCardLayouter; ///< The contact card layouter.
122 int DALI_EXPORT_API main( int argc, char **argv )
124 Application application = Application::New( &argc, &argv, THEME_PATH );
125 ContactCardController contactCardController( application );
126 application.MainLoop();