//--------------------------------------------------------------- //--------------------------------------------------------------- void GooglePlayIAPJavaInterface::StartListeningForTransactionUpdates(const CSNetworking::IAPSystem::TransactionStatusDelegate& in_delegate) { CS_ASSERT(in_delegate != nullptr, "Cannot have null transaction delegate"); m_transactionStatusDelegate = in_delegate; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); env->CallVoidMethod(GetJavaObject(), GetMethodID("RestorePendingUnmanagedTransactions")); Json::Value jData; if(CSCore::JsonUtils::ReadJson(CSCore::StorageLocation::k_cache, k_pendingCacheFile, jData)) { const Json::Value::Members& members = jData.getMemberNames(); jobjectArray transactionIDs = env->NewObjectArray(members.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); u32 index = 0; for(Json::Value::Members::const_iterator it = members.begin(); it != members.end(); ++it, ++index) { jstring jtransactionId = JavaInterfaceUtils::CreateJStringFromSTDString(*it); env->SetObjectArrayElement(transactionIDs, index, jtransactionId); env->DeleteLocalRef(jtransactionId); } env->CallVoidMethod(GetJavaObject(), GetMethodID("RestorePendingManagedTransactions"), transactionIDs); env->DeleteLocalRef(transactionIDs); } }
ActivityState* ActivityState::create(ANativeActivity* activity) { JOP_ASSERT(ns_instance == nullptr, "There must only be one ActivityState!"); ns_instance.reset(new ActivityState); ns_instance->nativeActivity = activity; ANativeActivity_setWindowFlags(activity, AWINDOW_FLAG_KEEP_SCREEN_ON, AWINDOW_FLAG_KEEP_SCREEN_ON); Thread::attachJavaThread(activity->vm, activity->env); // Get the screen size { auto env = Thread::getCurrentJavaEnv(); if (!env) { JOP_DEBUG_ERROR("No current java environment, function \"" << __func__ << "\""); return get(); } jclass activityClass = env->GetObjectClass(activity->clazz); jclass displayMetricsClass = env->FindClass("android/util/DisplayMetrics"); jmethodID displayMetricsInit = env->GetMethodID(displayMetricsClass, "<init>", "()V"); jobject displayMetricsObject = env->NewObject(displayMetricsClass, displayMetricsInit); jmethodID getWindowManagerMethod = env->GetMethodID(activityClass, "getWindowManager", "()Landroid/view/WindowManager;"); jobject windowManagerObject = env->CallObjectMethod(activity->clazz, getWindowManagerMethod); jclass windowManagerClass = env->FindClass("android/view/WindowManager"); jmethodID getDefaultDisplayMethod = env->GetMethodID(windowManagerClass, "getDefaultDisplay", "()Landroid/view/Display;"); jobject displayObject = env->CallObjectMethod(windowManagerObject, getDefaultDisplayMethod); jclass displayClass = env->FindClass("android/view/Display"); jmethodID getMetricsMethod = env->GetMethodID(displayClass, "getMetrics", "(Landroid/util/DisplayMetrics;)V"); env->CallVoidMethod(displayObject, getMetricsMethod, displayMetricsObject); jfieldID pixelsWidth = env->GetFieldID(displayMetricsClass, "widthPixels", "I"); jfieldID pixelsHeight = env->GetFieldID(displayMetricsClass, "heightPixels", "I"); ns_instance->screenSize.x = env->GetIntField(displayMetricsObject, pixelsWidth); ns_instance->screenSize.y = env->GetIntField(displayMetricsObject, pixelsHeight); //jmethodID getRefreshRateMethod = env->GetMethodID(displayClass, "getRefreshRate", "(Landroid/view/Display;)F"); ns_instance->screenRefreshRate = 60;//env->CallFloatMethod(displayObject, getRefreshRateMethod); env->DeleteLocalRef(activityClass); env->DeleteLocalRef(displayMetricsObject); env->DeleteLocalRef(windowManagerObject); env->DeleteLocalRef(windowManagerClass); env->DeleteLocalRef(displayObject); env->DeleteLocalRef(displayClass); } return get(); }
template <class R> GVRActivityT<R>::GVRActivityT(JNIEnv & jni_, jobject activityObject_) : forceScreenClear( false ) , ModelLoaded( false ) , UiJni(&jni_) , viewManager(NULL) { viewManager = new GVRViewManager(jni_,activityObject_); javaObject = UiJni->NewGlobalRef( activityObject_ ); activityClass = GetGlobalClassReference( activityClassName ); vrAppSettingsClass = GetGlobalClassReference(app_settings_name); oneTimeInitMethodId = GetMethodID("oneTimeInit", "()V"); oneTimeShutdownMethodId = GetMethodID("oneTimeShutDown", "()V"); drawFrameMethodId = GetMethodID("drawFrame", "()V"); beforeDrawEyesMethodId = GetMethodID("beforeDrawEyes", "()V"); drawEyeViewMethodId = GetMethodID("onDrawEyeView", "(IF)V"); afterDrawEyesMethodId = GetMethodID("afterDrawEyes", "()V"); onKeyEventNativeMethodId = GetMethodID("onKeyEventNative", "(II)Z"); updateSensoredSceneMethodId = GetMethodID("updateSensoredScene", "()Z"); getAppSettingsMethodId = GetMethodID("getAppSettings", "()Lorg/gearvrf/utility/VrAppSettings;"); }
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pjvm, void *reserved) { ILOG("JNI_OnLoad"); gJvm = pjvm; // cache the JavaVM pointer auto env = getEnv(); //replace with one of your classes in the line below auto randomClass = env->FindClass("org/ppsspp/ppsspp/NativeActivity"); jclass classClass = env->GetObjectClass(randomClass); auto classLoaderClass = env->FindClass("java/lang/ClassLoader"); auto getClassLoaderMethod = env->GetMethodID(classClass, "getClassLoader", "()Ljava/lang/ClassLoader;"); gClassLoader = env->NewGlobalRef(env->CallObjectMethod(randomClass, getClassLoaderMethod)); gFindClassMethod = env->GetMethodID(classLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;"); return JNI_VERSION_1_6; }
static void bitmap_dispose(Class *cl, Object *obj, Msg *msg) { struct HIDDBitMapAmigaIntuiData *data = INST_DATA(cl, obj); struct pHidd_BitMap_PrivateSet private_set_msg; EnterFunc(bug("BitMapAmigaIntui::Dispose()\n")); if(data->screen) { /* We use an own buffer so set the BaseAddress to NULL to prevent the superclass to free our own buffer. */ struct TagItem set[] = { {aHidd_BitMap_BaseAddress, NULL}, {TAG_END , 0 } }; CloseScreen(data->screen); private_set_msg.mID = GetMethodID(IID_Hidd_BitMap, moHidd_BitMap_PrivateSet); private_set_msg.attrList = set; DoSuperMethod(cl, obj, (Msg) &private_set_msg); } DoSuperMethod(cl, obj, (Msg) msg); ReturnVoid("BitMapAmigaIntui::Dispose"); }
bool NetCenter::ConnectServiceWhitFD(int fd , const char* host_name, int port) { if (!_run_flg) { return false; } SocketAddress addr(host_name, port); CriticalSectionScoped css(&cs_); std::map<SOCKET, struct stSocketObj*>::iterator it = socket_objs.find(fd); if (socket_objs.end() == it) { return false; } if (it->second->dispatch->Connect(addr) != 0) { return false; } if (it->second->dispatch->GetState() == jsbn::AsyncSocket::CS_CONNECTED) { jmethodID m = GetMethodID(jni(), *j_observer_class_, "StatusReportWithFD", "(II)V"); jni()->CallVoidMethod(*j_observer_global_, m, it->second->dispatch->GetDescriptor(), (int)ENE_CONNECTED); } return true; }
//------------------------------------------------------- //------------------------------------------------------- void TextEntryJavaInterface::SetTextBuffer(const std::string& in_text) { JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring text = JavaInterfaceUtils::CreateJStringFromSTDString(in_text); env->CallVoidMethod(GetJavaObject(), GetMethodID("setTextBuffer"), text); env->DeleteLocalRef(text); }
//-------------------------------------------------------------- /// Present //-------------------------------------------------------------- void EmailComposerJavaInterface::Present(const std::vector<std::string>& inastrRecipientAddresses, const std::string& instrSubject, const std::string& instrContents, bool inbFormatAsHtml, const std::string& instrAttachmentFilename, const ResultDelegate& inDelegate) { mDelegate = inDelegate; JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); //build the recipient list u32 udwCount = 0; jobjectArray ajstrRecipients = pEnv->NewObjectArray(inastrRecipientAddresses.size(), pEnv->FindClass("java/lang/String"), pEnv->NewStringUTF("")); for(auto it = inastrRecipientAddresses.begin(); it != inastrRecipientAddresses.end(); ++it) { jstring jstrRecipient = JavaUtils::CreateJStringFromSTDString(*it); pEnv->SetObjectArrayElement(ajstrRecipients,udwCount++, jstrRecipient); pEnv->DeleteLocalRef(jstrRecipient); } jstring jstrSubject = JavaUtils::CreateJStringFromSTDString(instrSubject); jstring jstrContents = JavaUtils::CreateJStringFromSTDString(instrContents); jstring jstrAttachmentFilename = JavaUtils::CreateJStringFromSTDString(instrAttachmentFilename); //call method pEnv->CallVoidMethod(GetJavaObject(), GetMethodID("Present"), ajstrRecipients, jstrSubject, jstrContents, inbFormatAsHtml, jstrAttachmentFilename); //clean up pEnv->DeleteLocalRef(ajstrRecipients); pEnv->DeleteLocalRef(jstrSubject); pEnv->DeleteLocalRef(jstrContents); pEnv->DeleteLocalRef(jstrAttachmentFilename); }
//--------------------------------------------------------------- //--------------------------------------------------------------- void AmazonIAPJavaInterface::StopListeningForTransactionUpdates() { m_transactionStatusDelegate = nullptr; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); env->CallVoidMethod(GetJavaObject(), GetMethodID("StopListeningForTransactionUpdates")); }
//--------------------------------------------------------------- //--------------------------------------------------------------- void AmazonIAPJavaInterface::RequestProductDescriptions(const std::vector<std::string>& in_productIds, const CSNetworking::IAPSystem::ProductDescDelegate& in_delegate) { CS_ASSERT(in_productIds.empty() == false, "Cannot request no product descriptions"); CS_ASSERT(in_delegate != nullptr, "Cannot have null product description delegate"); CS_ASSERT(m_productsRequestDelegate == nullptr, "Only 1 product description request can be active at a time"); m_productsRequestDelegate = in_delegate; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring jstrEmptyString = env->NewStringUTF(""); jclass jStringClass = env->FindClass("java/lang/String"); jobjectArray productIDs = env->NewObjectArray(in_productIds.size(), jStringClass, jstrEmptyString); u32 productIDIndex = 0; for(std::vector<std::string>::const_iterator it = in_productIds.begin(); it != in_productIds.end(); ++it) { jstring productID = JavaUtils::CreateJStringFromSTDString(*it); env->SetObjectArrayElement(productIDs, productIDIndex, productID); env->DeleteLocalRef(productID); productIDIndex++; } env->CallVoidMethod(GetJavaObject(), GetMethodID("RequestProductDescriptions"), productIDs); env->DeleteLocalRef(productIDs); env->DeleteLocalRef(jstrEmptyString); env->DeleteLocalRef(jStringClass); }
//----------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------- TimeIntervalMs CoreJavaInterface::GetSystemTimeInMilliseconds() { TimeIntervalMs output = 0; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); output = (TimeIntervalMs)env->CallLongMethod(GetJavaObject(), GetMethodID("getSystemTimeInMilliseconds")); return output; }
//------------------------------------------------------ //------------------------------------------------------ void DialogueBoxJavaInterface::MakeToast(const std::string& in_text) { JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring message = JavaInterfaceUtils::CreateJStringFromSTDString(in_text); env->CallVoidMethod(GetJavaObject(), GetMethodID("makeToast"), message); env->DeleteLocalRef(message); }
void JniWebView::Deinitialize(int id) { controls.erase(id); jmethodID mid = GetMethodID("Deinitialize", "(I)V"); if (mid) GetEnvironment()->CallStaticVoidMethod(GetJavaClass(), mid, id); }
//--------------------------------------------------------------- //--------------------------------------------------------------- void AmazonIAPJavaInterface::RequestProductPurchase(const std::string& in_productId) { JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring productID = JavaUtils::CreateJStringFromSTDString(in_productId); env->CallVoidMethod(GetJavaObject(), GetMethodID("RequestProductPurchase"), productID); env->DeleteLocalRef(productID); }
void JniWebView::SetBackgroundTransparency(int id, bool enabled) { jmethodID mid = GetMethodID("SetBackgroundTransparency", "(IZ)V"); if (mid) { GetEnvironment()->CallStaticVoidMethod(GetJavaClass(), mid, id, enabled); } }
void JniWebView::SetVisible(int id, bool isVisible) { jmethodID mid = GetMethodID("SetVisible", "(IZ)V"); if (mid) { GetEnvironment()->CallStaticVoidMethod(GetJavaClass(), mid, id, isVisible); } }
void JniWebView::SetRect(int id, const Rect& controlRect) { Rect rect = V2P(controlRect); jmethodID mid = GetMethodID("SetRect", "(IFFFF)V"); if (mid) { GetEnvironment()->CallStaticVoidMethod(GetJavaClass(), mid, id, rect.x, rect.y, rect.dx, rect.dy); } }
void JniWebView::Initialize(WebViewControl* control, int id, const Rect& controlRect) { controls[id] = control; Rect rect = V2P(controlRect); jmethodID mid = GetMethodID("Initialize", "(IFFFF)V"); if (mid) GetEnvironment()->CallStaticVoidMethod(GetJavaClass(), mid, id, rect.x, rect.y, rect.dx, rect.dy); }
jobject invokeStaticMethod(JNIEnv* env, const char* class_name, const char* method_name, const char* sig, jclass pareValues[]) { jclass obj_class = FindClass(env, class_name); jmethodID methodId = GetMethodID(obj_class, method_name, sig); }
//--------------------------------------------------------------- //--------------------------------------------------------------- void AmazonIAPJavaInterface::StartListeningForTransactionUpdates(const CSNetworking::IAPSystem::TransactionStatusDelegate& in_delegate) { CS_ASSERT(in_delegate != nullptr, "Cannot have null transaction delegate"); m_transactionStatusDelegate = in_delegate; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); env->CallVoidMethod(GetJavaObject(), GetMethodID("StartListeningForTransactionUpdates")); }
//-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- s32 CoreJavaInterface::GetScreenHeight() { if (m_screenHeight == 0) { JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); m_screenHeight = env->CallIntMethod(GetJavaObject(), GetMethodID("getScreenHeight")); } return m_screenHeight; }
//-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- f32 CoreJavaInterface::GetScreenDensity() { if (m_screenDensity < 0.0f) { JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); m_screenDensity = env->CallFloatMethod(GetJavaObject(), GetMethodID("getScreenDensity")); } return m_screenDensity; }
//-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- std::string CoreJavaInterface::GetAPKDirectory() { std::string apkRootPath = " "; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring jstrAkpPath = static_cast<jstring>(env->CallObjectMethod(GetJavaObject(), GetMethodID("getAPKDirectory"))); apkRootPath = JavaUtils::CreateSTDStringFromJString(jstrAkpPath); env->DeleteLocalRef(jstrAkpPath); return apkRootPath; }
//-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- std::string CoreJavaInterface::GetPackageName() { std::string packageName = ""; JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring jstrName = static_cast<jstring>(env->CallObjectMethod(GetJavaObject(), GetMethodID("getPackageName"))); packageName = JavaUtils::CreateSTDStringFromJString(jstrName); env->DeleteLocalRef(jstrName); return packageName; }
//------------------------------------------------ /// Stop Listening //------------------------------------------------ void AccelerometerJavaInterface::StopListening() { if (true == mbListening) { mAccelerationChangedDelegate = nullptr; JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); pEnv->CallVoidMethod(GetJavaObject(), GetMethodID("StopListening")); mbListening = false; } }
void JniWebView::OpenURL(int id, const String& urlToOpen) { jmethodID mid = GetMethodID("OpenURL", "(ILjava/lang/String;)V"); if (mid) { jstring jUrlToOpen = GetEnvironment()->NewStringUTF(urlToOpen.c_str()); GetEnvironment()->CallStaticVoidMethod(GetJavaClass(), mid, id, jUrlToOpen); GetEnvironment()->DeleteLocalRef(jUrlToOpen); } }
uint32 JniDpiHelper::GetScreenDPI() { uint32 dpi = 0; jmethodID mid = GetMethodID("GetScreenDPI", "()I"); if (mid) { dpi = GetEnvironment()->CallStaticIntMethod(GetJavaClass(), mid); } return dpi; }
void MeganekkoActivity::OneTimeShutdown() { delete SoundEffectPlayer; SoundEffectPlayer = NULL; delete SoundEffectContext; SoundEffectContext = NULL; jmethodID oneTimeShutdownMethodId = GetMethodID("oneTimeShutDown", "()V"); app->GetJava()->Env->CallVoidMethod(app->GetJava()->ActivityObject, oneTimeShutdownMethodId); }
//----------------------------------------------------- //----------------------------------------------------- void DialogueBoxJavaInterface::ShowSystemDialogue(s32 in_dialogID, const std::string& in_title, const std::string& in_message, const std::string& in_confirm) { JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); jstring title = JavaInterfaceUtils::CreateJStringFromSTDString(in_title); jstring message = JavaInterfaceUtils::CreateJStringFromSTDString(in_message); jstring confirm = JavaInterfaceUtils::CreateJStringFromSTDString(in_confirm); env->CallVoidMethod(GetJavaObject(), GetMethodID("showSystemDialogue"), in_dialogID, title, message, confirm); env->DeleteLocalRef(title); env->DeleteLocalRef(message); env->DeleteLocalRef(confirm); }
//------------------------------------------------ /// Start Listening //------------------------------------------------ void AccelerometerJavaInterface::StartListening(const AccelerationChangedDelegate& inAccelerationChangedDelegate) { if (true == IsAvailable() && false == mbListening) { JNIEnv* pEnv = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr(); pEnv->CallVoidMethod(GetJavaObject(), GetMethodID("StartListening")); mAccelerationChangedDelegate = inAccelerationChangedDelegate; mbListening = true; } }