author | hgs |
Fri, 15 Oct 2010 12:29:39 +0300 | |
changeset 80 | d6dafc5d983f |
parent 49 | 35baca0e7a2e |
permissions | -rw-r--r-- |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
80 | 2 |
* Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* Description: formatternative |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#include <memory> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
#include <stringresourcereader.h> |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
|
80 | 22 |
#ifndef RD_JAVA_UI_QT |
49 | 23 |
#include <AknUtils.h> |
24 |
#endif // RD_JAVA_UI_QT |
|
25 |
||
80 | 26 |
#include "com_nokia_mj_impl_utils_FormatterAvkon.h" |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
#include "com_nokia_mj_impl_utils_ResourceLoader.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
#include "javajniutils.h" |
49 | 29 |
#include "s60commonutils.h" |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
30 |
#include "logger.h" |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
enum EDateTimeFormat |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
33 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
34 |
DATE_LONG = 1, |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
35 |
DATE_SHORT = 2, |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
/*TIME_SHORT = 3, |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
TIME_LONG = 4, |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
DATETIME_SHORT = 5, |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
DATETIME_LONG = 6*/ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
40 |
}; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
42 |
const TUint JavaUpperTimeFor1970 = 14474675; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
const TUint JavaLowerTimeFor1970 = 254771200; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
// const TInt KMaxDateTimeStringSize = 50; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
const TInt KMaxDateFormatSize = 30; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
const TInt KMaxNumberFormatSize = 40; |
49 | 48 |
using namespace java::util; |
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
|
80 | 51 |
JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_FormatterAvkon__1formatInteger |
52 |
(JNIEnv *aJni, jclass, jint aNumber) |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
54 |
JELOG2(EUtils); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
55 |
TReal64 realNumber = aNumber; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
56 |
std::auto_ptr<HBufC> numberString(HBufC::New(KMaxNumberFormatSize)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
57 |
if (numberString.get() == 0) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
59 |
return 0; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
60 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
61 |
TPtr numberPtr = numberString->Des(); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
62 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
TRealFormat numberFormat; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
TInt error = numberPtr.Num(realNumber, numberFormat); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
if (error < KErrNone) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
WLOG2(EUtils, |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
"Cannot format %d to current locale. Error: %d", aNumber, error); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
70 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
71 |
|
49 | 72 |
#ifndef RD_JAVA_UI_QT |
73 |
AknTextUtils::LanguageSpecificNumberConversion( numberPtr ); |
|
74 |
#endif // RD_JAVA_UI_QT |
|
75 |
||
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
76 |
return aJni->NewString( |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
77 |
(const jchar*)numberPtr.Ptr(), numberPtr.Length()); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
78 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
79 |
|
80 | 80 |
JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_FormatterAvkon__1formatDate |
81 |
(JNIEnv * aJni, jclass, jlong timeInMillis) |
|
21
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
82 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
83 |
std::auto_ptr<HBufC> dateString(HBufC::New(KMaxDateFormatSize)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
84 |
if (dateString.get() == 0) |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
85 |
{ |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
86 |
return 0; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
87 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
88 |
TPtr datePtr(dateString->Des()); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
89 |
TBuf<KMaxDateFormatSize> dateStringBuf; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
90 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
91 |
// Java Date object is calculated by millisecs from 1.1.1970 0:00:00 GMT |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
92 |
// Need conversion for Symbian TTime |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
93 |
TInt64 timeNum = *reinterpret_cast<TInt64*>(&timeInMillis); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
94 |
TInt64 timeBeginNum = |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
95 |
MAKE_TINT64(JavaUpperTimeFor1970, JavaLowerTimeFor1970); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
96 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
97 |
TTime timeBegin(timeBeginNum); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
98 |
TTimeIntervalMicroSeconds delta(timeNum * 1000); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
99 |
TTime time = timeBegin + delta; |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
100 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
_LIT(KTestFormat, "%/0%1%/1%2%/2%3%/3"); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
102 |
TRAP_IGNORE(time.FormatL(dateStringBuf, KTestFormat)); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |
datePtr.Append(dateStringBuf); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
104 |
|
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
105 |
return aJni->NewString( |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
106 |
(const jchar*)datePtr.Ptr(), datePtr.Length()); |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
107 |
} |
2a9601315dfc
Revision: v2.1.22
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
108 |
|
80 | 109 |
JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_FormatterAvkon__1formatDigits |
110 |
(JNIEnv * aEnv, jclass, jstring str) |
|
49 | 111 |
{ |
112 |
jstring ret = str; |
|
113 |
std::wstring wstr = JniUtils::jstringToWstring(aEnv, str); |
|
114 |
HBufC* buf = S60CommonUtils::wstringToDes(wstr.c_str()); |
|
115 |
TPtr ptr(buf->Des()); |
|
116 |
||
117 |
#ifndef RD_JAVA_UI_QT |
|
118 |
AknTextUtils::LanguageSpecificNumberConversion( ptr ); |
|
119 |
#endif // RD_JAVA_UI_QT |
|
120 |
ret = S60CommonUtils::NativeToJavaString(*aEnv, ptr); |
|
121 |
delete buf; buf = NULL; |
|
122 |
return ret; |
|
123 |
} |
|
124 |
||
80 | 125 |
JNIEXPORT jint JNICALL Java_com_nokia_mj_impl_utils_ResourceLoader__1getLocaleId |
126 |
(JNIEnv *, jclass) |
|
49 | 127 |
{ |
80 | 128 |
return (jint)User::Language(); |
49 | 129 |
} |