|
@@ -5,24 +5,20 @@ import android.text.TextUtils;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
-import android.widget.AdapterView;
|
|
|
import android.widget.LinearLayout;
|
|
|
-import android.widget.Spinner;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.appcompat.widget.AppCompatImageView;
|
|
|
-import androidx.appcompat.widget.AppCompatTextView;
|
|
|
|
|
|
import com.compdfkit.core.annotation.CPDFTextAttribute;
|
|
|
-import com.compdfkit.core.utils.CPDFSysFontUtils;
|
|
|
import com.compdfkit.tools.R;
|
|
|
import com.compdfkit.tools.common.utils.view.colorpicker.CColorPickerFragment;
|
|
|
import com.compdfkit.tools.common.utils.view.colorpicker.widget.ColorPickerView;
|
|
|
import com.compdfkit.tools.common.utils.view.sliderbar.CSliderBar;
|
|
|
import com.compdfkit.tools.common.views.pdfproperties.basic.CBasicPropertiesFragment;
|
|
|
import com.compdfkit.tools.common.views.pdfproperties.colorlist.ColorListView;
|
|
|
-import com.compdfkit.tools.common.views.pdfproperties.font.CExternFontSpinnerAdapter;
|
|
|
+import com.compdfkit.tools.common.views.pdfproperties.font.CPDFFontView;
|
|
|
import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CAnnotStyle;
|
|
|
import com.compdfkit.tools.common.views.pdfproperties.pdfstyle.CStyleFragmentDatas;
|
|
|
import com.compdfkit.tools.common.views.pdfproperties.preview.CStylePreviewView;
|
|
@@ -31,7 +27,7 @@ import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
- implements View.OnClickListener, ColorPickerView.COnColorChangeListener , ColorPickerView.COnColorAlphaChangeListener{
|
|
|
+ implements View.OnClickListener, ColorPickerView.COnColorChangeListener, ColorPickerView.COnColorAlphaChangeListener {
|
|
|
|
|
|
private CStylePreviewView previewView;
|
|
|
|
|
@@ -39,12 +35,6 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
|
|
|
private CSliderBar opacitySliderBar;
|
|
|
|
|
|
- private AppCompatTextView tvFontType;
|
|
|
-
|
|
|
- private AppCompatImageView tvFontItalic;
|
|
|
-
|
|
|
- private AppCompatImageView tvFontBold;
|
|
|
-
|
|
|
private LinearLayout llAlignment;
|
|
|
|
|
|
private AppCompatImageView ivAlignmentLeft;
|
|
@@ -55,9 +45,7 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
|
|
|
private CSliderBar fontSizeSliderBar;
|
|
|
|
|
|
- private Spinner fontSpinner;
|
|
|
-
|
|
|
- CExternFontSpinnerAdapter fontSpinnerAdapter;
|
|
|
+ private CPDFFontView fontView;
|
|
|
|
|
|
private List<View> alignmentViews = new ArrayList<>();
|
|
|
|
|
@@ -76,18 +64,12 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
previewView = rootView.findViewById(R.id.style_preview);
|
|
|
colorListView = rootView.findViewById(R.id.border_color_list_view);
|
|
|
opacitySliderBar = rootView.findViewById(R.id.slider_bar);
|
|
|
- tvFontType = rootView.findViewById(R.id.tv_font_type);
|
|
|
- tvFontItalic = rootView.findViewById(R.id.iv_font_italic);
|
|
|
- tvFontBold = rootView.findViewById(R.id.iv_font_bold);
|
|
|
llAlignment = rootView.findViewById(R.id.ll_alignment_type);
|
|
|
ivAlignmentLeft = rootView.findViewById(R.id.iv_alignment_left);
|
|
|
ivAlignmentCenter = rootView.findViewById(R.id.iv_alignment_center);
|
|
|
ivAlignmentRight = rootView.findViewById(R.id.iv_alignment_right);
|
|
|
fontSizeSliderBar = rootView.findViewById(R.id.font_size_slider_bar);
|
|
|
- fontSpinner = rootView.findViewById(R.id.spinner_font);
|
|
|
- tvFontType.setOnClickListener(this);
|
|
|
- tvFontItalic.setOnClickListener(this);
|
|
|
- tvFontBold.setOnClickListener(this);
|
|
|
+ fontView = rootView.findViewById(R.id.font_view);
|
|
|
ivAlignmentLeft.setOnClickListener(this);
|
|
|
ivAlignmentCenter.setOnClickListener(this);
|
|
|
ivAlignmentRight.setOnClickListener(this);
|
|
@@ -115,48 +97,15 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
previewView.setFontItalic(annotStyle.isFontItalic());
|
|
|
previewView.setFontType(annotStyle.getFontType());
|
|
|
previewView.setFontSize(annotStyle.getFontSize());
|
|
|
- List<CPDFTextAttribute.FontNameHelper.FontType> fontTypes = new ArrayList<>();
|
|
|
- fontTypes.add(CPDFTextAttribute.FontNameHelper.FontType.Unknown);
|
|
|
- fontTypes.add(CPDFTextAttribute.FontNameHelper.FontType.Courier);
|
|
|
- fontTypes.add(CPDFTextAttribute.FontNameHelper.FontType.Helvetica);
|
|
|
- fontTypes.add(CPDFTextAttribute.FontNameHelper.FontType.Times_Roman);
|
|
|
- fontSpinnerAdapter = new CExternFontSpinnerAdapter(getContext(), fontTypes, CPDFSysFontUtils.GetSysFontName());
|
|
|
- fontSpinner.setAdapter(fontSpinnerAdapter);
|
|
|
-
|
|
|
- String externFontName = annotStyle.getExternFontName();
|
|
|
- if (TextUtils.isEmpty(externFontName)) {
|
|
|
- switch (annotStyle.getFontType()) {
|
|
|
- case Unknown:
|
|
|
- fontSpinner.setSelection(0);
|
|
|
- break;
|
|
|
- case Courier:
|
|
|
- fontSpinner.setSelection(1);
|
|
|
- break;
|
|
|
- case Helvetica:
|
|
|
- fontSpinner.setSelection(2);
|
|
|
- break;
|
|
|
- case Times_Roman:
|
|
|
- fontSpinner.setSelection(3);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
+
|
|
|
+ if (!TextUtils.isEmpty(annotStyle.getExternFontName())) {
|
|
|
+ fontView.initFont(annotStyle.getExternFontName(), annotStyle.isFontBold(), annotStyle.isFontItalic());
|
|
|
} else {
|
|
|
- List<String> fontNameList = CPDFSysFontUtils.GetSysFontName();
|
|
|
- if (fontNameList != null) {
|
|
|
- for (int i = 0; i < fontNameList.size(); i++) {
|
|
|
- if (fontNameList.get(i).contains(externFontName)) {
|
|
|
- fontSpinner.setSelection(fontSpinnerAdapter.getStandardFontCount() + i);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ fontView.initFont(annotStyle.getFontType().name(), annotStyle.isFontBold(), annotStyle.isFontItalic());
|
|
|
}
|
|
|
|
|
|
colorListView.setSelectColor(annotStyle.getTextColor());
|
|
|
opacitySliderBar.setProgress(annotStyle.getTextColorOpacity());
|
|
|
- tvFontBold.setSelected(annotStyle.isFontBold());
|
|
|
- tvFontItalic.setSelected(annotStyle.isFontItalic());
|
|
|
switch (annotStyle.getAlignment()) {
|
|
|
case LEFT:
|
|
|
selectAlignmentView(ivAlignmentLeft);
|
|
@@ -175,7 +124,7 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
colorListView.setOnColorSelectListener(this::color);
|
|
|
colorListView.setColorPickerClickListener(() -> {
|
|
|
CAnnotStyle cAnnotStyle = viewModel.getStyle();
|
|
|
- showFragment(CStyleFragmentDatas.colorPicker(), (CColorPickerFragment colorPickerFragment)->{
|
|
|
+ showFragment(CStyleFragmentDatas.colorPicker(), (CColorPickerFragment colorPickerFragment) -> {
|
|
|
colorPickerFragment.initColor(cAnnotStyle.getTextColor(), cAnnotStyle.getTextColorOpacity());
|
|
|
colorPickerFragment.setColorPickerListener(this);
|
|
|
colorPickerFragment.setColorAlphaChangeListener(this);
|
|
@@ -197,51 +146,42 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.FontSize);
|
|
|
viewModel.getStyle().setFontSize(progress);
|
|
|
setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.All);
|
|
|
- } else if (isStop == false){
|
|
|
+ } else if (isStop == false) {
|
|
|
this.onChangeFontSize(progress);
|
|
|
}
|
|
|
});
|
|
|
viewModel.addStyleChangeListener(this);
|
|
|
- fontSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
+ fontView.setFontChangeListener(new CPDFFontView.CFontChangeListener() {
|
|
|
@Override
|
|
|
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ public void font(CPDFTextAttribute.FontNameHelper.FontType fontType, String outFontName) {
|
|
|
if (viewModel != null) {
|
|
|
setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.FontType);
|
|
|
- if (position < fontSpinnerAdapter.getStandardFontCount()) {
|
|
|
- CPDFTextAttribute.FontNameHelper.FontType fontType = (CPDFTextAttribute.FontNameHelper.FontType) fontSpinner.getItemAtPosition(position);
|
|
|
- viewModel.getStyle().setFontType(fontType);
|
|
|
+ if (!TextUtils.isEmpty(outFontName)) {
|
|
|
+ viewModel.getStyle().setExternFontName(outFontName);
|
|
|
} else {
|
|
|
- String fontName = (String) fontSpinner.getItemAtPosition(position);
|
|
|
- viewModel.getStyle().setExternFontName(fontName);
|
|
|
+ viewModel.getStyle().setFontType(fontType);
|
|
|
}
|
|
|
setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.All);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onNothingSelected(AdapterView<?> parent) {
|
|
|
-
|
|
|
+ public void fontStyle(boolean bold, boolean italic) {
|
|
|
+ if (viewModel != null) {
|
|
|
+ setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.Bold);
|
|
|
+ viewModel.getStyle().setFontBold(bold);
|
|
|
+ setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.All);
|
|
|
+ setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.Italic);
|
|
|
+ viewModel.getStyle().setFontItalic(italic);
|
|
|
+ setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.All);
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- if (v.getId() == R.id.iv_font_bold) {
|
|
|
- tvFontBold.setSelected(!tvFontBold.isSelected());
|
|
|
- if (viewModel != null) {
|
|
|
- setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.Bold);
|
|
|
- viewModel.getStyle().setFontBold(tvFontBold.isSelected());
|
|
|
- setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.All);
|
|
|
- }
|
|
|
- } else if (v.getId() == R.id.iv_font_italic) {
|
|
|
- tvFontItalic.setSelected(!tvFontItalic.isSelected());
|
|
|
- if (viewModel != null) {
|
|
|
- setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.Italic);
|
|
|
- viewModel.getStyle().setFontItalic(tvFontItalic.isSelected());
|
|
|
- setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.All);
|
|
|
- }
|
|
|
- } else if (v.getId() == R.id.iv_alignment_left) {
|
|
|
+ if (v.getId() == R.id.iv_alignment_left) {
|
|
|
selectAlignmentView(ivAlignmentLeft);
|
|
|
setAlignment(CAnnotStyle.Alignment.LEFT);
|
|
|
} else if (v.getId() == R.id.iv_alignment_center) {
|
|
@@ -253,13 +193,13 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void selectAlignmentView(AppCompatImageView alignmentView){
|
|
|
+ private void selectAlignmentView(AppCompatImageView alignmentView) {
|
|
|
for (View view : alignmentViews) {
|
|
|
view.setSelected(view == alignmentView);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void setAlignment(CAnnotStyle.Alignment alignment){
|
|
|
+ private void setAlignment(CAnnotStyle.Alignment alignment) {
|
|
|
if (viewModel != null) {
|
|
|
setUpdatePropertyType(CAnnotStyle.EditUpdatePropertyType.Alignment);
|
|
|
viewModel.getStyle().setAlignment(alignment);
|
|
@@ -318,18 +258,7 @@ public class CEditTextProperFragment extends CBasicPropertiesFragment
|
|
|
@Override
|
|
|
public void onChangeAnnotExternFontType(String fontName) {
|
|
|
if (previewView != null) {
|
|
|
- List<String> fontList = CPDFSysFontUtils.getSysFontPathList();
|
|
|
- String font = "";
|
|
|
- for (String item : fontList) {
|
|
|
- if (TextUtils.isEmpty(item)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if (item.contains(fontName + ".")) {
|
|
|
- font = item;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- previewView.setExternFontType(font);
|
|
|
+ previewView.setExternFontType(fontName);
|
|
|
}
|
|
|
}
|
|
|
|