Force show keyboard when presenting FragmentDialogs with EditText.

Bug: 26823589
Change-Id: I593ed0e7ef40c9c95c311ca529d3826d73496458
This commit is contained in:
Aga Wronska
2016-03-02 16:00:22 -08:00
parent d25d2f5346
commit 02c532fb54
3 changed files with 20 additions and 0 deletions

View File

@@ -82,6 +82,9 @@ public class CreateDirectoryFragment extends DialogFragment {
builder.setNegativeButton(android.R.string.cancel, null);
final AlertDialog dialog = builder.create();
// Workaround for the problem - virtual keyboard doesn't show on the phone.
Shared.ensureKeyboardPresent(context, dialog);
editText.setOnEditorActionListener(
new OnEditorActionListener() {
@Override

View File

@@ -17,9 +17,12 @@
package com.android.documentsui;
import android.content.Context;
import android.content.res.Configuration;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.text.format.Time;
import android.view.WindowManager;
import android.app.AlertDialog;
import java.text.Collator;
import java.util.ArrayList;
@@ -155,4 +158,15 @@ public final class Shared {
return sCollator.compare(lhs, rhs);
}
public static boolean isHardwareKeyboardAvailable(Context context) {
return context.getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
}
public static void ensureKeyboardPresent(Context context, AlertDialog dialog) {
if (!isHardwareKeyboardAvailable(context)) {
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
}
}

View File

@@ -92,6 +92,9 @@ public class RenameDocumentFragment extends DialogFragment {
final AlertDialog dialog = builder.create();
// Workaround for the problem - virtual keyboard doesn't show on the phone.
Shared.ensureKeyboardPresent(context, dialog);
mEditText.setOnEditorActionListener(
new OnEditorActionListener() {
@Override