<commit_before>package eu.e43.impeller.activity;

import java.io.File;
import java.io.IOException;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.net.http.HttpResponseCache;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import eu.e43.impeller.Constants;
import eu.e43.impeller.content.PumpContentProvider;
import eu.e43.impeller.uikit.ImageLoader;
import eu.e43.impeller.account.Authenticator;

import static android.os.Build.*;

public abstract class ActivityWithAccount extends ActionBarActivity {
	public static final int LOGIN_REQUEST_CODE = 65535;
    private static final int LOGIN_REQUEST_CODE_STARTUP = 65534;
	private static final String TAG = "ActivityWithAccount";

    public    AccountManager 	m_accountManager 	= null;
    private   Account           m_newAccount        = null; // For resume dance
	public    Account           m_account           = null;
	private   ImageLoader       m_imageLoader		= null;
    private   Intent            m_startIntent       = null;

	public ActivityWithAccount() {
		super();
	}

    public Account getAccount() {
        return m_account;
    }

	protected abstract void onCreateEx(Bundle savedInstanceState);
    protected void onStartIntent(Intent startIntent) {}

	@Override
	protected final void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		m_accountManager = AccountManager.get(this);

        Intent startIntent = getIntent();
        if(savedInstanceState != null && savedInstanceState.containsKey("account")) {
            m_account = savedInstanceState.getParcelable("account");
        } else if(startIntent.hasExtra(Constants.EXTRA_ACCOUNT)) {
            Account a = (Account) startIntent.getParcelableExtra(Constants.EXTRA_ACCOUNT);
            if(a.type.equals(Authenticator.ACCOUNT_TYPE)) {
                m_account = a;
            }
        }

        if(savedInstanceState == null)
            m_startIntent = startIntent;

		onCreateEx(savedInstanceState);

        if(m_account != null) {
            haveGotAccount(m_account);
            return;
        } else queryForAccount(QueryReason.Startup);
    }

    public enum QueryReason {
        Startup,
        User
    }

    /** Query the user for an account (asynchronously). Default implementation uses a chooser. Call
     *  haveGotAccount when you are successful (else finish)
     */
    protected void queryForAccount(QueryReason reason) {
	    // No account passed or account is invalid
        Intent chooseIntent = new Intent(this, AccountPickerActivity.class);
        this.startActivityForResult(chooseIntent, reason == QueryReason.Startup ? LOGIN_REQUEST_CODE_STARTUP : LOGIN_REQUEST_CODE);
	}

    /** Save the account */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if(m_account != null) outState.putParcelable("account", m_account);<commit_msg>When known , set account before calling super.onCreate (since it may use it re-initializing things)<commit_after>package eu.e43.impeller.activity;

import java.io.File;
import java.io.IOException;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Intent;
import android.net.http.HttpResponseCache;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import eu.e43.impeller.Constants;
import eu.e43.impeller.content.PumpContentProvider;
import eu.e43.impeller.uikit.ImageLoader;
import eu.e43.impeller.account.Authenticator;

import static android.os.Build.*;

public abstract class ActivityWithAccount extends ActionBarActivity {
	public static final int LOGIN_REQUEST_CODE = 65535;
    private static final int LOGIN_REQUEST_CODE_STARTUP = 65534;
	private static final String TAG = "ActivityWithAccount";

    public    AccountManager 	m_accountManager 	= null;
    private   Account           m_newAccount        = null; // For resume dance
	public    Account           m_account           = null;
	private   ImageLoader       m_imageLoader		= null;
    private   Intent            m_startIntent       = null;

	public ActivityWithAccount() {
		super();
	}

    public Account getAccount() {
        return m_account;
    }

	protected abstract void onCreateEx(Bundle savedInstanceState);
    protected void onStartIntent(Intent startIntent) {}

	@Override
	protected final void onCreate(Bundle savedInstanceState) {
        Intent startIntent = getIntent();
        if(savedInstanceState != null && savedInstanceState.containsKey("account")) {
            m_account = savedInstanceState.getParcelable("account");
        } else if(startIntent.hasExtra(Constants.EXTRA_ACCOUNT)) {
            Account a = (Account) startIntent.getParcelableExtra(Constants.EXTRA_ACCOUNT);
            if(a.type.equals(Authenticator.ACCOUNT_TYPE)) {
                m_account = a;
            }
        }

		super.onCreate(savedInstanceState);
		m_accountManager = AccountManager.get(this);

        if(savedInstanceState == null)
            m_startIntent = startIntent;

		onCreateEx(savedInstanceState);

        if(m_account != null) {
            haveGotAccount(m_account);
            return;
        } else queryForAccount(QueryReason.Startup);
    }

    public enum QueryReason {
        Startup,
        User
    }

    /** Query the user for an account (asynchronously). Default implementation uses a chooser. Call
     *  haveGotAccount when you are successful (else finish)
     */
    protected void queryForAccount(QueryReason reason) {
	    // No account passed or account is invalid
        Intent chooseIntent = new Intent(this, AccountPickerActivity.class);
        this.startActivityForResult(chooseIntent, reason == QueryReason.Startup ? LOGIN_REQUEST_CODE_STARTUP : LOGIN_REQUEST_CODE);
	}

    /** Save the account */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if(m_account != null) outState.putParcelable("account", m_account);
{'fraction_non_alphanumeric': 0.08325434439178515, 'fraction_numerical': 0.0069510268562401265, 'mean_word_length': 3.3333333333333335, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2137389', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1695, 'n_words': 406}