<commit_before>package com.firebase.ui.auth.data.remote;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.FirebaseUiException;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.data.model.Resource;
import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.util.data.ProviderAvailability;
import com.firebase.ui.auth.viewmodel.idp.ProviderSignInBase;
import com.google.firebase.auth.TwitterAuthProvider;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterConfig;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterAuthClient;

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public class TwitterSignInHandler extends ProviderSignInBase<Void> {
    static {
        if (ProviderAvailability.IS_TWITTER_AVAILABLE) {
            initializeTwitter();
        }
    }

    private final TwitterAuthClient mClient;
    private final TwitterSessionResult mCallback = new TwitterSessionResult();

    public TwitterSignInHandler(Application application) {
        super(application);
        mClient = new TwitterAuthClient();
    }

    public static void initializeTwitter() {
        Context context = AuthUI.getApplicationContext();

        // Note: this has no effect if Twitter is already initialized so it's safe to call
        // multiple times.
        Twitter.initialize(new TwitterConfig.Builder(context)
                .twitterAuthConfig(new TwitterAuthConfig(
                        context.getString(R.string.twitter_consumer_key),
                        context.getString(R.string.twitter_consumer_secret)))
                .build());
    }

    private static IdpResponse createIdpResponse(
            TwitterSession session, String email, String name, Uri photoUri) {
        return new IdpResponse.Builder(
                new User.Builder(TwitterAuthProvider.PROVIDER_ID, email)
                        .setName(name)<commit_msg>Init in static block<commit_after>package com.firebase.ui.auth.data.remote;

import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.RestrictTo;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.FirebaseUiException;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.data.model.Resource;
import com.firebase.ui.auth.data.model.User;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.util.data.ProviderAvailability;
import com.firebase.ui.auth.viewmodel.idp.ProviderSignInBase;
import com.google.firebase.auth.TwitterAuthProvider;
import com.twitter.sdk.android.core.Callback;
import com.twitter.sdk.android.core.Result;
import com.twitter.sdk.android.core.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterConfig;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.core.TwitterException;
import com.twitter.sdk.android.core.TwitterSession;
import com.twitter.sdk.android.core.identity.TwitterAuthClient;

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public class TwitterSignInHandler extends ProviderSignInBase<Void> {
    static {
        if (ProviderAvailability.IS_TWITTER_AVAILABLE) {
            Context context = AuthUI.getApplicationContext();

            // Note: this has no effect if Twitter is already initialized so it's safe to call
            // multiple times.
            Twitter.initialize(new TwitterConfig.Builder(context)
                    .twitterAuthConfig(new TwitterAuthConfig(
                            context.getString(R.string.twitter_consumer_key),
                            context.getString(R.string.twitter_consumer_secret)))
                    .build());
        }
    }

    private final TwitterAuthClient mClient;
    private final TwitterSessionResult mCallback = new TwitterSessionResult();

    public TwitterSignInHandler(Application application) {
        super(application);
        mClient = new TwitterAuthClient();
    }

    public static void initializeTwitter() {
        // This method is intentionally empty, but calling it forces the static {} block of this
        // class to be executed (if it wasn't already).
        //
        // Even though it's currently safe to initialize Twitter more than once, this protects
        // against a future behavior change and gives a small efficiency gain.
    }

    private static IdpResponse createIdpResponse(
            TwitterSession session, String email, String name, Uri photoUri) {
        return new IdpResponse.Builder(
                new User.Builder(TwitterAuthProvider.PROVIDER_ID, email)
                        .setName(name)
{'fraction_non_alphanumeric': 0.09095821325648415, 'fraction_numerical': 0.0, 'mean_word_length': 3.518307567127746, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6543822', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1482, 'n_words': 313}