javauis/runtimeui_akn/src.s60/jni.cpp
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 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:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "javajniutils.h"
       
    20 #include "jstringutils.h"
       
    21 #include "runtimeuiavkon.h"
       
    22 #include "com_nokia_mj_impl_rt_ui_avkon_RuntimeUiAvkon.h"
       
    23 
       
    24 using namespace java::runtimeui;
       
    25 
       
    26 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_rt_ui_avkon_RuntimeUiAvkon__1confirm
       
    27 (JNIEnv * aEnv, jobject, jstring aAppName, jobject aConfirmData, jboolean aIdentified)
       
    28 {
       
    29     // unmarshall the JNI parameters
       
    30     JStringUtils appName(*aEnv, aAppName);
       
    31     jclass confirmDataClass = aEnv->GetObjectClass(aConfirmData);
       
    32     jmethodID getQuestionMethod = aEnv->GetMethodID(
       
    33                                       confirmDataClass,"getQuestion", "()Ljava/lang/String;");
       
    34     jstring jQuestion = (jstring)aEnv->CallObjectMethod(
       
    35                             aConfirmData, getQuestionMethod);
       
    36     JStringUtils question(*aEnv, jQuestion);
       
    37     std::vector<HBufC*> answerOptions;
       
    38     jmethodID getAnswerOptionsMethod = aEnv->GetMethodID(
       
    39                                            confirmDataClass,"getAnswerOptions", "()[Ljava/lang/String;");
       
    40     jobjectArray jAnswerOptions = (jobjectArray)aEnv->CallObjectMethod(
       
    41                                       aConfirmData, getAnswerOptionsMethod);
       
    42     bool answerAvailable = -1;
       
    43     TRAP_IGNORE(
       
    44         if (jAnswerOptions != NULL)
       
    45 {
       
    46     int len = aEnv->GetArrayLength(jAnswerOptions);
       
    47         answerOptions.reserve(len);
       
    48         for (int i=0; i<len; i++)
       
    49         {
       
    50             jstring jAnswerOption = (jstring)aEnv->GetObjectArrayElement(
       
    51                                         jAnswerOptions, i);
       
    52             JStringUtils answerOption(*aEnv, jAnswerOption);
       
    53             answerOptions.push_back(answerOption.AllocLC());
       
    54         }
       
    55     }
       
    56     jmethodID getAnswerSuggestionMethod = aEnv->GetMethodID(
       
    57                                               confirmDataClass,"getAnswerSuggestion", "()I");
       
    58     jint jAnswerSuggestion = (jint)aEnv->CallIntMethod(
       
    59                                  aConfirmData, getAnswerSuggestionMethod);
       
    60     ConfirmData confirmData(question, answerOptions, jAnswerSuggestion);
       
    61     // delegate the UI implementation to handle the confirm operation
       
    62     answerAvailable = RuntimeUiAvkon::confirm(appName, confirmData, aIdentified);
       
    63     // cleanup the vector
       
    64     for (int i=0; i<answerOptions.size(); i++)
       
    65 {
       
    66     CleanupStack::PopAndDestroy();
       
    67     }
       
    68     answerOptions.clear();
       
    69     // marshall the answer back to Java
       
    70     jmethodID setAnswerMethod = aEnv->GetMethodID(
       
    71                                     confirmDataClass,"setAnswer", "(I)V");
       
    72     aEnv->CallVoidMethod(aConfirmData, setAnswerMethod, confirmData.iAnswer);
       
    73     );
       
    74     return answerAvailable;
       
    75 }
       
    76 
       
    77 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_rt_ui_avkon_RuntimeUiAvkon__1error
       
    78 (JNIEnv * aEnv, jobject, jstring aAppName, jstring aShortMsg, jstring aDetailedMsg)
       
    79 {
       
    80     // unmarshall the JNI parameters
       
    81     JStringUtils appName(*aEnv, aAppName);
       
    82     JStringUtils shortMsg(*aEnv, aShortMsg);
       
    83     JStringUtils detailedMsg(*aEnv, aDetailedMsg);
       
    84     // delegate the UI implementation to handle the error operation
       
    85     RuntimeUiAvkon::error(appName, shortMsg, detailedMsg);
       
    86 }