private void updateViews() { // Default 24 px font questionFontSizeSpinner.selectItemFromValue(Integer.toString(setting.getQuestionFontSize()), 6); answerFontSizeSpinner.selectItemFromValue(Integer.toString(setting.getAnswerFontSize()), 6); // Default center questionAlignSpinner.selectItemFromValue(setting.getQuestionTextAlign().toString(), 1); answerAlignSpinner.selectItemFromValue(setting.getAnswerTextAlign().toString(), 1); // Default US but need special care questionLocaleSpinner.selectItemFromValue(setting.getQuestionAudio(), 2); answerLocaleSpinner.selectItemFromValue(setting.getAnswerAudio(), 2); if (!Strings.isNullOrEmpty(setting.getQuestionAudioLocation())) { // User audio questionLocaleSpinner.setSelection(1); } else if (Strings.isNullOrEmpty(setting.getQuestionAudio())) { // Disabled questionLocaleSpinner.setSelection(0); } if (!Strings.isNullOrEmpty(setting.getAnswerAudioLocation())) { // User audio answerLocaleSpinner.setSelection(1); } else if (Strings.isNullOrEmpty(setting.getAnswerAudio())) { // Disabled answerLocaleSpinner.setSelection(0); } // Default to single sided styleSpinner.selectItemFromValue(setting.getCardStyle().toString(), 0); // Default to 50, the index in the array for value 50 is 5. qaRatioSpinner.selectItemFromValue(setting.getQaRatio().toString(), 5); colorCheckbox.setChecked(!setting.isDefaultColor()); if (colorCheckbox.isChecked()) { colorRow.setVisibility(View.VISIBLE); } else { colorRow.setVisibility(View.GONE); } Integer colorButtonTextColor = colorSpinner.getSelectedItemPosition(); if (colorButtonTextColor != null) { colorButton.setTextColor(colorButtonTextColor); } else { final int defaultTextColor = ContextCompat.getColor(this, android.R.color.primary_text_dark); colorButton.setText(defaultTextColor); } qTypefaceCheckbox.setChecked(!Strings.isNullOrEmpty(setting.getQuestionFont())); if (qTypefaceCheckbox.isChecked()) { qTypefaceEdit.setVisibility(View.VISIBLE); qTypefaceEdit.setText(setting.getQuestionFont()); } else { qTypefaceEdit.setVisibility(View.GONE); } aTypefaceCheckbox.setChecked(!Strings.isNullOrEmpty(setting.getAnswerFont())); if (aTypefaceCheckbox.isChecked()) { aTypefaceEdit.setVisibility(View.VISIBLE); aTypefaceEdit.setText(setting.getAnswerFont()); } else { aTypefaceEdit.setVisibility(View.GONE); } displayInHTMLCheckbox.setChecked(!(fieldsDisplayedInHTML.isEmpty())); linebreakCheckbox.setChecked(setting.getHtmlLineBreakConversion()); field1Checkbox.setChecked( !(questionFields.size() == 1 && questionFields.contains(CardField.QUESTION))); field2Checkbox.setChecked( !(answerFields.size() == 1 && answerFields.contains(CardField.ANSWER))); }
@Override public void run() { // Dismiss the progress dialog settingDao = dbOpenHelper.getSettingDao(); setContentView(R.layout.settings_screen); questionFontSizeSpinner = (AMSpinner) findViewById(R.id.question_font_size_spinner); answerFontSizeSpinner = (AMSpinner) findViewById(R.id.answer_font_size_spinner); questionAlignSpinner = (AMSpinner) findViewById(R.id.question_align_spinner); answerAlignSpinner = (AMSpinner) findViewById(R.id.answer_align_spinner); styleSpinner = (AMSpinner) findViewById(R.id.card_style_spinner); qaRatioSpinner = (AMSpinner) findViewById(R.id.ratio_spinner); questionLocaleSpinner = (AMSpinner) findViewById(R.id.question_locale_spinner); answerLocaleSpinner = (AMSpinner) findViewById(R.id.answer_locale_spinner); audioLocationEdit = (EditText) findViewById(R.id.settings_audio_location); // If we got no text, we will use the default location. if (!Strings.isNullOrEmpty(setting.getQuestionAudio())) { audioLocationEdit.setText(setting.getQuestionAudioLocation()); } if (!Strings.isNullOrEmpty(setting.getAnswerAudio())) { audioLocationEdit.setText(setting.getAnswerAudioLocation()); } if (Strings.isNullOrEmpty(audioLocationEdit.getText().toString())) { audioLocationEdit.setText(AMEnv.DEFAULT_AUDIO_PATH); } colorCheckbox = (CheckBox) findViewById(R.id.checkbox_customize_color); colorCheckbox.setOnClickListener(settingFieldOnClickListener); colorRow = (TableRow) findViewById(R.id.color_row); colorSpinner = (AMSpinner) findViewById(R.id.color_item_spinner); colorButton = (Button) findViewById(R.id.settings_color_button); colorButton.setOnClickListener(settingFieldOnClickListener); colors = new ArrayList<Integer>(5); colors.add(setting.getQuestionTextColor()); colors.add(setting.getAnswerTextColor()); colors.add(setting.getQuestionBackgroundColor()); colors.add(setting.getAnswerBackgroundColor()); colors.add(setting.getSeparatorColor()); qTypefaceCheckbox = (CheckBox) findViewById(R.id.checkbox_typeface_question); qTypefaceCheckbox.setOnClickListener(settingFieldOnClickListener); aTypefaceCheckbox = (CheckBox) findViewById(R.id.checkbox_typeface_answer); aTypefaceCheckbox.setOnClickListener(settingFieldOnClickListener); qTypefaceEdit = (EditText) findViewById(R.id.edit_typeface_question); qTypefaceEdit.setOnClickListener(settingFieldOnClickListener); aTypefaceEdit = (EditText) findViewById(R.id.edit_typeface_answer); aTypefaceEdit.setOnClickListener(settingFieldOnClickListener); displayInHTMLCheckbox = (CheckBox) findViewById(R.id.display_html); displayInHTMLCheckbox.setOnClickListener(settingFieldOnClickListener); fieldsDisplayedInHTML = setting.getDisplayInHTMLEnum(); linebreakCheckbox = (CheckBox) findViewById(R.id.linebreak_conversion); linebreakCheckbox.setOnClickListener(settingFieldOnClickListener); field1Checkbox = (CheckBox) findViewById(R.id.checkbox_field1); field1Checkbox.setOnClickListener(settingFieldOnClickListener); questionFields = setting.getQuestionFieldEnum(); field2Checkbox = (CheckBox) findViewById(R.id.checkbox_field2); field2Checkbox.setOnClickListener(settingFieldOnClickListener); answerFields = setting.getAnswerFieldEnum(); updateViews(); setSpinnerListeners(); }