Fix focus behavior in setup screens.

- properly put actionNext on most fields
- make sure actionDone doesn't do funky things with focus so that a
non-editable field gets focus. we may want to consider not making this
focusable in the future.

Bug: 5367827
Change-Id: I4e7bb13801d96a4f1e6fd02a2d43713200738b18
This commit is contained in:
Ben Komalo 2011-09-26 15:25:13 -07:00
parent 92922ea4a4
commit 3432bdb757
5 changed files with 50 additions and 12 deletions

View File

@ -30,7 +30,7 @@
<EditText
android:id="@+id/account_username"
android:inputType="textEmailAddress"
android:imeOptions="actionDone"
android:imeOptions="actionNext"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:contentDescription="@string/account_setup_exchange_username_label" />
@ -43,7 +43,7 @@
<EditText
android:id="@+id/account_password"
android:inputType="textPassword"
android:imeOptions="actionDone"
android:imeOptions="actionNext"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
<!-- This text may be changed in code if the server is IMAP, etc. -->

View File

@ -32,7 +32,7 @@
android:layout_width="match_parent"
android:contentDescription="@string/account_setup_incoming_username_label"
android:inputType="textEmailAddress"
android:imeOptions="actionDone" />
android:imeOptions="actionNext" />
<TextView
android:text="@string/account_setup_incoming_password_label"
android:layout_height="wrap_content"
@ -45,7 +45,7 @@
android:layout_width="match_parent"
android:contentDescription="@string/account_setup_incoming_password_label"
android:inputType="textPassword"
android:imeOptions="actionDone" />
android:imeOptions="actionNext" />
<!-- This text may be changed in code if the server is IMAP, etc. -->
<TextView
android:id="@+id/account_server_label"
@ -62,7 +62,7 @@
android:layout_width="match_parent"
android:contentDescription="@string/account_setup_incoming_pop_server_label"
android:inputType="textUri"
android:imeOptions="actionDone" />
android:imeOptions="actionNext" />
<TextView
android:text="@string/account_setup_incoming_port_label"
android:layout_height="wrap_content"

View File

@ -16,23 +16,26 @@
package com.android.email.activity.setup;
import com.android.email.R;
import com.android.email.activity.UiUtilities;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.utility.Utility;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.android.email.R;
import com.android.email.activity.UiUtilities;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.utility.Utility;
import java.net.URI;
import java.net.URISyntaxException;
@ -282,6 +285,32 @@ public abstract class AccountServerBaseFragment extends Fragment
}
}
/**
* A keyboard listener which dismisses the keyboard when "DONE" is pressed, but doesn't muck
* around with focus. This is useful in settings screens, as we don't want focus to change
* since some fields throw up errors when they're focused to give the user more info.
*/
protected final OnEditorActionListener mDismissImeOnDoneListener =
new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// Dismiss soft keyboard but don't modify focus.
final Context context = getActivity();
if (context == null) {
return false;
}
InputMethodManager imm = (InputMethodManager) context.getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm != null && imm.isActive()) {
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
}
return true;
}
return false;
}
};
/**
* Clears the "next" button de-bounce flags and allows the "next" button to activate.
*/

View File

@ -104,7 +104,7 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
: R.layout.account_setup_exchange_fragment;
View view = inflater.inflate(layoutId, container, false);
Context context = getActivity();
final Context context = getActivity();
mUsernameView = UiUtilities.getView(view, R.id.account_username);
mPasswordView = UiUtilities.getView(view, R.id.account_password);
@ -132,6 +132,10 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
mUsernameView.addTextChangedListener(validationTextWatcher);
mPasswordView.addTextChangedListener(validationTextWatcher);
mServerView.addTextChangedListener(validationTextWatcher);
EditText lastView = mServerView;
lastView.setOnEditorActionListener(mDismissImeOnDoneListener);
String deviceId = "";
try {
deviceId = Device.getDeviceId(context);

View File

@ -27,6 +27,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
@ -284,21 +285,25 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
private void configureEditor() {
if (mConfigured) return;
Account account = SetupData.getAccount();
TextView lastView = mImapPathPrefixView;
mBaseScheme = account.mHostAuthRecv.mProtocol;
if (HostAuth.SCHEME_POP3.equals(mBaseScheme)) {
mServerLabelView.setText(R.string.account_setup_incoming_pop_server_label);
mServerView.setContentDescription(
getResources().getString(R.string.account_setup_incoming_pop_server_label));
mImapPathPrefixSectionView.setVisibility(View.GONE);
lastView = mPortView;
} else if (HostAuth.SCHEME_IMAP.equals(mBaseScheme)) {
mServerLabelView.setText(R.string.account_setup_incoming_imap_server_label);
mServerView.setContentDescription(
getResources().getString(R.string.account_setup_incoming_imap_server_label));
mDeletePolicyLabelView.setVisibility(View.GONE);
mDeletePolicyView.setVisibility(View.GONE);
mPortView.setImeOptions(EditorInfo.IME_ACTION_NEXT);
} else {
throw new Error("Unknown account type: " + account);
}
lastView.setOnEditorActionListener(mDismissImeOnDoneListener);
mConfigured = true;
}