ae01d9742ef5584b5d7d4d90662a3d97cd3bcc21
[platform/core/uifw/dali-demo.git] / examples / remote-image-loading / remote-image-loading-example.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
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  *
16  */
17
18
19 #include <shared/utility.h>
20 #include <stdlib.h>
21 #include <iostream>
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali/devel-api/actors/actor-devel.h>
25
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30 // This example shows the load-time image scaling and filtering features.
31 //
32 class MyTester : public ConnectionTracker
33 {
34 public:
35   MyTester(Application &application) : mApplication(application)
36   {
37     // Connect to the Application's Init signal
38     mApplication.InitSignal().Connect(this, &MyTester::Create);
39   }
40
41   ~MyTester()
42   {
43     // Nothing to do here;
44   }
45
46   void ConnectEventSignal(Control control)
47   {
48     control.TouchSignal().Connect(this, &MyTester::OnControlTouch);
49
50     control.SetProperty( Actor::Property::KEYBOARD_FOCUSABLE,true);
51     control.KeyEventSignal().Connect(this, &MyTester::OnControlKeyEvent);
52     control.KeyInputFocusGainedSignal().Connect(this, &MyTester::OnFocusSet);
53     control.KeyInputFocusLostSignal().Connect(this, &MyTester::OnFocusUnSet);
54   }
55
56   // The Init signal is received once (only) during the Application lifetime
57   void Create(Application &application)
58   {
59     mWindow = application.GetWindow();
60     mWindow.SetBackgroundColor(Color::BLACK);
61     mWindow.KeyEventSignal().Connect(this, &MyTester::OnKey);
62     mWindow.TouchSignal().Connect(this, &MyTester::OnTouch);
63
64     TextLabel rubric = TextLabel::New( "You will need a working internet connection to see the images below");
65     rubric.SetProperty( TextLabel::Property::MULTI_LINE, true );
66     rubric.SetProperty( TextLabel::Property::TEXT_COLOR, Color::WHITE );
67     rubric.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
68     rubric.SetResizePolicy( ResizePolicy::DIMENSION_DEPENDENCY, Dimension::HEIGHT );
69     rubric.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
70     rubric.SetProperty( Actor::Property::ANCHOR_POINT, ParentOrigin::TOP_CENTER );
71     mWindow.Add( rubric );
72
73     mImageView1 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/293/259/19/520_000000000000293259191500x1500_72dpi_RGB_q70.jpg");
74
75     mImageView1.SetProperty( Dali::Actor::Property::NAME,"mImageView1");
76     mImageView1.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
77     mImageView1.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
78     mImageView1.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
79     mImageView1.SetProperty( Actor::Property::POSITION, Vector2(0, 100));
80     mImageView1.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
81     mWindow.Add(mImageView1);
82
83     mImageView2 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/651/88/520_000000000000212651881500x1500_72dpi_RGB_q70.jpg");
84     mImageView2.SetProperty( Dali::Actor::Property::NAME,"mImageView2");
85     mImageView2.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
86     mImageView2.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
87     mImageView2.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
88     mImageView2.SetProperty( Actor::Property::POSITION, Vector2(400, 100));
89     mImageView2.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
90     mWindow.Add(mImageView2);
91
92     mImageView3 = Toolkit::ImageView::New("http://static.midomi.com/s/s/images/000/000/000/000/212/353/21/520_000000000000212353211500x1500_72dpi_RGB_q70.jpg");
93     mImageView3.SetProperty( Dali::Actor::Property::NAME,"mImageView3");
94     mImageView3.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
95     mImageView3.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
96     mImageView3.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
97     mImageView3.SetProperty( Actor::Property::POSITION, Vector2(0, 400));
98     mImageView3.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
99     mWindow.Add(mImageView3);
100
101     mImageView4 = Toolkit::ImageView::New("http://d2k43l0oslhof9.cloudfront.net/platform/image/contents/vc/20/01/58/20170629100630071189_0bf6b911-a847-cba4-e518-be40fe2f579420170629192203240.jpg");
102     mImageView4.SetProperty( Dali::Actor::Property::NAME,"mImageView4");
103     mImageView4.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
104     mImageView4.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
105     mImageView4.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
106     mImageView4.SetProperty( Actor::Property::POSITION, Vector2(400, 400));
107     mImageView4.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
108     mWindow.Add(mImageView4);
109
110     mImageView5 = Toolkit::ImageView::New("http://static.midomi.com/h/images/w/weather_sunny.png");
111     mImageView5.SetProperty( Dali::Actor::Property::NAME,"mImageView5");
112     mImageView4.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
113     mImageView5.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
114     mImageView5.SetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT, false);
115     mImageView5.SetProperty( Actor::Property::POSITION, Vector2(800, 100));
116     mImageView5.SetBackgroundColor(Vector4(0.0f, 0.0f, 0.0f, 0.0f));
117     mWindow.Add(mImageView5);
118
119     // Tie-in input event handlers:
120     mWindow.KeyEventSignal().Connect( this, &MyTester::OnKeyEvent );
121   }
122
123   void OnAnimationEnd(Animation &source)
124   {
125     std::cout<<"OnAnimationEnd" << std::endl;
126   }
127
128   void OnKeyEvent(const KeyEvent& event)
129   {
130     if( event.GetState() == KeyEvent::DOWN )
131     {
132       if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
133       {
134         mApplication.Quit();
135       }
136     }
137   }
138
139   void OnKey(const KeyEvent &event)
140   {
141     if (event.GetState() == KeyEvent::DOWN)
142     {
143       std::cout<<"Window key : " << event.GetKeyCode() << std::endl;
144     }
145   }
146
147   void OnTouch(const TouchEvent &touch)
148   {
149     if (touch.GetState(0) == PointState::DOWN)
150     {
151       std::cout<<"Window touch" << std::endl;
152     }
153   }
154
155   bool OnControlKeyEvent(Toolkit::Control control, const KeyEvent &event)
156   {
157     if (event.GetState() == KeyEvent::DOWN)
158     {
159       std::cout<<"Control down key : " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", keyCode : " << event.GetKeyCode() << std::endl;
160     }
161     else
162     {
163       std::cout<<"Control up key : " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", keyCode : " << event.GetKeyCode() << std::endl;
164     }
165     return false;
166   }
167
168   bool OnControlTouch(Actor actor, const TouchEvent &touch)
169   {
170     if (touch.GetState(0) == PointState::DOWN)
171     {
172
173       std::cout<<"Control touch " << actor.GetProperty< std::string >( Dali::Actor::Property::NAME ) << ", parent " << actor.GetParent().GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl;
174     }
175
176     return false;
177   }
178
179   void OnFocusSet(Control control)
180   {
181     std::cout<<"OnFocusSet " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl;
182   }
183
184   void OnFocusUnSet(Control control)
185   {
186     std::cout<<"OnFocusUnSet " << control.GetProperty< std::string >( Dali::Actor::Property::NAME ) << std::endl;
187   }
188
189 private:
190   Window mWindow;
191   Application &mApplication;
192
193   Control mControl1;
194   Control mControl2;
195   ImageView mImageView1;
196   ImageView mImageView2;
197   ImageView mImageView3;
198   ImageView mImageView4;
199   ImageView mImageView5;
200
201   TextLabel mTextLabel1;
202   TextLabel mTextLabel2;
203   TextField mTextField;
204   TextEditor mTextEditor;
205
206   Animation mAnimation;
207   Timer     mTimer;
208
209 };
210
211 int DALI_EXPORT_API main(int argc, char **argv)
212 {
213   Application application = Application::New(&argc, &argv, "");
214   MyTester test(application);
215   application.MainLoop();
216   return 0;
217 }