|
1 /* |
|
2 * Copyright (c) 2006-2007 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: Class is used to find out from java is midlet foreground or not |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 |
|
23 #include "cmmaforeground.h" |
|
24 #include "cmmaforegroundevent.h" |
|
25 // INCLUDE FILES |
|
26 #include <jdebug.h> |
|
27 |
|
28 // xm-radio fix |
|
29 #include "CMIDEnv.h" |
|
30 |
|
31 CMMAForeground* CMMAForeground::NewL(MMMAEventPoster* aEventPoster, |
|
32 jobject aForegroundListener, |
|
33 jmethodID aJavaMethod , |
|
34 CMIDToolkit* aToolkit) |
|
35 { |
|
36 DEBUG("CMMAForeground::NewL + "); |
|
37 CMMAForeground* self = new(ELeave) CMMAForeground; |
|
38 |
|
39 CleanupStack::PushL(self); |
|
40 self->ConstructL(aEventPoster, aForegroundListener, aJavaMethod, aToolkit); |
|
41 CleanupStack::Pop(); |
|
42 |
|
43 DEBUG("CMMAForeground::NewL - "); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CMMAForeground::~CMMAForeground() |
|
48 { |
|
49 DEBUG("CMMAForeground::~CMMAForeground() + "); |
|
50 if (iMidEnv) |
|
51 { |
|
52 // unregister for getting the foreground change event |
|
53 DEBUG("CMMAForeground::~CMMAForeground() : iMidEnv RemoveObserver +"); |
|
54 iMidEnv->RemoveObserver(*this); |
|
55 DEBUG("CMMAForeground::~CMMAForeground() : iMidEnv RemoveObserver -"); |
|
56 } |
|
57 |
|
58 CEikonEnv* eikEnv = ((CEikonEnv*)CEikonEnv::Static()); |
|
59 |
|
60 if (eikEnv) |
|
61 { |
|
62 DEBUG("CMMAForeground::~CMMAForeground() : eikEnv RemoveForegroundObserver +"); |
|
63 eikEnv->RemoveForegroundObserver(*this); |
|
64 DEBUG("CMMAForeground::~CMMAForeground() : eikEnv RemoveForegroundObserver -"); |
|
65 } |
|
66 |
|
67 if (iEventPoster && iDeleteRefEvent) |
|
68 { |
|
69 iEventPoster->PostEvent(iDeleteRefEvent); |
|
70 } |
|
71 else |
|
72 { |
|
73 delete iDeleteRefEvent; |
|
74 } |
|
75 delete iForegroundEvent; |
|
76 delete iActiveScheduler; |
|
77 DEBUG("CMMAForeground::~CMMAForeground() - "); |
|
78 } |
|
79 |
|
80 CMMAForeground::CMMAForeground() |
|
81 : iIsForeground(ETrue) // Initialize IsForeground to true, we might have already missed the event (HandleForegroundL), events before observer registration |
|
82 { |
|
83 } |
|
84 |
|
85 void CMMAForeground::ConstructL(MMMAEventPoster* aEventPoster, |
|
86 jobject aForegroundListener, |
|
87 jmethodID aJavaMethod , |
|
88 CMIDToolkit* aToolkit) // xm-radio fix |
|
89 { |
|
90 DEBUG_INT("CMMAForeground::ConstructL + ISFOREGROUND = %d",iIsForeground); |
|
91 |
|
92 iActiveScheduler = new(ELeave) CActiveSchedulerWait(); |
|
93 iEventPoster = aEventPoster; |
|
94 iForegroundListener = aForegroundListener; |
|
95 iJavaMethod = aJavaMethod; |
|
96 |
|
97 iForegroundEvent = new(ELeave) CMMAForegroundEvent( |
|
98 aForegroundListener, |
|
99 aJavaMethod, |
|
100 CMMAEvent::EReusableEvent); |
|
101 iDeleteRefEvent = new(ELeave) CMMADeleteRefEvent(aForegroundListener); |
|
102 |
|
103 // xm-radio fix |
|
104 iToolkit = aToolkit; |
|
105 |
|
106 if (iToolkit) |
|
107 { |
|
108 DEBUG("CMMAForeground::ConstructL : iToolkit->Env(); +"); |
|
109 iMidEnv = iToolkit->Env(); |
|
110 DEBUG("CMMAForeground::ConstructL : iToolkit->Env(); -"); |
|
111 } |
|
112 |
|
113 if (iMidEnv) |
|
114 { |
|
115 DEBUG("CMMAForeground::ConstructL : iMidEnv->AddObserverL + "); |
|
116 // register for getting the foreground change event |
|
117 iMidEnv->AddObserverL(*this); |
|
118 DEBUG("CMMAForeground::ConstructL : iMidEnv->AddObserverL - "); |
|
119 } |
|
120 |
|
121 CEikonEnv* eikEnv = ((CEikonEnv*)CEikonEnv::Static()); |
|
122 |
|
123 if (eikEnv) |
|
124 { |
|
125 DEBUG("CMMAForeground::ConstructL - eikAppUi->AddForegroundObserverL() + "); |
|
126 eikEnv->AddForegroundObserverL(*this); |
|
127 DEBUG("CMMAForeground::ConstructL - eikAppUi->AddForegroundObserverL() - "); |
|
128 } |
|
129 |
|
130 DEBUG("CMMAForeground::ConstructL - "); |
|
131 } |
|
132 |
|
133 TBool CMMAForeground::IsForeground() |
|
134 { |
|
135 DEBUG_INT2("THREADID = %d : CMMAForeground::IsForeground : ISFOREGROUND = %d",RThread().Id(),iIsForeground); |
|
136 return iIsForeground; |
|
137 } |
|
138 |
|
139 void CMMAForeground::SetForeground(TBool aIsForeground) |
|
140 { |
|
141 iIsForeground = aIsForeground; |
|
142 DEBUG_INT("CMMAForeground::SetForeground - ISFOREGROUND = %d",iIsForeground); |
|
143 } |
|
144 |
|
145 // Implement MMIDEnvObserver |
|
146 |
|
147 void CMMAForeground::HandleSwitchOnL(TBool /*aSwitchOn*/) |
|
148 { |
|
149 // Dummy implementation, no intent to do anything |
|
150 } |
|
151 |
|
152 /** |
|
153 * Handles the case when the MIDlet is brought to the foreground. |
|
154 */ |
|
155 void CMMAForeground::HandleForegroundL(TBool aForeground) |
|
156 { |
|
157 DEBUG_INT("CMMAForeground::HandleForegroundL %d", aForeground); |
|
158 iIsForeground = aForeground; |
|
159 } |
|
160 |
|
161 /** |
|
162 * Handles a change to resources which are shared accross the environment. |
|
163 */ |
|
164 void CMMAForeground::HandleResourceChangeL(TInt /*aType*/) |
|
165 { |
|
166 // Dummy implementation, no intent to do anything |
|
167 } |
|
168 |
|
169 // Handles the application coming to the foreground. |
|
170 void CMMAForeground::HandleGainingForeground() |
|
171 { |
|
172 iIsForeground = ETrue; |
|
173 } |
|
174 |
|
175 // Handles the application going into the background. |
|
176 void CMMAForeground::HandleLosingForeground() |
|
177 { |
|
178 iIsForeground = EFalse; |
|
179 } |
|
180 // End of File |