[DEV] multiple instance work on android

This commit is contained in:
Edouard DUPIN 2013-09-04 21:02:55 +02:00
parent 547c9c4d65
commit be8264edf9
7 changed files with 141 additions and 145 deletions

View File

@ -15,36 +15,21 @@ import android.service.wallpaper.WallpaperService.Engine;
import android.util.Log; import android.util.Log;
public class Ewol { public class Ewol {
private static int counterInstance = -1; // Global instance increment at eveny new instance
private int instanceID = -1; // local and private instance ID private int instanceID = -1; // local and private instance ID
/* Default constructor (why not ?)*/ public <T extends EwolCallback> Ewol(T activityInstance, int typeApplication)
public Ewol()
{ {
// TODO : Set an unique intance ID instanceID = -1;
counterInstance ++; instanceID = EWsetJavaVirtualMachineStart(activityInstance, typeApplication);
instanceID = counterInstance; Log.d("Ewol", "new : " + instanceID);
Log.d("Ewol", "new " + counterInstance + " : " + instanceID);
} }
// internal Acces not at the native function ...
public <T extends Activity & EwolCallback> void setJavaVirtualMachineStart(T activityInstance)
{
// TODO : Get the instance ID here ...
EWsetJavaVirtualMachineStart(activityInstance);
}
public <T extends WallpaperService & EwolCallback> void setJavaVirtualMachineStartWallpaperEngine(T serviceInstance)
{
// TODO : Get the instance ID here ...
EWsetJavaVirtualMachineStartWallpaperEngine(serviceInstance);
}
public void setJavaVirtualMachineStop() public void setJavaVirtualMachineStop()
{ {
EWsetJavaVirtualMachineStop(instanceID); EWsetJavaVirtualMachineStop(instanceID);
} }
public void paramSetArchiveDir(int mode, String myString) public void paramSetArchiveDir(int mode, String myString)
{ {
Log.d("Ewol", "call : " + instanceID);
EWparamSetArchiveDir(instanceID, mode, myString); EWparamSetArchiveDir(instanceID, mode, myString);
} }
@ -59,36 +44,30 @@ public class Ewol {
// set display properties : // set display properties :
public void displayPropertyMetrics(float ratioX, float ratioY) public void displayPropertyMetrics(float ratioX, float ratioY)
{ {
Log.d("Ewol", "call : " + instanceID);
EWdisplayPropertyMetrics(instanceID, ratioX, ratioY); EWdisplayPropertyMetrics(instanceID, ratioX, ratioY);
} }
// IO native function : // IO native function :
// Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same) // Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same)
public void inputEventMotion(int pointerID, float x, float y) public void inputEventMotion(int pointerID, float x, float y)
{ {
Log.d("Ewol", "call : " + instanceID);
EWinputEventMotion(instanceID, pointerID, x, y); EWinputEventMotion(instanceID, pointerID, x, y);
} }
public void inputEventState(int pointerID, boolean isDown, float x, float y) public void inputEventState(int pointerID, boolean isDown, float x, float y)
{ {
Log.d("Ewol", "call : " + instanceID);
EWinputEventState(instanceID, pointerID, isDown, x, y); EWinputEventState(instanceID, pointerID, isDown, x, y);
} }
// Specific for the type of input : TOOL_TYPE_MOUSE // Specific for the type of input : TOOL_TYPE_MOUSE
public void mouseEventMotion(int pointerID, float x, float y) public void mouseEventMotion(int pointerID, float x, float y)
{ {
Log.d("Ewol", "call : " + instanceID);
EWmouseEventMotion(instanceID, pointerID, x, y); EWmouseEventMotion(instanceID, pointerID, x, y);
} }
public void mouseEventState(int pointerID, boolean isDown, float x, float y) public void mouseEventState(int pointerID, boolean isDown, float x, float y)
{ {
Log.d("Ewol", "call : " + instanceID);
EWmouseEventState(instanceID, pointerID, isDown, x, y); EWmouseEventState(instanceID, pointerID, isDown, x, y);
} }
// other unknow event ... // other unknow event ...
public void unknowEvent(int eventID) public void unknowEvent(int eventID)
{ {
Log.d("Ewol", "call : " + instanceID);
EWunknowEvent(instanceID, eventID); EWunknowEvent(instanceID, eventID);
} }
@ -114,23 +93,19 @@ public class Ewol {
// renderer Event : // renderer Event :
public void renderInit() public void renderInit()
{ {
Log.d("Ewol", "call : " + instanceID);
EWrenderInit(instanceID); EWrenderInit(instanceID);
} }
public void renderResize(int w, int h) public void renderResize(int w, int h)
{ {
Log.d("Ewol", "call : " + instanceID);
EWrenderResize(instanceID, w, h); EWrenderResize(instanceID, w, h);
} }
public void renderDraw() public void renderDraw()
{ {
Log.d("Ewol", "call : " + instanceID);
EWrenderDraw(instanceID); EWrenderDraw(instanceID);
} }
private native <T extends Activity & EwolCallback> void EWsetJavaVirtualMachineStart(T activityInstance); private native <T extends EwolCallback> int EWsetJavaVirtualMachineStart(T activityInstance, int typeApplication);
private native <T extends WallpaperService & EwolCallback> void EWsetJavaVirtualMachineStartWallpaperEngine(T serviceInstance);
private native void EWsetJavaVirtualMachineStop(int instanceId); private native void EWsetJavaVirtualMachineStop(int instanceId);
private native void EWparamSetArchiveDir(int instanceId, int mode, String myString); private native void EWparamSetArchiveDir(int instanceId, int mode, String myString);

View File

@ -56,9 +56,8 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
} }
public EwolActivity() public EwolActivity()
{ {
EWOL = new Ewol();
// set the java evironement in the C sources : // set the java evironement in the C sources :
EWOL.setJavaVirtualMachineStart(this); EWOL = new Ewol(this, EWOL_APPL_TYPE_ACTIVITY);
} }
protected void initApkPath(String org, String vendor, String project) { protected void initApkPath(String org, String vendor, String project) {
@ -218,6 +217,12 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
{ {
setTitle(value); setTitle(value);
} }
public void stop()
{
// end application is requested ...
finish();
}
} }

View File

@ -69,17 +69,23 @@ public class EwolAudioTask implements Runnable, EwolConstants
} }
public void Pause() public void Pause()
{ {
if(m_musicTrack == null) return; if(m_musicTrack == null) {
return;
}
m_musicTrack.pause(); m_musicTrack.pause();
} }
public void Resume() public void Resume()
{ {
if(m_musicTrack == null) return; if(m_musicTrack == null) {
return;
}
m_musicTrack.play(); m_musicTrack.play();
} }
public void AutoStop() public void AutoStop()
{ {
if(m_musicTrack == null) return; if(m_musicTrack == null) {
return;
}
m_stopAudioThreads=true; m_stopAudioThreads=true;
} }
}/* no ; here !!! */ }/* no ; here !!! */

