|
@@ -0,0 +1,275 @@
|
|
|
+/**
|
|
|
+ * Copyright © 2014-2023 PDF Technologies, Inc. All Rights Reserved.
|
|
|
+ *
|
|
|
+ * THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
|
|
|
+ * AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
|
|
|
+ * UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
|
|
|
+ * This notice may not be removed from this file.
|
|
|
+ */
|
|
|
+
|
|
|
+package com.compdfkit.tools.form.pdfproperties.pdflistbox;
|
|
|
+
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+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.AppCompatEditText;
|
|
|
+import androidx.appcompat.widget.AppCompatImageView;
|
|
|
+import androidx.appcompat.widget.AppCompatTextView;
|
|
|
+
|
|
|
+import com.compdfkit.core.annotation.CPDFTextAttribute;
|
|
|
+import com.compdfkit.tools.R;
|
|
|
+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.CPropertiesSwitchView;
|
|
|
+import com.compdfkit.tools.common.views.pdfproperties.basic.CBasicPropertiesFragment;
|
|
|
+import com.compdfkit.tools.common.views.pdfproperties.colorlist.CColorListView;
|
|
|
+import com.compdfkit.tools.common.views.pdfproperties.font.CFontSpinnerAdapter;
|
|
|
+import com.compdfkit.tools.common.views.pdfproperties.textfields.CTextFieldsView;
|
|
|
+import com.compdfkit.tools.common.views.pdfstyle.CAnnotStyle;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+public class CListBoxStyleFragment extends CBasicPropertiesFragment implements View.OnClickListener{
|
|
|
+
|
|
|
+ public static CListBoxStyleFragment newInstance() {
|
|
|
+ return new CListBoxStyleFragment();
|
|
|
+ }
|
|
|
+
|
|
|
+ private CTextFieldsView textFieldsView;
|
|
|
+
|
|
|
+ private CColorListView borderColorListView;
|
|
|
+
|
|
|
+ private CColorListView backgroundColorListView;
|
|
|
+
|
|
|
+ private CColorListView textColorListView;
|
|
|
+
|
|
|
+ private AppCompatTextView tvFontType;
|
|
|
+
|
|
|
+ private AppCompatImageView ivFontItalic;
|
|
|
+
|
|
|
+ private AppCompatImageView ivFontBold;
|
|
|
+
|
|
|
+ private CPropertiesSwitchView hideFormSwitch;
|
|
|
+
|
|
|
+ private CSliderBar fontSizeSliderBar;
|
|
|
+
|
|
|
+ private Spinner fontSpinner;
|
|
|
+
|
|
|
+ @Nullable
|
|
|
+ @Override
|
|
|
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
|
+ View rootView = inflater.inflate(R.layout.tools_properties_list_box_style_fragment, container, false);
|
|
|
+ textFieldsView = rootView.findViewById(R.id.text_field_view);
|
|
|
+ borderColorListView = rootView.findViewById(R.id.border_color_list_view);
|
|
|
+ backgroundColorListView = rootView.findViewById(R.id.background_color_list_view);
|
|
|
+ textColorListView = rootView.findViewById(R.id.text_color_list_view);
|
|
|
+ tvFontType = rootView.findViewById(R.id.tv_font_type);
|
|
|
+ ivFontItalic = rootView.findViewById(R.id.iv_font_italic);
|
|
|
+ ivFontBold = rootView.findViewById(R.id.iv_font_bold);
|
|
|
+ fontSizeSliderBar = rootView.findViewById(R.id.font_size_slider_bar);
|
|
|
+ fontSpinner = rootView.findViewById(R.id.spinner_font);
|
|
|
+ hideFormSwitch = rootView.findViewById(R.id.switch_hide_form);
|
|
|
+
|
|
|
+ tvFontType.setOnClickListener(this);
|
|
|
+ ivFontItalic.setOnClickListener(this);
|
|
|
+ ivFontBold.setOnClickListener(this);
|
|
|
+ return rootView;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
+ super.onViewCreated(view, savedInstanceState);
|
|
|
+ CAnnotStyle annotStyle = viewModel.getStyle();
|
|
|
+ if (annotStyle != null) {
|
|
|
+ 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);
|
|
|
+ CFontSpinnerAdapter fontSpinnerAdapter = new CFontSpinnerAdapter(getContext(), fontTypes);
|
|
|
+ fontSpinner.setAdapter(fontSpinnerAdapter);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ textFieldsView.setText(annotStyle.getFormFieldName());
|
|
|
+ borderColorListView.setSelectColor(annotStyle.getLineColor());
|
|
|
+ backgroundColorListView.setSelectColor(annotStyle.getFillColor());
|
|
|
+ textColorListView.setSelectColor(annotStyle.getTextColor());
|
|
|
+ ivFontBold.setSelected(annotStyle.isFontBold());
|
|
|
+ ivFontItalic.setSelected(annotStyle.isFontItalic());
|
|
|
+ hideFormSwitch.setChecked(annotStyle.isHideForm());
|
|
|
+ fontSizeSliderBar.setProgress(annotStyle.getFontSize());
|
|
|
+ }
|
|
|
+ viewModel.addStyleChangeListener(this);
|
|
|
+ borderColorListView.setOnColorSelectListener(color -> {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setLineColor(color);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ borderColorListView.setColorPickerClickListener(() -> {
|
|
|
+ CAnnotStyle cAnnotStyle = viewModel.getStyle();
|
|
|
+ showColorPickerFragment(cAnnotStyle.getLineColor(), cAnnotStyle.getLineColorOpacity(), new ColorPickerView.COnColorChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void color(int color) {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setLineColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void opacity(int opacity) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ backgroundColorListView.setOnColorSelectListener(color -> {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setFillColor(color);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ backgroundColorListView.setColorPickerClickListener(() -> {
|
|
|
+ CAnnotStyle cAnnotStyle = viewModel.getStyle();
|
|
|
+ showColorPickerFragment(cAnnotStyle.getFillColor(), cAnnotStyle.getFillColorOpacity(), new ColorPickerView.COnColorChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void color(int color) {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setFillColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void opacity(int opacity) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ textColorListView.setOnColorSelectListener(color -> {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setTextColor(color);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ textColorListView.setColorPickerClickListener(() -> {
|
|
|
+ CAnnotStyle cAnnotStyle = viewModel.getStyle();
|
|
|
+ showColorPickerFragment(cAnnotStyle.getTextColor(), cAnnotStyle.getTextColorOpacity(), new ColorPickerView.COnColorChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void color(int color) {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setTextColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void opacity(int opacity) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ fontSizeSliderBar.setChangeListener((progress, percentageValue, isStop) -> {
|
|
|
+ if (isStop) {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setFontSize(progress);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ fontSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
|
+ if (viewModel != null) {
|
|
|
+ CPDFTextAttribute.FontNameHelper.FontType fontType = (CPDFTextAttribute.FontNameHelper.FontType) fontSpinner.getItemAtPosition(position);
|
|
|
+ viewModel.getStyle().setFontType(fontType);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNothingSelected(AdapterView<?> parent) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+ textFieldsView.setTextChangedListener((s, start, before, count) -> {
|
|
|
+ if (viewModel != null) {
|
|
|
+ if (TextUtils.isEmpty(s)){
|
|
|
+ viewModel.getStyle().setFormFieldName("");
|
|
|
+ }else {
|
|
|
+ viewModel.getStyle().setFormFieldName(s.toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ hideFormSwitch.setListener((buttonView, isChecked) -> {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setHideForm(isChecked);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ if (v.getId() == R.id.tv_font_type) {
|
|
|
+ showFontTypeFragment(viewModel.getStyle().getFontType(), fontType -> {
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setFontType(fontType);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (v.getId() == R.id.iv_font_bold) {
|
|
|
+ ivFontBold.setSelected(!ivFontBold.isSelected());
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setFontBold(ivFontBold.isSelected());
|
|
|
+ }
|
|
|
+ } else if (v.getId() == R.id.iv_font_italic) {
|
|
|
+ ivFontItalic.setSelected(!ivFontItalic.isSelected());
|
|
|
+ if (viewModel != null) {
|
|
|
+ viewModel.getStyle().setFontItalic(ivFontItalic.isSelected());
|
|
|
+ }
|
|
|
+ } else {}
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onChangeTextColor(int textColor) {
|
|
|
+ if (!isOnResume) {
|
|
|
+ if (textColorListView != null) {
|
|
|
+ textColorListView.setSelectColor(textColor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onChangeLineColor(int color) {
|
|
|
+ if (!isOnResume) {
|
|
|
+ if (borderColorListView != null) {
|
|
|
+ borderColorListView.setSelectColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onChangeFillColor(int color) {
|
|
|
+ if (!isOnResume) {
|
|
|
+ if (backgroundColorListView != null) {
|
|
|
+ backgroundColorListView.setSelectColor(color);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|