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/focus-manager/keyinput-focus-manager.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
28 #include "simple-visuals-application.h"
31 using namespace Dali::Toolkit;
41 const char* ICON_IMAGE( DEMO_IMAGE_DIR "application-icon-13.png" );
43 SimpleVisualsApplication::SimpleVisualsApplication( Application& application )
44 : mApplication( application ),
47 application.InitSignal().Connect( this, &SimpleVisualsApplication::Create );
50 Dali::Actor SimpleVisualsApplication::OnKeyboardPreFocusChange( Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction )
52 Actor nextFocusActor = proposed;
54 if( !current && !proposed )
56 // Set the initial focus to the first tile in the current page should be focused.
57 nextFocusActor = mMyControl;
61 if ( current == mMyControl )
63 nextFocusActor = mMyControl2;
67 nextFocusActor = mMyControl;
71 return nextFocusActor;
75 void SimpleVisualsApplication::OnKeyEvent( const KeyEvent& keyEvent )
77 static int keyPressed = 0;
79 if( keyEvent.state == KeyEvent::Down)
81 if( keyPressed == 0 ) // Is this the first down event?
83 printf("Key pressed: %s %d\n", keyEvent.keyPressedName.c_str(), keyEvent.keyCode );
85 if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
89 else if( keyEvent.keyPressedName.compare("Return") == 0 )
95 else if( keyEvent.state == KeyEvent::Up )
101 void SimpleVisualsApplication::Create( Application& application )
103 Stage stage = Stage::GetCurrent();
104 stage.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
106 // Connect to key events so can quit application
107 stage.KeyEventSignal().Connect(this, &SimpleVisualsApplication::OnKeyEvent);
109 // Hide the indicator bar
110 application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE );
112 // Create a table view to parent the 2 MyControls
113 TableView contentLayout = TableView::New( 2, 2 );
114 contentLayout.SetName("ContentLayout");
115 contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
116 contentLayout.SetResizePolicy( ResizePolicy::SIZE_RELATIVE_TO_PARENT, Dimension::HEIGHT );
117 contentLayout.SetSizeModeFactor( Vector3( 1.0f, .5f, 1.0f ) );
118 contentLayout.SetAnchorPoint( AnchorPoint::CENTER );
119 contentLayout.SetParentOrigin( ParentOrigin::CENTER );
120 contentLayout.SetCellPadding( Vector2( 50.0f, 15.0f ) );
121 contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
123 // Listen to focus change so can see Visual change from NORMAL to FOCUSED state
124 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &SimpleVisualsApplication::OnKeyboardPreFocusChange );
126 stage.Add( contentLayout );
128 // Create 2 MyControls and add to table view.
129 mMyControl = MyControl::New();
130 mMyControl.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
131 mMyControl.SetParentOrigin(ParentOrigin::TOP_LEFT);
133 mMyControl2 = MyControl::New();
134 mMyControl2.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
135 mMyControl2.SetParentOrigin(ParentOrigin::CENTER);
137 contentLayout.AddChild( mMyControl2, TableView::CellPosition(0, 0) );
138 contentLayout.AddChild( mMyControl, TableView::CellPosition(0, 1) );