Skip to content

Commit c5e5bb5

Browse files
author
Oskari Leppäaho
authored
Merge pull request YousicianGit#12 from YousicianGit/fix/deadlock
Fix deadlock
2 parents 1f58a67 + 3dd2d81 commit c5e5bb5

4 files changed

Lines changed: 8 additions & 55 deletions

File tree

-1.77 KB
Binary file not shown.

release/NativeEditPlugin/scripts/NativeEditBox.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ public void SetTextNative(string newText)
295295
this.SendPluginMsg(jsonMsg);
296296
}
297297

298+
// GetTextNative won't work on Android, because of threading issues. It should not be needed though,
299+
// as the Unity InputField's text property is updated as the native text changes, so it should match
300+
// the native text.
301+
#if !UNITY_ANDROID
298302
public string GetTextNative()
299303
{
300304
JsonObject jsonMsg = new JsonObject();
@@ -308,6 +312,7 @@ public string GetTextNative()
308312
Debug.Log(string.Format("GetTextNative {0}", jsonRet.GetString("text")));
309313
return jsonRet.GetString("text");
310314
}
315+
#endif
311316

312317
private void RemoveNative()
313318
{

src/androidProj/nativeeditplugin/src/main/java/com/bkmin/android/EditBox.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class EditBox {
4343
private static String MSG_CREATE = "CreateEdit";
4444
private static String MSG_REMOVE = "RemoveEdit";
4545
private static String MSG_SET_TEXT = "SetText";
46-
private static String MSG_GET_TEXT = "GetText";
4746
private static String MSG_SET_RECT = "SetRect";
4847
private static String MSG_SET_FOCUS = "SetFocus";
4948
private static String MSG_SET_VISIBLE = "SetVisible";
@@ -138,11 +137,6 @@ else if (msg.equals(MSG_SET_TEXT))
138137
String text = jsonMsg.getString("text");
139138
this.SetText(text);
140139
}
141-
else if (msg.equals(MSG_GET_TEXT))
142-
{
143-
String text = this.GetText();
144-
jsonRet.put("text", text);
145-
}
146140
else if (msg.equals(MSG_SET_RECT))
147141
{
148142
this.SetRect(jsonMsg);

src/androidProj/nativeeditplugin/src/main/java/com/bkmin/android/NativeEditPlugin.java

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -78,32 +78,6 @@ public void run() {
7878
RelativeLayout.LayoutParams.MATCH_PARENT);
7979
topViewGroup.addView(mainLayout, rlp);
8080
SetInitialized();
81-
82-
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
83-
@Override
84-
public void onGlobalLayout() {
85-
86-
Rect r = new Rect();
87-
rootView.getWindowVisibleDisplayFrame(r);
88-
int screenHeight = rootView.getRootView().getHeight();
89-
90-
// r.bottom is the position above soft keypad or device button.
91-
// if keypad is shown, the r.bottom is smaller than that before.
92-
keyboardHeight = screenHeight - r.bottom;
93-
boolean bKeyOpen = (keyboardHeight > screenHeight * 0.15);
94-
95-
float fKeyHeight = (float) keyboardHeight / (float) screenHeight;
96-
97-
JSONObject json = new JSONObject();
98-
try {
99-
json.put("msg", MSG_SHOW_KEYBOARD);
100-
json.put("show", bKeyOpen);
101-
json.put("keyheight", fKeyHeight);
102-
} catch (JSONException e) {
103-
}
104-
SendUnityMessage(json);
105-
}
106-
});
10781
Log.i(LOG_TAG, "InitEditBoxPlugin okay");
10882
}
10983
});
@@ -123,33 +97,13 @@ public static void SendUnityMessage(JSONObject jsonMsg)
12397
UnityPlayer.UnitySendMessage(unityName, "OnMsgFromPlugin", jsonMsg.toString());
12498
}
12599

126-
static JSONObject jsonStaticRet = null;
127100
public static String SendUnityMsgToPlugin(final int nSenderId, final String jsonMsg) {
128101
final Runnable task = new Runnable() {
129102
public void run() {
130-
jsonStaticRet = EditBox.processRecvJsonMsg(nSenderId, jsonMsg);
131-
synchronized (this) {
132-
this.notify();
133-
}
103+
EditBox.processRecvJsonMsg(nSenderId, jsonMsg);
134104
}
135105
};
136-
synchronized (task) {
137-
unityActivity.runOnUiThread(task);
138-
try
139-
{
140-
task.wait();
141-
}
142-
catch ( InterruptedException e )
143-
{
144-
e.printStackTrace();
145-
}
146-
}
147-
148-
if (jsonStaticRet != null) {
149-
return jsonStaticRet.toString();
150-
}
151-
else {
152-
return "";
153-
}
106+
unityActivity.runOnUiThread(task);
107+
return new JSONObject().toString();
154108
}
155109
}

0 commit comments

Comments
 (0)