Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 498ec28

Browse files
committed
[[ ExternalsApiV5 ]] Added 'EngineApi' interface which the Android Engine class implements, together with accessor to externals API.
[[ ExternalsApiV5 ]] Added 'ActivityRun' method to Externals API (java-side). [[ ExternalsApiV5 ]] Implemented RunOnSystemThread method in java LC class. [[ ExternalsApiV5 ]] Implemented Wait object in java LC class. [[ ExternalsApiV5 ]] Added simple test functions for activities and running on system thread.
1 parent fb0e36e commit 498ec28

File tree

12 files changed

+420
-11
lines changed

12 files changed

+420
-11
lines changed

engine/engine.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@
11151115
4D6F92F412AA5CC000026A72 /* w32sound.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = w32sound.cpp; path = src/w32sound.cpp; sourceTree = "<group>"; };
11161116
4D6F92F512AA5CC000026A72 /* w32textlayout.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = w32textlayout.cpp; path = src/w32textlayout.cpp; sourceTree = "<group>"; };
11171117
4D6F92FA12AA5E2600026A72 /* textlayout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = textlayout.h; path = src/textlayout.h; sourceTree = "<group>"; };
1118+
4D7667AC17A137D500E692E0 /* EngineApi.java */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.java; path = EngineApi.java; sourceTree = "<group>"; };
11181119
4D7740F21226B930001C9150 /* lnxans.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lnxans.cpp; path = src/lnxans.cpp; sourceTree = "<group>"; };
11191120
4D7740F31226B930001C9150 /* lnxans.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = lnxans.h; path = src/lnxans.h; sourceTree = "<group>"; };
11201121
4D7740F41226B930001C9150 /* lnxaudio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = lnxaudio.cpp; path = src/lnxaudio.cpp; sourceTree = "<group>"; };
@@ -1989,6 +1990,7 @@
19891990
4DD54D1C134F591500981610 /* LiveCodeActivity.java */,
19901991
4DD54D1D134F591500981610 /* ShakeEventListener.java */,
19911992
4DD54D1E134F591500981610 /* URLLoader.java */,
1993+
4D7667AC17A137D500E692E0 /* EngineApi.java */,
19921994
);
19931995
path = android;
19941996
sourceTree = "<group>";

engine/src/externalv1.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ enum MCExternalInterfaceQueryTag
215215
// MW-2013-06-14: [[ ExternalsApiV5 ]] Accessor to get the JavaEnv for the
216216
// system thread.
217217
kMCExternalInterfaceQuerySystemJavaEnv = 7, // V5
218+
219+
// MW-2013-07-25: [[ ExternalsApiV5 ]] Accessor to get the EngineApi object
220+
kMCExternalInterfaceQueryEngine = 8, // V5
218221
};
219222

220223
enum
@@ -1961,6 +1964,9 @@ extern void *MCAndroidGetContainer(void);
19611964
extern void *MCAndroidGetScriptJavaEnv(void);
19621965
extern void *MCAndroidGetSystemJavaEnv(void);
19631966

1967+
// MW-2013-07-25: [[ ExternalsApiV5 ]] Method to get the Engine object.
1968+
extern void *MCAndroidGetEngine(void);
1969+
19641970
static MCExternalError MCExternalInterfaceQuery(MCExternalInterfaceQueryTag op, void *r_value)
19651971
{
19661972
#if defined(TARGET_SUBPLATFORM_IPHONE)
@@ -1999,6 +2005,11 @@ static MCExternalError MCExternalInterfaceQuery(MCExternalInterfaceQueryTag op,
19992005
*(void **)r_value = MCAndroidGetSystemJavaEnv();
20002006
break;
20012007

2008+
// MW-2013-07-25: [[ ExternalsApiV5 ]] Implementation of the Engine accessor.
2009+
case kMCExternalInterfaceQueryEngine:
2010+
*(void **)r_value = MCAndroidGetEngine();
2011+
break;
2012+
20022013
default:
20032014
return kMCExternalErrorInvalidInterfaceQuery;
20042015
}

engine/src/java/com/runrev/android/Engine.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
// invoke methods from the native code so we wrap all this up into a single
6363
// view object.
6464

65-
public class Engine extends View
65+
public class Engine extends View implements EngineApi
6666
{
6767
public static final String TAG = "revandroid.Engine";
6868

@@ -1741,6 +1741,7 @@ else if (resultCode == Activity.RESULT_OK)
17411741
private static final int CREATE_CALENDAR_RESULT = 11;
17421742
private static final int UPDATE_CALENDAR_RESULT = 12;
17431743
private static final int SHOW_CALENDAR_RESULT = 13;
1744+
private static final int RUN_ACTIVITY_RESULT = 14;
17441745

17451746
public void onActivityResult (int requestCode, int resultCode, Intent data)
17461747
{
@@ -1783,6 +1784,9 @@ public void onActivityResult (int requestCode, int resultCode, Intent data)
17831784
case SHOW_CALENDAR_RESULT:
17841785
onShowCalendarEventResult(resultCode, data);
17851786
break;
1787+
case RUN_ACTIVITY_RESULT:
1788+
onRunActivityResult(resultCode, data);
1789+
break;
17861790
default:
17871791
break;
17881792
}
@@ -2651,6 +2655,69 @@ private void onMediaResult(int resultCode, Intent data)
26512655
}
26522656
}
26532657

