Skip to content

Commit 4e2f92c

Browse files
authored
Merge pull request YousicianGit#36 from YousicianGit/fix/lifecyclenotification
Implemented show/hide of keyboard in the native side
2 parents 503e864 + 0db6e0e commit 4e2f92c

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

  • src/androidProj/nativeeditplugin/src/main/java/com/bkmin/android

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.json.JSONObject;
55

66
import android.app.Activity;
7+
import android.content.Context;
78
import android.graphics.Color;
89
import android.graphics.Rect;
910
import android.graphics.Typeface;
@@ -24,7 +25,27 @@
2425
import android.widget.TextView;
2526

2627
public class EditBox {
27-
private EditText edit;
28+
29+
// Simplest way to notify the EditBox about the application lifecycle.
30+
class EditTextLifeCycle extends EditText
31+
{
32+
EditBox observerBox;
33+
public EditTextLifeCycle(Context context, EditBox box)
34+
{
35+
super(context);
36+
this.observerBox = box;
37+
}
38+
39+
@Override
40+
public void onWindowFocusChanged(boolean hasWindowFocus)
41+
{
42+
super.onWindowFocusChanged(hasWindowFocus);
43+
if (!hasWindowFocus)
44+
observerBox.notifyFocusChanged(hasWindowFocus);
45+
}
46+
}
47+
48+
private EditTextLifeCycle edit;
2849
private final RelativeLayout layout;
2950
private int tag;
3051
private int characterLimit;
@@ -97,6 +118,12 @@ private void showKeyboard(boolean isShow)
97118
}
98119
}
99120

121+
private void notifyFocusChanged(boolean hasWindowFocus)
122+
{
123+
if(!hasWindowFocus)
124+
showKeyboard(false);
125+
}
126+
100127
private void processJsonMsg(JSONObject jsonMsg)
101128
{
102129
try
@@ -180,7 +207,7 @@ private void Create(int _tag, JSONObject jsonObj)
180207
String alignment = jsonObj.getString("align");
181208
boolean multiline = jsonObj.getBoolean("multiline");
182209

183-
edit = new EditText(NativeEditPlugin.unityActivity.getApplicationContext());
210+
edit = new EditTextLifeCycle(NativeEditPlugin.unityActivity.getApplicationContext(), this);
184211

185212
// It's important to set this first as it resets some things, for example character hiding if content type is password.
186213
edit.setSingleLine(!multiline);

0 commit comments

Comments
 (0)