/** * Implementation of PhoneGap and other APIs exposed in JavaScript. * This function is used to detect different messages and call the * respective function in MoSync. * * @return true if message was handled, false if not. */ bool PhoneGapMessageHandler::handlePhoneGapMessage(JSONMessage& message) { // Send device information to PhoneGap if ((message.getParam("service") == "Device") && (message.getParam("action") == "Get")) { sendDeviceProperties(message.getParam("PhoneGapCallBackId")); } // Process the vibration message else if ((message.getParam("service") == "Notification") && (message.getParam("action") == "vibrate")) { int duration = message.getArgsFieldInt("duration"); maVibrate(duration); } //Process the beep message else if ((message.getParam("service") == "Notification") && (message.getParam("action") == "beep")) { int repeatCount = message.getParamInt("args"); for (int i = 0; i < repeatCount; i++) { if (mBeepSound > 0) { maSoundPlay(mBeepSound, 0, maGetDataSize(mBeepSound)); } } } else if ((message.getParam("service") == "Connection") && (message.getParam("action") == "getConnectionInfo")) { sendConnectionType(message.getParam("PhoneGapCallBackId")); } else if ((message.getParam("service") == "Accelerometer") || (message.getParam("service") == "GeoLocation") || (message.getParam("service") == "Compass")) { mPhoneGapSensors.handleMessage(message); } else if (message.getParam("service") == "SensorManager") { mPhoneGapSensorManager.handleMessage(message); } else if (message.getParam("service") == "File") { mPhoneGapFile.handleMessage(message); } else if (message.getParam("service") == "PushNotification") { mPushNotificationManager.handleMessage(message); } else if (message.getParam("service") == "Capture") { mPhoneGapCapture.handleMessage(message); } else { // Message was not handled. return false; } // Message was handled. return true; }
/** * Implementation of PhoneGap and other APIs exposed in JavaScript. * This function is used to detect different messages and call the * respective function in MoSync. * * @return true if message was handled, false if not. */ bool PhoneGapMessageHandler::handlePhoneGapMessage(JSONMessage& message) { // MoSync servcies implemented on top of the PhoneGap protocol // for convenience. We can move this to its own message handler // at a later point. if ((message.getParam("service") == "mosync") && (message.getParam("action") == "mosync.notification.messageBox")) { String titleText = message.getParam("title"); String messageText = message.getParam("message"); maMessageBox(titleText.c_str(), messageText.c_str()); } // Send device information to PhoneGap else if ((message.getParam("service") == "Device") && (message.getParam("action") == "Get")) { sendDeviceProperties(message.getParam("PhoneGapCallBackId")); } // Process the vibration message else if ((message.getParam("service") == "Notification") && (message.getParam("action") == "vibrate")) { int duration = message.getArgsFieldInt("duration"); maVibrate(duration); } //Process the beep message else if ((message.getParam("service") == "Notification") && (message.getParam("action") == "beep")) { int repeatCount = message.getParamInt("args"); for (int i = 0; i < repeatCount; i++) { if (mBeepSound > 0) { maSoundPlay(mBeepSound, 0, maGetDataSize(mBeepSound)); } } } else if ((message.getParam("service") == "Connection") && (message.getParam("action") == "getConnectionInfo")) { sendConnectionType(message.getParam("PhoneGapCallBackId")); } else if ((message.getParam("service") == "Accelerometer") || (message.getParam("service") == "GeoLocation") || (message.getParam("service") == "Compass")) { mPhoneGapSensors.handleMessage(message); } else if (message.getParam("service") == "SensorManager") { mPhoneGapSensorManager.handleMessage(message); } else if (message.getParam("service") == "File") { mPhoneGapFile.handleMessage(message); } else if (message.getParam("service") == "PushNotification") { mPushNotificationManager.handleMessage(message); } else if (message.getParam("service") == "Capture") { mPhoneGapCapture.handleMessage(message); } else { // Message was not handled. return false; } // Message was handled. return true; }