camerauis/cameraapp/generic/inc/cambatterypanecontroller.h
branchRCL_3
changeset 24 bac7acad7cb3
parent 0 1ddebce53859
child 25 2c87b2808fd7
equal deleted inserted replaced
23:61bc0f252b2b 24:bac7acad7cb3
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Header file for CCamBatteryPaneController class.
       
    15 *
       
    16 *  Copyright © 2007-2008 Nokia.  All rights reserved.
       
    17 *  This material, including documentation and any related computer
       
    18 *  programs, is protected by copyright controlled by Nokia.  All
       
    19 *  rights are reserved.  Copying, including reproducing, storing,
       
    20 *  adapting or translating, any or all of this material requires the
       
    21 *  prior written consent of Nokia.  This material also contains
       
    22 *  confidential information which may not be disclosed to others
       
    23 *  without the prior written consent of Nokia.
       
    24 
       
    25 *
       
    26 *
       
    27 */
       
    28 
       
    29 
       
    30 #ifndef CAMBATTERYPANECONTROLLER_H
       
    31 #define CAMBATTERYPANECONTROLLER_H
       
    32 
       
    33 // INCLUDES
       
    34 
       
    35 #include <e32base.h>
       
    36 #include "CamPropertyObserver.h" // MPropertyObserver
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 // Battery strength and animation timer constants.
       
    41 const TInt KMinBatteryStrength      = 0;
       
    42 const TInt KMaxBatteryStrength      = 7;
       
    43 const TInt KBatteryRechargeTick     = 500000;
       
    44 
       
    45 // FORWARD DECLARATIONS
       
    46 
       
    47 class CCamBatteryPaneDrawer;
       
    48 class CCamPropertyWatcher;
       
    49 class CWindowGc;
       
    50 class CBitmapContext;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /**
       
    55 * Abstract API for battery pane observer.
       
    56 * Derived classes, which have subscribed to CCamBatteryPaneController
       
    57 * receive notification when the battery pane contents change
       
    58 */
       
    59 class MCamBatteryPaneObserver
       
    60     {
       
    61     public:    
       
    62         /**
       
    63         * The battery pane contents have changed
       
    64         */
       
    65         virtual void BatteryPaneUpdated() = 0;
       
    66     };   
       
    67 
       
    68 /**
       
    69 * Watches changes in battery strength and charge properties and provides
       
    70 * animation of recharging. Notifies observer of changes in the battery pane.
       
    71 * Handles drawing requests by passing them to owned CCamBatteryPaneDrawer
       
    72 * object.
       
    73 */
       
    74 class CCamBatteryPaneController: public CBase, public MPropertyObserver
       
    75     {
       
    76     
       
    77     public: // Construction and destruction
       
    78         /**
       
    79         * Descructor
       
    80         */
       
    81         ~CCamBatteryPaneController();
       
    82         /**
       
    83         * Two-phased constructor
       
    84         * @param aObserver              Battery pane observer
       
    85         * @param aCallbackActive        Callback to the observer active
       
    86         * @return Pointer to the created 
       
    87         */
       
    88         static CCamBatteryPaneController* NewL(
       
    89                 MCamBatteryPaneObserver& aObserver,
       
    90                 TBool aCallbackActive );
       
    91     
       
    92     
       
    93     public: // From MPropertyObserver
       
    94         /**
       
    95         * The value of a watched property has changed
       
    96         * @param aCategory The category of the property
       
    97         * @param aKey the Identifier of the property
       
    98         */    
       
    99         void HandlePropertyChangedL( const TUid& aCategory, const TUint aKey );
       
   100         
       
   101                
       
   102     public: // New functions
       
   103         /**
       
   104         * Pause battery pane controller. With value ETrue, stops listening
       
   105         * to battery pane events, with EFalse reinitializes and starts
       
   106         * listening to the events again.
       
   107         */
       
   108         void Pause( TBool aPause );        
       
   109     
       
   110         /**
       
   111         * Activate or deactivate callbacks to observer when there
       
   112         * are changes in the battery pane.
       
   113         * @param aActive Callback to observer active
       
   114         */          
       
   115         void SetCallbackActive( TBool aActive );
       
   116         
       
   117         /**
       
   118         * Set location in the screen, where the battery pane is
       
   119         * to be drawn.
       
   120         * @param aLocation Drawing location
       
   121         */        
       
   122         void SetLocation( TPoint aLocation );
       
   123         
       
   124         /**
       
   125         * Set battery strength.
       
   126         * @param aStrength Battery strength
       
   127         */
       
   128         void SetBatteryStrength( TInt aStrength );
       
   129                 
       
   130         /**
       
   131         * Start the recharging animation
       
   132         */        
       
   133         void StartRecharging();        
       
   134         
       
   135         /**
       
   136         * Stop the recharging animation
       
   137         */  
       
   138         void StopRecharging();
       
   139         
       
   140         /**
       
   141         * Get battery pane's rectangle
       
   142         * @return rectangle
       
   143         */
       
   144         TRect Rect() const; 
       
   145         
       
   146         /**
       
   147         * Get rectangle of the animated part of battery pane
       
   148         * @return rectangle
       
   149         */
       
   150         TRect AnimationRect() const;                 
       
   151 
       
   152         /**
       
   153         * Draw the battery pane
       
   154         * @param aGc Graphics context
       
   155         */                 
       
   156         void Draw( CBitmapContext& aGc ) const;
       
   157         //void Draw( CWindowGc& aGc ) const;
       
   158         
       
   159         /**
       
   160         * Handle resource change event
       
   161         * @param aType Type of the resource change
       
   162         */
       
   163         void HandleResourceChange( TInt aType );        
       
   164         
       
   165     protected:
       
   166         /**
       
   167         * Second phase constructor
       
   168         */
       
   169         void ConstructL();
       
   170     
       
   171     private:
       
   172         /**
       
   173         * Constructor.
       
   174         * @param aObserver Battery pane observer
       
   175         * @param aCallbackActive Callback to the observer active
       
   176         */
       
   177         CCamBatteryPaneController(
       
   178             MCamBatteryPaneObserver& aObserver,
       
   179             TBool aCallbackActive );
       
   180 
       
   181         /**
       
   182         * 
       
   183         * @param aThis Pointer to the object owning the ticker
       
   184         */
       
   185         static TInt TickerCallback( TAny* aThis );        
       
   186         
       
   187         /**
       
   188         * Changes the (charging) battery strenght value as needed to show the next
       
   189         * frame of the animation.
       
   190         */
       
   191         void UpdateRechargeBatteryStrength();
       
   192         
       
   193         /**
       
   194         * Notifies observer of changes in the battery pane,
       
   195         * if iCallbackActive is set
       
   196         */
       
   197         void NotifyObserver();
       
   198         
       
   199         /**
       
   200         * Read current status of the properties. Set battery level
       
   201         * and start/stop battery recharging animation accordingly.
       
   202         */
       
   203         void ReadCurrentState();
       
   204         
       
   205         /**
       
   206         * Start/stop the charging animation, depending on aStatus value
       
   207         * @param aStatus Value of the charging status property
       
   208         */
       
   209         void HandleChargingStatusChange( TInt aStatus );
       
   210         
       
   211     private:            
       
   212         // Current battery strength
       
   213         TInt                        iBatteryStrength;
       
   214     
       
   215         // Recharging animation status
       
   216         TBool                       iRecharging;
       
   217         TInt                        iRechargeBatteryStrength;
       
   218     
       
   219         // Object that handles the actual drawing
       
   220         CCamBatteryPaneDrawer*      iDrawer;
       
   221         
       
   222         // Recharge animation timer
       
   223         CPeriodic*                  iTicker;
       
   224    
       
   225         // Observer of the battery pane changes
       
   226         MCamBatteryPaneObserver&    iObserver;
       
   227         TBool                       iCallbackActive;
       
   228     
       
   229         // Property watchers for battery charging and strength
       
   230         CCamPropertyWatcher*        iBatteryStrengthWatcher;
       
   231         CCamPropertyWatcher*        iBatteryChargingWatcher;
       
   232         
       
   233         TBool                       iPaused;
       
   234     };
       
   235         
       
   236 #endif