From a1c4737a23609a00aa14ec8be11c38e32bdc99d4 Mon Sep 17 00:00:00 2001 From: Ian Macphail Date: Wed, 17 Apr 2013 16:08:18 +0100 Subject: [PATCH] changes to enable dynamic loading of AdModule class if available --- .../src/java/com/runrev/android/Engine.java | 32 ++++++++--------- engine/src/mblad.cpp | 3 ++ engine/src/mblandroidad.cpp | 35 +++++++++++++++++-- engine/src/mbliphonead.mm | 8 +++++ 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/engine/src/java/com/runrev/android/Engine.java b/engine/src/java/com/runrev/android/Engine.java index 5bee20dcd83..566c999d520 100644 --- a/engine/src/java/com/runrev/android/Engine.java +++ b/engine/src/java/com/runrev/android/Engine.java @@ -103,7 +103,6 @@ public class Engine extends View private NativeControlModule m_native_control_module; private SoundModule m_sound_module; private NotificationModule m_notification_module; - /* private AdModule m_ad_module; */ private PowerManager.WakeLock m_wake_lock; @@ -149,7 +148,6 @@ public void handleMessage(Message p_message) { m_native_control_module = new NativeControlModule(this, ((LiveCodeActivity)getContext()).s_main_layout); m_sound_module = new SoundModule(this); m_notification_module = new NotificationModule(this); - /* m_ad_module = new AdModule(this, ((LiveCodeActivity)getContext()).s_main_layout); */ // MM-2012-08-03: [[ Bug 10316 ]] Initialise the wake lock object. PowerManager t_power_manager = (PowerManager) p_context.getSystemService(p_context.POWER_SERVICE); @@ -931,22 +929,24 @@ Object createInputControl() //////////////////////////////////////////////////////////////////////////////// - /* - // ad functionality - void addAd(Object p_control) - { - } + // IM-2013-04-17: [[ AdModule ]] attempt to load AdModule class, returning null if the class cannot be found + Object loadAdModule() + { + try + { + Class t_ad_module_class; + Constructor t_ad_module_constructor; - void removeAd(Object p_control) - { - m_ad_module.removeAd(p_control); - } + t_ad_module_class = Class.forName("com.runrev.android.AdModule"); + t_ad_module_constructor = t_ad_module_class.getConstructor(new Class[] {Engine.class, ViewGroup.class}); - Object createInneractiveAd(String p_key, int p_type, int p_left, int p_top, int p_timeout, Map p_meta_data) - { - return m_ad_module.createInneractiveAd(p_key, p_type, p_left, p_top, p_timeout, p_meta_data); - } - */ + return t_ad_module_constructor.newInstance(new Object[] {this, ((LiveCodeActivity)getContext()).s_main_layout}); + } + catch (Exception e) + { + return null; + } + } //////////////////////////////////////////////////////////////////////////////// diff --git a/engine/src/mblad.cpp b/engine/src/mblad.cpp index f81f05c51a8..050d581b910 100644 --- a/engine/src/mblad.cpp +++ b/engine/src/mblad.cpp @@ -45,6 +45,7 @@ along with LiveCode. If not see . */ //////////////////////////////////////////////////////////////////////////////// bool MCParseParameters(MCParameter*& p_parameters, const char *p_format, ...); +void MCSystemInneractiveAdInit(); bool MCSystemInneractiveAdCreate(MCExecContext &ctxt, MCAd*& r_ad, MCAdType p_type, MCAdTopLeft p_top_left, uint32_t p_timeout, MCVariableValue *p_meta_data); //////////////////////////////////////////////////////////////////////////////// @@ -59,6 +60,8 @@ void MCAdInitialize(void) s_ads = nil; s_last_ad_id = 0; s_inneractive_ad_key = nil; + + MCSystemInneractiveAdInit(); } void MCAdFinalize(void) diff --git a/engine/src/mblandroidad.cpp b/engine/src/mblandroidad.cpp index f9fcb23057a..b823653ed50 100644 --- a/engine/src/mblandroidad.cpp +++ b/engine/src/mblandroidad.cpp @@ -48,6 +48,10 @@ along with LiveCode. If not see . */ //////////////////////////////////////////////////////////////////////////////// +static jobject s_admodule = nil; + +//////////////////////////////////////////////////////////////////////////////// + class MCAndroidInneractiveAd : public MCAd { public: @@ -86,7 +90,7 @@ MCAndroidInneractiveAd::MCAndroidInneractiveAd(MCAdType p_type, MCAdTopLeft p_to bool MCAndroidInneractiveAd::Create(void) { - MCAndroidEngineRemoteCall("createInneractiveAd", "osiiiim", &m_view, MCAdGetInneractiveKey(), m_type, m_top_left.x, m_top_left.y, m_timeout, m_meta_data); + MCAndroidObjectRemoteCall(s_admodule, "createInneractiveAd", "osiiiim", &m_view, MCAdGetInneractiveKey(), m_type, m_top_left.x, m_top_left.y, m_timeout, m_meta_data); if (m_meta_data != nil) { JNIEnv *env; @@ -104,7 +108,7 @@ void MCAndroidInneractiveAd::Delete() if (m_view != nil) { - MCAndroidEngineRemoteCall("removeAd", "vo", nil, m_view); + MCAndroidObjectRemoteCall(s_admodule, "removeAd", "vo", nil, m_view); env->DeleteGlobalRef(m_view); m_view = nil; } @@ -167,8 +171,31 @@ bool MCAndroidInneractiveAd::FindByView(jobject p_view, MCAndroidInneractiveAd * //////////////////////////////////////////////////////////////////////////////// +void MCSystemInneractiveAdInit() +{ + s_admodule = nil; +} + +////////// + +// IM-2013-04-17: [[ AdModule ]] call out to Engine method to load AdModule class +bool MCAndroidInneractiveAdInitModule() +{ + if (s_admodule != nil) + return true; + + MCAndroidEngineCall("loadAdModule", "o", &s_admodule); + + return s_admodule != nil; +} + +////////// + bool MCSystemInneractiveAdCreate(MCExecContext &ctxt, MCAd *&r_ad, MCAdType p_type, MCAdTopLeft p_top_left, uint32_t p_timeout, MCVariableValue *p_meta_data) { + if (!MCAndroidInneractiveAdInitModule()) + return false; + bool t_success; t_success = true; @@ -234,6 +261,10 @@ JNIEXPORT void JNICALL Java_com_runrev_android_InneractiveAdWrapper_doAdUpdate(J #else +void MCSystemInneractiveAdInit() +{ +} + bool MCSystemInneractiveAdCreate(MCExecContext &ctxt, MCAd *&r_ad, MCAdType p_type, MCAdTopLeft p_top_left, uint32_t p_timeout, MCVariableValue *p_meta_data) { return false; diff --git a/engine/src/mbliphonead.mm b/engine/src/mbliphonead.mm index a11a901929d..aa43bbaf303 100644 --- a/engine/src/mbliphonead.mm +++ b/engine/src/mbliphonead.mm @@ -423,6 +423,10 @@ static void do_display_ad(void *p_context) //////////////////////////////////////////////////////////////////////////////// +void MCSystemInneractiveAdInit() +{ +} + bool MCSystemInneractiveAdCreate(MCExecContext &ctxt, MCAd*& r_ad, MCAdType p_type, MCAdTopLeft p_top_left, uint32_t p_timeout, MCVariableValue *p_meta_data) { NSMutableDictionary *t_meta_data; @@ -455,6 +459,10 @@ bool MCSystemInneractiveAdCreate(MCExecContext &ctxt, MCAd*& r_ad, MCAdType p_ty #else +void MCSystemInneractiveAdInit() +{ +} + bool MCSystemInneractiveAdCreate(MCExecContext &ctxt, MCAd*& r_ad, MCAdType p_type, MCAdTopLeft p_top_left, uint32_t p_timeout, MCVariableValue *p_meta_data) { return false;