|
1 /******************************************************************************* |
|
2 * Copyright (c) 2009, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - initial implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 #include <QWidget> |
|
13 #include <coecntrl.h> |
|
14 #include <touchfeedback.h> |
|
15 #include <com_nokia_mid_ui_internal_OS.h> |
|
16 #include "autorelease.h" |
|
17 #include "csoftnotification.h" |
|
18 |
|
19 static CCoeControl* convertToSymbian(QWidget* window) |
|
20 { |
|
21 CCoeControl* control = 0; |
|
22 if (window && window->winId()) |
|
23 { |
|
24 control = reinterpret_cast<CCoeControl*> (window->winId()); |
|
25 } |
|
26 return control; |
|
27 } |
|
28 |
|
29 JNIEXPORT void JNICALL Java_com_nokia_mid_ui_internal_OS_MTouchFeedback_1InstantFeedback( |
|
30 JNIEnv *, jclass, jint aStyle) |
|
31 { |
|
32 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
33 if (feedback) |
|
34 { |
|
35 feedback->InstantFeedback(static_cast<TTouchLogicalFeedback> (aStyle)); |
|
36 } |
|
37 } |
|
38 |
|
39 JNIEXPORT jboolean JNICALL Java_com_nokia_mid_ui_internal_OS_MTouchFeedback_1TouchFeedbackSupported( |
|
40 JNIEnv *, jclass) |
|
41 { |
|
42 jboolean enabled = JNI_FALSE; |
|
43 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
44 if (feedback) |
|
45 { |
|
46 enabled = feedback->TouchFeedbackSupported() ? JNI_TRUE : JNI_FALSE; |
|
47 } |
|
48 return enabled; |
|
49 } |
|
50 |
|
51 JNIEXPORT void JNICALL Java_com_nokia_mid_ui_internal_OS_MTouchFeedback_1SetFeedbackArea( |
|
52 JNIEnv *, jclass, jint aControl, jint aAreaIndex, jint aX, jint aY, |
|
53 jint aWidth, jint aHeight, jint aStyle) |
|
54 { |
|
55 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
56 if (feedback) |
|
57 { |
|
58 CCoeControl* control = convertToSymbian( |
|
59 reinterpret_cast<QWidget*> (aControl)); |
|
60 TRect feedbackRect(aX, aY, aX + aWidth, aY + aHeight); |
|
61 feedback->SetFeedbackArea(control, static_cast<TUint32> (aAreaIndex), |
|
62 feedbackRect, static_cast<TTouchLogicalFeedback> (aStyle), |
|
63 ETouchEventStylusDown); |
|
64 } |
|
65 } |
|
66 |
|
67 JNIEXPORT void JNICALL Java_com_nokia_mid_ui_internal_OS_MTouchFeedback_1RemoveFeedbackArea( |
|
68 JNIEnv *, jclass, jint aControl, jint aAreaIndex) |
|
69 { |
|
70 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
71 if (feedback) |
|
72 { |
|
73 CCoeControl* control = convertToSymbian( |
|
74 reinterpret_cast<QWidget*> (aControl)); |
|
75 feedback->RemoveFeedbackArea(control, aAreaIndex); |
|
76 } |
|
77 } |
|
78 |
|
79 JNIEXPORT void JNICALL Java_com_nokia_mid_ui_internal_OS_MTouchFeedback_1RemoveFeedbackForControl( |
|
80 JNIEnv *, jclass, jint aControl) |
|
81 { |
|
82 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
83 if (feedback) |
|
84 { |
|
85 CCoeControl* control = convertToSymbian( |
|
86 reinterpret_cast<QWidget*> (aControl)); |
|
87 feedback->RemoveFeedbackForControl(control); |
|
88 } |
|
89 } |
|
90 |
|
91 JNIEXPORT void JNICALL Java_com_nokia_mid_ui_internal_OS_MTouchFeedback_1MoveFeedbackAreaToFirstPriority( |
|
92 JNIEnv *, jclass, jint aControl, jint aAreaIndex) |
|
93 { |
|
94 MTouchFeedback* feedback = MTouchFeedback::Instance(); |
|
95 if (feedback) |
|
96 { |
|
97 CCoeControl* control = convertToSymbian( |
|
98 reinterpret_cast<QWidget*> (aControl)); |
|
99 feedback->MoveFeedbackAreaToFirstPriority(control, |
|
100 static_cast<TUint32> (aAreaIndex)); |
|
101 } |
|
102 } |
|
103 |
|
104 JNIEXPORT jint JNICALL Java_com_nokia_mid_ui_internal_OS_createNativePeer( |
|
105 JNIEnv* aJniEnv, jclass /*aClazz*/, jint aMidletId, |
|
106 jint aNotificationId, jobject aPeer) |
|
107 { |
|
108 jobject peer = aJniEnv->NewWeakGlobalRef(aPeer); |
|
109 if (!peer) |
|
110 return KErrNoMemory; |
|
111 |
|
112 // creates soft notification instance |
|
113 CSoftNotification* softNote = NULL; |
|
114 TRAPD(err, softNote = CSoftNotification::NewL(aMidletId, |
|
115 aNotificationId)); |
|
116 if(err!=KErrNone) |
|
117 { |
|
118 aJniEnv->DeleteWeakGlobalRef((jweak)peer); |
|
119 return err; |
|
120 } |
|
121 |
|
122 // callback object class |
|
123 jclass clazz = aJniEnv->GetObjectClass(peer); |
|
124 jmethodID methodId = aJniEnv->GetMethodID(clazz, "notificationCallback", |
|
125 "(I)V"); |
|
126 |
|
127 softNote->SetPeerObserver(peer, methodId, aJniEnv); |
|
128 aJniEnv->DeleteLocalRef(clazz); |
|
129 return reinterpret_cast<jint> (softNote); |
|
130 } |
|
131 |
|
132 JNIEXPORT jint JNICALL |
|
133 Java_com_nokia_mid_ui_internal_OS_getId(JNIEnv* /*aJniEnv*/, |
|
134 jclass /*aPeer*/, jint aSoftNotificationHandle) |
|
135 { |
|
136 CSoftNotification* softNotification = |
|
137 reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle); |
|
138 return softNotification->Id(); |
|
139 } |
|
140 |
|
141 HBufC* JavaStringToSymbianString(JNIEnv* aJniEnv, jstring aText) |
|
142 { |
|
143 HBufC* bufferText = NULL; |
|
144 |
|
145 jboolean isCopy; |
|
146 const jchar* javaChars = aJniEnv->GetStringChars(aText, &isCopy); |
|
147 if (javaChars) |
|
148 { |
|
149 AutoReleaseStringChars cleaner(aJniEnv, aText, javaChars); |
|
150 jsize length = aJniEnv->GetStringLength(aText); |
|
151 TRAPD(err, bufferText = HBufC::NewL(length)); |
|
152 if (err == KErrNone) |
|
153 { |
|
154 TText* ptr = const_cast<TText*> (bufferText->Des().Ptr()); |
|
155 memcpy(ptr, javaChars, length * sizeof(jchar)); |
|
156 bufferText->Des().SetLength(length); |
|
157 } |
|
158 else |
|
159 { |
|
160 return bufferText; |
|
161 } |
|
162 } |
|
163 else |
|
164 { |
|
165 return bufferText; |
|
166 } |
|
167 |
|
168 return bufferText; |
|
169 } |
|
170 |
|
171 JNIEXPORT jint JNICALL |
|
172 Java_com_nokia_mid_ui_internal_OS_setText(JNIEnv* aJniEnv, jclass /*aPeer*/, |
|
173 jint aSoftNotificationHandle, jstring aPrimaryText, jstring aSecondaryText) |
|
174 { |
|
175 CSoftNotification* softNotification = |
|
176 reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle); |
|
177 // Convert from java string to Symbian descriptor |
|
178 HBufC* bufferPrimaryText = NULL; |
|
179 if (aPrimaryText != NULL) |
|
180 { |
|
181 bufferPrimaryText = JavaStringToSymbianString(aJniEnv, aPrimaryText); |
|
182 if (bufferPrimaryText == NULL) |
|
183 { |
|
184 return KErrNoMemory; |
|
185 } |
|
186 } |
|
187 |
|
188 HBufC* bufferSecondaryText = NULL; |
|
189 if (aSecondaryText != NULL) |
|
190 { |
|
191 bufferSecondaryText = JavaStringToSymbianString(aJniEnv, |
|
192 aSecondaryText); |
|
193 if (bufferSecondaryText == NULL) |
|
194 { |
|
195 return KErrNoMemory; |
|
196 } |
|
197 } |
|
198 TRAPD(err,softNotification->SetTextL(*bufferPrimaryText, *bufferSecondaryText)); |
|
199 return err; |
|
200 } |
|
201 |
|
202 JNIEXPORT jint JNICALL |
|
203 Java_com_nokia_mid_ui_internal_OS_removeSoftNotification(JNIEnv* /*aJniEnv*/, |
|
204 jclass /*aPeer*/, jint aSoftNotificationHandle) |
|
205 { |
|
206 CSoftNotification* softNotification = |
|
207 reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle); |
|
208 TRAPD(err,softNotification->RemoveSoftNotificationL()); |
|
209 delete softNotification; |
|
210 return err; |
|
211 } |
|
212 |
|
213 JNIEXPORT jint JNICALL |
|
214 Java_com_nokia_mid_ui_internal_OS_showSoftNotification(JNIEnv* /*aJniEnv*/, |
|
215 jclass /*aPeer*/, jint aSoftNotificationHandle) |
|
216 { |
|
217 CSoftNotification* softNotification = |
|
218 reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle); |
|
219 jboolean status(false); |
|
220 TRAPD(err,status = softNotification->ShowSoftNotificationL()); |
|
221 if(status) |
|
222 { |
|
223 return err; |
|
224 } |
|
225 else |
|
226 { |
|
227 return KErrNone; |
|
228 } |
|
229 } |
|
230 |
|
231 JNIEXPORT jint JNICALL |
|
232 Java_com_nokia_mid_ui_internal_OS_setImagePath(JNIEnv* aJniEnv, |
|
233 jclass /*aPeer*/, jint aSoftNotificationHandle, jstring aImagePath ) |
|
234 { |
|
235 CSoftNotification* softNotification = |
|
236 reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle); |
|
237 // Convert from java string to Symbian descriptor |
|
238 HBufC* bufferImagePath = NULL; |
|
239 if (aImagePath != NULL) |
|
240 { |
|
241 bufferImagePath = JavaStringToSymbianString(aJniEnv, aImagePath); |
|
242 if (bufferImagePath == NULL) |
|
243 { |
|
244 return KErrNoMemory; |
|
245 } |
|
246 } |
|
247 TRAPD(err,softNotification->SetImagePathL(*bufferImagePath)); |
|
248 return err; |
|
249 } |
|
250 |
|
251 JNIEXPORT void JNICALL |
|
252 Java_com_nokia_mid_ui_internal_OS_destroy(JNIEnv* /*aJniEnv*/, |
|
253 jclass /*clazz*/, jint aSoftNotificationHandle) |
|
254 { |
|
255 if (aSoftNotificationHandle > KErrNone) |
|
256 { |
|
257 CSoftNotification |
|
258 * softNotification = |
|
259 reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle); |
|
260 delete softNotification; |
|
261 } |
|
262 } |