0

Amazon's Cognito for mobile comes with a built-in UI which you can customize on the web console, but I've heard that there are more customizable features than just the options presented there.

Below is the my authentication activity in which I believe this customization would take place. This activity works and presents Amazon's default login screen, but I can't find any reference to the login's layout. Does anybody have any experience customizing the UI significantly and is it possible to do it programmatically?

public class AuthenticatorActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_authenticator);

        // Add a call to initialize AWSMobileClient
        AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
            @Override
            public void onComplete(AWSStartupResult awsStartupResult) {
                SignInUI signin = (SignInUI) AWSMobileClient.getInstance().getClient(AuthenticatorActivity.this, SignInUI.class);
                signin.login(AuthenticatorActivity.this, MainNavigationActivity.class).execute();
            }
        }).execute();

        // Sign-in listener
        IdentityManager.getDefaultIdentityManager().addSignInStateChangeListener(new SignInStateChangeListener() {
            @Override
            public void onUserSignedIn() {
                Log.d("SignIn", "User Signed In");
            }

            // Sign-out listener
            @Override
            public void onUserSignedOut() {

                Log.d("SignIn", "User Signed Out");
                showSignIn();
            }
        });
        showSignIn();
    }

    /*
     * Display the AWS SDK sign-in/sign-up UI
     */
    private void showSignIn() {

        Log.d("SignIn", "showSignIn");

        SignInUI signin = (SignInUI) AWSMobileClient.getInstance().getClient(AuthenticatorActivity.this, SignInUI.class);
        signin.login(AuthenticatorActivity.this, MainNavigationActivity.class).execute();
    }
}

1 Answer 1

1

Turns out there is very limited support for customization and it is all outlined here: https://docs.aws.amazon.com/aws-mobile/latest/developerguide/add-aws-mobile-user-sign-in-customize.html

  • To present the Email and Password user SignInUI, set userPools to true.
  • To present Facebook or Google user SignInUI, add signInButton(FacebookButton.class) or signInButton(GoogleButton.class).
  • To change the logo, use the logoResId.
  • To change the background color, use backgroundColor.
  • To cancel the sign-in flow, set .canCancel(true).
  • To change the font in the sign-in views, use the fontFamily method and pass in the string that represents a font family.
  • To draw the backgroundColor full screen, use fullScreenBackgroundColor.

import android.app.Activity;

import android.graphics.Color;
import android.os.Bundle;
import com.amazonaws.mobile.auth.facebook.FacebookButton;
import com.amazonaws.mobile.auth.google.GoogleButton;
import com.amazonaws.mobile.auth.ui.AuthUIConfiguration;
import com.amazonaws.mobile.auth.ui.SignInUI;  
import com.amazonaws.mobile.client.AWSMobileClient;
import com.amazonaws.mobile.client.AWSStartupHandler;
import com.amazonaws.mobile.client.AWSStartupResult;

public class YourMainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
        @Override
        public void onComplete(final AWSStartupResult awsStartupResult) {
            AuthUIConfiguration config =
                new AuthUIConfiguration.Builder()
                    .userPools(true)  // true? show the Email and Password UI
                    .signInButton(FacebookButton.class) // Show Facebook button
                    .signInButton(GoogleButton.class) // Show Google button
                    .logoResId(R.drawable.mylogo) // Change the logo
                    .backgroundColor(Color.BLUE) // Change the backgroundColor
                    .isBackgroundColorFullScreen(true) // Full screen backgroundColor the backgroundColor full screenff
                    .fontFamily("sans-serif-light") // Apply sans-serif-light as the global font
                    .canCancel(true)
                    .build();
            SignInUI signinUI = (SignInUI) AWSMobileClient.getInstance().getClient(YourMainActivity.this, SignInUI.class);
            signinUI.login(YourMainActivity.this, YourNextActivity.class).authUIConfiguration(config).execute();
        }
    }).execute();
}
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.