bool ofxAndroidAlertListBox(string title, const vector<string> & list){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidAlertListBox(): couldn't find OFAndroid java class"; return ""; } jmethodID alertListBox = ofGetJNIEnv()->GetStaticMethodID(javaClass,"alertListBox","(Ljava/lang/String;[Ljava/lang/String;)Z"); if(!alertListBox){ ofLogError("ofxAndroidUtils") << "ofxAndroidAlertListBox(): couldn't find OFAndroid alertListBox method"; return ""; } jstring jTitle = ofGetJNIEnv()->NewStringUTF(title.c_str()); jclass jStringClass = ofGetJNIEnv()->FindClass("java/lang/String"); jobjectArray jList = ofGetJNIEnv()->NewObjectArray(list.size(), jStringClass, NULL); for(int i=0;i<(int)list.size(); i++){ jstring element = ofGetJNIEnv()->NewStringUTF(list[i].c_str()); ofGetJNIEnv()->SetObjectArrayElement(jList,i,(jobject)element); ofGetJNIEnv()->DeleteLocalRef((jobject)element); } jboolean res = ofGetJNIEnv()->CallStaticBooleanMethod(javaClass,alertListBox,jTitle,jList); ofGetJNIEnv()->DeleteLocalRef((jobject)jTitle); ofGetJNIEnv()->DeleteLocalRef((jobject)jList); return res; }
bool ofxAndroidIsMobileOnline(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidIsMobileOnline(): couldn't find OFAndroid java class"; return false; } jmethodID isMobileOnline = ofGetJNIEnv()->GetStaticMethodID(javaClass,"isMobileOnline","()Z"); if(!isMobileOnline){ ofLogError("ofxAndroidUtils") << "ofxAndroidIsMobileOnline(): couldn't find OFAndroid isMobileOnline method"; return false; } return ofGetJNIEnv()->CallStaticBooleanMethod(javaClass,isMobileOnline); }
void ofxAndroidGPS::startGPS(){ jclass OFAndroid = ofGetJavaOFAndroid(); if(OFAndroid==0){ ofLog(OF_LOG_ERROR,"cannot find OFAndroid java class"); return; } jmethodID setupGPS = ofGetJNIEnv()->GetStaticMethodID(OFAndroid,"setupGPS","()V"); if(!setupGPS){ ofLog(OF_LOG_ERROR,"cannot find OFAndroid.setupGPS method"); return; } ofGetJNIEnv()->CallStaticVoidMethod(OFAndroid,setupGPS); }
void ofxAndroidMonitorNetworkState(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidMonitorNetworkState(): couldn't find OFAndroid java class"; return; } jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"monitorNetworkState","()V"); if(!method){ ofLogError("ofxAndroidUtils") << "ofxAndroidMonitorNetworkState(): couldn't find OFAndroid monitorNetworkState method"; return; } ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method); }
void ofxAndroidDismissProgressBox(int id){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidDismissProgressBox(): couldn't find OFAndroid java class"; return; } jmethodID dismissProgressBox = ofGetJNIEnv()->GetStaticMethodID(javaClass,"dismissProgressBox","(I)V"); if(!dismissProgressBox){ ofLogError("ofxAndroidUtils") << "ofxAndroidDismissProgressBox(): couldn't find OFAndroid dismissProgressBox method"; return; } ofGetJNIEnv()->CallStaticVoidMethod(javaClass,dismissProgressBox,id); }
void ofxAndroidSetViewItemChecked(string item_name, bool checked){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLog(OF_LOG_ERROR,"ofxAndroidSetViewItemChecked: cannot find OFAndroid java class"); return; } jmethodID setViewItemChecked = ofGetJNIEnv()->GetStaticMethodID(javaClass,"setViewItemChecked","(Ljava/lang/String;Z)V"); if(!setViewItemChecked){ ofLog(OF_LOG_ERROR,"cannot find OFAndroid setViewItemChecked method"); return; } ofGetJNIEnv()->CallStaticVoidMethod(javaClass,setViewItemChecked,ofGetJNIEnv()->NewStringUTF(item_name.c_str()),checked); }
void ofxAndroidUnlockScreenSleep(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidUnlockScreenSleep(): couldn't find OFAndroid java class"; return; } jmethodID unlockScreenSleep = ofGetJNIEnv()->GetStaticMethodID(javaClass,"unlockScreenSleep","()V"); if(!unlockScreenSleep){ ofLogError("ofxAndroidUtils") << "ofxAndroidUnlockScreenSleep(): couldn't find OFAndroid unlockScreenSleep method"; return; } ofGetJNIEnv()->CallStaticVoidMethod(javaClass,unlockScreenSleep); }
jobject ofGetOFActivityObject(){ JNIEnv * env = ofGetJNIEnv(); if(!env) return NULL; jclass OFAndroid = ofGetJavaOFAndroid(); if(!OFAndroid) return NULL; jfieldID ofActivityID = env->GetStaticFieldID(OFAndroid,"ofActivity","Landroid/app/Activity;"); if(!ofActivityID){ ofLogError() << "Failed to get field ID for ofActivity"; return NULL; } return env->GetStaticObjectField(OFAndroid,ofActivityID); }
void ofxAndroidPauseApp(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidPauseApp(): couldn't find OFAndroid java class"; return; } jmethodID pauseApp = ofGetJNIEnv()->GetStaticMethodID(javaClass,"pauseApp","()V"); if(!pauseApp){ ofLogError("ofxAndroidUtils") << "ofxAndroidPauseApp(): couldn't find OFAndroid pauseApp method"; return; } ofGetJNIEnv()->CallStaticVoidMethod(javaClass,pauseApp); }
jobject ofGetOFActivityObject(){ JNIEnv * env = ofGetJNIEnv(); if(!env) return NULL; jclass OFAndroid = ofGetJavaOFAndroid(); if(!OFAndroid) return NULL; jfieldID ofActivityID = env->GetStaticFieldID(OFAndroid,"ofActivity","Lcc/openframeworks/OFActivity;"); if(!ofActivityID){ ofLogError("ofAppAndroidWindow") << "couldn't get field ID for ofActivity"; return NULL; } return env->GetStaticObjectField(OFAndroid,ofActivityID); }
void ofxAndroidDisableMulticast(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidDisableMulticast(): couldn't find OFAndroid java class"; return; } jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"disableMulticast","()V"); if(!method){ ofLogError("ofxAndroidUtils") << "ofxAndroidDisableMulticast(): couldn't find OFAndroid disableMulticast method"; return; } ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method); }
bool ofxAndroidCheckSDCardMounted(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidCheckSDCardMounted(): couldn't find OFAndroid java class"; return false; } jmethodID unlockScreenSleep = ofGetJNIEnv()->GetStaticMethodID(javaClass,"checkSDCardMounted","()Z"); if(!unlockScreenSleep){ ofLogError("ofxAndroidUtils") << "ofxAndroidCheckSDCardMounted(): couldn't find OFAndroid checkSDCardMounted method"; return false; } return ofGetJNIEnv()->CallStaticBooleanMethod(javaClass,unlockScreenSleep); }
void ofxAndroidLaunchBrowser(string url){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidLaunchBrowser(): couldn't find OFAndroid java class"; return; } jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"launchBrowser","(Ljava/lang/String;)V"); if(!method){ ofLogError("ofxAndroidUtils") << "ofxAndroidLaunchBrowser(): couldn't find OFAndroid launchBrowser method"; return; } jstring jUrl = ofGetJNIEnv()->NewStringUTF(url.c_str()); ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,jUrl); ofGetJNIEnv()->DeleteLocalRef((jobject)jUrl); }
void ofxAndroidToast(string msg){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidToast(): couldn't find OFAndroid java class"; return; } jmethodID toast = ofGetJNIEnv()->GetStaticMethodID(javaClass,"toast","(Ljava/lang/String;)V"); if(!toast){ ofLogError("ofxAndroidUtils") << "ofxAndroidToast(): couldn't find OFAndroid toast method"; return; } jstring jMsg = ofGetJNIEnv()->NewStringUTF(msg.c_str()); ofGetJNIEnv()->CallStaticVoidMethod(javaClass,toast,jMsg); ofGetJNIEnv()->DeleteLocalRef((jobject)jMsg); }
void ofxAndroidYesNoBox(string msg){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidYesNoBox(): couldn't find OFAndroid java class"; return; } jmethodID method = ofGetJNIEnv()->GetStaticMethodID(javaClass,"yesNoBox","(Ljava/lang/String;)V"); if(!method){ ofLogError("ofxAndroidUtils") << "ofxAndroidYesNoBox(): couldn't find OFAndroid okCancelBox method"; return; } jstring jMsg = ofGetJNIEnv()->NewStringUTF(msg.c_str()); ofGetJNIEnv()->CallStaticVoidMethod(javaClass,method,jMsg); ofGetJNIEnv()->DeleteLocalRef((jobject)jMsg); }
int ofxAndroidProgressBox(string msg){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidProgressBox(): couldn't find OFAndroid java class"; return -1; } jmethodID progressBox = ofGetJNIEnv()->GetStaticMethodID(javaClass,"progressBox","(Ljava/lang/String;)I"); if(!progressBox){ ofLogError("ofxAndroidUtils") << "ofxAndroidProgressBox(): couldn't find OFAndroid alertBox method"; return -1; } jstring jMsg = ofGetJNIEnv()->NewStringUTF(msg.c_str()); int ret = ofGetJNIEnv()->CallStaticIntMethod(javaClass,progressBox,jMsg); ofGetJNIEnv()->DeleteLocalRef((jobject)jMsg); return ret; }
string ofxAndroidRandomUUID(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidRandomUUID(): couldn't find OFAndroid java class"; return ""; } jmethodID randomUUID = ofGetJNIEnv()->GetStaticMethodID(javaClass,"getRandomUUID","()Ljava/lang/String;"); if(!randomUUID){ ofLogError("ofxAndroidUtils") << "ofxAndroidRandomUUID(): couldn't find OFAndroid randomUUID method"; return ""; } jstring str = (jstring) ofGetJNIEnv()->CallStaticObjectMethod(javaClass,randomUUID); jboolean isCopy; return ofGetJNIEnv()->GetStringUTFChars(str,&isCopy); }
string ofxAndroidGetTextBoxResult(){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidGetTextBoxResult(): could't find OFAndroid java class"; return ""; } jmethodID getLastTextBoxResult = ofGetJNIEnv()->GetStaticMethodID(javaClass,"getLastTextBoxResult","()Ljava/lang/String;"); if(!getLastTextBoxResult){ ofLogError("ofxAndroidUtils") << "ofxAndroidGetTextBoxResult(): couldn't find OFAndroid getLastTextBoxResult method"; return ""; } jstring str = (jstring) ofGetJNIEnv()->CallStaticObjectMethod(javaClass,getLastTextBoxResult); jboolean isCopy; return ofGetJNIEnv()->GetStringUTFChars(str,&isCopy); }
void ofxAndroidAlertTextBox(string question, string text){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidAlertTextBox(): couldn't find OFAndroid java class"; return; } jmethodID alertTextBox = ofGetJNIEnv()->GetStaticMethodID(javaClass,"alertTextBox","(Ljava/lang/String;Ljava/lang/String;)V"); if(!alertTextBox){ ofLogError("ofxAndroidUtils") << "ofxAndroidAlertTextBox(): couldn't find OFAndroid alertTextBox method"; return; } jstring jQuestion = ofGetJNIEnv()->NewStringUTF(question.c_str()); jstring jMsg = ofGetJNIEnv()->NewStringUTF(text.c_str()); ofGetJNIEnv()->CallStaticVoidMethod(javaClass,alertTextBox,jQuestion,jMsg); ofGetJNIEnv()->DeleteLocalRef((jobject)jMsg); ofGetJNIEnv()->DeleteLocalRef((jobject)jQuestion); }
string ofxAndroidGetStringRes(string id){ jclass javaClass = ofGetJavaOFAndroid(); if(javaClass==0){ ofLogError("ofxAndroidUtils") << "ofxAndroidGetStringRes(): couldn't find OFAndroid java class"; return ""; } jmethodID getStringRes = ofGetJNIEnv()->GetStaticMethodID(javaClass,"getStringRes","(Ljava/lang/String;)Ljava/lang/String;"); if(!getStringRes){ ofLogError("ofxAndroidUtils") << "ofxAndroidGetStringRes(): couldn't find OFAndroid getStringRes method"; return ""; } jstring jId = ofGetJNIEnv()->NewStringUTF(id.c_str()); jstring str = (jstring) ofGetJNIEnv()->CallStaticObjectMethod(javaClass,getStringRes,jId); ofGetJNIEnv()->DeleteLocalRef((jobject)jId); jboolean isCopy; return ofGetJNIEnv()->GetStringUTFChars(str,&isCopy); }