2658+
////////////////////////////////////////////////////////////////////////////////
2659+
2660+
// EngineApi implementation
2661+
2662+
public Activity getActivity()
2663+
{
2664+
return (LiveCodeActivity)getContext();
2665+
}
2666+
2667+
public ViewGroup getContainer()
2668+
{
2669+
return (ViewGroup)getParent();
2670+
}
2671+
2672+
private boolean m_pending_activity_running = false;
2673+
private int m_pending_activity_result_code = 0;
2674+
private Intent m_pending_activity_data = null;
2675+
public void runActivity(Intent p_intent, ActivityResultCallback p_callback)
2676+
{
2677+
// We aren't re-entrant, so just invoke the callback as 'cancelled' if one is
2678+
// already running.
2679+
if (m_pending_activity_running)
2680+
{
2681+
p_callback . handleActivityResult(Activity.RESULT_CANCELED, null);
2682+
return;
2683+
}
2684+
2685+
// Mark an activity as running.
2686+
m_pending_activity_running = true;
2687+
2688+
// Run the activity.
2689+
((LiveCodeActivity)getContext()) . startActivityForResult(p_intent, RUN_ACTIVITY_RESULT);
2690+
2691+
// Wait until the activity returns.
2692+
while(m_pending_activity_running)
2693+
doWait(60.0, false, true);
2694+
2695+
// Take local copies of the instance vars (to stop hanging data).
2696+
Intent t_data;
2697+
int t_result_code;
2698+
t_data = m_pending_activity_data;
2699+
t_result_code = m_pending_activity_result_code;
2700+
2701+
// Reset the instance vars (to stop hanging data and so that the callback
2702+
// can start another activity if it wants).
2703+
m_pending_activity_data = null;
2704+
m_pending_activity_result_code = 0;
2705+
2706+
p_callback . handleActivityResult(t_result_code, t_data);
2707+
}
2708+
2709+
private void onRunActivityResult(int p_result_code, Intent p_data)
2710+
{
2711+
// Store the result details.
2712+
m_pending_activity_data = p_data;
2713+
m_pending_activity_result_code = p_result_code;
2714+
m_pending_activity_running = false;
2715+
2716+
// Make sure we signal a switch back to the script thread.
2717+
if (m_wake_on_event)
2718+
doProcess(false);
2719+
}
2720+
26542721
////////////////////////////////////////////////////////////////////////////////
26552722