View File

@ -7,12 +7,13 @@
*/ */
package org.ewol; package org.ewol;
import android.util.Log;
public interface EwolCallback { public interface EwolCallback
{
public void keyboardUpdate(boolean show); public void keyboardUpdate(boolean show);
public void eventNotifier(String[] args); public void eventNotifier(String[] args);
public void orientationUpdate(int screenMode); public void orientationUpdate(int screenMode);
public void titleSet(String value); public void titleSet(String value);
public void stop();
} }

View File

@ -23,4 +23,8 @@ public interface EwolConstants {
public static final int EWOL_ORIENTATION_AUTO = 0; public static final int EWOL_ORIENTATION_AUTO = 0;
public static final int EWOL_ORIENTATION_LANDSCAPE = 1; public static final int EWOL_ORIENTATION_LANDSCAPE = 1;
public static final int EWOL_ORIENTATION_PORTRAIT = 2; public static final int EWOL_ORIENTATION_PORTRAIT = 2;
public static final int EWOL_APPL_TYPE_ACTIVITY = 0;
public static final int EWOL_APPL_TYPE_WALLPAPER = 1;
} }

View File

@ -50,11 +50,10 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
EWOL.paramSetArchiveDir(0, apkFilePath); EWOL.paramSetArchiveDir(0, apkFilePath);
} }
@Override public Engine onCreateEngine() { @Override public Engine onCreateEngine()
{
EWOL = new Ewol();
// set the java evironement in the C sources : // set the java evironement in the C sources :
EWOL.setJavaVirtualMachineStartWallpaperEngine(this); EWOL = new Ewol(this, EWOL_APPL_TYPE_WALLPAPER);
// Load the application directory // Load the application directory
EWOL.paramSetArchiveDir(1, getFilesDir().toString()); EWOL.paramSetArchiveDir(1, getFilesDir().toString());
@ -184,21 +183,28 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
public void keyboardUpdate(boolean show) public void keyboardUpdate(boolean show)
{ {
// never display keyboard on wallpaer... // never display keyboard on wallpaer...
Log.d("EwolCallback", "KEABOARD UPDATE is not implemented ...");
} }
public void eventNotifier(String[] args) public void eventNotifier(String[] args)
{ {
// just for the test ... // just for the test ...
Log.d("EwolCallback", "EVENT NOTIFIER is not implemented ...");
} }
public void orientationUpdate(int screenMode) public void orientationUpdate(int screenMode)
{ {
Log.d("EwolCallback", "SET ORIENTATION is not implemented ...");
} }
public void titleSet(String value) public void titleSet(String value)
{ {
// no title in the wallpaper ... // no title in the wallpaper ...
Log.d("EwolCallback", "SET TITLE is not implemented ...");
} }
public void Stop()
{
Log.d("EwolCallback", "STOP is not implemented ...");
};
} }

