Fix dangling keyboard
This commit is contained in:
parent
4dab6b6191
commit
59ce9105ac
@ -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) {
|
||||
|
@ -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 <T> ArrayAdapter<T> makeAdapter(@NonNull Context context) {
|
||||
final ArrayAdapter<T> 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),
|
||||
|
Loading…
Reference in New Issue
Block a user