javacommons/utils/src.s60/formatternative.cpp
changeset 49 35baca0e7a2e
parent 21 2a9601315dfc
child 80 d6dafc5d983f
equal deleted inserted replaced
35:85266cc22c7f 49:35baca0e7a2e
    14 * Description:  formatternative
    14 * Description:  formatternative
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 //#include <avkon.rsg>
       
    20 #include <memory>
    19 #include <memory>
    21 #include <stringresourcereader.h>
    20 #include <stringresourcereader.h>
       
    21 
       
    22 #ifdef RD_JAVA_UI_QT
       
    23 #include <QLocale>
       
    24 #else // RD_JAVA_UI_QT
       
    25 #include <AknUtils.h>
       
    26 #endif // RD_JAVA_UI_QT
    22 
    27 
    23 #include "com_nokia_mj_impl_utils_Formatter.h"
    28 #include "com_nokia_mj_impl_utils_Formatter.h"
    24 #include "com_nokia_mj_impl_utils_ResourceLoader.h"
    29 #include "com_nokia_mj_impl_utils_ResourceLoader.h"
    25 #include "javajniutils.h"
    30 #include "javajniutils.h"
       
    31 #include "s60commonutils.h"
    26 #include "logger.h"
    32 #include "logger.h"
    27 
    33 
    28 enum EDateTimeFormat
    34 enum EDateTimeFormat
    29 {
    35 {
    30     DATE_LONG       = 1,
    36     DATE_LONG       = 1,
    39 const TUint JavaLowerTimeFor1970 = 254771200;
    45 const TUint JavaLowerTimeFor1970 = 254771200;
    40 
    46 
    41 // const TInt KMaxDateTimeStringSize = 50;
    47 // const TInt KMaxDateTimeStringSize = 50;
    42 const TInt KMaxDateFormatSize = 30;
    48 const TInt KMaxDateFormatSize = 30;
    43 const TInt KMaxNumberFormatSize = 40;
    49 const TInt KMaxNumberFormatSize = 40;
       
    50 using namespace java::util;
    44 
    51 
    45 // _LIT( KAvkonResFile, "z:\\resource\\avkon.rsc" );
       
    46 
    52 
    47 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_Formatter__1formatInteger
    53 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_Formatter__1formatInteger
    48 (JNIEnv *aJni, jobject, jint aNumber)
    54 (JNIEnv *aJni, jobject, jint aNumber)
    49 {
    55 {
    50     JELOG2(EUtils);
    56     JELOG2(EUtils);
    62     if (error < KErrNone)
    68     if (error < KErrNone)
    63     {
    69     {
    64         WLOG2(EUtils,
    70         WLOG2(EUtils,
    65               "Cannot format %d to current locale. Error: %d", aNumber, error);
    71               "Cannot format %d to current locale. Error: %d", aNumber, error);
    66     }
    72     }
       
    73 
       
    74 #ifndef RD_JAVA_UI_QT
       
    75         AknTextUtils::LanguageSpecificNumberConversion( numberPtr );
       
    76 #endif // RD_JAVA_UI_QT
    67 
    77 
    68     return aJni->NewString(
    78     return aJni->NewString(
    69                (const jchar*)numberPtr.Ptr(), numberPtr.Length());
    79                (const jchar*)numberPtr.Ptr(), numberPtr.Length());
    70 }
    80 }
    71 
    81 
   103 
   113 
   104 {
   114 {
   105     return (jint)User::Language();
   115     return (jint)User::Language();
   106 }
   116 }
   107 
   117 
       
   118 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_Formatter__1formatDigits
       
   119   (JNIEnv * aEnv, jclass, jstring str)
       
   120 {
       
   121     jstring ret = str;
       
   122     std::wstring wstr = JniUtils::jstringToWstring(aEnv, str);
       
   123     HBufC* buf = S60CommonUtils::wstringToDes(wstr.c_str());
       
   124     TPtr ptr(buf->Des());
       
   125 
       
   126 #ifndef RD_JAVA_UI_QT
       
   127     AknTextUtils::LanguageSpecificNumberConversion( ptr );
       
   128 #endif // RD_JAVA_UI_QT
       
   129     ret = S60CommonUtils::NativeToJavaString(*aEnv, ptr);
       
   130     delete buf; buf = NULL;
       
   131     return ret;
       
   132 }
       
   133 
       
   134 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_utils_ResourceLoader__1getLocaleIdQt
       
   135   (JNIEnv *env, jclass)
       
   136 {
       
   137 #ifdef RD_JAVA_UI_QT
       
   138     QString localeName = QLocale::system().name();
       
   139     jstring loc = env->NewString(localeName.utf16(), localeName.size());
       
   140     return loc;
       
   141 #else // RD_JAVA_UI_QT
       
   142     (void)env;     // just to suppress a warning
       
   143     return NULL;
       
   144 #endif // RD_JAVA_UI_QT
       
   145 }