2 * Copyright (c) 2017 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.
18 #include "my-control.h"
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
23 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
24 #include <dali-toolkit/devel-api/focus-manager/keyinput-focus-manager.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
30 #include "simple-visuals-application.h"
33 using namespace Dali::Toolkit;
43 const char* ICON_IMAGE( DEMO_IMAGE_DIR "application-icon-13.png" );
45 SimpleVisualsApplication::SimpleVisualsApplication( Application& application )
46 : mApplication( application ),
49 application.InitSignal().Connect( this, &SimpleVisualsApplication::Create );
52 Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction )
54 Actor nextFocusActor = proposed;
56 if( !current && !proposed )
58 // Set the initial focus to the first tile in the current page should be focused.
59 nextFocusActor = mMyControl;
63 if ( current == mMyControl )
65 nextFocusActor = mMyControl2;
69 nextFocusActor = mMyControl;
73 return nextFocusActor;
77 void SimpleVisualsApplication::OnKeyEvent( const KeyEvent& keyEvent )
79 static int keyPressed = 0;
81 if( keyEvent.state == KeyEvent::Down)
83 if( keyPressed == 0 ) // Is this the first down event?
85 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
87 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
91 else if( keyEvent.keyPressedName.compare("Return") == 0 )
97 else if( keyEvent.state == KeyEvent::Up )
103 void SimpleVisualsApplication::Create( Application& application )
105 Stage stage = Stage::GetCurrent();
106 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
108 // Connect to key events so can quit application
109 stage.KeyEventSignal().Connect(this, &SimpleVisualsApplication::OnKeyEvent);
111 // Hide the indicator bar
112 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
114 // Create a table view to parent the 2 MyControls
115 TableView contentLayout = TableView::New( 2, 2 );
116 contentLayout.SetName("ContentLayout");
117 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
118 contentLayout.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
119 contentLayout.SetSizeModeFactor( Vector3( 1.0f, .5f, 1.0f ) );
120 contentLayout.SetAnchorPoint( AnchorPoint::CENTER );
121 contentLayout.SetParentOrigin( ParentOrigin::CENTER );
122 contentLayout.SetCellPadding( Vector2( 50.0f, 15.0f ) );
123 contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
125 // Listen to focus change so can see Visual change from NORMAL to FOCUSED state
126 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &SimpleVisualsApplication::OnKeyboardPreFocusChange );
128 stage.Add( contentLayout );
130 // Create 2 MyControls and add to table view.
131 mMyControl = MyControl::New();
132 mMyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
133 mMyControl.SetParentOrigin(ParentOrigin::TOP_LEFT);
135 mMyControl2 = MyControl::New();
136 mMyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
137 mMyControl2.SetParentOrigin(ParentOrigin::CENTER);
139 contentLayout.AddChild( mMyControl2, TableView::CellPosition(0, 0) );
140 contentLayout.AddChild( mMyControl, TableView::CellPosition(0, 1) );