<commit_before>package com.tuenti.tuentitv.ui.activity;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import butterknife.InjectView;
import butterknife.OnFocusChange;
import com.squareup.picasso.Picasso;
import com.tuenti.tuentitv.R;
import com.tuenti.tuentitv.ui.model.Account;
import com.tuenti.tuentitv.ui.presenter.LoginPresenter;
import com.tuenti.tuentitv.ui.transformation.CircleTransform;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;

public class LoginActivity extends BaseActivity implements LoginPresenter.View {

  private static final int PASSWORD_REQUEST_CODE = 1;

  @Inject LoginPresenter loginPresenter;

  @InjectView(R.id.ll_accounts_container) ViewGroup ll_accounts_container;
  @InjectView(R.id.iv_app_logo) View iv_app_logo;

  private float accountItemYSelected;
  private float accountItemYNotSelected;

  @Override protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.login_activity);
    super.onCreate(savedInstanceState);
    hookListeners();
    loginPresenter.setView(this);
    loginPresenter.loadAccounts();
  }

  @OnFocusChange(R.id.iv_app_logo) void onFocusChanged(boolean focused) {
    if (!focused) {
      iv_app_logo.setFocusable(false);
    }
  }

  @Override public void showAccounts(List<Account> accounts) {
    for (int i = 0; i < accounts.size(); i++) {
      View v_account = ll_accounts_container.getChildAt(i);
      showAccount(accounts.get(i), v_account);
    }
  }

  @Override public void showPasswordBox() {
    Intent intent = new Intent(this, EnterPasswordActivity.class);
    startActivityForResult(intent, PASSWORD_REQUEST_CODE);
  }

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PASSWORD_REQUEST_CODE && passwordIsCorrect(data)) {
      finish();
    }
  }

  private void hookListeners() {
    hookScaleAnimations();
    hookAccountClickListeners();
  }

  private void hookScaleAnimations() {
    for (int i = 0; i < ll_accounts_container.getChildCount(); i++) {
      View v_account = ll_accounts_container.getChildAt(i);
      configureScaleAnimator(v_account);
    }
  }

  private void configureScaleAnimator(View v_account_container) {
    View ib_account = v_account_container.findViewById(R.id.ib_account);
    View tv_account_name = v_account_container.findViewById(R.id.tv_account_name);
    ib_account.setOnFocusChangeListener(new OnFocusChangeAccountListener(tv_account_name));
  }

  private void showAccount(Account account, View v_account_container) {
    TextView tv_account_name = (TextView) v_account_container.findViewById(R.id.tv_account_name);
    ImageButton ib_account = (ImageButton) v_account_container.findViewById(R.id.ib_account);
    tv_account_name.setText(account.getName());
    Picasso.with(this)
        .load(account.getAvatarUrl())
        .transform(new CircleTransform(getResources().getDimension(R.dimen.account_item_size)))
        .placeholder(R.drawable.icn_user_default_blue)
        .into(ib_account);
  }

  private void hookAccountClickListeners() {
    for (int i = 0; i < ll_accounts_container.getChildCount() - 1; i++) {
      ImageButton ib_accoun =
          (ImageButton) ll_accounts_container.getChildAt(i).findViewById(R.id.ib_account);
      ib_accoun.setOnClickListener(new OnAccountClickListener(i));
    }
  }

  private boolean passwordIsCorrect(Intent data) {
    return data.getBooleanExtra(EnterPasswordActivity.RESULT_KEY, false);
  }

  private class OnFocusChangeAccountListener implements View.OnFocusChangeListener {

    private final View view;

    public OnFocusChangeAccountListener(View view) {
      this.view = view;
    }

    @Override public void onFocusChange(View v, boolean hasFocus) {
      float to = hasFocus ? 1.6f : 1;
      ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(view, "scaleX", to);
      scaleXAnimator.setDuration(getResources().getInteger(R.integer.short_animation_time));
      scaleXAnimator.start();
      ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(view, "scaleY", to);
      scaleYAnimator.setDuration(getResources().getInteger(R.integer.short_animation_time));
      scaleYAnimator.start();
    }
  }
