Skip to content

Commit

Permalink
Merge pull request #5843 from grzesiek2010/COLLECT-5828
Browse files Browse the repository at this point in the history
Fixed showing keyboard
  • Loading branch information
lognaturel committed Nov 29, 2023
2 parents 895c9b0 + 188d481 commit b81862e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 56 deletions.
Expand Up @@ -1475,11 +1475,6 @@ public void showView(SwipeHandler.View next, FormAnimationType from) {
outAnimation.setDuration(0);
}

// drop keyboard before transition...
if (currentView != null) {
softKeyboardController.hideSoftKeyboard(currentView);
}

RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

Expand Down
Expand Up @@ -393,7 +393,7 @@ public EntitiesRepositoryProvider provideEntitiesRepositoryProvider(Application

@Provides
public SoftKeyboardController provideSoftKeyboardController() {
return new SoftKeyboardController();
return SoftKeyboardController.INSTANCE;
}

@Provides
Expand Down

This file was deleted.

@@ -0,0 +1,25 @@
package org.odk.collect.android.utilities

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.View
import android.view.inputmethod.InputMethodManager

object SoftKeyboardController {
fun showSoftKeyboard(view: View) {
// Subtle delay in displaying the keyboard is necessary for the keyboard to be displayed at all,
// for example, when returning from the hierarchy view.
Handler(Looper.getMainLooper()).postDelayed({
if (view.requestFocus()) {
val inputMethodManager = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.showSoftInput(view, 0)
}
}, 100)
}

fun hideSoftKeyboard(view: View) {
val inputMethodManager = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
}
Expand Up @@ -199,12 +199,6 @@ public IAnswerData getAnswer() {
public void setData(Object answer) {
}

@Override
public void setFocus(Context context) {
// focus on launch button
launchIntentButton.requestFocus();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return !event.isAltPressed() && super.onKeyDown(keyCode, event);
Expand Down
Expand Up @@ -82,10 +82,6 @@ public void clearAnswer() {
widgetValueChanged();
}

@Override
public void setFocus(Context context) {
}

@Override
public void setOnLongClickListener(OnLongClickListener l) {
showRankingDialogButton.setOnLongClickListener(l);
Expand Down

0 comments on commit b81862e

Please sign in to comment.