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;
89 * Notify the observer when the indicator visible status is changed.
90 * @param[in] isShowing Whether the indicator is visible.
92 virtual void IndicatorVisibilityChanged( bool isVisible ) = 0;
97 * Class to encapsulate lock file
103 * Constructor. open lock file
105 LockFile(const char* filename);
113 * Grab an exclusive lock on this file
114 * @return true if the lock succeeded, false if it failed
124 * Test if there is an error with the lock file, and clears
126 * @return true if an error was thrown
128 bool RetrieveAndClearErrorStatus();
131 std::string mFilename;
137 * Class to ensure lock/unlock through object destruction
143 * Constructor - creates a lock on the lockfile
144 * @param[in] lockFile The lockfile to use
146 ScopedLock( LockFile* lockFile );
149 * Destructor - removes the lock (if any) on the lockfile
154 * Method to test if the locking succeeded
155 * @return TRUE if locked
160 LockFile* mLockFile; ///< The lock file to use
161 bool mLocked; ///< Whether the lock succeeded
167 * Constructor. Creates a new indicator and opens a connection for
168 * the required orientation.
169 * @param[in] orientation The orientation in which to draw the indicator
170 * @param[in] observer The indicator closed
172 Indicator( Adaptor* adaptor,
173 Dali::Window::WindowOrientation orientation,
174 Dali::Window::IndicatorStyle style,
175 Observer* observer );
180 virtual ~Indicator();
182 void SetAdaptor(Adaptor* adaptor);
185 * Get the actor which contains the indicator image. Ensure that the handle is
186 * released when no longer needed.
187 * Changes from the indicator service will modify the image and resize the actor appropriately.
188 * @return The indicator actor.
190 Dali::Actor GetActor();
193 * Opens a new connection for the required orientation.
194 * @param[in] orientation The new orientation
196 void Open( Dali::Window::WindowOrientation orientation );
199 * Close the current connection. Will respond with Observer::IndicatorClosed()
201 * @note, IndicatorClosed() will be called synchronously if there's no update
202 * in progress, or asychronously if waiting for SignalUploaded )
207 * Set the opacity mode of the indicator background.
208 * @param[in] mode opacity mode
210 void SetOpacityMode( Dali::Window::IndicatorBgOpacity mode );
213 * Set whether the indicator is visible or not.
214 * @param[in] visibleMode visible mode for indicator bar.
215 * @param[in] forceUpdate true if want to change visible mode forcely
217 void SetVisible( Dali::Window::IndicatorVisibleMode visibleMode, bool forceUpdate = false );
220 * Check whether the indicator is connected to the indicator service.
221 * @return whether the indicator is connected or not.
226 * Send message to the indicator service.
227 * @param[in] messageDomain Message Reference number
228 * @param[in] messageId Reference number of the message this message refers to
229 * @param[in] data The data to send as part of the message
230 * @param[in] size Length of the data, in bytes, to send
231 * @return whether the message is sent successfully or not
233 bool SendMessage( int messageDomain, int messageId, const void *data, int size );
237 * Initialize the indicator actors
242 * Set the opacity of the background image
244 void SetBackgroundOpacity( Dali::Window::IndicatorBgOpacity opacity );
247 * Touch event callback.
248 * It should pass the valid touch event to indicator server
250 * @param[in] indicator The indicator actor that was touched
251 * @param[in] touchEvent The touch event
253 bool OnTouched(Dali::Actor indicator, const TouchEvent& touchEvent);
256 * Pan gesture callback.
257 * It finds flick down gesture to show hidden indicator image
259 * @param[in] actor The actor for gesture
260 * @param[in] gesture The gesture event
262 void OnPan( Dali::Actor actor, const Dali::PanGesture& gesture );
265 * Touch event callback on stage.
266 * If stage is touched, hide showing indicator image
268 * @param[in] touchEvent The touch event
270 void OnStageTouched(const Dali::TouchEvent& touchEvent);
273 * Return the given orientation in degrees
275 * @param[in] orientation The given indicator orientation
276 * @return value of 0, 90, 180 or 270
278 int OrientationToDegrees( Dali::Window::WindowOrientation orientation );
281 * Connect to the indicator service matching the orientation
282 * @param[in] orientation The current indicator orientation
284 bool Connect( Dali::Window::WindowOrientation orientation );
287 * Connect to the indicator service
288 * @param[in] serviceName The indicator service name
290 bool Connect( const char *serviceName );
293 * Start the reconnection timer. This will run every second until we reconnect to
294 * the indicator service.
296 void StartReconnectionTimer();
299 * If connection failed, attempt to re-connect every second
301 bool OnReconnectTimer();
304 * Disconnect from the indicator service
309 * Close existing lock file and open the new lock file.
310 * @param[in] epcEvent Current ecore event.
312 void NewLockFile(Ecore_Ipc_Event_Server_Data *epcEvent);
315 * Handle Resize event
316 * @param[in] width The new width
317 * @param[in] height The new height
319 void Resize(int width, int height);
322 * Load the shared indicator image
323 * @param[in] epcEvent The event containing the image data
325 void LoadSharedImage(Ecore_Ipc_Event_Server_Data *epcEvent);
328 * Load the pixmap indicator image
329 * @param[in] epcEvent The event containing the image data
331 void LoadPixmapImage( Ecore_Ipc_Event_Server_Data *epcEvent );
334 * Inform dali that the indicator data has been updated.
336 void UpdateImageData();
339 * Lock the temporary file, Copy the shared image into IndicatorBuffer
340 * and then unlock the temporary file.
341 * Caller should ensure we are not writing image to gl texture.
346 * Update the background with the correct colors
348 void SetBackground();
351 * Create a new image for the indicator, and set up signal handling for it.
353 void CreateNewImage();
356 * Create a new pixmap image for the indicator, and set up signal handling for it.
358 void CreateNewPixmapImage();
361 * Indicator type has changed.
363 * @param[in] type The new indicator type
365 void OnIndicatorTypeChanged( Type type );
368 * Check whether the indicator could be visible or invisible
369 * @return true if indicator should be shown
371 bool CheckVisibleState();
374 * Show/Hide indicator actor with effect
375 * @param[in] duration how long need to show the indicator,
376 * if it equal to 0, hide the indicator
377 * if it less than 0, show always
379 void ShowIndicator(float duration);
382 * Showing timer callback
387 * Showing animation finished callback
388 * @param[in] animation
390 void OnAnimationFinished(Dali::Animation& animation);
392 private: // Implementation of ServerConnection::Observer
394 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
396 virtual void DataReceived(void* event);
399 * @copydoc Dali::Internal::Adaptor::ServerConnection::Observer::DataReceived()
401 virtual void ConnectionClosed();
405 * Construct the gradient mesh
407 void ConstructBackgroundMesh();
411 IndicatorBufferPtr mIndicatorBuffer; ///< class which handles indicator rendering
412 PixmapId mPixmap; ///< Pixmap including indicator content
413 Dali::Image mImage; ///< Image created from mIndicatorBuffer
414 Dali::ImageActor mIndicatorImageActor; ///< Actor created from mImage
416 Dali::AnimatableMesh mBackgroundMesh;
417 Dali::MeshActor mBackgroundActor; ///< Actor for background
418 Dali::Actor mIndicatorActor; ///< Handle to topmost indicator actor
419 Dali::Actor mEventActor; ///< Handle to event
420 Dali::PanGestureDetector mPanDetector; ///< Pan detector to find flick gesture for hidden indicator
421 float mGestureDeltaY; ///< Checking how much panning moved
422 bool mGestureDetected; ///< Whether find the flick gesture
424 Dali::Timer mReconnectTimer; ///< Reconnection timer
425 SlotDelegate< Indicator > mConnection;
427 Dali::Window::IndicatorStyle mStyle; ///< Style of the indicator
428 Dali::Window::IndicatorBgOpacity mOpacityMode; ///< Opacity enum for background
429 Indicator::State mState; ///< The connection state
432 ServerConnection* mServerConnection;
433 LockFile* mLock; ///< File lock for the shared file
434 SharedFile* mSharedFile; ///< Shared file
435 Indicator::Observer* mObserver; ///< Upload observer
437 Dali::Window::WindowOrientation mOrientation;
438 int mRotation; ///< Orientation in degrees
441 Dali::Window::IndicatorVisibleMode mVisible; ///< Whether the indicator is visible
443 Dali::Timer mShowTimer; ///< Timer to show indicator
444 bool mIsShowing; ///< Whether the indicator is showing on the screen
445 Dali::Animation mIndicatorAnimation; ///< Animation to show/hide indicator image
447 bool mIsAnimationPlaying; ///< Whether the animation is playing