kopia lustrzana https://github.com/olgamiller/SSTVEncoder2
Updated loading of the system fonts (by listing all existing /system/fonts/*.ttf files),
removed adjustment of italic and bold selection for fonts with suffix "-Italic" or "-Bold"master
rodzic
53b1f39ca9
commit
5c50012f71
app/src/main/java/om/sstvencoder
|
@ -18,10 +18,12 @@ package om.sstvencoder;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
|
@ -35,6 +37,7 @@ import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import om.sstvencoder.TextOverlay.Label;
|
import om.sstvencoder.TextOverlay.Label;
|
||||||
|
@ -52,9 +55,7 @@ public class EditTextActivity extends AppCompatActivity
|
||||||
public static final String EXTRA = "EDIT_TEXT_EXTRA";
|
public static final String EXTRA = "EDIT_TEXT_EXTRA";
|
||||||
private Label mLabel;
|
private Label mLabel;
|
||||||
private EditColorMode mEditColor;
|
private EditColorMode mEditColor;
|
||||||
private FontFamilySet mFontFamilySet;
|
private List<String> mFontFilePathList;
|
||||||
private FontFamilySet.FontFamily mSelectedFontFamily;
|
|
||||||
private List<String> mFontFamilyNameList;
|
|
||||||
private CheckBox mEditItalic, mEditBold, mEditOutline;
|
private CheckBox mEditItalic, mEditBold, mEditOutline;
|
||||||
private int mClearTextButtonWidth;
|
private int mClearTextButtonWidth;
|
||||||
|
|
||||||
|
@ -77,7 +78,6 @@ public class EditTextActivity extends AppCompatActivity
|
||||||
mEditBold.setChecked(mLabel.getBold());
|
mEditBold.setChecked(mLabel.getBold());
|
||||||
mEditItalic.setChecked(mLabel.getItalic());
|
mEditItalic.setChecked(mLabel.getItalic());
|
||||||
initFontFamilySpinner(mLabel.getFamilyName());
|
initFontFamilySpinner(mLabel.getFamilyName());
|
||||||
updateBoldAndItalic();
|
|
||||||
mEditOutline.setChecked(mLabel.getOutline());
|
mEditOutline.setChecked(mLabel.getOutline());
|
||||||
initOutlineSizeSpinner(mLabel.getOutlineSize());
|
initOutlineSizeSpinner(mLabel.getOutlineSize());
|
||||||
findViewById(R.id.edit_color).setBackgroundColor(mLabel.getForeColor());
|
findViewById(R.id.edit_color).setBackgroundColor(mLabel.getForeColor());
|
||||||
|
@ -148,12 +148,20 @@ public class EditTextActivity extends AppCompatActivity
|
||||||
private void initFontFamilySpinner(String familyName) {
|
private void initFontFamilySpinner(String familyName) {
|
||||||
Spinner spinner = findViewById(R.id.edit_font_family);
|
Spinner spinner = findViewById(R.id.edit_font_family);
|
||||||
spinner.setOnItemSelectedListener(this);
|
spinner.setOnItemSelectedListener(this);
|
||||||
mFontFamilySet = new FontFamilySet(this);
|
mFontFilePathList = Utility.getSystemFontFilePaths();
|
||||||
mSelectedFontFamily = mFontFamilySet.getFontFamily(familyName);
|
mFontFilePathList.add(0, Label.DEFAULT_FONT);
|
||||||
mFontFamilyNameList = mFontFamilySet.getFontFamilyDisplayNameList();
|
List<String> fontFamilyNameList = getFontNames(mFontFilePathList);
|
||||||
spinner.setAdapter(new ArrayAdapter<>(this,
|
spinner.setAdapter(new ArrayAdapter<>(this,
|
||||||
android.R.layout.simple_spinner_dropdown_item, mFontFamilyNameList));
|
android.R.layout.simple_spinner_dropdown_item, fontFamilyNameList));
|
||||||
spinner.setSelection(mFontFamilyNameList.indexOf(mSelectedFontFamily.displayName));
|
spinner.setSelection(mFontFilePathList.indexOf(familyName));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> getFontNames(List<String> fontFilePathList) {
|
||||||
|
List<String> fontNameList = new ArrayList<>();
|
||||||
|
for (String path : fontFilePathList) {
|
||||||
|
fontNameList.add(Utility.getFileNameWithoutExtension(path));
|
||||||
|
}
|
||||||
|
return fontNameList;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initTextSizeSpinner(float textSize) {
|
private void initTextSizeSpinner(float textSize) {
|
||||||
|
@ -219,28 +227,7 @@ public class EditTextActivity extends AppCompatActivity
|
||||||
mLabel.setOutlineSize(positionToOutlineSize(position));
|
mLabel.setOutlineSize(positionToOutlineSize(position));
|
||||||
}
|
}
|
||||||
else if (parentId == R.id.edit_font_family) {
|
else if (parentId == R.id.edit_font_family) {
|
||||||
String displayName = mFontFamilyNameList.get(position);
|
mLabel.setFamilyName(mFontFilePathList.get(position));
|
||||||
mSelectedFontFamily = mFontFamilySet.getFontFamilyFromDisplayName(displayName);
|
|
||||||
mLabel.setFamilyName(mSelectedFontFamily.name);
|
|
||||||
updateBoldAndItalic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateBoldAndItalic() {
|
|
||||||
boolean bold = mSelectedFontFamily.bold;
|
|
||||||
mEditBold.setEnabled(bold);
|
|
||||||
findViewById(R.id.text_bold).setEnabled(bold);
|
|
||||||
if (!mEditBold.isEnabled()) {
|
|
||||||
mEditBold.setChecked(false);
|
|
||||||
mLabel.setBold(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean italic = mSelectedFontFamily.italic;
|
|
||||||
mEditItalic.setEnabled(italic);
|
|
||||||
findViewById(R.id.text_italic).setEnabled(italic);
|
|
||||||
if (!mEditItalic.isEnabled()) {
|
|
||||||
mEditItalic.setChecked(false);
|
|
||||||
mLabel.setItalic(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.lang.reflect.Modifier;
|
||||||
public class Label implements Serializable {
|
public class Label implements Serializable {
|
||||||
public static final float TEXT_SIZE_NORMAL = 2f;
|
public static final float TEXT_SIZE_NORMAL = 2f;
|
||||||
public static final float OUTLINE_SIZE_NORMAL = 0.05f;
|
public static final float OUTLINE_SIZE_NORMAL = 0.05f;
|
||||||
|
public static final String DEFAULT_FONT = "Default";
|
||||||
private String mText;
|
private String mText;
|
||||||
private float mTextSize, mOutlineSize;
|
private float mTextSize, mOutlineSize;
|
||||||
private String mFamilyName;
|
private String mFamilyName;
|
||||||
|
|
|
@ -22,6 +22,9 @@ import android.graphics.Path;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
class LabelPainter {
|
class LabelPainter {
|
||||||
|
@ -130,7 +133,13 @@ class LabelPainter {
|
||||||
|
|
||||||
private void setPaintSettings(float sizeFactor) {
|
private void setPaintSettings(float sizeFactor) {
|
||||||
mPaint.setAlpha(255);
|
mPaint.setAlpha(255);
|
||||||
mPaint.setTypeface(Typeface.create(mLabel.getFamilyName(), getTypeface()));
|
try {
|
||||||
|
Typeface tf = Typeface.create(
|
||||||
|
createTypefaceFromFontFile(),
|
||||||
|
createTypefaceFromFontAttributes());
|
||||||
|
mPaint.setTypeface(tf);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
setTextPaintSettings();
|
setTextPaintSettings();
|
||||||
setSizePaintSettings(sizeFactor);
|
setSizePaintSettings(sizeFactor);
|
||||||
}
|
}
|
||||||
|
@ -151,7 +160,19 @@ class LabelPainter {
|
||||||
mPaint.setStrokeWidth(mLabel.getOutlineSize() * textSize);
|
mPaint.setStrokeWidth(mLabel.getOutlineSize() * textSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTypeface() {
|
private Typeface createTypefaceFromFontFile() {
|
||||||
|
Typeface typeface = null; // Typeface.DEFAULT
|
||||||
|
String fontFilePath = mLabel.getFamilyName();
|
||||||
|
|
||||||
|
if (!fontFilePath.equalsIgnoreCase(Label.DEFAULT_FONT)) {
|
||||||
|
File fontFile = new File(fontFilePath);
|
||||||
|
if (fontFile.exists() && fontFile.canRead())
|
||||||
|
typeface = Typeface.createFromFile(fontFilePath);
|
||||||
|
}
|
||||||
|
return typeface;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int createTypefaceFromFontAttributes() {
|
||||||
int typeface = Typeface.NORMAL;
|
int typeface = Typeface.NORMAL;
|
||||||
|
|
||||||
if (mLabel.getBold() && mLabel.getItalic())
|
if (mLabel.getBold() && mLabel.getItalic())
|
||||||
|
|
|
@ -28,10 +28,14 @@ import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
final class Utility {
|
final class Utility {
|
||||||
|
static final String DIRECTORY_SYSTEM_FONTS = "/system/fonts";
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
static Rect getEmbeddedRect(int w, int h, int iw, int ih) {
|
static Rect getEmbeddedRect(int w, int h, int iw, int ih) {
|
||||||
Rect rect;
|
Rect rect;
|
||||||
|
@ -113,4 +117,32 @@ final class Utility {
|
||||||
String state = Environment.getExternalStorageState();
|
String state = Environment.getExternalStorageState();
|
||||||
return Environment.MEDIA_MOUNTED.equals(state);
|
return Environment.MEDIA_MOUNTED.equals(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static List<String> getSystemFontFilePaths() {
|
||||||
|
List<String> fontList = new ArrayList<>();
|
||||||
|
File fontsDir = new File(DIRECTORY_SYSTEM_FONTS);
|
||||||
|
String fontFileExtension = ".ttf";
|
||||||
|
|
||||||
|
if (fontsDir.exists() && fontsDir.isDirectory()) {
|
||||||
|
File[] files = fontsDir.listFiles();
|
||||||
|
if (files != null) {
|
||||||
|
for (File file : files) {
|
||||||
|
if (file.isFile() && file.getName().endsWith(fontFileExtension)) {
|
||||||
|
fontList.add(file.getAbsolutePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return fontList;
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getFileNameWithoutExtension(String filePath) {
|
||||||
|
File file = new File(filePath);
|
||||||
|
String fileName = file.getName();
|
||||||
|
int dotIndex = fileName.lastIndexOf('.');
|
||||||
|
if (dotIndex > 0 && dotIndex < fileName.length() - 1) {
|
||||||
|
return fileName.substring(0, dotIndex);
|
||||||
|
}
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue