diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java index 372158625cc..0c56cf2e8f7 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormFillingActivity.java @@ -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); diff --git a/collect_app/src/main/java/org/odk/collect/android/injection/config/AppDependencyModule.java b/collect_app/src/main/java/org/odk/collect/android/injection/config/AppDependencyModule.java index ed58a7696ca..35b81ba3ca7 100644 --- a/collect_app/src/main/java/org/odk/collect/android/injection/config/AppDependencyModule.java +++ b/collect_app/src/main/java/org/odk/collect/android/injection/config/AppDependencyModule.java @@ -393,7 +393,7 @@ public EntitiesRepositoryProvider provideEntitiesRepositoryProvider(Application @Provides public SoftKeyboardController provideSoftKeyboardController() { - return new SoftKeyboardController(); + return SoftKeyboardController.INSTANCE; } @Provides diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/SoftKeyboardController.java b/collect_app/src/main/java/org/odk/collect/android/utilities/SoftKeyboardController.java deleted file mode 100644 index 2b9f914322f..00000000000 --- a/collect_app/src/main/java/org/odk/collect/android/utilities/SoftKeyboardController.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2018 Nafundi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.odk.collect.android.utilities; - -import android.content.Context; -import androidx.annotation.NonNull; -import android.view.View; -import android.view.inputmethod.InputMethodManager; - -import org.odk.collect.android.application.Collect; - -public class SoftKeyboardController { - public void showSoftKeyboard(@NonNull View view) { - if (view.requestFocus()) { - getInputMethodManager().showSoftInput(view, 0); - } - } - - public void hideSoftKeyboard(@NonNull View view) { - getInputMethodManager().hideSoftInputFromWindow(view.getWindowToken(), 0); - } - - private InputMethodManager getInputMethodManager() { - return (InputMethodManager) Collect.getInstance().getSystemService(Context.INPUT_METHOD_SERVICE); - } -} diff --git a/collect_app/src/main/java/org/odk/collect/android/utilities/SoftKeyboardController.kt b/collect_app/src/main/java/org/odk/collect/android/utilities/SoftKeyboardController.kt new file mode 100644 index 00000000000..6426b7e6656 --- /dev/null +++ b/collect_app/src/main/java/org/odk/collect/android/utilities/SoftKeyboardController.kt @@ -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) + } +} diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/ExPrinterWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/ExPrinterWidget.java index 31db6cc44b3..c2732ee25b1 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/ExPrinterWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/ExPrinterWidget.java @@ -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); diff --git a/collect_app/src/main/java/org/odk/collect/android/widgets/items/RankingWidget.java b/collect_app/src/main/java/org/odk/collect/android/widgets/items/RankingWidget.java index a014667a332..0d970f5b2ef 100644 --- a/collect_app/src/main/java/org/odk/collect/android/widgets/items/RankingWidget.java +++ b/collect_app/src/main/java/org/odk/collect/android/widgets/items/RankingWidget.java @@ -82,10 +82,6 @@ public void clearAnswer() { widgetValueChanged(); } - @Override - public void setFocus(Context context) { - } - @Override public void setOnLongClickListener(OnLongClickListener l) { showRankingDialogButton.setOnLongClickListener(l);