TEST_DEFINE_TEST(TestCtx, ObjectTests) { auto t = Module.GetRootObject<test::IObjectTests>("GetTests"); if (!t) { TEST_REPORT_ERROR("ObjectTests not implemented!"); return; } auto some_obj = t->ReturnNewObject(); TEST_THROWS_NOTHING(some_obj->Method()); TEST_EQUALS((bool)t->ReturnNull(), false); TEST_EQUALS(t->CheckNotNull(nullptr), false); TEST_EQUALS(t->CheckNotNull(some_obj), true); TEST_EQUALS((bool)t->CallbackReturn(Ctx.MakeComponent<test::IObjectTestsCallbackReturn, ObjectTestsCallback>(some_obj)), true); auto cb = Ctx.MakeComponent<test::IObjectTestsCallbackReturn, ObjectTestsCallback>(nullptr); TEST_EQUALS((bool)t->CallbackReturn(cb), false); TEST_EQUALS(t->CallbackParam(joint::Cast<test::IObjectTestsCallbackParam>(cb), nullptr), false); TEST_EQUALS(t->CallbackParam(joint::Cast<test::IObjectTestsCallbackParam>(cb), some_obj), true); auto o_impl = Ctx.MakeComponentWrapper<SomeObject>(); auto o = Ctx.MakeComponentProxy<test::ISomeObject>(o_impl); TEST_THROWS_NOTHING(t->InvokeObjectMethod(o)); TEST_EQUALS(o_impl->GetInvokationsCount(), 1); auto o2 = t->ReturnSameObject(o); o2->Method(); TEST_EQUALS(o_impl->GetInvokationsCount(), 2); }
static jobject NewPurchaseManagerObject(string pubkey) { if (!jni->purchases_class) jni->purchases_class = CheckNotNull (jclass(jni->env->NewGlobalRef(jni->env->FindClass("com/lucidfusionlabs/billing/PurchaseManager")))); static jmethodID mid = CheckNotNull (jni->env->GetStaticMethodID(jni->purchases_class, "createStaticInstance", "(Lcom/lucidfusionlabs/core/LifecycleActivity;Ljava/lang/String;)Lcom/lucidfusionlabs/billing/PurchaseManager;")); LocalJNIString pk(jni->env, JNI::ToJString(jni->env, pubkey)); return jni->env->CallStaticObjectMethod(jni->purchases_class, mid, jni->activity, pk.v); }
static jobject NewAdvertisingObject(int t, int p, const string &did, const StringVec &td) { if (!jni->advertising_class) jni->advertising_class = CheckNotNull (jclass(jni->env->NewGlobalRef(jni->env->FindClass("com/lucidfusionlabs/ads/Advertising")))); static jmethodID mid = CheckNotNull (jni->env->GetStaticMethodID(jni->advertising_class, "createStaticInstance", "(Lcom/lucidfusionlabs/core/LifecycleActivity;IILjava/lang/String;Ljava/util/List;)Lcom/lucidfusionlabs/ads/Advertising;")); LocalJNIString di(jni->env, JNI::ToJString(jni->env, did)); LocalJNIObject l(jni->env, JNI::ToJStringArrayList(jni->env, td)); return jni->env->CallStaticObjectMethod(jni->advertising_class, mid, jni->activity, jint(t), jint(p), di.v, l.v); }
void PreparePurchase(const StringVec &products, Callback done_cb, PurchasesInterface::ProductCB product_cb) { static jmethodID mid = CheckNotNull (jni->env->GetMethodID(jni->purchases_class, "queryPurchase", "(Ljava/util/ArrayList;Lcom/lucidfusionlabs/core/NativeCallback;Lcom/lucidfusionlabs/billing/NativeProductCB;)Z")); LocalJNIObject p(jni->env, JNI::ToJStringArrayList(jni->env, products)); LocalJNIObject dcb(jni->env, done_cb ? JNI::ToNativeCallback(jni->env, move(done_cb)) : nullptr); LocalJNIObject pcb(jni->env, product_cb ? ToNativeProductCB(jni->env, move(product_cb)) : nullptr); jni->env->CallBooleanMethod(impl.v, mid, p.v, dcb.v, pcb.v); }
bool MakePurchase(ProductInterface *product, IntCB result_cb) { static jmethodID mid = CheckNotNull (jni->env->GetMethodID(jni->purchases_class, "makePurchase", "(Ljava/lang/String;Lcom/lucidfusionlabs/core/NativeIntCB;)Z")); if (!product) return false; LocalJNIObject rcb(jni->env, result_cb ? JNI::ToNativeIntCB(jni->env, move(result_cb)) : nullptr); LocalJNIString pid(jni->env, JNI::ToJString(jni->env, product->id)); return jni->env->CallBooleanMethod(impl.v, mid, pid.v, rcb.v); }
void Show(TableViewInterface *t, bool show_or_hide) { static jmethodID mid = CheckNotNull(jni->env->GetMethodID(jni->tablescreen_class, "setAdvertising", "(Landroid/support/v7/app/AppCompatActivity;Lcom/lucidfusionlabs/core/ViewOwner;)V")); jni->env->CallVoidMethod(dynamic_cast<AndroidTableView*>(t)->impl.v, mid, jni->activity, show_or_hide ? impl.v : nullptr); }
void Audio::PlayBackgroundMusic(SoundAsset *sa) { JNI *jni = Singleton<LFL::JNI>::Get(); static jmethodID jni_activity_method_play_background_music = CheckNotNull(jni->env->GetMethodID(jni->activity_class, "playBackgroundMusic", "(Landroid/media/MediaPlayer;)V")); jni->env->CallVoidMethod(jni->activity, jni_activity_method_play_background_music, jobject(sa->handle)); }
void Audio::SetVolume(int v) { JNI *jni = Singleton<LFL::JNI>::Get(); static jmethodID mid = CheckNotNull(jni->env->GetMethodID(jni->activity_class, "setVolume", "(I)V")); jint jv = v; return jni->env->CallVoidMethod(jni->activity, mid, jv); }
int Audio::GetVolume() { JNI *jni = Singleton<LFL::JNI>::Get(); static jmethodID mid = CheckNotNull(jni->env->GetMethodID(jni->activity_class, "getVolume", "()I")); return jni->env->CallIntMethod(jni->activity, mid); }
void RestorePurchases(Callback done_cb) { static jmethodID mid = CheckNotNull (jni->env->GetMethodID(jni->purchases_class, "restorePurchases", "()Z")); if (jni->env->CallBooleanMethod(impl.v, mid) && done_cb) done_cb(); }
void LoadPurchases() { static jmethodID mid = CheckNotNull (jni->env->GetMethodID(jni->purchases_class, "loadPurchasesFromInternalStorage", "()Z")); jni->env->CallBooleanMethod(impl.v, mid); }
bool HavePurchase(const string &product_id) { static jmethodID mid = CheckNotNull (jni->env->GetMethodID(jni->purchases_class, "havePurchase", "(Ljava/lang/String;)Z")); LocalJNIString p(jni->env, JNI::ToJString(jni->env, product_id)); return jni->env->CallBooleanMethod(impl.v, mid, p.v); }
bool CanPurchase() { static jmethodID mid = CheckNotNull (jni->env->GetMethodID(jni->purchases_class, "canPurchase", "()Z")); return jni->env->CallBooleanMethod(impl.v, mid); }
static jobject ToNativeProductCB(JNIEnv *env, PurchasesInterface::ProductCB c) { static jclass nativeproductcb_class = CheckNotNull(jclass(env->NewGlobalRef(env->FindClass("com/lucidfusionlabs/billing/NativeProductCB")))); static jmethodID mid = CheckNotNull(env->GetMethodID(nativeproductcb_class, "<init>", "(J)V")); jlong cb = uintptr_t(new PurchasesInterface::ProductCB(move(c))); return env->NewObject(nativeproductcb_class, mid, cb); }