|
4 | 4 | import org.json.JSONObject; |
5 | 5 |
|
6 | 6 | import android.app.Activity; |
| 7 | +import android.content.Context; |
7 | 8 | import android.graphics.Color; |
8 | 9 | import android.graphics.Rect; |
9 | 10 | import android.graphics.Typeface; |
|
24 | 25 | import android.widget.TextView; |
25 | 26 |
|
26 | 27 | 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; |
28 | 49 | private final RelativeLayout layout; |
29 | 50 | private int tag; |
30 | 51 | private int characterLimit; |
@@ -97,6 +118,12 @@ private void showKeyboard(boolean isShow) |
97 | 118 | } |
98 | 119 | } |
99 | 120 |
|
| 121 | + private void notifyFocusChanged(boolean hasWindowFocus) |
| 122 | + { |
| 123 | + if(!hasWindowFocus) |
| 124 | + showKeyboard(false); |
| 125 | + } |
| 126 | + |
100 | 127 | private void processJsonMsg(JSONObject jsonMsg) |
101 | 128 | { |
102 | 129 | try |
@@ -180,7 +207,7 @@ private void Create(int _tag, JSONObject jsonObj) |
180 | 207 | String alignment = jsonObj.getString("align"); |
181 | 208 | boolean multiline = jsonObj.getBoolean("multiline"); |
182 | 209 |
|
183 | | - edit = new EditText(NativeEditPlugin.unityActivity.getApplicationContext()); |
| 210 | + edit = new EditTextLifeCycle(NativeEditPlugin.unityActivity.getApplicationContext(), this); |
184 | 211 |
|
185 | 212 | // It's important to set this first as it resets some things, for example character hiding if content type is password. |
186 | 213 | edit.setSingleLine(!multiline); |
|
0 commit comments