in car_app_library/showcase/common/src/main/java/androidx/car/app/sample/showcase/common/templates/SignInTemplateDemoScreen.java [141:191]
private Template getUsernameSignInTemplate() {
InputCallback listener = new InputCallback() {
@Override
public void onInputSubmitted(@NonNull String text) {
if (mState == State.USERNAME) {
mUsername = text;
submitUsername();
}
}
@Override
public void onInputTextChanged(@NonNull String text) {
// This callback demonstrates how to use handle the text changed event.
// In this case, we check that the user name doesn't exceed a certain length.
if (mState == State.USERNAME) {
mUsername = text;
mErrorMessage = validateUsername();
// Invalidate the template (and hence possibly update the error message) only
// if clearing up the error string, or if the error is changing.
if (!mLastErrorMessage.isEmpty()
&& (mErrorMessage.isEmpty()
|| !mLastErrorMessage.equals(mErrorMessage))) {
invalidate();
}
}
}
};
InputSignInMethod.Builder builder = new InputSignInMethod.Builder(listener)
.setHint("Email")
.setKeyboardType(InputSignInMethod.KEYBOARD_EMAIL);
if (mErrorMessage != null) {
builder.setErrorMessage(mErrorMessage);
mLastErrorMessage = mErrorMessage;
}
if (mUsername != null) {
builder.setDefaultValue(mUsername);
}
InputSignInMethod signInMethod = builder.build();
return new SignInTemplate.Builder(signInMethod)
.addAction(mProviderSignInAction)
.addAction(getCarContext().getCarAppApiLevel() > CarAppApiLevels.LEVEL_3
? mQRCodeSignInAction : mPinSignInAction)
.setTitle("Sign in")
.setInstructions("Enter your credentials")
.setHeaderAction(Action.BACK)
.setAdditionalText(mAdditionalText)
.build();
}