javauis/mmapi_qt/volumekeys/src/Foreground.cpp
branchRCL_3
changeset 24 0fd27995241b
child 26 dc7c549001d5
equal deleted inserted replaced
20:f9bb0fca356a 24:0fd27995241b
       
     1 /*
       
     2 * Copyright (c) 2006 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:  JNI implementation for handling midlet foreground status
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // EXTERNAL INCLUDES
       
    20 //#include <jutils.h>
       
    21 #include <logger.h>
       
    22 
       
    23 //#include <mswtclient.h>
       
    24 //#include <swtcliententry.h>
       
    25 
       
    26 // INTERNAL INCLUDES
       
    27 #include "com_nokia_microedition_volumekeys_ForegroundListener.h"
       
    28 #include "cmmaforeground.h"
       
    29 #include "mmafunctionserver.h"
       
    30 #include "cmmaglobalvolume.h"
       
    31 
       
    32 // for xm-radio fix
       
    33 //#include "CMIDToolkit.h"
       
    34 
       
    35 /**
       
    36  * Static delegator function for initialize.
       
    37  * @param aReturnHandle Native class object.
       
    38  * @param aEventSource Event source handle.
       
    39  * @param aForegroundListener ForegroundListener java object.
       
    40  * @param aJavaMethod java method ID.
       
    41  */
       
    42 LOCAL_C void CreateForegroundL(
       
    43     TInt* aReturnHandle,
       
    44     MMAFunctionServer* aEventSource,
       
    45     jobject aForegroundListener,
       
    46     jmethodID aJavaMethod/*,
       
    47     CMIDToolkit* aToolkit*/) // xm-radio fix
       
    48 {
       
    49     CMMAForeground* foreground =
       
    50         CMMAForeground::NewL(aEventSource,
       
    51                              aForegroundListener,
       
    52                              aJavaMethod/*,
       
    53                              aToolkit */// xm-radio fix
       
    54                             );
       
    55     CleanupStack::PushL(foreground);
       
    56 
       
    57     // Create global volume which handles the volume events
       
    58     CMMAGlobalVolume* globalVolume = CMMAGlobalVolume::NewL(foreground);
       
    59     // Global volume takes the ownership of the foreground listener
       
    60     CleanupStack::Pop(foreground);
       
    61     // Set global volume to MMA event source. The ownership transfers to
       
    62     // MMA event sources as it handles adding and removing players
       
    63     aEventSource->SetGlobalVolume(globalVolume);
       
    64     *aReturnHandle = reinterpret_cast <TInt>(foreground);
       
    65 }
       
    66 
       
    67 /*
       
    68  * Class:     com_nokia_microedition_volumekeys_ForegroundListener
       
    69  * Method:    _initialize
       
    70  * Signature: (ILjava/lang/Object;)I
       
    71  */
       
    72 JNIEXPORT jint JNICALL Java_com_nokia_microedition_volumekeys_ForegroundListener__1initialize
       
    73 (JNIEnv* aJni,
       
    74  jobject /*aJobject*/,
       
    75  jint aEventSourceHandle,
       
    76  jobject aForegroundListener /*,
       
    77  jint aToolkitHandle*/)   // for xm-radio fix
       
    78 {
       
    79     MMAFunctionServer* eventSource =
       
    80     	reinterpret_cast< MMAFunctionServer *>(aEventSourceHandle);
       
    81 
       
    82     jobject fgListenerObject = NULL;
       
    83     fgListenerObject = aJni->NewWeakGlobalRef(aForegroundListener);
       
    84 
       
    85     jclass foregroundListenerClass = aJni->GetObjectClass(fgListenerObject);
       
    86 
       
    87     jmethodID javaMethod = aJni->GetMethodID(
       
    88                                foregroundListenerClass,
       
    89                                "update",
       
    90                                "()V");
       
    91 
       
    92     TInt foregroundHandle = NULL;
       
    93 
       
    94     // xm-radio fix
       
    95     /*
       
    96     CMIDToolkit* ptoolkit = JavaUnhand< CMIDToolkit >(aToolkitHandle);
       
    97 */
       
    98     jint error = eventSource->ExecuteTrap(CreateForegroundL,
       
    99                                           &foregroundHandle,
       
   100                                           eventSource,
       
   101                                           fgListenerObject,
       
   102                                           javaMethod/*,
       
   103                                           ptoolkit*/);  // xm-radio fix
       
   104 
       
   105     if (error != KErrNone)
       
   106     {
       
   107         aJni->DeleteGlobalRef(fgListenerObject);
       
   108     }
       
   109 
       
   110     return (error != KErrNone) ? error : foregroundHandle;
       
   111 }
       
   112 
       
   113 /**
       
   114  * Static delegator function for setforeground
       
   115  * @param aCMMAForeground native class.
       
   116  * @param aIsForeground boolean is midlet foreground or not.
       
   117 
       
   118  */
       
   119 LOCAL_C void SetForeground(
       
   120     CMMAForeground* aCMMAForeground,
       
   121     TBool aIsForeground)
       
   122 {
       
   123     aCMMAForeground->SetForeground(aIsForeground);
       
   124 }
       
   125 
       
   126 /*
       
   127 * Class:     com_nokia_microedition_volumekeys_ForegroundListener
       
   128 * Method:    _setForeground
       
   129 * Signature: (IZ)V
       
   130 */
       
   131 JNIEXPORT void JNICALL Java_com_nokia_microedition_volumekeys_ForegroundListener__1setForeground
       
   132 (JNIEnv* /*aJni*/,
       
   133  jobject /*aJobject*/,
       
   134  jint aEventSourceHandle,
       
   135  jint aForegroundHandle,
       
   136  jboolean aIsForeground)
       
   137 {
       
   138     MMAFunctionServer* eventSource =
       
   139         reinterpret_cast<MMAFunctionServer*>(aEventSourceHandle);
       
   140 
       
   141     CMMAForeground* nativeHandle =
       
   142         reinterpret_cast<CMMAForeground*>(aForegroundHandle);
       
   143 
       
   144     eventSource->ExecuteV(SetForeground,
       
   145                           nativeHandle,
       
   146                           (TBool) aIsForeground);
       
   147 }
       
   148 
       
   149 
       
   150 /*
       
   151 JNIEXPORT jboolean JNICALL Java_com_nokia_microedition_volumekeys_ForegroundListener__1isESWT
       
   152 (JNIEnv *, jobject)
       
   153 {
       
   154 
       
   155 
       
   156     MSwtClient* client = NULL;
       
   157     TRAP_IGNORE(client = SWT::CreateClientL());
       
   158 
       
   159     if (!client)
       
   160     {
       
   161         return false; // LCDUI midlet running
       
   162     }
       
   163     else
       
   164     {
       
   165         delete client;
       
   166         client = NULL;
       
   167         return true;  // eSWT midlet running
       
   168     }
       
   169 }
       
   170 
       
   171 */
       
   172 //  END OF FILE