26562723
// url launch callback
@@ -2694,6 +2761,8 @@ public static native void doPurchaseStateChanged(boolean verified, int purchaseS
26942761

26952762
public static native String doGetCustomPropertyValue(String set, String property);
26962763

2764+
public static native void doWait(double time, boolean dispatch, boolean anyevent);
2765+
26972766
// sensor handlers
26982767
public static native void doLocationChanged(double p_latitude, double p_longitude, double p_altitude, float p_timestamp, float p_accuracy, double p_speed, double p_course);
26992768
public static native void doHeadingChanged(double p_heading, double p_magnetic_heading, double p_true_heading, float p_timestamp,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Copyright (C) 2003-2013 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
package com.runrev.android;
18+
19+
import java.lang.*;
20+
import android.app.*;
21+
import android.view.*;
22+
import android.content.*;
23+
24+
public interface EngineApi
25+
{
26+
public interface ActivityResultCallback
27+
{
28+
public abstract void handleActivityResult(int resultCode, Intent data);
29+
};
30+
31+
// Runs the activity then waits for the result, invoking the callback
32+
// with the resultCode and data. (Must be run from script thread, callback will
33+
// be on script thread).
34+
public abstract void runActivity(Intent intent, ActivityResultCallback callback);
35+
36+
public abstract Activity getActivity();
37+
public abstract ViewGroup getContainer();
38+
};

engine/src/mblandroiddc.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,12 @@ void *MCAndroidGetScriptJavaEnv(void)
14711471
return s_java_env;
14721472
}
14731473

1474+
// MW-2013-07-25: [[ ExternalsApiV5 ]] Return the engine object (EngineApi really)
1475+
void *MCAndroidGetEngine(void)
1476+
{
1477+
return s_android_view;
1478+
}
1479+
14741480
////////////////////////////////////////////////////////////////////////////////
14751481

14761482
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doCreate(JNIEnv *env, jobject object, jobject activity, jobject container, jobject view) __attribute__((visibility("default")));
@@ -1482,6 +1488,7 @@ extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doPause(JNIEnv
14821488
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doResume(JNIEnv *env, jobject object) __attribute__((visibility("default")));
14831489
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doLowMemory(JNIEnv *env, jobject object) __attribute__((visibility("default")));
14841490
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doProcess(JNIEnv *env, jobject object, bool timedout) __attribute__((visibility("default")));
1491+
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doWait(JNIEnv *env, jobject object, double time, bool dispatch, bool anyevent) __attribute__((visibility("default")));
14851492
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doReconfigure(JNIEnv *env, jobject object, int w, int h, jobject bitmap) __attribute__((visibility("default")));
14861493
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doTouch(JNIEnv *env, jobject object, int action, int id, int timestamp, int x, int y) __attribute__((visibility("default")));
14871494
extern "C" JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doKeyPress(JNIEnv *env, jobject object, int modifiers, int char_code, int key_code) __attribute__((visibility("default")));
@@ -1650,6 +1657,14 @@ JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doProcess(JNIEnv *env, job
16501657
co_yield_to_engine();
16511658
}
16521659

1660+
JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doWait(JNIEnv *env, jobject object, double time, bool dispatch, bool anyevent)
1661+
{
1662+
if (!s_engine_running)
1663+
return;
1664+
1665+
MCscreen -> wait(time, dispatch, anyevent);
1666+
}
1667+
16531668
JNIEXPORT void JNICALL Java_com_runrev_android_Engine_doReconfigure(JNIEnv *env, jobject object, int w, int h, jobject bitmap)
16541669
{
16551670
MCLog("doReconfigure(%d, %d, %p)", w, h, bitmap);

lcidlc/src/InterfaceGenerate.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,6 +1145,7 @@ static bool InterfaceGenerateExports(InterfaceRef self, CoderRef p_coder)
11451145
{
11461146
{ "InterfaceQueryActivity", "jobject", nil, nil },
11471147
{ "InterfaceQueryContainer", "jobject", nil, nil },
1148+
{ "InterfaceQueryEngine", "jobject", nil, nil },
11481149
{ "ObjectResolve", "jlong", "jobject chunk", "chunk" },
11491150
{ "ObjectRetain", "void", "jlong object", "object" },
11501151
{ "ObjectRelease", "void", "jlong object", "object" },
@@ -1153,6 +1154,14 @@ static bool InterfaceGenerateExports(InterfaceRef self, CoderRef p_coder)
11531154
{ "ObjectPost", "void", "jlong object, jobject message, jobject signature, jobject arguments", "object, message, signature, arguments" },
11541155
{ "ContextMe", "jlong", nil, nil },
11551156
{ "ContextTarget", "jlong", nil, nil },
1157+
{ "RunOnSystemThread", "void", "jobject runnable", "runnable" },
1158+
{ "WaitCreate", "jlong", "jint options", "options" },
1159+
{ "WaitRelease", "void", "jlong wait", "wait" },
1160+
{ "WaitIsRunning", "jboolean", "jlong wait", "wait" },
1161+
{ "WaitRun", "void", "jlong wait", "wait" },
1162+
{ "WaitReset", "void", "jlong wait", "wait" },
1163+
{ "WaitBreak", "void", "jlong wait", "wait" },
1164+
11561165
};
11571166
t_java_class_name = strdup(NameGetCString(self -> qualified_name));
11581167
for(uint32_t i = 0; t_java_class_name[i] != '\0'; i++)

0 commit comments

Comments
 (0)