private void showColorPickerDialog() { final int spinnerPos = colorSpinner.getSelectedItemPosition(); Integer currentColor = colors.get(spinnerPos); final int defaultTextColor = ContextCompat.getColor(this, android.R.color.primary_text_dark); final int defaultBackgroundColor = ContextCompat.getColor(this, android.R.color.background_dark); final ColorPickerView colorPickerView = new ColorPickerView(this); colorPickerView.showAlpha(false); if (currentColor != null) { colorPickerView.setColor(currentColor); } else if (spinnerPos == QUESTION_TEXT_SPINNER_POS || spinnerPos == ANSWER_TEXT_SPINNER_POS) { colorPickerView.setColor(defaultTextColor); } else if (spinnerPos == QUESTION_BACKGROUND_SPINNER_POS || spinnerPos == ANSWER_BACKGROUND_SPINNER_POS) { colorPickerView.setColor(defaultBackgroundColor); } new AlertDialog.Builder(this) .setTitle(R.string.color_button_text) .setView(colorPickerView) .setPositiveButton( R.string.ok_text, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { colorButton.setTextColor(colorPickerView.getColor()); colors.set(spinnerPos, colorPickerView.getColor()); } }) .create() .show(); }
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))); }