2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 * @file splash_screen_support.cpp
18 * @author Andrzej Surdej (a.surdej@samsung.com)
19 * @brief Implementation file for splash screen support
22 #include "splash_screen_support.h"
23 #include <dpl/log/log.h>
25 const short SPLASH_SCREEN_LAYER = 10;
26 const double SPLASH_SCREEN_MAXIUM_TIMER = 5.0; // sec
27 const double SPLASH_SCREEN_BUFFER_TIMER = 0.3; // sec
28 const int INDICATOR_H = 60;
30 static void evas_object_reposition(Evas_Object* obj, int x, int y, int w, int h)
32 evas_object_resize(obj,w, h);
33 evas_object_move(obj, x, y);
36 SplashScreenSupport::SplashScreenSupport(Evas_Object* parent, const char* image_path, bool indicator, bool landscape) :
39 m_splashScreenBg(NULL),
47 m_indicator(indicator)
51 if (!m_parent || !image_path)
53 LogError("Invalid parameter");
58 m_splashScreenBg = evas_object_rectangle_add(evas_object_evas_get(m_parent));
59 evas_object_color_set(m_splashScreenBg, 255, 255, 255, 255);
61 m_splashScreen = elm_image_add(m_splashScreenBg);
62 elm_image_no_scale_set(m_splashScreen, EINA_FALSE);
64 if (elm_image_file_set(m_splashScreen, image_path, NULL))
67 if (elm_image_animated_available_get(m_splashScreen))
69 elm_image_animated_set(m_splashScreen, EINA_TRUE);
70 elm_image_animated_play_set(m_splashScreen, EINA_FALSE);
74 Evas_Coord x, y, w, h;
75 evas_object_geometry_get(m_parent, &x, &y, &w, &h);
77 m_deviceWidth = (w < h) ? w : h;
78 m_deviceHeight = (w > h) ? w : h;
89 int indicator_h = INDICATOR_H * elm_config_scale_get();
104 elm_image_object_size_get(m_splashScreen, &m_imageWidth, &m_imageHeight);
106 if (m_imageWidth == 0 || m_imageHeight == 0)
108 LogError("Splash screen image size error!");
114 double ratio_win = (double)w/h;
115 double ratio_image = (double)m_imageWidth/m_imageHeight;
118 evas_object_reposition(m_splashScreenBg, x, y, w, h);
119 evas_object_reposition(m_splashScreen, x, y, w, h);
121 double scaled_image_w = w;
122 double scaled_image_h = (w/ratio_image);
124 Evas_Object* imageObject = elm_image_object_get(m_splashScreen);
126 if (ratio_image <= ratio_win)
128 evas_object_image_fill_set(imageObject, 0, 0-((scaled_image_h-h)/2), scaled_image_w, scaled_image_h);
129 evas_object_reposition(imageObject, x, y, w, h);
133 evas_object_image_fill_set(imageObject, 0, 0, scaled_image_w, scaled_image_h);
134 evas_object_reposition(imageObject, 0, y+(h-scaled_image_h)/2, scaled_image_w, scaled_image_h);
137 m_initialized = true;
141 SplashScreenSupport::~SplashScreenSupport()
147 evas_object_del(m_splashScreen);
148 evas_object_del(m_splashScreenBg);
153 ecore_timer_del(m_timer);
158 Eina_Bool SplashScreenSupport::timerCallback(void *data)
162 SplashScreenSupport* This = static_cast<SplashScreenSupport*>(data);
164 if (This->isShowing())
166 This->stopSplashScreen();
169 return ECORE_CALLBACK_CANCEL;
172 void SplashScreenSupport::startSplashScreen()
174 LogDebug("splashImageOn");
178 if (elm_image_animated_get(m_splashScreen) == EINA_TRUE)
180 elm_image_animated_play_set(m_splashScreen, EINA_TRUE);
183 evas_object_layer_set(m_splashScreenBg, SPLASH_SCREEN_LAYER);
184 evas_object_layer_set(m_splashScreen, SPLASH_SCREEN_LAYER);
186 evas_object_show(m_splashScreenBg);
187 evas_object_show(m_splashScreen);
193 ecore_timer_del(m_timer);
196 m_timer = ecore_timer_add(SPLASH_SCREEN_MAXIUM_TIMER, timerCallback, this);
201 void SplashScreenSupport::stopSplashScreenBuffered()
207 ecore_timer_del(m_timer);
210 m_timer = ecore_timer_add(SPLASH_SCREEN_BUFFER_TIMER, timerCallback, this);
214 void SplashScreenSupport::stopSplashScreen()
216 LogDebug("splashImageOff");
220 if (elm_image_animated_get(m_splashScreen) == EINA_TRUE)
222 elm_image_animated_play_set(m_splashScreen, EINA_FALSE);
225 evas_object_hide(m_splashScreen);
226 evas_object_hide(m_splashScreenBg);
228 evas_object_del(m_splashScreen);
229 evas_object_del(m_splashScreenBg);
231 m_initialized = false;
236 ecore_timer_del(m_timer);
242 bool SplashScreenSupport::isShowing()
247 void SplashScreenSupport::resizeSplashScreen()
249 if (m_initialized && m_isShowing)
252 int angle = elm_win_rotation_get(m_parent);
254 if (angle == 0 || angle == 180)
263 int indicator_h = INDICATOR_H * elm_config_scale_get();
278 double ratio_win = (double)w/h;
279 double ratio_image = (double)m_imageWidth/m_imageHeight;
281 evas_object_reposition(m_splashScreenBg, x, y, w, h);
282 evas_object_reposition(m_splashScreen, x, y, w, h);
284 double scaled_image_w = w;
285 double scaled_image_h = (w/ratio_image);
287 Evas_Object* imageObject = elm_image_object_get(m_splashScreen);
289 if (ratio_image <= ratio_win)
291 evas_object_image_fill_set(imageObject, 0, 0-((scaled_image_h-h)/2), scaled_image_w, scaled_image_h);
292 evas_object_reposition(imageObject, x, y, w, h);
296 evas_object_image_fill_set(imageObject, 0, 0, scaled_image_w, scaled_image_h);
297 evas_object_reposition(imageObject, 0, y+(h-scaled_image_h)/2, scaled_image_w, scaled_image_h);