Skip to content

Commit

Permalink
Add API to get user input with native text fields (libgdx#7004)
Browse files Browse the repository at this point in the history
* Add API to get user input with native text fields

* Correctly register new core files in gdx.gwt.xml

* feat: Add support for custom autosuggestion

* Generate MobiVM MetalANGLE backend

* feat(android): Remove material dependencie for show/hide password

* feat: Add first basic test

* Apply formatter

* fix: Do adjusting of width, also if adjustNothing is not set

* fix: Properly layout EditText always for AndroidRKeyboardHeightProvider

* feat(android): Use androidx compat library for android 23+

* Apply formatter

* fix(android): Revert android < 11 back to StandardKeyboardHeightProvider

fix(android): Try to fix y axis scaling issue, when keyboard just got smaller

fix(android): Use proper mask for determining softInputMode

* fix(ios): Fix compiler error

* fix(android): Don't capitalize start of sentence in doNotCorrect mode

* fix(android): Correctly calculate keyboard height in some cases

* fix: Make NativeInputTest work more reliable

* fix(android): Guard against negative DropwDownHeight

* Generate MobiVM MetalANGLE backend

* Apply formatter

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
Berstanio and actions-user authored Feb 11, 2024
1 parent cac39bd commit 86721d6
Show file tree
Hide file tree
Showing 29 changed files with 2,053 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.badlogic.gdx.*;
import com.badlogic.gdx.backends.android.keyboardheight.AndroidXKeyboardHeightProvider;
import com.badlogic.gdx.backends.android.keyboardheight.KeyboardHeightProvider;
import com.badlogic.gdx.backends.android.keyboardheight.StandardKeyboardHeightProvider;
import com.badlogic.gdx.backends.android.surfaceview.FillResolutionStrategy;
import com.badlogic.gdx.utils.*;

Expand Down Expand Up @@ -60,6 +63,7 @@ public class AndroidApplication extends Activity implements AndroidApplicationBa
protected boolean useImmersiveMode = false;
private int wasFocusChanged = -1;
private boolean isWaitingForAudio = false;
private KeyboardHeightProvider keyboardHeightProvider;

protected boolean renderUnderCutout = false;

Expand Down Expand Up @@ -176,6 +180,14 @@ public void dispose () {
if (getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS) input.setKeyboardAvailable(true);

setLayoutInDisplayCutoutMode(this.renderUnderCutout);

// As per the docs, it might work unreliable < 23 https://developer.android.com/jetpack/androidx/releases/core#1.5.0-alpha02
// So, I guess since 23 is pretty rare we can use the old API for the users
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
keyboardHeightProvider = new AndroidXKeyboardHeightProvider(this);
} else {
keyboardHeightProvider = new StandardKeyboardHeightProvider(this);
}
}

protected FrameLayout.LayoutParams createLayoutParams () {
Expand Down Expand Up @@ -250,6 +262,7 @@ protected void onPause () {
graphics.onPauseGLSurfaceView();

super.onPause();
keyboardHeightProvider.setKeyboardHeightObserver(null);
}

@Override
Expand Down Expand Up @@ -278,11 +291,19 @@ protected void onResume () {
this.isWaitingForAudio = false;
}
super.onResume();
keyboardHeightProvider.setKeyboardHeightObserver((DefaultAndroidInput)Gdx.input);
((AndroidGraphics)getGraphics()).getView().post(new Runnable() {
@Override
public void run () {
keyboardHeightProvider.start();
}
});
}

@Override
protected void onDestroy () {
super.onDestroy();
keyboardHeightProvider.close();
}

@Override
Expand Down Expand Up @@ -508,4 +529,8 @@ protected AndroidFiles createFiles () {
this.getFilesDir(); // workaround for Android bug #10515463
return new DefaultAndroidFiles(this.getAssets(), this, true);
}

public KeyboardHeightProvider getKeyboardHeightProvider () {
return keyboardHeightProvider;
}
}
Loading

0 comments on commit 86721d6

Please sign in to comment.