<commit_msg>Avoid NPE pressing back on EnterPasswordActivity<commit_after>package com.tuenti.tuentitv.ui.activity;

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import butterknife.InjectView;
import butterknife.OnFocusChange;
import com.squareup.picasso.Picasso;
import com.tuenti.tuentitv.R;
import com.tuenti.tuentitv.ui.model.Account;
import com.tuenti.tuentitv.ui.presenter.LoginPresenter;
import com.tuenti.tuentitv.ui.transformation.CircleTransform;
import java.util.LinkedList;
import java.util.List;
import javax.inject.Inject;

public class LoginActivity extends BaseActivity implements LoginPresenter.View {

  private static final int PASSWORD_REQUEST_CODE = 1;

  @Inject LoginPresenter loginPresenter;

  @InjectView(R.id.ll_accounts_container) ViewGroup ll_accounts_container;
  @InjectView(R.id.iv_app_logo) View iv_app_logo;

  private float accountItemYSelected;
  private float accountItemYNotSelected;

  @Override protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.login_activity);
    super.onCreate(savedInstanceState);
    hookListeners();
    loginPresenter.setView(this);
    loginPresenter.loadAccounts();
  }

  @OnFocusChange(R.id.iv_app_logo) void onFocusChanged(boolean focused) {
    if (!focused) {
      iv_app_logo.setFocusable(false);
    }
  }

  @Override public void showAccounts(List<Account> accounts) {
    for (int i = 0; i < accounts.size(); i++) {
      View v_account = ll_accounts_container.getChildAt(i);
      showAccount(accounts.get(i), v_account);
    }
  }

  @Override public void showPasswordBox() {
    Intent intent = new Intent(this, EnterPasswordActivity.class);
    startActivityForResult(intent, PASSWORD_REQUEST_CODE);
  }

  @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == PASSWORD_REQUEST_CODE && passwordIsCorrect(data)) {
      finish();
    }
  }

  private void hookListeners() {
    hookScaleAnimations();
    hookAccountClickListeners();
  }

  private void hookScaleAnimations() {
    for (int i = 0; i < ll_accounts_container.getChildCount(); i++) {
      View v_account = ll_accounts_container.getChildAt(i);
      configureScaleAnimator(v_account);
    }
  }

  private void configureScaleAnimator(View v_account_container) {
    View ib_account = v_account_container.findViewById(R.id.ib_account);
    View tv_account_name = v_account_container.findViewById(R.id.tv_account_name);
    ib_account.setOnFocusChangeListener(new OnFocusChangeAccountListener(tv_account_name));
  }

  private void showAccount(Account account, View v_account_container) {
    TextView tv_account_name = (TextView) v_account_container.findViewById(R.id.tv_account_name);
    ImageButton ib_account = (ImageButton) v_account_container.findViewById(R.id.ib_account);
    tv_account_name.setText(account.getName());
    Picasso.with(this)
        .load(account.getAvatarUrl())
        .transform(new CircleTransform(getResources().getDimension(R.dimen.account_item_size)))
        .placeholder(R.drawable.icn_user_default_blue)
        .into(ib_account);
  }

  private void hookAccountClickListeners() {
    for (int i = 0; i < ll_accounts_container.getChildCount() - 1; i++) {
      ImageButton ib_accoun =
          (ImageButton) ll_accounts_container.getChildAt(i).findViewById(R.id.ib_account);
      ib_accoun.setOnClickListener(new OnAccountClickListener(i));
    }
  }

  private boolean passwordIsCorrect(Intent data) {
    return data != null && data.getBooleanExtra(EnterPasswordActivity.RESULT_KEY, false);
  }

  private class OnFocusChangeAccountListener implements View.OnFocusChangeListener {

    private final View view;

    public OnFocusChangeAccountListener(View view) {
      this.view = view;
    }

    @Override public void onFocusChange(View v, boolean hasFocus) {
      float to = hasFocus ? 1.6f : 1;
      ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(view, "scaleX", to);
      scaleXAnimator.setDuration(getResources().getInteger(R.integer.short_animation_time));
      scaleXAnimator.start();
      ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(view, "scaleY", to);
      scaleYAnimator.setDuration(getResources().getInteger(R.integer.short_animation_time));
      scaleYAnimator.start();
    }
  }

{'fraction_non_alphanumeric': 0.09818546142714016, 'fraction_numerical': 0.0017811421574084382, 'mean_word_length': 4.773778920308484, 'pattern_counts': {'":': 0, '<': 11, '<?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': '6272807', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2709, 'n_words': 491}