72
|
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>
|
78
|
15 |
#include <com_nokia_mj_impl_nokiauiapi_OS.h>
|
72
|
16 |
#include "autorelease.h"
|
87
|
17 |
#include "CSoftNotification.h"
|
72
|
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 |
|
78
|
29 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_MTouchFeedback_1InstantFeedback(
|
72
|
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 |
|
78
|
39 |
JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_MTouchFeedback_1TouchFeedbackSupported(
|
72
|
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 |
|
78
|
51 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_MTouchFeedback_1SetFeedbackArea(
|
72
|
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 |
|
78
|
67 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_MTouchFeedback_1RemoveFeedbackArea(
|
72
|
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 |
|
78
|
79 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_MTouchFeedback_1RemoveFeedbackForControl(
|
72
|
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 |
|
78
|
91 |
JNIEXPORT void JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_MTouchFeedback_1MoveFeedbackAreaToFirstPriority(
|
72
|
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 |
|
78
|
104 |
JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_nokiauiapi_OS_createNativePeer(
|
72
|
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
|
78
|
133 |
Java_com_nokia_mj_impl_nokiauiapi_OS_getId(JNIEnv* /*aJniEnv*/,
|
72
|
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
|
78
|
172 |
Java_com_nokia_mj_impl_nokiauiapi_OS_setText(JNIEnv* aJniEnv, jclass /*aPeer*/,
|
72
|
173 |
jint aSoftNotificationHandle, jstring aPrimaryText, jstring aSecondaryText)
|
|
174 |
{
|
87
|
175 |
if (aPrimaryText == NULL || aSecondaryText == NULL)
|
|
176 |
{
|
|
177 |
// These arguments are checked already on Java side, no need to try
|
|
178 |
// to recover from NULL strings.
|
|
179 |
return KErrArgument;
|
|
180 |
}
|
|
181 |
|
72
|
182 |
CSoftNotification* softNotification =
|
|
183 |
reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle);
|
|
184 |
// Convert from java string to Symbian descriptor
|
|
185 |
HBufC* bufferPrimaryText = NULL;
|
87
|
186 |
bufferPrimaryText = JavaStringToSymbianString(aJniEnv, aPrimaryText);
|
|
187 |
if (bufferPrimaryText == NULL)
|
72
|
188 |
{
|
87
|
189 |
return KErrNoMemory;
|
72
|
190 |
}
|
|
191 |
|
|
192 |
HBufC* bufferSecondaryText = NULL;
|
87
|
193 |
bufferSecondaryText = JavaStringToSymbianString(aJniEnv,
|
|
194 |
aSecondaryText);
|
|
195 |
if (bufferSecondaryText == NULL)
|
72
|
196 |
{
|
87
|
197 |
return KErrNoMemory;
|
72
|
198 |
}
|
87
|
199 |
|
72
|
200 |
TRAPD(err,softNotification->SetTextL(*bufferPrimaryText, *bufferSecondaryText));
|
|
201 |
return err;
|
|
202 |
}
|
|
203 |
|
|
204 |
JNIEXPORT jint JNICALL
|
78
|
205 |
Java_com_nokia_mj_impl_nokiauiapi_OS_removeSoftNotification(JNIEnv* /*aJniEnv*/,
|
72
|
206 |
jclass /*aPeer*/, jint aSoftNotificationHandle)
|
|
207 |
{
|
|
208 |
CSoftNotification* softNotification =
|
|
209 |
reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle);
|
|
210 |
TRAPD(err,softNotification->RemoveSoftNotificationL());
|
|
211 |
delete softNotification;
|
|
212 |
return err;
|
|
213 |
}
|
|
214 |
|
|
215 |
JNIEXPORT jint JNICALL
|
78
|
216 |
Java_com_nokia_mj_impl_nokiauiapi_OS_showSoftNotification(JNIEnv* /*aJniEnv*/,
|
72
|
217 |
jclass /*aPeer*/, jint aSoftNotificationHandle)
|
|
218 |
{
|
|
219 |
CSoftNotification* softNotification =
|
|
220 |
reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle);
|
|
221 |
jboolean status(false);
|
|
222 |
TRAPD(err,status = softNotification->ShowSoftNotificationL());
|
|
223 |
if(status)
|
|
224 |
{
|
|
225 |
return err;
|
|
226 |
}
|
|
227 |
else
|
|
228 |
{
|
|
229 |
return KErrNone;
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
JNIEXPORT jint JNICALL
|
78
|
234 |
Java_com_nokia_mj_impl_nokiauiapi_OS_setImagePath(JNIEnv* aJniEnv,
|
72
|
235 |
jclass /*aPeer*/, jint aSoftNotificationHandle, jstring aImagePath )
|
|
236 |
{
|
87
|
237 |
if (aImagePath == NULL)
|
|
238 |
{
|
|
239 |
return KErrArgument;
|
|
240 |
}
|
|
241 |
|
72
|
242 |
CSoftNotification* softNotification =
|
|
243 |
reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle);
|
|
244 |
// Convert from java string to Symbian descriptor
|
|
245 |
HBufC* bufferImagePath = NULL;
|
87
|
246 |
bufferImagePath = JavaStringToSymbianString(aJniEnv, aImagePath);
|
|
247 |
if (bufferImagePath == NULL)
|
72
|
248 |
{
|
87
|
249 |
return KErrNoMemory;
|
72
|
250 |
}
|
87
|
251 |
|
72
|
252 |
TRAPD(err,softNotification->SetImagePathL(*bufferImagePath));
|
|
253 |
return err;
|
|
254 |
}
|
|
255 |
|
|
256 |
JNIEXPORT void JNICALL
|
78
|
257 |
Java_com_nokia_mj_impl_nokiauiapi_OS_destroy(JNIEnv* /*aJniEnv*/,
|
72
|
258 |
jclass /*clazz*/, jint aSoftNotificationHandle)
|
|
259 |
{
|
|
260 |
if (aSoftNotificationHandle > KErrNone)
|
|
261 |
{
|
|
262 |
CSoftNotification
|
|
263 |
* softNotification =
|
|
264 |
reinterpret_cast<CSoftNotification*> (aSoftNotificationHandle);
|
|
265 |
delete softNotification;
|
|
266 |
}
|
|
267 |
}
|