1 #ifndef __DALI_INTERNAL_INDICATOR_H__
2 #define __DALI_INTERNAL_INDICATOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/images/bitmap-image.h>
23 #include <dali/public-api/actors/image-actor.h>
24 #include <dali/public-api/actors/mesh-actor.h>
25 #include <dali/public-api/geometry/animatable-mesh.h>
28 #include <dali/public-api/animation/animation.h>
29 #include <dali/public-api/events/pan-gesture.h>
30 #include <dali/public-api/events/pan-gesture-detector.h>
33 #include <indicator-buffer.h>
34 #include <server-connection.h>
35 #include <shared-file.h>
50 typedef unsigned int PixmapId;
53 * The Indicator class connects to the indicator server, and gets and draws the indicator
54 * for the given orientation.
56 class Indicator : public ConnectionTracker, public ServerConnection::Observer
67 INDICATOR_TYPE_UNKNOWN,
77 * Notify the observer if the indicator type changes
78 * @param[in] type The new indicator type
80 virtual void IndicatorTypeChanged( Type type ) = 0;
83 * Notify the observer when the upload has completed.
84 * @param[in] indicator The indicator that has finished uploading.
86 virtual void IndicatorClosed(Indicator* indicator) = 0;
91 * Class to encapsulate lock file
97 * Constructor. open lock file
99 LockFile(const char* filename);
107 * Grab an exclusive lock on this file
108 * @return true if the lock succeeded, false if it failed
118 * Test if there is an error with the lock file, and clears
120 * @return true if an error was thrown
122 bool RetrieveAndClearErrorStatus();
125 std::string mFilename;
131 * Class to ensure lock/unlock through object destruction
137 * Constructor - creates a lock on the lockfile
138 * @param[in] lockFile The lockfile to use
140 ScopedLock( LockFile* lockFile );
143 * Destructor - removes the lock (if any) on the lockfile
148 * Method to test if the locking succeeded
149 * @return TRUE if locked
154 LockFile* mLockFile; ///< The lock file to use
155 bool mLocked; ///< Whether the lock succeeded
161 * Constructor. Creates a new indicator and opens a connection for
162 * the required orientation.
163 * @param[in] orientation The orientation in which to draw the indicator
164 * @param[in] observer The indicator closed
166 Indicator( Adaptor* adaptor,
167 Dali::Window::WindowOrientation orientation,
168 Dali::Window::IndicatorStyle style,
169 Observer* observer );
174 virtual ~Indicator();
176 void SetAdaptor(Adaptor* adaptor);
179 * Get the actor which contains the indicator image. Ensure that the handle is
180 * released when no longer needed.
181 * Changes from the indicator service will modify the image and resize the actor appropriately.
182 * @return The indicator actor.
184 Dali::Actor GetActor();
187 * Opens a new connection for the required orientation.
188 * @param[in] orientation The new orientation
190 void Open( Dali::Window::WindowOrientation orientation );
193 * Close the current connection. Will respond with Observer::IndicatorClosed()
195 * @note, IndicatorClosed() will be called synchronously if there's no update
196 * in progress, or asychronously if waiting for SignalUploaded )
201 * Set the opacity mode of the indicator background.
202 * @param[in] mode opacity mode
204 void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
207 * Set whether the indicator is visible or not.
208 * @param[in] visibleMode visible mode for indicator bar.
209 * @param[in] forceUpdate true if want to change visible mode forcely
211 void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
214 * Check whether the indicator is connected to the indicator service.
215 * @return whether the indicator is connected or not.
220 * Send message to the indicator service.
221 * @param[in] messageDomain Message Reference number
222 * @param[in] messageId Reference number of the message this message refers to
223 * @param[in] data The data to send as part of the message
224 * @param[in] size Length of the data, in bytes, to send
225 * @return whether the message is sent successfully or not
227 bool SendMessage( int messageDomain, int messageId, const void *data, int size );
231 * Initialize the indicator actors
236 * Set the opacity of the background image
238 void SetBackgroundOpacity( Dali::Window::IndicatorBgOpacity opacity );
241 * Touch event callback.
242 * It should pass the valid touch event to indicator server
244 * @param[in] indicator The indicator actor that was touched
245 * @param[in] touchEvent The touch event
247 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
250 * Pan gesture callback.
251 * It finds flick down gesture to show hidden indicator image
253 * @param[in] actor The actor for gesture
254 * @param[in] gesture The gesture event
256 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
259 * Touch event callback on stage.
260 * If stage is touched, hide showing indicator image
262 * @param[in] touchEvent The touch event
264 void OnStageTouched(const Dali::TouchEvent& touchEvent);
267 * Return the given orientation in degrees
269 * @param[in] orientation The given indicator orientation
270 * @return value of 0, 90, 180 or 270
272 int OrientationToDegrees( Dali::Window::WindowOrientation orientation );
275 * Connect to the indicator service matching the orientation
276 * @param[in] orientation The current indicator orientation
278 bool Connect( Dali::Window::WindowOrientation orientation );
281 * Connect to the indicator service
282 * @param[in] serviceName The indicator service name
284 bool Connect( const char *serviceName );
287 * Start the reconnection timer. This will run every second until we reconnect to
288 * the indicator service.
290 void StartReconnectionTimer();
293 * If connection failed, attempt to re-connect every second
295 bool OnReconnectTimer();
298 * Disconnect from the indicator service
303 * Close existing lock file and open the new lock file.
304 * @param[in] epcEvent Current ecore event.
306 void NewLockFile(Ecore_Ipc_Event_Server_Data *epcEvent);
309 * Handle Resize event
310 * @param[in] width The new width
311 * @param[in] height The new height
313 void Resize(int width, int height);
316 * Load the shared indicator image
317 * @param[in] epcEvent The event containing the image data
319 void LoadSharedImage(Ecore_Ipc_Event_Server_Data *epcEvent);
322 * Load the pixmap indicator image
323 * @param[in] epcEvent The event containing the image data
325 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
328 * Inform dali that the indicator data has been updated.
330 void UpdateImageData();
333 * Lock the temporary file, Copy the shared image into IndicatorBuffer
334 * and then unlock the temporary file.
335 * Caller should ensure we are not writing image to gl texture.
340 * Update the background with the correct colors
342 void SetBackground();
345 * Create a new image for the indicator, and set up signal handling for it.
347 void CreateNewImage();
350 * Create a new pixmap image for the indicator, and set up signal handling for it.
352 void CreateNewPixmapImage();
355 * Indicator type has changed.
357 * @param[in] type The new indicator type
359 void OnIndicatorTypeChanged( Type type );
362 * Check whether the indicator could be visible or invisible
363 * @return true if indicator should be shown
365 bool CheckVisibleState();
368 * Show/Hide indicator actor with effect
369 * @param[in] duration how long need to show the indicator,
370 * if it equal to 0, hide the indicator
371 * if it less than 0, show always
373 void ShowIndicator(float duration);
376 * Showing timer callback
381 * Showing animation finished callback
382 * @param[in] animation
384 void OnAnimationFinished(Dali::Animation& animation);
386 private: // Implementation of ServerConnection::Observer
388 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
390 virtual void DataReceived(void* event);
393 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
395 virtual void ConnectionClosed();
399 * Construct the gradient mesh
401 void ConstructBackgroundMesh();
405 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
406 PixmapId mPixmap; ///< Pixmap including indicator content
407 Dali::Image mImage; ///< Image created from mIndicatorBuffer
408 Dali::ImageActor mIndicatorImageActor; ///< Actor created from mImage
410 Dali::AnimatableMesh mBackgroundMesh;
411 Dali::MeshActor mBackgroundActor; ///< Actor for background
412 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
413 Dali::Actor mEventActor; ///< Handle to event
414 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
415 float mGestureDeltaY; ///< Checking how much panning moved
416 bool mGestureDetected; ///< Whether find the flick gesture
418 Dali::Timer mReconnectTimer; ///< Reconnection timer
419 SlotDelegate< Indicator > mConnection;
421 Dali::Window::IndicatorStyle mStyle; ///< Style of the indicator
422 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
423 Indicator::State mState; ///< The connection state
426 ServerConnection* mServerConnection;
427 LockFile* mLock; ///< File lock for the shared file
428 SharedFile* mSharedFile; ///< Shared file
429 Indicator::Observer* mObserver; ///< Upload observer
431 Dali::Window::WindowOrientation mOrientation;
432 int mRotation; ///< Orientation in degrees
435 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
437 Dali::Timer mShowTimer; ///< Timer to show indicator
438 bool mIsShowing; ///< Whether the indicator is showing on the screen
439 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
441 bool mIsAnimationPlaying; ///< Whether the animation is playing