1 /* |
|
2 * Copyright (c) 2006 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 the License "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: Class which implements handling Hardware Volume Key events. |
|
15 * This class implements methods of MRemConCoreApiTargetObserver |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <RemConCoreApiTarget.h> |
|
22 #include <remconinterfaceselector.h> |
|
23 #include <aknconsts.h> // KAknStandardKeyboardRepeatRate |
|
24 |
|
25 #include "BavpHwKeyEvents.h" |
|
26 #include "BavpLogger.h" |
|
27 |
|
28 // CONSTANTS |
|
29 const TInt KVolumeFirstChangePeriod = KAknKeyboardRepeatInitialDelay; |
|
30 const TInt KVolumeChangePeriod = KAknStandardKeyboardRepeatRate; |
|
31 const TInt KVolumeChangeUp = 1; |
|
32 const TInt KVolumeChangeDown = -1; |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CBavpHwKeyEvents::NewL |
|
38 // Two-phased constructor. |
|
39 // ---------------------------------------------------------------------------- |
|
40 CBavpHwKeyEvents* CBavpHwKeyEvents::NewL( MBavpHwKeyEventsObserver& aObserver ) |
|
41 { |
|
42 Log( EFalse, _L("CBavpHwKeyEvents::NewL") ); |
|
43 |
|
44 CBavpHwKeyEvents* self = new ( ELeave ) CBavpHwKeyEvents( aObserver ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CBavpHwKeyEvents::~CBavpHwKeyEvents |
|
53 // Destructor |
|
54 // ---------------------------------------------------------------------------- |
|
55 CBavpHwKeyEvents::~CBavpHwKeyEvents() |
|
56 { |
|
57 Log( EFalse, _L("CBavpHwKeyEvents::~CBavpHwKeyEvents") ); |
|
58 |
|
59 if ( iVolumeTimer ) |
|
60 { |
|
61 iVolumeTimer->Cancel(); |
|
62 delete iVolumeTimer; |
|
63 } |
|
64 |
|
65 delete iInterfaceSelector; |
|
66 iCoreTarget = NULL; // For LINT. Owned by iInterfaceSelector |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CBavpHwKeyEvents::CBavpHwKeyEvents |
|
71 // C++ default constructor can NOT contain any code, that |
|
72 // might leave. |
|
73 // ---------------------------------------------------------------------------- |
|
74 CBavpHwKeyEvents::CBavpHwKeyEvents( MBavpHwKeyEventsObserver& aObserver ) |
|
75 : iObserver( aObserver ) |
|
76 { |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CBavpHwKeyEvents::ConstructL |
|
81 // Symbian 2nd phase constructor can leave. |
|
82 // ----------------------------------------------------------------------------- |
|
83 void CBavpHwKeyEvents::ConstructL( ) |
|
84 { |
|
85 Log( EFalse, _L("CBavpHwKeyEvents::ConstructL") ); |
|
86 |
|
87 iInterfaceSelector = CRemConInterfaceSelector::NewL(); |
|
88 |
|
89 // Owned by iInterfaceSelector |
|
90 iCoreTarget = CRemConCoreApiTarget::NewL( *iInterfaceSelector, *this ); |
|
91 iInterfaceSelector->OpenTargetL(); |
|
92 |
|
93 // Volume key pressed and held (repeat) timer. |
|
94 iVolumeTimer = CPeriodic::NewL( EPriorityNormal ); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CBavpHwKeyEvents::MrccatoCommand |
|
99 // Handles hardware key events. The volume up/down keys can be clicked once, |
|
100 // for volume to increase/decrease one increment, or held down and the volume |
|
101 // will increase/decrease gradually until the limit is reached. The transport |
|
102 // keys (play, pause,..) will call the HandleCommandL method on the controller. |
|
103 // ---------------------------------------------------------------------------- |
|
104 void CBavpHwKeyEvents::MrccatoCommand( TRemConCoreApiOperationId aOperationId, |
|
105 TRemConCoreApiButtonAction aButtonAct ) |
|
106 { |
|
107 Log( EFalse, _L("CBavpHwKeyEvents::MrccatoCommand, OpID"), aOperationId ); |
|
108 |
|
109 switch ( aOperationId ) |
|
110 { |
|
111 case ERemConCoreApiVolumeUp: |
|
112 { |
|
113 switch ( aButtonAct ) |
|
114 { |
|
115 case ERemConCoreApiButtonPress: |
|
116 { |
|
117 // Volume up held down for 0.6 seconds |
|
118 iChange = KVolumeChangeUp; |
|
119 iVolumeTimer->Start( KVolumeFirstChangePeriod, |
|
120 KVolumeChangePeriod, |
|
121 TCallBack( VolumeTimerCallback, this ) ); |
|
122 break; |
|
123 } |
|
124 case ERemConCoreApiButtonClick: |
|
125 { |
|
126 // Volume up clicked once |
|
127 iChange = KVolumeChangeUp; |
|
128 DoChangeVolume(); |
|
129 break; |
|
130 } |
|
131 case ERemConCoreApiButtonRelease: |
|
132 { |
|
133 // Volume up key released, stop timer |
|
134 iVolumeTimer->Cancel(); |
|
135 break; |
|
136 } |
|
137 default: |
|
138 { |
|
139 // Never hits this |
|
140 break; |
|
141 } |
|
142 } |
|
143 break; |
|
144 } |
|
145 case ERemConCoreApiVolumeDown: |
|
146 { |
|
147 switch ( aButtonAct ) |
|
148 { |
|
149 case ERemConCoreApiButtonPress: |
|
150 { |
|
151 // Volume down key held for 0.6 seconds |
|
152 iChange = KVolumeChangeDown; |
|
153 iVolumeTimer->Start( KVolumeFirstChangePeriod, |
|
154 KVolumeChangePeriod, |
|
155 TCallBack( VolumeTimerCallback, this ) ); |
|
156 break; |
|
157 } |
|
158 case ERemConCoreApiButtonClick: |
|
159 { |
|
160 // Volume down clicked once |
|
161 iChange = KVolumeChangeDown; |
|
162 DoChangeVolume(); |
|
163 break; |
|
164 } |
|
165 case ERemConCoreApiButtonRelease: |
|
166 { |
|
167 // Volume down key released, stop timer |
|
168 iVolumeTimer->Cancel(); |
|
169 break; |
|
170 } |
|
171 default: |
|
172 { |
|
173 // Never hits this |
|
174 break; |
|
175 } |
|
176 } |
|
177 break; |
|
178 } |
|
179 default: |
|
180 { |
|
181 // Don’t do anything here. |
|
182 break; |
|
183 } |
|
184 } |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // CBavpHwKeyEvents::DoChangeVolume( ) |
|
189 // Change volume depending on the level of increase or decrease |
|
190 // ---------------------------------------------------------------------------- |
|
191 void CBavpHwKeyEvents::DoChangeVolume( ) |
|
192 { |
|
193 Log( EFalse, _L("CBavpHwKeyEvents::DoChangeVolume") ); |
|
194 |
|
195 iObserver.BavpHwKeyVolumeChange( iChange ); |
|
196 } |
|
197 |
|
198 // ---------------------------------------------------------------------------- |
|
199 // CBavpHwKeyEvents::ChangeVolume |
|
200 // Method call to change volume |
|
201 // ---------------------------------------------------------------------------- |
|
202 TInt CBavpHwKeyEvents::VolumeTimerCallback( TAny* aObject ) |
|
203 { |
|
204 // cast, and call non-static function |
|
205 static_cast<CBavpHwKeyEvents*>( aObject )->DoChangeVolume( ); |
|
206 return KErrNone; |
|
207 } |
|
208 |
|
209 // End of File |
|
210 |
|
211 |
|