Delay showSoftInput() call.
We need to wait onFocusView() call back for actually showing software keyboard. Bug: 3053354 Change-Id: Idd946e3b8a372ddbabb8b36600c77290f77a06e6
This commit is contained in:
@@ -20,9 +20,11 @@ import com.android.settings.R;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.View.OnFocusChangeListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
@@ -32,7 +34,7 @@ import android.widget.EditText;
|
|||||||
* Shows simplified UI for configuring a wifi network. Used only in SetupWizard for XLarge
|
* Shows simplified UI for configuring a wifi network. Used only in SetupWizard for XLarge
|
||||||
* screen.
|
* screen.
|
||||||
*/
|
*/
|
||||||
public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase {
|
public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase, OnFocusChangeListener {
|
||||||
private static final String TAG = "SetupWizard";
|
private static final String TAG = "SetupWizard";
|
||||||
|
|
||||||
private Button mConnectButton;
|
private Button mConnectButton;
|
||||||
@@ -44,6 +46,7 @@ public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase {
|
|||||||
private WifiConfigController mController;
|
private WifiConfigController mController;
|
||||||
private AccessPoint mAccessPoint;
|
private AccessPoint mAccessPoint;
|
||||||
private boolean mEdit;
|
private boolean mEdit;
|
||||||
|
private Handler mHandler = new Handler();
|
||||||
|
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
|
|
||||||
@@ -66,25 +69,18 @@ public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase {
|
|||||||
|
|
||||||
mView = mInflater.inflate(R.layout.wifi_config_ui_for_setup_wizard, parent, false);
|
mView = mInflater.inflate(R.layout.wifi_config_ui_for_setup_wizard, parent, false);
|
||||||
mController = new WifiConfigController(this, mView, mAccessPoint, edit);
|
mController = new WifiConfigController(this, mView, mAccessPoint, edit);
|
||||||
trySetFocusAndLaunchSoftInput(R.id.password);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void trySetFocusAndLaunchSoftInput(int id) {
|
// Set Focus to password View.
|
||||||
final View viewToBeFocused = mView.findViewById(id);
|
final View viewToBeFocused = mView.findViewById(R.id.password);
|
||||||
if (viewToBeFocused != null && viewToBeFocused.getVisibility() == View.VISIBLE) {
|
if (viewToBeFocused != null && viewToBeFocused.getVisibility() == View.VISIBLE &&
|
||||||
|
viewToBeFocused instanceof EditText) {
|
||||||
|
// After acquiring the focus, we show software keyboard.
|
||||||
|
viewToBeFocused.setOnFocusChangeListener(this);
|
||||||
final boolean requestFocusResult = viewToBeFocused.requestFocus();
|
final boolean requestFocusResult = viewToBeFocused.requestFocus();
|
||||||
Log.i(TAG, String.format("Focus request to %x %s.", id,
|
Log.i(TAG, String.format("Focus request %s.",
|
||||||
(requestFocusResult ? "successful" : "failed")));
|
(requestFocusResult ? "successful" : "failed")));
|
||||||
if (requestFocusResult && viewToBeFocused instanceof EditText) {
|
if (!requestFocusResult) {
|
||||||
Log.i(TAG, String.format(
|
viewToBeFocused.setOnFocusChangeListener(null);
|
||||||
"Focused View (%x) is EditText. Try to show software keyboard", id));
|
|
||||||
final InputMethodManager inputMethodManager = (InputMethodManager)
|
|
||||||
mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
|
||||||
final boolean showSoftInputResult =
|
|
||||||
inputMethodManager.showSoftInput(viewToBeFocused, 0);
|
|
||||||
if (!showSoftInputResult) {
|
|
||||||
Log.w(TAG, "Failed to show software keyboard ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,4 +160,32 @@ public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase {
|
|||||||
public void setTitle(CharSequence title) {
|
public void setTitle(CharSequence title) {
|
||||||
Log.d(TAG, "Ignoring setTitle");
|
Log.d(TAG, "Ignoring setTitle");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class FocusRunnable implements Runnable {
|
||||||
|
final InputMethodManager mInputMethodManager;
|
||||||
|
final View mViewToBeFocused;
|
||||||
|
public FocusRunnable(Context context, View viewToBeFocused) {
|
||||||
|
mInputMethodManager = (InputMethodManager)
|
||||||
|
context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
mViewToBeFocused = viewToBeFocused;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mInputMethodManager.focusIn(mViewToBeFocused);
|
||||||
|
final boolean showSoftInputResult =
|
||||||
|
mInputMethodManager.showSoftInput(mViewToBeFocused, 0);
|
||||||
|
if (!showSoftInputResult) {
|
||||||
|
Log.w(TAG, "Failed to show software keyboard ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFocusChange(View view, boolean hasFocus) {
|
||||||
|
view.setOnFocusChangeListener(null);
|
||||||
|
if (hasFocus) {
|
||||||
|
mHandler.post(new FocusRunnable(mActivity, view));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -111,7 +111,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
setContentView(R.layout.wifi_settings_for_setup_wizard_xl);
|
setContentView(R.layout.wifi_settings_for_setup_wizard_xl);
|
||||||
|
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
|
||||||
|
|
||||||
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
mWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
||||||
// There's no button here enabling wifi network, so we need to enable it without
|
// There's no button here enabling wifi network, so we need to enable it without
|
||||||
// users' request.
|
// users' request.
|
||||||
@@ -188,6 +188,7 @@ public class WifiSettingsForSetupWizardXL extends Activity implements OnClickLis
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void hideSoftwareKeyboard() {
|
private void hideSoftwareKeyboard() {
|
||||||
|
Log.i(TAG, "Hiding software keyboard.");
|
||||||
final View focusedView = getCurrentFocus();
|
final View focusedView = getCurrentFocus();
|
||||||
if (focusedView != null) {
|
if (focusedView != null) {
|
||||||
mInputMethodManager.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
|
mInputMethodManager.hideSoftInputFromWindow(focusedView.getWindowToken(), 0);
|
||||||
|
Reference in New Issue
Block a user