<commit_before>package org.mercycorps.translationcards.activity.addDeck;


import android.annotation.TargetApi;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.AutoCompleteTextView.OnDismissListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.mercycorps.translationcards.MainApplication;
import org.mercycorps.translationcards.R;
import org.mercycorps.translationcards.data.Language;
import org.mercycorps.translationcards.service.LanguageService;

import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnTextChanged;

public class EnterDeckSourceLanguageActivity extends AddDeckActivity {
    @Bind (R.id.deck_source_language_input) AutoCompleteTextView sourceLanguageInput;
    @Bind (R.id.deck_source_language_next_label) LinearLayout nextButton;
    @Bind(R.id.deck_source_language_next_text) TextView nextButtonText;
    @Bind(R.id.deck_source_language_next_image) ImageView nextButtonImage;
    @Bind(R.id.invalid_source_language_message) TextView invalidLanguageErrorView;
    private LanguageService languageService;

    @Override
    public void inflateView() {
        setContentView(R.layout.activity_deck_source_language);
    }

    @Override
    public void initStates() {
        languageService = ((MainApplication)getApplication()).getLanguageService();
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                this,
                android.R.layout.simple_dropdown_item_1line,
                languageService.getLanguageNames()
        );

        sourceLanguageInput = (AutoCompleteTextView) findViewById(R.id.deck_source_language_input);
        sourceLanguageInput.setAdapter(adapter);
        fillSourceLanguageField();
        checkLanguageForError();

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setOnDismissListener();
        } else {
            setTextWatcher();
        }
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private void setOnDismissListener() {
        OnDismissListener onDismissListener = new OnDismissListener() {
            @Override
            public void onDismiss() {
                checkLanguageForError();
            }
        };

        sourceLanguageInput.setOnDismissListener(onDismissListener);
    }

    private void setTextWatcher() {
        TextWatcher textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                checkLanguageForError();
            }
        };

        sourceLanguageInput.addTextChangedListener(textWatcher);
    }

    public void checkLanguageForError() {
        Integer viewVisibility = isSourceLanguageValid() ? View.GONE : View.VISIBLE;
        invalidLanguageErrorView.setVisibility(viewVisibility);
    }

    private void fillSourceLanguageField() {
        sourceLanguageInput.setText(languageService.getTitleCaseName(getContextFromIntent().getSourceLanguage()));
    }

    @Override
    public void setBitmapsForActivity() {
        setBitmap(R.id.deck_source_language_image, R.drawable.enter_phrase_image);
    }

    @OnClick(R.id.deck_source_language_next_label)<commit_msg>Coleman #150 - set text field to red if invalid source language entered<commit_after>package org.mercycorps.translationcards.activity.addDeck;


import android.annotation.TargetApi;
import android.graphics.PorterDuff;
import android.os.Build;
import android.support.v4.content.ContextCompat;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.AutoCompleteTextView.OnDismissListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.mercycorps.translationcards.MainApplication;
import org.mercycorps.translationcards.R;
import org.mercycorps.translationcards.data.Language;
import org.mercycorps.translationcards.service.LanguageService;

import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnTextChanged;

public class EnterDeckSourceLanguageActivity extends AddDeckActivity {
    @Bind (R.id.deck_source_language_input) AutoCompleteTextView sourceLanguageInput;
    @Bind (R.id.deck_source_language_next_label) LinearLayout nextButton;
    @Bind(R.id.deck_source_language_next_text) TextView nextButtonText;
    @Bind(R.id.deck_source_language_next_image) ImageView nextButtonImage;
    @Bind(R.id.invalid_source_language_message) TextView invalidLanguageErrorView;
    private LanguageService languageService;

    @Override
    public void inflateView() {
        setContentView(R.layout.activity_deck_source_language);
    }

    @Override
    public void initStates() {
        languageService = ((MainApplication)getApplication()).getLanguageService();
        ArrayAdapter<String> adapter = new ArrayAdapter<>(
                this,
                android.R.layout.simple_dropdown_item_1line,
                languageService.getLanguageNames()
        );

        sourceLanguageInput = (AutoCompleteTextView) findViewById(R.id.deck_source_language_input);
        sourceLanguageInput.setAdapter(adapter);
        fillSourceLanguageField();
        checkLanguageForError();

        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
            setOnDismissListener();
        } else {
            setTextWatcher();
        }
    }

    @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
    private void setOnDismissListener() {
        OnDismissListener onDismissListener = new OnDismissListener() {
            @Override
            public void onDismiss() {
                checkLanguageForError();
            }
        };

        sourceLanguageInput.setOnDismissListener(onDismissListener);
    }

    private void setTextWatcher() {
        TextWatcher textWatcher = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                checkLanguageForError();
            }
        };

        sourceLanguageInput.addTextChangedListener(textWatcher);
    }

    public void checkLanguageForError() {
        if(isSourceLanguageValid()) {
            invalidLanguageErrorView.setVisibility(View.GONE);
            sourceLanguageInput.getBackground().clearColorFilter();
        } else {
            invalidLanguageErrorView.setVisibility(View.VISIBLE);
            sourceLanguageInput.getBackground().setColorFilter(getResources().getColor(R.color.red), PorterDuff.Mode.SRC_ATOP);
        }
    }

    private void fillSourceLanguageField() {
        sourceLanguageInput.setText(languageService.getTitleCaseName(getContextFromIntent().getSourceLanguage()));
    }

    @Override
    public void setBitmapsForActivity() {
        setBitmap(R.id.deck_source_language_image, R.drawable.enter_phrase_image);
    }

    @OnClick(R.id.deck_source_language_next_label)
{'fraction_non_alphanumeric': 0.08207315496962647, 'fraction_numerical': 0.0014217396923872302, 'mean_word_length': 3.4217142857142857, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '6005338', 'n_tokens_mistral': 2106, 'n_tokens_neox': 2048, 'n_words': 343}