@@ -62,6 +62,7 @@ public class CocosEditBoxActivity extends Activity {
62
62
// a color of dark green, was used for confirm button background
63
63
private static final int DARK_GREEN = Color .parseColor ("#1fa014" );
64
64
private static final int DARK_GREEN_PRESS = Color .parseColor ("#008e26" );
65
+ private static final String ORIENTATION = "orientation" ;
65
66
66
67
private static CocosEditBoxActivity sThis = null ;
67
68
private Cocos2dxEditText mEditText = null ;
@@ -70,6 +71,7 @@ public class CocosEditBoxActivity extends Activity {
70
71
private boolean mConfirmHold = true ;
71
72
private int mEditTextID = 1 ;
72
73
private int mButtonLayoutID = 2 ;
74
+ private int mInitialSystemWindowInsetBottom = -1 ;
73
75
74
76
/***************************************************************************************
75
77
Inner class.
@@ -208,13 +210,13 @@ private void removeListeners() {
208
210
this .removeTextChangedListener (mTextWatcher );
209
211
}
210
212
211
- private boolean isSystemAdjustUIWhenPopKeyboard (int bottom ) {
213
+ private boolean isSystemAdjustUIWhenPopKeyboard () {
212
214
int bottomOffset = 0 ;
213
215
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
214
216
bottomOffset = getWindow ().getDecorView ().getRootWindowInsets ().getSystemWindowInsetBottom ();
215
217
}
216
218
// view will be scrolled to the target position by system,
217
- if (Math .abs (bottom - bottomOffset ) < 10 ) {
219
+ if (Math .abs (mInitialSystemWindowInsetBottom - bottomOffset ) > 100 ) {
218
220
return true ;
219
221
}
220
222
return false ;
@@ -232,7 +234,7 @@ public void onGlobalLayout() {
232
234
if (!keyboardVisible ) {
233
235
keyboardVisible = true ;
234
236
}
235
- if (!isSystemAdjustUIWhenPopKeyboard (heightDiff )) {
237
+ if (!isSystemAdjustUIWhenPopKeyboard ()) {
236
238
getRootView ().scrollTo (0 , heightDiff );
237
239
}
238
240
} else {
@@ -287,6 +289,8 @@ public void onClick(View view) {
287
289
"text"
288
290
);
289
291
} else {
292
+ int orientation = extras .getInt (ORIENTATION );
293
+ setRequestedOrientation (orientation );
290
294
show (extras .getString ("defaultValue" ),
291
295
extras .getInt ("maxLength" ),
292
296
extras .getBoolean ("isMultiline" ),
@@ -296,6 +300,14 @@ public void onClick(View view) {
296
300
}
297
301
}
298
302
303
+ @ Override
304
+ public void onAttachedToWindow () {
305
+ View decorView = getWindow ().getDecorView ();
306
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .M ) {
307
+ mInitialSystemWindowInsetBottom = decorView .getRootWindowInsets ().getSystemWindowInsetBottom ();
308
+ }
309
+ }
310
+
299
311
/***************************************************************************************
300
312
Public functions.
301
313
**************************************************************************************/
@@ -434,6 +446,7 @@ public void run() {
434
446
i .putExtra ("confirmHold" , confirmHold );
435
447
i .putExtra ("confirmType" , confirmType );
436
448
i .putExtra ("inputType" , inputType );
449
+ i .putExtra (ORIENTATION , GlobalObject .getActivity ().getRequestedOrientation ());
437
450
GlobalObject .getActivity ().startActivity (i );
438
451
}
439
452
});
0 commit comments