|
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 #include "tsdevicestate.h" |
|
20 #include "tsapplogging.h" |
|
21 |
|
22 #include <AknUtils.h> |
|
23 #include <hwrmdomainpskeys.h> |
|
24 |
|
25 // ----------------------------------------------------------------------------- |
|
26 // CTsDeviceState::NewL |
|
27 // ----------------------------------------------------------------------------- |
|
28 // |
|
29 CTsDeviceState* CTsDeviceState::NewL() |
|
30 { |
|
31 CTsDeviceState* self = new ( ELeave ) CTsDeviceState; |
|
32 CleanupStack::PushL( self ); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop( self ); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CTsDeviceState::CTsDeviceState |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CTsDeviceState::CTsDeviceState() |
|
43 { |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CTsDeviceState::ConstructL |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 void CTsDeviceState::ConstructL() |
|
51 { |
|
52 iFlipStatusObserver = new ( ELeave ) CTsPropertyListener(KPSUidHWRM, |
|
53 KHWRMFlipStatus, *this); |
|
54 // check if touch is enabled or not |
|
55 CheckTouchState(); |
|
56 // are we in portrait or landscape |
|
57 CheckOrientation(); |
|
58 // checks the qwerty input mode. |
|
59 CheckDeviceType(); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CTsDeviceState::~CTsDeviceState |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CTsDeviceState::~CTsDeviceState() |
|
67 { |
|
68 iObservers.Close(); |
|
69 delete iFlipStatusObserver; |
|
70 } |
|
71 |
|
72 // -------------------------------------------------------------------------- |
|
73 // CTsDeviceState::HandleResourceChange |
|
74 // -------------------------------------------------------------------------- |
|
75 // |
|
76 void CTsDeviceState::HandleResourceChange( TInt aType ) |
|
77 { |
|
78 TSLOG_CONTEXT( HandleResourceChange, TSLOG_LOCAL ); |
|
79 TSLOG2_IN( "aType = %d (active count = %d)", aType, iResChangeActiveCount ); |
|
80 |
|
81 // increase function entrance count |
|
82 ++iResChangeActiveCount; |
|
83 // if we are still in a previous call then do nothing else |
|
84 if ( iResChangeActiveCount == 1 ) |
|
85 { |
|
86 // the active count may increase during execution of the body of the loop |
|
87 // (if some observers have active scheduler waits, for example) |
|
88 while ( iResChangeActiveCount > 0 ) |
|
89 { |
|
90 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
91 { |
|
92 TSLOG0( TSLOG_INFO, "dyn layout var switch" ); |
|
93 // This might be a screen orientation or touch-nontouch switch, |
|
94 // so let's check the situation and notify observers if needed. |
|
95 CheckTouchState(); |
|
96 CheckOrientation(); |
|
97 } |
|
98 else if ( aType == KAknsMessageSkinChange ) |
|
99 { |
|
100 TSLOG0( TSLOG_INFO, "skin change" ); |
|
101 NotifyObservers( MTsDeviceStateObserver::ESkin ); |
|
102 } |
|
103 --iResChangeActiveCount; |
|
104 } |
|
105 } |
|
106 |
|
107 TSLOG_OUT(); |
|
108 } |
|
109 |
|
110 // -------------------------------------------------------------------------- |
|
111 // CTsDeviceState::PropertyChanged |
|
112 // -------------------------------------------------------------------------- |
|
113 // |
|
114 void CTsDeviceState::PropertyChanged(TUid aCategory, TUint aKey) |
|
115 { |
|
116 TSLOG_CONTEXT( PropertyChanged, TSLOG_LOCAL ); |
|
117 TSLOG2_IN( "aKey = %d aNewValue = %d", aCategory, aKey ); |
|
118 CheckDeviceType(); |
|
119 TSLOG_OUT(); |
|
120 } |
|
121 |
|
122 // -------------------------------------------------------------------------- |
|
123 // CTsDeviceState::CheckTouchState |
|
124 // -------------------------------------------------------------------------- |
|
125 // |
|
126 void CTsDeviceState::CheckTouchState() |
|
127 { |
|
128 TSLOG_CONTEXT( CheckTouchState, TSLOG_LOCAL ); |
|
129 TSLOG_IN(); |
|
130 |
|
131 TTouchState oldValue = iTouchState; |
|
132 iTouchState = AknLayoutUtils::PenEnabled() ? ETouchEnabled : ETouchDisabled; |
|
133 if ( iTouchState != oldValue ) |
|
134 { |
|
135 NotifyObservers( MTsDeviceStateObserver::ETouchState ); |
|
136 } |
|
137 |
|
138 TSLOG1_OUT( "new value for iTouchState: %d", iTouchState ); |
|
139 } |
|
140 |
|
141 // -------------------------------------------------------------------------- |
|
142 // CTsDeviceState::CheckOrientation |
|
143 // -------------------------------------------------------------------------- |
|
144 // |
|
145 void CTsDeviceState::CheckOrientation() |
|
146 { |
|
147 TSLOG_CONTEXT( CheckOrientation, TSLOG_LOCAL ); |
|
148 TSLOG_IN(); |
|
149 |
|
150 TRect rect; |
|
151 AknLayoutUtils::LayoutMetricsRect ( AknLayoutUtils::EScreen, rect ); |
|
152 TOrientation oldValue = iOrientation; |
|
153 iOrientation = rect.Width() > rect.Height() ? ELandscape : EPortrait; |
|
154 if ( iOrientation != oldValue ) |
|
155 { |
|
156 NotifyObservers( MTsDeviceStateObserver::EOrientation ); |
|
157 } |
|
158 |
|
159 TSLOG1_OUT( "new value for iOrientation: %d", iOrientation ); |
|
160 } |
|
161 |
|
162 // -------------------------------------------------------------------------- |
|
163 // CTsDeviceState::DeviceType |
|
164 // -------------------------------------------------------------------------- |
|
165 // |
|
166 void CTsDeviceState::CheckDeviceType() |
|
167 { |
|
168 TSLOG_CONTEXT( CheckQwerty, TSLOG_LOCAL ); |
|
169 TSLOG_IN(); |
|
170 |
|
171 TInt oldDeviceType = iDeviceType; |
|
172 TInt value( 0 ); |
|
173 if( RProperty::Get( KPSUidHWRM, KHWRMFlipStatus, value ) == KErrNone ) |
|
174 { |
|
175 iDeviceType = (value == EPSHWRMFlipOpen ? EHybrid : EFullTouch); |
|
176 } |
|
177 |
|
178 if( iDeviceType != oldDeviceType ) |
|
179 { |
|
180 NotifyObservers( MTsDeviceStateObserver::EDeviceType); |
|
181 } |
|
182 |
|
183 TSLOG1_OUT( "new value for iDeviceType: %d", iDeviceType ); |
|
184 } |
|
185 |
|
186 // -------------------------------------------------------------------------- |
|
187 // CTsDeviceState::TouchState |
|
188 // -------------------------------------------------------------------------- |
|
189 // |
|
190 CTsDeviceState::TTouchState CTsDeviceState::TouchState() const |
|
191 { |
|
192 return iTouchState; |
|
193 } |
|
194 |
|
195 // -------------------------------------------------------------------------- |
|
196 // CTsDeviceState::Orientation |
|
197 // -------------------------------------------------------------------------- |
|
198 // |
|
199 CTsDeviceState::TOrientation CTsDeviceState::Orientation() const |
|
200 { |
|
201 return iOrientation; |
|
202 } |
|
203 |
|
204 // -------------------------------------------------------------------------- |
|
205 // CTsDeviceState::Qwerty |
|
206 // -------------------------------------------------------------------------- |
|
207 // |
|
208 CTsDeviceState::TDeviceType CTsDeviceState::DeviceType() const |
|
209 { |
|
210 return iDeviceType; |
|
211 } |
|
212 |
|
213 // -------------------------------------------------------------------------- |
|
214 // CTsDeviceState::ObserverIdentity |
|
215 // -------------------------------------------------------------------------- |
|
216 // |
|
217 TBool CTsDeviceState::ObserverIdentity( const SObserver& aA, |
|
218 const SObserver& aB ) |
|
219 { |
|
220 return aA.iObserver == aB.iObserver; |
|
221 } |
|
222 |
|
223 // -------------------------------------------------------------------------- |
|
224 // CTsDeviceState::AddDeviceStateObserverL |
|
225 // -------------------------------------------------------------------------- |
|
226 // |
|
227 void CTsDeviceState::AddObserverL( MTsDeviceStateObserver& aObserver, |
|
228 TInt aMask ) |
|
229 { |
|
230 iObservers.AppendL( SObserver( aMask, &aObserver ) ); |
|
231 } |
|
232 |
|
233 // -------------------------------------------------------------------------- |
|
234 // CTsDeviceState::RemoveObserver |
|
235 // -------------------------------------------------------------------------- |
|
236 // |
|
237 void CTsDeviceState::RemoveObserver( MTsDeviceStateObserver& aObserver ) |
|
238 { |
|
239 for ( ; ; ) |
|
240 { |
|
241 TInt pos = iObservers.Find( SObserver( MTsDeviceStateObserver::EAny, |
|
242 &aObserver ), ObserverIdentity ); |
|
243 if ( pos >= 0 ) |
|
244 { |
|
245 iObservers.Remove( pos ); |
|
246 } |
|
247 else |
|
248 { |
|
249 break; |
|
250 } |
|
251 } |
|
252 } |
|
253 |
|
254 // -------------------------------------------------------------------------- |
|
255 // CTsDeviceState::NotifyObservers |
|
256 // -------------------------------------------------------------------------- |
|
257 // |
|
258 void CTsDeviceState::NotifyObservers( |
|
259 MTsDeviceStateObserver::TChangeType aType ) |
|
260 { |
|
261 for ( TInt i = 0, ie = iObservers.Count(); i != ie; ++i ) |
|
262 { |
|
263 const SObserver& obs( iObservers[i] ); |
|
264 if ( obs.iMask & aType ) |
|
265 { |
|
266 obs.iObserver->HandleDeviceStateChanged( aType ); |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 |
|
272 // end of file |