From 24c5c1804be4c5963a29bb08c50a01a7a5a63e6c Mon Sep 17 00:00:00 2001 From: Olga Miller Date: Sun, 5 Mar 2017 13:07:52 +0100 Subject: [PATCH] Edit text color in color dialog (as outline color) --- .../java/om/sstvencoder/ColorFragment.java | 12 +++- .../java/om/sstvencoder/EditTextActivity.java | 57 ++++++++++++++----- .../main/res/layout/activity_edit_text.xml | 34 +++++++++-- app/src/main/res/values/strings.xml | 1 + 4 files changed, 84 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/om/sstvencoder/ColorFragment.java b/app/src/main/java/om/sstvencoder/ColorFragment.java index c089f76..411cde6 100644 --- a/app/src/main/java/om/sstvencoder/ColorFragment.java +++ b/app/src/main/java/om/sstvencoder/ColorFragment.java @@ -33,16 +33,24 @@ public class ColorFragment extends DialogFragment public interface OnColorSelectedListener { void onColorSelected(DialogFragment fragment, int color); + + void onCancel(DialogFragment fragment); } private List mListeners; + private int mTitle; private int mColor; public ColorFragment() { mListeners = new ArrayList<>(); + mTitle = R.string.color; mColor = Color.WHITE; } + public void setTitle(int title) { + mTitle = title; + } + public void setColor(int color) { mColor = color; } @@ -59,7 +67,7 @@ public class ColorFragment extends DialogFragment ColorPaletteView colorView = (ColorPaletteView) view.findViewById(R.id.select_color); colorView.setColor(mColor); colorView.addOnColorSelectedListener(this); - builder.setTitle(R.string.outline_color); + builder.setTitle(mTitle); builder.setView(view); return builder.create(); } @@ -77,6 +85,8 @@ public class ColorFragment extends DialogFragment @Override public void onCancel(View v) { + for (OnColorSelectedListener listener : mListeners) + listener.onCancel(this); dismiss(); } } diff --git a/app/src/main/java/om/sstvencoder/EditTextActivity.java b/app/src/main/java/om/sstvencoder/EditTextActivity.java index f749174..49dc249 100644 --- a/app/src/main/java/om/sstvencoder/EditTextActivity.java +++ b/app/src/main/java/om/sstvencoder/EditTextActivity.java @@ -25,23 +25,28 @@ import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; -import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Spinner; import java.util.List; -import om.sstvencoder.ColorPalette.ColorPaletteView; import om.sstvencoder.TextOverlay.Label; public class EditTextActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener, ColorFragment.OnColorSelectedListener { + + private enum EditColorMode { + None, + Text, + Outline + } + public static final int REQUEST_CODE = 101; public static final String EXTRA = "EDIT_TEXT_EXTRA"; private EditText mEditText; - private ColorPaletteView mColorPaletteView; - private int mOutlineColor; + private int mColor, mOutlineColor; + private EditColorMode mEditColor; private float mTextSize, mOutlineSize; private FontFamilySet mFontFamilySet; private FontFamilySet.FontFamily mSelectedFontFamily; @@ -52,8 +57,8 @@ public class EditTextActivity extends AppCompatActivity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit_text); + mEditColor = EditColorMode.None; mEditText = (EditText) findViewById(R.id.edit_text); - mColorPaletteView = (ColorPaletteView) findViewById(R.id.edit_color); mEditBold = (CheckBox) findViewById(R.id.edit_bold); mEditItalic = (CheckBox) findViewById(R.id.edit_italic); mEditOutline = (CheckBox) findViewById(R.id.edit_outline); @@ -67,14 +72,16 @@ public class EditTextActivity extends AppCompatActivity initTextSizeSpinner(label.getTextSize()); mEditBold.setChecked(label.getBold()); mEditItalic.setChecked(label.getItalic()); - mColorPaletteView.setColor(label.getForeColor()); initFontFamilySpinner(label.getFamilyName()); updateBoldAndItalic(); mEditOutline.setChecked(label.getOutline()); initOutlineSizeSpinner(label.getOutlineSize()); + + mColor = label.getForeColor(); + findViewById(R.id.edit_color).setBackgroundColor(mColor); + mOutlineColor = label.getOutlineColor(); - Button colorButton = (Button) findViewById(R.id.edit_outline_color); - colorButton.setBackgroundColor(mOutlineColor); + findViewById(R.id.edit_outline_color).setBackgroundColor(mOutlineColor); } private void initFontFamilySpinner(String familyName) { @@ -181,18 +188,42 @@ public class EditTextActivity extends AppCompatActivity return super.onOptionsItemSelected(item); } + public void onColorClick(View view) { + showColorDialog(R.string.color, mColor); + mEditColor = EditColorMode.Text; + } + public void onOutlineColorClick(View view) { + showColorDialog(R.string.outline_color, mOutlineColor); + mEditColor = EditColorMode.Outline; + } + + private void showColorDialog(int title, int color) { ColorFragment fragment = new ColorFragment(); - fragment.setColor(mOutlineColor); + fragment.setTitle(title); + fragment.setColor(color); fragment.addOnColorSelectedListener(this); fragment.show(getSupportFragmentManager(), ColorFragment.class.getName()); } @Override public void onColorSelected(DialogFragment fragment, int color) { - mOutlineColor = color; - Button colorButton = (Button) findViewById(R.id.edit_outline_color); - colorButton.setBackgroundColor(mOutlineColor); + switch (mEditColor) { + case Text: + mOutlineColor = color; + findViewById(R.id.edit_color).setBackgroundColor(mOutlineColor); + break; + case Outline: + mOutlineColor = color; + findViewById(R.id.edit_outline_color).setBackgroundColor(mOutlineColor); + break; + } + mEditColor = EditColorMode.None; + } + + @Override + public void onCancel(DialogFragment fragment) { + mEditColor = EditColorMode.None; } private void done() { @@ -210,7 +241,7 @@ public class EditTextActivity extends AppCompatActivity label.setFamilyName(mSelectedFontFamily.name); label.setItalic(mEditItalic.isChecked()); label.setBold(mEditBold.isChecked()); - label.setForeColor(mColorPaletteView.getColor()); + label.setForeColor(mColor); label.setOutline(mEditOutline.isChecked()); label.setOutlineSize(mOutlineSize); label.setOutlineColor(mOutlineColor); diff --git a/app/src/main/res/layout/activity_edit_text.xml b/app/src/main/res/layout/activity_edit_text.xml index 49cf28c..6e596ae 100644 --- a/app/src/main/res/layout/activity_edit_text.xml +++ b/app/src/main/res/layout/activity_edit_text.xml @@ -53,9 +53,36 @@ android:id="@+id/edit_bold" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="0.7" + android:layout_weight="0.3" android:text="@string/bold"/> + + +