kopia lustrzana https://github.com/olgamiller/SSTVEncoder2
Edit text color in color dialog (as outline color)
rodzic
605a34b5d3
commit
24c5c1804b
|
@ -33,16 +33,24 @@ public class ColorFragment extends DialogFragment
|
|||
|
||||
public interface OnColorSelectedListener {
|
||||
void onColorSelected(DialogFragment fragment, int color);
|
||||
|
||||
void onCancel(DialogFragment fragment);
|
||||
}
|
||||
|
||||
private List<OnColorSelectedListener> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
switch (mEditColor) {
|
||||
case Text:
|
||||
mOutlineColor = color;
|
||||
Button colorButton = (Button) findViewById(R.id.edit_outline_color);
|
||||
colorButton.setBackgroundColor(mOutlineColor);
|
||||
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);
|
||||
|
|
|
@ -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"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0.4"
|
||||
android:clickable="true"
|
||||
android:onClick="onColorClick"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/edit_color"
|
||||
android:layout_width="32sp"
|
||||
android:layout_height="32sp"
|
||||
android:background="@android:color/white"
|
||||
android:onClick="onColorClick"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/color"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="6sp"
|
||||
android:clickable="true"
|
||||
android:onClick="onColorClick"
|
||||
android:text="@string/color"
|
||||
android:textColor="?android:attr/textColorPrimary"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -106,9 +133,4 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<om.sstvencoder.ColorPalette.ColorPaletteView
|
||||
android:id="@+id/edit_color"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -36,5 +36,6 @@
|
|||
<string name="bold">Bold</string>
|
||||
<string name="italic">Italic</string>
|
||||
<string name="outline">Outline</string>
|
||||
<string name="color">Color</string>
|
||||
<string name="outline_color">Outline Color</string>
|
||||
</resources>
|
Ładowanie…
Reference in New Issue