View File

@ -55,7 +55,8 @@ class AndroidContext : public ewol::eContext
JNIEnv* m_JavaVirtualMachinePointer; //!< the JVM JNIEnv* m_JavaVirtualMachinePointer; //!< the JVM
jclass m_javaClassEwol; //!< main activity class (android ...) jclass m_javaClassEwol; //!< main activity class (android ...)
jclass m_javaClassEwolCallback; jclass m_javaClassEwolCallback;
jobject m_javaObjectEwolCallbackAndActivity; jobject m_javaObjectEwolCallback;
jmethodID m_javaMethodEwolCallbackStop; //!< Stop function identifier
jmethodID m_javaMethodEwolCallbackEventNotifier; //!< basic methode to call ... jmethodID m_javaMethodEwolCallbackEventNotifier; //!< basic methode to call ...
jmethodID m_javaMethodEwolCallbackKeyboardUpdate; //!< basic methode to call ... jmethodID m_javaMethodEwolCallbackKeyboardUpdate; //!< basic methode to call ...
jmethodID m_javaMethodEwolCallbackOrientationUpdate; jmethodID m_javaMethodEwolCallbackOrientationUpdate;
@ -82,7 +83,8 @@ class AndroidContext : public ewol::eContext
m_JavaVirtualMachinePointer(NULL), m_JavaVirtualMachinePointer(NULL),
m_javaClassEwol(0), m_javaClassEwol(0),
m_javaClassEwolCallback(0), m_javaClassEwolCallback(0),
m_javaObjectEwolCallbackAndActivity(0), m_javaObjectEwolCallback(0),
m_javaMethodEwolCallbackStop(0),
m_javaMethodEwolCallbackEventNotifier(0), m_javaMethodEwolCallbackEventNotifier(0),
m_javaMethodEwolCallbackKeyboardUpdate(0), m_javaMethodEwolCallbackKeyboardUpdate(0),
m_javaMethodEwolCallbackOrientationUpdate(0), m_javaMethodEwolCallbackOrientationUpdate(0),
@ -126,6 +128,14 @@ class AndroidContext : public ewol::eContext
java_check_exception(_env); java_check_exception(_env);
return; return;
} }
ret=SafeInitMethodID(m_javaMethodEwolCallbackStop,
m_javaClassEwolCallback,
"stop",
"()V");
if (ret==false) {
java_check_exception(_env);
return;
}
ret=SafeInitMethodID(m_javaMethodEwolCallbackEventNotifier, ret=SafeInitMethodID(m_javaMethodEwolCallbackEventNotifier,
m_javaClassEwolCallback, m_javaClassEwolCallback,
@ -154,7 +164,7 @@ class AndroidContext : public ewol::eContext
return; return;
} }
m_javaObjectEwolCallbackAndActivity = _env->NewGlobalRef(_objCallback); m_javaObjectEwolCallback = _env->NewGlobalRef(_objCallback);
//javaObjectEwolCallbackAndActivity = objCallback; //javaObjectEwolCallbackAndActivity = objCallback;
m_javaDefaultClassString = m_JavaVirtualMachinePointer->FindClass("java/lang/String" ); m_javaDefaultClassString = m_JavaVirtualMachinePointer->FindClass("java/lang/String" );
@ -174,8 +184,8 @@ class AndroidContext : public ewol::eContext
void UnInit(JNIEnv* _env) void UnInit(JNIEnv* _env)
{ {
_env->DeleteGlobalRef(m_javaObjectEwolCallbackAndActivity); _env->DeleteGlobalRef(m_javaObjectEwolCallback);
m_javaObjectEwolCallbackAndActivity = NULL; m_javaObjectEwolCallback = NULL;
} }
@ -187,7 +197,16 @@ class AndroidContext : public ewol::eContext
void Stop(void) void Stop(void)
{ {
// TODO : send a message to the android system to stop ... EWOL_DEBUG("C->java : send message to the java : STOP REQUESTED");
int status;
if(!java_attach_current_thread(&status)) {
return;
}
//Call java ...
m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallback, m_javaMethodEwolCallbackStop);
// manage execption :
java_check_exception(m_JavaVirtualMachinePointer);
java_detach_current_thread(status);
} }
void ClipBoardGet(ewol::clipBoard::clipboardListe_te _clipboardID) void ClipBoardGet(ewol::clipBoard::clipboardListe_te _clipboardID)
@ -278,7 +297,7 @@ class AndroidContext : public ewol::eContext
} }
//Call java ... //Call java ...
m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallbackAndActivity, m_javaMethodEwolCallbackKeyboardUpdate, _showIt); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallback, m_javaMethodEwolCallbackKeyboardUpdate, _showIt);
// manage execption : // manage execption :
java_check_exception(m_JavaVirtualMachinePointer); java_check_exception(m_JavaVirtualMachinePointer);
java_detach_current_thread(status); java_detach_current_thread(status);
@ -300,7 +319,7 @@ class AndroidContext : public ewol::eContext
jint param = (jint)_orientation; jint param = (jint)_orientation;
//Call java ... //Call java ...
m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallbackAndActivity, m_javaMethodEwolCallbackOrientationUpdate, param); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallback, m_javaMethodEwolCallbackOrientationUpdate, param);
// manage execption : // manage execption :
java_check_exception(m_JavaVirtualMachinePointer); java_check_exception(m_JavaVirtualMachinePointer);
@ -319,7 +338,7 @@ class AndroidContext : public ewol::eContext
etk::Char tmpChar = _title.c_str(); etk::Char tmpChar = _title.c_str();
//Call java ... //Call java ...
jstring title = m_JavaVirtualMachinePointer->NewStringUTF(tmpChar); jstring title = m_JavaVirtualMachinePointer->NewStringUTF(tmpChar);
m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallbackAndActivity, m_javaMethodEwolActivitySetTitle, title); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallback, m_javaMethodEwolActivitySetTitle, title);
m_JavaVirtualMachinePointer->DeleteLocalRef(title); m_JavaVirtualMachinePointer->DeleteLocalRef(title);
// manage execption : // manage execption :
java_check_exception(m_JavaVirtualMachinePointer); java_check_exception(m_JavaVirtualMachinePointer);
@ -359,7 +378,7 @@ class AndroidContext : public ewol::eContext
} }
EWOL_DEBUG("C->java : 555"); EWOL_DEBUG("C->java : 555");
//Call java ... //Call java ...
m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallbackAndActivity, m_javaMethodEwolCallbackEventNotifier, args); m_JavaVirtualMachinePointer->CallVoidMethod(m_javaObjectEwolCallback, m_javaMethodEwolCallbackEventNotifier, args);
EWOL_DEBUG("C->java : 666"); EWOL_DEBUG("C->java : 666");
java_check_exception(m_JavaVirtualMachinePointer); java_check_exception(m_JavaVirtualMachinePointer);
@ -416,7 +435,7 @@ extern "C"
} }
/* Call to initialize the graphics state */ /* Call to initialize the graphics state */
void Java_org_ewol_Ewol_EWparamSetArchiveDir(JNIEnv* _env, jclass _cls, jint _mode, jstring _myString, jint _id) void Java_org_ewol_Ewol_EWparamSetArchiveDir(JNIEnv* _env, jclass _cls, jint _id, jint _mode, jstring _myString)
{ {
if( _id>=s_listInstance.Size() if( _id>=s_listInstance.Size()
|| _id<0 || _id<0
@ -425,6 +444,7 @@ extern "C"
// TODO : Generate error in java to stop the current instance // TODO : Generate error in java to stop the current instance
return; return;
} }
//EWOL_CRITICAL(" call with ID : " << _id);
// direct setting of the date in the string system ... // direct setting of the date in the string system ...
jboolean isCopy; jboolean isCopy;
const char* str = _env->GetStringUTFChars(_myString, &isCopy); const char* str = _env->GetStringUTFChars(_myString, &isCopy);
@ -436,52 +456,29 @@ extern "C"
} }
} }
// TODO : Return the local ID ... jint Java_org_ewol_Ewol_EWsetJavaVirtualMachineStart(JNIEnv* _env, jclass _classBase, jobject _objCallback, int _typeApplication)
void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStart(JNIEnv* _env, jclass _classBase, jobject _objCallback)
{ {
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Creating EWOL context **"); EWOL_DEBUG("** Creating EWOL context **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
AndroidContext* tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_application); AndroidContext* tmpContext = NULL;
if (org_ewol_EwolConstants_EWOL_APPL_TYPE_ACTIVITY == _typeApplication) {
tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_application);
} else if (org_ewol_EwolConstants_EWOL_APPL_TYPE_WALLPAPER == _typeApplication) {
tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
} else {
EWOL_CRITICAL(" try to create an instance with no apply type: " << _typeApplication);
return -1;
}
if (NULL == tmpContext) { if (NULL == tmpContext) {
EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.Size()-1)); EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.Size()-1));
// TODO : return -1; return -1;
} }
// TODO : Change this ==> this generate the new ID ...
if (s_listInstance.Size()>0) {
// note : For now : memory leek and errors ...
s_listInstance[0] = tmpContext;
} else {
// for future case : all time this ... // for future case : all time this ...
s_listInstance.PushBack(tmpContext); s_listInstance.PushBack(tmpContext);
// esize_t newID = s_listInstance.Size()-1; int32_t newID = s_listInstance.Size()-1;
// return newID; return newID;
} }
}
// TODO : Return the local ID ...
void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStartWallpaperEngine(JNIEnv* _env, jclass _classBase, jobject _objCallback)
{
EWOL_DEBUG("*******************************************");
EWOL_DEBUG("** Creating EWOL context **");
EWOL_DEBUG("*******************************************");
AndroidContext* tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
if (NULL == tmpContext) {
EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.Size()-1));
// TODO : return -1;
}
// TODO : Change this ==> this generate the new ID ...
if (s_listInstance.Size()>0) {
// note : For now : memory leek and errors ...
s_listInstance[0] = tmpContext;
} else {
// for future case : all time this ...
s_listInstance.PushBack(tmpContext);
// esize_t newID = s_listInstance.Size()-1;
// return newID;
}
}
void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStop(JNIEnv* _env, jclass _cls, jint _id) void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStop(JNIEnv* _env, jclass _cls, jint _id)
{ {
@ -489,10 +486,12 @@ extern "C"
EWOL_DEBUG("** Remove JVM Pointer **"); EWOL_DEBUG("** Remove JVM Pointer **");
EWOL_DEBUG("*******************************************"); EWOL_DEBUG("*******************************************");
if( _id>=s_listInstance.Size() if( _id>=s_listInstance.Size()
|| _id<0 || _id<0) {
|| NULL==s_listInstance[_id] ) {
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id); EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
// TODO : Generate error in java to stop the current instance return;
}
if (NULL==s_listInstance[_id]) {
EWOL_ERROR("the requested instance _id=" << (int32_t)_id << " is already removed ...");
return; return;
} }
s_listInstance[_id]->UnInit(_env); s_listInstance[_id]->UnInit(_env);