Fix dangling keyboard

This commit is contained in:
serso 2016-03-27 19:50:01 +02:00
parent 4dab6b6191
commit 59ce9105ac
2 changed files with 21 additions and 6 deletions

View File

@ -24,6 +24,7 @@ package org.solovyev.android.calculator;
import android.app.Activity; import android.app.Activity;
import android.app.Application; import android.app.Application;
import android.app.Dialog;
import android.content.*; import android.content.*;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -181,6 +182,18 @@ public final class App {
return (CalculatorApplication) application; 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) { public static void hideIme(@NonNull View view) {
final IBinder token = view.getWindowToken(); final IBinder token = view.getWindowToken();
if (token != null) { if (token != null) {

View File

@ -108,16 +108,12 @@ public class ConverterFragment extends BaseDialogFragment
final Bundle args = new Bundle(1); final Bundle args = new Bundle(1);
args.putDouble(EXTRA_VALUE, value); args.putDouble(EXTRA_VALUE, value);
fragment.setArguments(args); fragment.setArguments(args);
App.showDialog(fragment, "converter", App.showDialog(fragment, "converter", activity.getSupportFragmentManager());
activity.getSupportFragmentManager());
} }
@Nonnull @Nonnull
private static <T> ArrayAdapter<T> makeAdapter(@NonNull Context context) { private static <T> ArrayAdapter<T> makeAdapter(@NonNull Context context) {
final ArrayAdapter<T> adapter = return new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);
new ArrayAdapter<>(context, R.layout.support_simple_spinner_dropdown_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
return adapter;
} }
@Override @Override
@ -384,6 +380,12 @@ public class ConverterFragment extends BaseDialogFragment
convert(false); convert(false);
} }
@Override
public void dismiss() {
App.hideIme(this);
super.dismiss();
}
private enum MyDimension { private enum MyDimension {
TIME(Dimension.TIME, R.string.cpp_converter_time), TIME(Dimension.TIME, R.string.cpp_converter_time),
AMOUNT_OF_SUBSTANCE(Dimension.AMOUNT_OF_SUBSTANCE, R.string.cpp_converter_amount_of_substance), AMOUNT_OF_SUBSTANCE(Dimension.AMOUNT_OF_SUBSTANCE, R.string.cpp_converter_amount_of_substance),