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))); }
public void onClick(View v) { // If the user click on these fields, then we assume user has changed some settings. settingsChanged = true; if (v == colorCheckbox) { if (colorCheckbox.isChecked()) { colorRow.setVisibility(View.VISIBLE); } else { colorRow.setVisibility(View.GONE); resetToDefaultColors(); } } if (v == colorButton) { showColorPickerDialog(); } if (v == qTypefaceCheckbox) { if (qTypefaceCheckbox.isChecked()) { qTypefaceEdit.setVisibility(View.VISIBLE); } else { qTypefaceEdit.setVisibility(View.GONE); setting.setQuestionFont(""); } } if (v == aTypefaceCheckbox) { if (aTypefaceCheckbox.isChecked()) { aTypefaceEdit.setVisibility(View.VISIBLE); } else { aTypefaceEdit.setVisibility(View.GONE); setting.setAnswerFont(""); } } if (v == displayInHTMLCheckbox) { if (displayInHTMLCheckbox.isChecked()) { // Create a AlertDialog for user to select fields display in HTML fieldsDisplayedInHTML = setting.getDisplayInHTMLEnum(); showCardFieldMultipleChoiceAlertDialog( fieldsDisplayedInHTML, R.string.settings_html_display); } else { fieldsDisplayedInHTML = EnumSet.noneOf(CardField.class); } if (fieldsDisplayedInHTML.size() == 0) { field1Checkbox.setChecked(false); } } if (v == field1Checkbox) { if (field1Checkbox.isChecked()) { questionFields = setting.getQuestionFieldEnum(); showCardFieldMultipleChoiceAlertDialog(questionFields, R.string.settings_field1); } else { questionFields = EnumSet.of(CardField.QUESTION); } if (questionFields.size() == 0) { field1Checkbox.setChecked(false); } } if (v == field2Checkbox) { if (field2Checkbox.isChecked()) { answerFields = setting.getAnswerFieldEnum(); showCardFieldMultipleChoiceAlertDialog(answerFields, R.string.settings_field2); } else { answerFields = EnumSet.of(CardField.ANSWER); } if (answerFields.size() == 0) { field2Checkbox.setChecked(false); } } if (v == qTypefaceEdit) { FileBrowserFragment df = new FileBrowserFragment(); Bundle b = new Bundle(); b.putString(FileBrowserFragment.EXTRA_FILE_EXTENSIONS, ".ttf"); b.putString(FileBrowserFragment.EXTRA_DEFAULT_ROOT, AMEnv.DEFAULT_ROOT_PATH); b.putBoolean(FileBrowserFragment.EXTRA_DISMISS_ON_SELECT, true); df.setArguments(b); df.setOnFileClickListener(qTypefaceEditFbListener); df.show(getSupportFragmentManager(), "qTypefaceEditFB"); } if (v == aTypefaceEdit) { FileBrowserFragment df = new FileBrowserFragment(); Bundle b = new Bundle(); b.putString(FileBrowserFragment.EXTRA_FILE_EXTENSIONS, ".ttf"); b.putString(FileBrowserFragment.EXTRA_DEFAULT_ROOT, AMEnv.DEFAULT_ROOT_PATH); b.putBoolean(FileBrowserFragment.EXTRA_DISMISS_ON_SELECT, true); df.setArguments(b); df.setOnFileClickListener(aTypefaceEditFbListener); df.show(getSupportFragmentManager(), "aTypefaceEditFB"); } }
@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(); }