mirror of
https://github.com/olgamiller/SSTVEncoder2.git
synced 2025-12-06 06:52:01 +01:00
Added border (bool, size, color) to Label, added border switch to EditTextActivity, draw white border of fixed size
This commit is contained in:
parent
9e5738f807
commit
6533062eb7
|
|
@ -42,7 +42,7 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
||||||
private FontFamilySet mFontFamilySet;
|
private FontFamilySet mFontFamilySet;
|
||||||
private FontFamilySet.FontFamily mSelectedFontFamily;
|
private FontFamilySet.FontFamily mSelectedFontFamily;
|
||||||
private List<String> mFontFamilyNameList;
|
private List<String> mFontFamilyNameList;
|
||||||
private CheckBox mEditItalic, mEditBold;
|
private CheckBox mEditItalic, mEditBold, mEditBorder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
@ -52,6 +52,7 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
||||||
mColorPaletteView = (ColorPaletteView) findViewById(R.id.edit_color);
|
mColorPaletteView = (ColorPaletteView) findViewById(R.id.edit_color);
|
||||||
mEditBold = (CheckBox) findViewById(R.id.edit_bold);
|
mEditBold = (CheckBox) findViewById(R.id.edit_bold);
|
||||||
mEditItalic = (CheckBox) findViewById(R.id.edit_italic);
|
mEditItalic = (CheckBox) findViewById(R.id.edit_italic);
|
||||||
|
mEditBorder = (CheckBox) findViewById(R.id.edit_border);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -65,6 +66,7 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
||||||
mColorPaletteView.setColor(label.getForeColor());
|
mColorPaletteView.setColor(label.getForeColor());
|
||||||
initFontFamilySpinner(label.getFamilyName());
|
initFontFamilySpinner(label.getFamilyName());
|
||||||
updateBoldAndItalic();
|
updateBoldAndItalic();
|
||||||
|
mEditBorder.setChecked(label.getBorder());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFontFamilySpinner(String familyName) {
|
private void initFontFamilySpinner(String familyName) {
|
||||||
|
|
@ -160,6 +162,7 @@ public class EditTextActivity extends AppCompatActivity implements AdapterView.O
|
||||||
label.setFamilyName(mSelectedFontFamily.name);
|
label.setFamilyName(mSelectedFontFamily.name);
|
||||||
label.setItalic(mEditItalic.isChecked());
|
label.setItalic(mEditItalic.isChecked());
|
||||||
label.setBold(mEditBold.isChecked());
|
label.setBold(mEditBold.isChecked());
|
||||||
|
label.setBorder(mEditBorder.isChecked());
|
||||||
label.setForeColor(mColorPaletteView.getColor());
|
label.setForeColor(mColorPaletteView.getColor());
|
||||||
return label;
|
return label;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ import java.io.Serializable;
|
||||||
|
|
||||||
public class Label implements Serializable {
|
public class Label implements Serializable {
|
||||||
private String mText;
|
private String mText;
|
||||||
private float mTextSize;
|
private float mTextSize, mBorderSize;
|
||||||
private String mFamilyName;
|
private String mFamilyName;
|
||||||
private boolean mBold, mItalic;
|
private boolean mBold, mItalic, mBorder;
|
||||||
private int mForeColor, mBackColor;
|
private int mForeColor, mBackColor, mBorderColor;
|
||||||
|
|
||||||
public Label() {
|
public Label() {
|
||||||
mText = "";
|
mText = "";
|
||||||
|
|
@ -34,6 +34,9 @@ public class Label implements Serializable {
|
||||||
mItalic = false;
|
mItalic = false;
|
||||||
mForeColor = Color.BLACK;
|
mForeColor = Color.BLACK;
|
||||||
mBackColor = Color.TRANSPARENT;
|
mBackColor = Color.TRANSPARENT;
|
||||||
|
mBorder = true;
|
||||||
|
mBorderSize = 0.05f;
|
||||||
|
mBorderColor = Color.WHITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText() {
|
public String getText() {
|
||||||
|
|
@ -49,9 +52,9 @@ public class Label implements Serializable {
|
||||||
return mTextSize;
|
return mTextSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTextSize(float textSize) {
|
public void setTextSize(float size) {
|
||||||
if (textSize > 0f)
|
if (size > 0f)
|
||||||
mTextSize = textSize;
|
mTextSize = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFamilyName() {
|
public String getFamilyName() {
|
||||||
|
|
@ -93,4 +96,28 @@ public class Label implements Serializable {
|
||||||
public void setBackColor(int color) {
|
public void setBackColor(int color) {
|
||||||
mBackColor = color;
|
mBackColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getBorder() {
|
||||||
|
return mBorder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorder(boolean border) {
|
||||||
|
mBorder = border;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getBorderSize() {
|
||||||
|
return mBorderSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderSize(float size) {
|
||||||
|
mBorderSize = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBorderColor() {
|
||||||
|
return mBorderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBorderColor(int color) {
|
||||||
|
mBorderColor = color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,9 @@ class LabelContainer {
|
||||||
writer.write("italic", label.getItalic());
|
writer.write("italic", label.getItalic());
|
||||||
writer.write("fore_color", label.getForeColor());
|
writer.write("fore_color", label.getForeColor());
|
||||||
writer.write("back_color", label.getBackColor());
|
writer.write("back_color", label.getBackColor());
|
||||||
|
writer.write("border", label.getBorder());
|
||||||
|
writer.write("border_size", label.getBorderSize());
|
||||||
|
writer.write("border_color", label.getBorderColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void readLabel(IReader reader, Label label) throws IOException {
|
private void readLabel(IReader reader, Label label) throws IOException {
|
||||||
|
|
@ -114,6 +117,9 @@ class LabelContainer {
|
||||||
label.setItalic(reader.readBoolean());
|
label.setItalic(reader.readBoolean());
|
||||||
label.setForeColor(reader.readInt());
|
label.setForeColor(reader.readInt());
|
||||||
label.setBackColor(reader.readInt());
|
label.setBackColor(reader.readInt());
|
||||||
|
label.setBorder(reader.readBoolean());
|
||||||
|
label.setBorderSize(reader.readFloat());
|
||||||
|
label.setBorderColor(reader.readInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ class LabelPainter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Canvas canvas) {
|
public void draw(Canvas canvas) {
|
||||||
|
drawBorder(canvas, mX, mY);
|
||||||
canvas.drawText(mLabel.getText(), mX, mY, mPaint);
|
canvas.drawText(mLabel.getText(), mX, mY, mPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,6 +56,7 @@ class LabelPainter {
|
||||||
RectF bounds = new RectF(getBounds());
|
RectF bounds = new RectF(getBounds());
|
||||||
float rx = 10f;
|
float rx = 10f;
|
||||||
float ry = 10f;
|
float ry = 10f;
|
||||||
|
mPaint.setStrokeWidth(0f);
|
||||||
|
|
||||||
mPaint.setColor(Color.LTGRAY);
|
mPaint.setColor(Color.LTGRAY);
|
||||||
mPaint.setAlpha(100);
|
mPaint.setAlpha(100);
|
||||||
|
|
@ -65,15 +67,15 @@ class LabelPainter {
|
||||||
mPaint.setStyle(Paint.Style.STROKE);
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
|
||||||
mPaint.setColor(Color.RED);
|
mPaint.setColor(Color.RED);
|
||||||
bounds.inset(-5.0f, -5.0f);
|
bounds.inset(-5f, -5f);
|
||||||
canvas.drawRoundRect(bounds, rx, ry, mPaint);
|
canvas.drawRoundRect(bounds, rx, ry, mPaint);
|
||||||
|
|
||||||
mPaint.setColor(Color.GREEN);
|
mPaint.setColor(Color.GREEN);
|
||||||
bounds.inset(1.0f, 1.0f);
|
bounds.inset(1f, 1f);
|
||||||
canvas.drawRoundRect(bounds, rx, ry, mPaint);
|
canvas.drawRoundRect(bounds, rx, ry, mPaint);
|
||||||
|
|
||||||
mPaint.setColor(Color.BLUE);
|
mPaint.setColor(Color.BLUE);
|
||||||
bounds.inset(1.0f, 1.0f);
|
bounds.inset(1f, 1f);
|
||||||
canvas.drawRoundRect(bounds, rx, ry, mPaint);
|
canvas.drawRoundRect(bounds, rx, ry, mPaint);
|
||||||
|
|
||||||
setPaintSettings(mSizeFactor);
|
setPaintSettings(mSizeFactor);
|
||||||
|
|
@ -84,9 +86,10 @@ class LabelPainter {
|
||||||
float factor = (dst.height() / (float) src.height());
|
float factor = (dst.height() / (float) src.height());
|
||||||
float x = (mX - src.left) * factor;
|
float x = (mX - src.left) * factor;
|
||||||
float y = (mY - src.top) * factor;
|
float y = (mY - src.top) * factor;
|
||||||
setTextSize(factor * mSizeFactor);
|
setSizePaintSettings(factor * mSizeFactor);
|
||||||
|
drawBorder(canvas, x, y);
|
||||||
canvas.drawText(mLabel.getText(), x, y, mPaint);
|
canvas.drawText(mLabel.getText(), x, y, mPaint);
|
||||||
setTextSize(mSizeFactor);
|
setSizePaintSettings(mSizeFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -114,16 +117,35 @@ class LabelPainter {
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setPaintSettings(float sizeFactor) {
|
private void drawBorder(Canvas canvas, float x, float y) {
|
||||||
mPaint.setAlpha(255);
|
if (mLabel.getBorder()) {
|
||||||
mPaint.setStyle(Paint.Style.FILL);
|
setBorderPaintSettings();
|
||||||
mPaint.setColor(mLabel.getForeColor());
|
canvas.drawText(mLabel.getText(), x, y, mPaint);
|
||||||
mPaint.setTypeface(Typeface.create(mLabel.getFamilyName(), getTypeface()));
|
setTextPaintSettings();
|
||||||
setTextSize(sizeFactor);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTextSize(float sizeFactor) {
|
private void setPaintSettings(float sizeFactor) {
|
||||||
mPaint.setTextSize(mLabel.getTextSize() * sizeFactor);
|
mPaint.setAlpha(255);
|
||||||
|
mPaint.setTypeface(Typeface.create(mLabel.getFamilyName(), getTypeface()));
|
||||||
|
setTextPaintSettings();
|
||||||
|
setSizePaintSettings(sizeFactor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBorderPaintSettings() {
|
||||||
|
mPaint.setStyle(Paint.Style.STROKE);
|
||||||
|
mPaint.setColor(mLabel.getBorderColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setTextPaintSettings() {
|
||||||
|
mPaint.setStyle(Paint.Style.FILL);
|
||||||
|
mPaint.setColor(mLabel.getForeColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setSizePaintSettings(float sizeFactor) {
|
||||||
|
float textSize = mLabel.getTextSize() * sizeFactor;
|
||||||
|
mPaint.setTextSize(textSize);
|
||||||
|
mPaint.setStrokeWidth(mLabel.getBorderSize() * textSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTypeface() {
|
private int getTypeface() {
|
||||||
|
|
@ -149,6 +171,7 @@ class LabelPainter {
|
||||||
private OutDrawer(float min) {
|
private OutDrawer(float min) {
|
||||||
mMinSize = min * 0.5f;
|
mMinSize = min * 0.5f;
|
||||||
mPaint.setAlpha(255);
|
mPaint.setAlpha(255);
|
||||||
|
mPaint.setStrokeWidth(0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void leftOut(RectF rect, float screenH) {
|
private void leftOut(RectF rect, float screenH) {
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,27 @@
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:textSize="32sp"/>
|
android:textSize="32sp"/>
|
||||||
|
|
||||||
<Spinner
|
<LinearLayout
|
||||||
android:id="@+id/edit_font_family"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/edit_font_family"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.7"
|
||||||
android:minHeight="32sp"/>
|
android:minHeight="32sp"/>
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/edit_text_size"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0.3"
|
||||||
|
android:minHeight="32sp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
@ -42,12 +57,12 @@
|
||||||
android:checked="true"
|
android:checked="true"
|
||||||
android:text="@string/bold"/>
|
android:text="@string/bold"/>
|
||||||
|
|
||||||
<Spinner
|
<CheckBox
|
||||||
android:id="@+id/edit_text_size"
|
android:id="@+id/edit_border"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.4"
|
android:layout_weight="0.4"
|
||||||
android:minHeight="32sp"/>
|
android:text="@string/border"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,4 +35,5 @@
|
||||||
<string name="chooser_title">Send Bug Report:</string>
|
<string name="chooser_title">Send Bug Report:</string>
|
||||||
<string name="bold">Bold</string>
|
<string name="bold">Bold</string>
|
||||||
<string name="italic">Italic</string>
|
<string name="italic">Italic</string>
|
||||||
|
<string name="border">Border</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Reference in a new issue