@@ -0,0 +1,2601 @@
+/*%0A * Copyright (C) 2017 Joao Paulo Fernandes Ventura, Udi Cohen%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *       http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.udinic.accounts_authenticator_example.authentication;%0A%0Aimport android.os.Bundle;%0Aimport android.support.annotation.NonNull;%0A%0Aimport com.google.android.gms.tasks.Continuation;%0Aimport com.google.android.gms.tasks.Task;%0Aimport com.google.firebase.auth.AuthResult;%0Aimport com.google.firebase.auth.FirebaseAuth;%0Aimport com.google.firebase.auth.GetTokenResult;%0A%0Aimport static android.accounts.AccountManager.KEY_ACCOUNT_NAME;%0Aimport static android.accounts.AccountManager.KEY_AUTHTOKEN;%0Aimport static android.accounts.AccountManager.KEY_PASSWORD;%0Aimport static com.google.common.base.Preconditions.checkNotNull;%0A%0Aclass SignUpTask implements Continuation%3CBundle, Task%3CBundle%3E%3E %7B%0A%0A    private Bundle mAuthData;%0A%0A    @Override%0A    public Task%3CBundle%3E then(@NonNull Task%3CBundle%3E task) throws Exception %7B%0A        mAuthData = checkNotNull(task.getResult());%0A        return signUp().continueWithTask(getAuthToken()).continueWith(getResult());%0A    %7D%0A%0A    private Task%3CAuthResult%3E signUp() %7B%0A        return FirebaseAuth.getInstance().createUserWithEmailAndPassword(%0A                checkNotNull(mAuthData.getString(KEY_ACCOUNT_NAME)),%0A                checkNotNull(mAuthData.getString(KEY_PASSWORD))%0A        );%0A    %7D%0A%0A    private Continuation%3CAuthResult, Task%3CGetTokenResult%3E%3E getAuthToken() %7B%0A        return new Continuation%3CAuthResult, Task%3CGetTokenResult%3E%3E() %7B%0A            @Override%0A            public Task%3CGetTokenResult%3E then(@NonNull Task%3CAuthResult%3E task) throws Exception %7B%0A                return task.getResult().getUser().getToken(true);%0A            %7D%0A        %7D;%0A    %7D%0A%0A    private Continuation%3CGetTokenResult, Bundle%3E getResult() %7B%0A        return new Continuation%3CGetTokenResult, Bundle%3E () %7B%0A            @Override%0A            public Bundle then(@NonNull Task%3CGetTokenResult%3E task) throws Exception %7B%0A                mAuthData.putString(KEY_AUTHTOKEN, checkNotNull(task.getResult().getToken()));%0A                return mAuthData;%0A            %7D%0A        %7D;%0A    %7D%0A%0A%7D%0A

Create Firebase sign up task