Merge "Disallow editing username after account creation"

This commit is contained in:
Todd Kennedy 2011-03-30 14:47:28 -07:00 committed by Android (Google) Code Review
commit aaec6a9a2b
4 changed files with 67 additions and 0 deletions

View File

@ -787,6 +787,9 @@ save attachment.</string>
being supported [CHAR LIMIT=none] -->
<string name="account_setup_failed_security_policies_unsupported">
This server requires security features that your Android device does not support.</string>
<!-- The user name can only be changed during initial account setup. [CHAR LIMIT=none] -->
<string name="account_setup_username_uneditable_error">You can\'t change an account\'s username.
To add an account with a different username, touch Add account.</string>
<!-- Warning given to users when they request disabling device administration (i.e. that their
administered accounts will be deleted) [CHAR LIMIT=none] -->
<string name="disable_admin_warning">WARNING: Deactivating the Email application\'s authority

View File

@ -29,7 +29,10 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.TextView;
import java.net.URI;
import java.net.URISyntaxException;
@ -52,6 +55,12 @@ public abstract class AccountServerBaseFragment extends Fragment
protected Context mContext;
protected Callback mCallback = EmptyCallback.INSTANCE;
/**
* Whether or not we are in "settings mode". We re-use the same screens for both the initial
* account creation as well as subsequent account modification. If <code>mSettingsMode</code>
* if <code>false</code>, we are in account creation mode. Otherwise, we are in account
* modification mode.
*/
protected boolean mSettingsMode;
/*package*/ HostAuth mLoadedSendAuth;
/*package*/ HostAuth mLoadedRecvAuth;
@ -158,6 +167,15 @@ public abstract class AccountServerBaseFragment extends Fragment
}
}
@Override
public void onPause() {
// Hide the soft keyboard if we lose focus
InputMethodManager imm =
(InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
super.onPause();
}
/**
* Implements OnClickListener
*/
@ -212,6 +230,42 @@ public abstract class AccountServerBaseFragment extends Fragment
new DuplicateCheckTask(accountId, checkHost, checkLogin, checkSettingsMode).execute();
}
/**
* Make the given text view uneditable. If the text view is ever focused, the specified
* error message will be displayed.
*/
protected void makeTextViewUneditable(final TextView view, final String errorMessage) {
// We're editing an existing account; don't allow modification of the user name
if (mSettingsMode) {
view.setKeyListener(null);
view.setFocusable(true);
view.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
// Framework will not auto-hide IME; do it ourselves
InputMethodManager imm = (InputMethodManager)mContext.
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
view.setError(errorMessage);
} else {
view.setError(null);
}
}
});
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (view.getError() == null) {
view.setError(errorMessage);
} else {
view.setError(null);
}
}
});
}
}
/**
* Clears the "next" button de-bounce flags and allows the "next" button to activate.
*/

View File

@ -121,6 +121,11 @@ public class AccountSetupExchangeFragment extends AccountServerBaseFragment
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
public void onTextChanged(CharSequence s, int start, int before, int count) { }
};
// We're editing an existing account; don't allow modification of the user name
if (mSettingsMode) {
makeTextViewUneditable(mUsernameView,
getString(R.string.account_setup_username_uneditable_error));
}
mUsernameView.addTextChangedListener(validationTextWatcher);
mPasswordView.addTextChangedListener(validationTextWatcher);
mServerView.addTextChangedListener(validationTextWatcher);

View File

@ -172,6 +172,11 @@ public class AccountSetupIncomingFragment extends AccountServerBaseFragment {
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
public void onTextChanged(CharSequence s, int start, int before, int count) { }
};
// We're editing an existing account; don't allow modification of the user name
if (mSettingsMode) {
makeTextViewUneditable(mUsernameView,
getString(R.string.account_setup_username_uneditable_error));
}
mUsernameView.addTextChangedListener(validationTextWatcher);
mPasswordView.addTextChangedListener(validationTextWatcher);
mServerView.addTextChangedListener(validationTextWatcher);