From 59ce9105ac96b9d8af69d970d83f9facdad98769 Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 27 Mar 2016 19:50:01 +0200 Subject: [PATCH] Fix dangling keyboard --- .../java/org/solovyev/android/calculator/App.java | 13 +++++++++++++ .../calculator/converter/ConverterFragment.java | 14 ++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/App.java b/app/src/main/java/org/solovyev/android/calculator/App.java index 64477c1e..93b8b8ff 100644 --- a/app/src/main/java/org/solovyev/android/calculator/App.java +++ b/app/src/main/java/org/solovyev/android/calculator/App.java @@ -24,6 +24,7 @@ package org.solovyev.android.calculator; import android.app.Activity; import android.app.Application; +import android.app.Dialog; import android.content.*; import android.content.pm.PackageManager; import android.content.res.Configuration; @@ -181,6 +182,18 @@ public final class App { return (CalculatorApplication) application; } + public static void hideIme(@NonNull DialogFragment fragment) { + final Dialog dialog = fragment.getDialog(); + if (dialog == null) { + return; + } + final View focusedView = dialog.getCurrentFocus(); + if (focusedView == null) { + return; + } + hideIme(focusedView); + } + public static void hideIme(@NonNull View view) { final IBinder token = view.getWindowToken(); if (token != null) { diff --git a/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java b/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java index 948a7b28..0ddc8087 100644 --- a/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/converter/ConverterFragment.java @@ -108,16 +108,12 @@ public class ConverterFragment extends BaseDialogFragment final Bundle args = new Bundle(1); args.putDouble(EXTRA_VALUE, value); fragment.setArguments(args); - App.showDialog(fragment, "converter", - activity.getSupportFragmentManager()); + App.showDialog(fragment, "converter", activity.getSupportFragmentManager()); } @Nonnull private static ArrayAdapter makeAdapter(@NonNull Context context) { - final ArrayAdapter adapter = - new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item); - adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); - return adapter; + return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item); } @Override @@ -384,6 +380,12 @@ public class ConverterFragment extends BaseDialogFragment convert(false); } + @Override + public void dismiss() { + App.hideIme(this); + super.dismiss(); + } + private enum MyDimension { TIME(Dimension.TIME, R.string.cpp_converter_time), AMOUNT_OF_SUBSTANCE(Dimension.AMOUNT_OF_SUBSTANCE, R.string.cpp_converter_amount_of_substance),