taskswitcher/taskswitcherui/taskswitcherapp/inc/tsdevicestate.h
changeset 4 4d54b72983ae
equal deleted inserted replaced
3:fb3763350a08 4:4d54b72983ae
       
     1 /*
       
     2 * Copyright (c) 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:  Device state (touch mode, screen orientation) handler
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TSDEVICESTATE_H_
       
    20 #define TSDEVICESTATE_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include "tsappui.h"
       
    24 #include "tsproplistener.h"
       
    25 
       
    26 /**
       
    27  * Interface for getting notifications about screen orientation
       
    28  * and/or touch state etc. changes.
       
    29  */
       
    30 class MTsDeviceStateObserver
       
    31     {
       
    32 public:
       
    33     /**
       
    34      * Type of change.
       
    35      */
       
    36     enum TChangeType
       
    37         {
       
    38         // screen orientation (portrait <=> landscape) has changed
       
    39         EOrientation = 0x01,
       
    40         // touch enabled/disabled status has changed
       
    41         ETouchState = 0x02,
       
    42         // skin has changed
       
    43         ESkin = 0x04,
       
    44         // input device mode change
       
    45         EDeviceType = 0x08,
       
    46         // all of the above
       
    47         EAny = 0xFF
       
    48         };
       
    49 
       
    50     /**
       
    51      * Called when a change, to which the observer is registered,
       
    52      * has happened.
       
    53      */
       
    54     virtual void HandleDeviceStateChanged( TChangeType aChangeType ) = 0;
       
    55     };
       
    56 
       
    57 /**
       
    58  * Class for keeping track of screen orientation and touch enabled/disabled changes.
       
    59  */
       
    60 class CTsDeviceState :
       
    61     public CBase,
       
    62     public MTsPropertyChangeObserver
       
    63     {
       
    64 public:
       
    65     /**
       
    66      * Enumeration for TouchState().
       
    67      */
       
    68     enum TTouchState
       
    69         {
       
    70         ETouchEnabled,
       
    71         ETouchDisabled
       
    72         };
       
    73 
       
    74     /**
       
    75      * Enumeration for Orientation().
       
    76      */
       
    77     enum TOrientation
       
    78         {
       
    79         EPortrait,
       
    80         ELandscape
       
    81         };
       
    82 
       
    83     /**
       
    84      * Enumeration for DeviceType().
       
    85      */
       
    86     enum TDeviceType
       
    87         {
       
    88         EHybrid = 0,
       
    89         EFullTouch  = 1
       
    90         };
       
    91 
       
    92     /**
       
    93      * Creates a new instance.
       
    94      */
       
    95     static CTsDeviceState* NewL();
       
    96 
       
    97     /**
       
    98      * Destructor.
       
    99      */
       
   100     ~CTsDeviceState();
       
   101 
       
   102     /**
       
   103      * Returns the current state of touch awareness.
       
   104      */
       
   105     TTouchState TouchState() const;
       
   106 
       
   107     /**
       
   108      * Returns the current screen orientation.
       
   109      */
       
   110     TOrientation Orientation() const;
       
   111 
       
   112     /**
       
   113      * Returns the current device input type.
       
   114      */
       
   115     TDeviceType DeviceType() const;
       
   116 
       
   117     /**
       
   118      * Registers an observer.
       
   119      * @param   aObserver   ref to observer
       
   120      * (same observer can be added several times with different mask if needed)
       
   121      * @param   aMask       bitmask composed from TChangeType values
       
   122      * (when to notify the observer)
       
   123      */
       
   124     void AddObserverL( MTsDeviceStateObserver& aObserver, TInt aMask );
       
   125 
       
   126     /**
       
   127      * Deregisters the given observer.
       
   128      * @param   aObserver   ref to observer
       
   129      */
       
   130     void RemoveObserver( MTsDeviceStateObserver& aObserver );
       
   131 
       
   132     /**
       
   133      * Called from appui.
       
   134      */
       
   135     void HandleResourceChange( TInt aType );
       
   136     
       
   137     //From MTsPropertyChangeObserver
       
   138 public:
       
   139     /**
       
   140      * Observer interface for getting notifications about a P&S property change.
       
   141      */
       
   142 	virtual void PropertyChanged( TUid aCategory, TUint aKey );
       
   143 private:
       
   144     /**
       
   145      * Constructor.
       
   146      */
       
   147     CTsDeviceState();
       
   148     
       
   149     /**
       
   150      * Performs 2nd phase construction.
       
   151      */
       
   152     void ConstructL();
       
   153 
       
   154     /**
       
   155      * Checks if touch is enabled or not and performs
       
   156      * appropriate actions.
       
   157      */
       
   158     void CheckTouchState();
       
   159 
       
   160     /**
       
   161      * Checks the screen orientation and performs
       
   162      * appropriate actions.
       
   163      */
       
   164     void CheckOrientation();
       
   165     
       
   166     /**
       
   167      * Checks the device input type.
       
   168      */
       
   169     void CheckDeviceType();
       
   170     
       
   171     /**
       
   172      * Notifies all observers that are registered for the given type.
       
   173      */
       
   174     void NotifyObservers( MTsDeviceStateObserver::TChangeType aType );
       
   175 
       
   176     class SObserver;
       
   177 
       
   178     /**
       
   179      * Identity function to perform comparison between observer array items.
       
   180      */
       
   181     static TBool ObserverIdentity( const SObserver& aA, const SObserver& aB );
       
   182 
       
   183 private:
       
   184     /**
       
   185      * Current touch enabled/disabled state.
       
   186      */
       
   187     TTouchState iTouchState;
       
   188     
       
   189     /**
       
   190      * Current screen orientation.
       
   191      */
       
   192     TOrientation iOrientation;
       
   193     
       
   194     /**
       
   195      * Current the device input type.
       
   196      */
       
   197     TDeviceType iDeviceType;
       
   198     
       
   199     /**
       
   200      * Observer array entry struct.
       
   201      */
       
   202     struct SObserver
       
   203         {
       
   204         TInt iMask;
       
   205         MTsDeviceStateObserver* iObserver; // not owned
       
   206         SObserver( TInt aMask, MTsDeviceStateObserver* aObserver )
       
   207             : iMask( aMask ), iObserver( aObserver ) { }
       
   208         };
       
   209         
       
   210     /**
       
   211      * Observer array.
       
   212      */
       
   213     RArray<SObserver> iObservers;
       
   214 
       
   215     /**
       
   216      * Counter to indicate that we have not yet returned
       
   217      * from a previous HandleResourceChange.
       
   218      */
       
   219     TInt iResChangeActiveCount;
       
   220     
       
   221     /**
       
   222      * Flip status change observer.
       
   223      */
       
   224     CTsPropertyListener* iFlipStatusObserver;
       
   225     };
       
   226 
       
   227 #endif // TSDEVICESTATE_H_